epm-mark 7.75 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2020, 2022, 2023  Etersoft
# Copyright (C) 2020, 2022, 2023  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

20 21
__alt_mark_hold_package()
{
22 23 24
        local pkg="$1"
        showcmd "echo \"RPM::Hold {\"^$pkg\";};\" > /etc/apt/apt.conf.d/hold-$pkg.conf"
        echo "RPM::Hold {\"^$pkg\";};" | sudorun tee "/etc/apt/apt.conf.d/hold-$pkg.conf" >/dev/null
25 26 27 28
}

__alt_test_glob()
{
29
    echo "$*" | grep -q "\.[*?]" && warning "Only glob symbols * and ? are supported. Don't use regexp here!"
30 31
}

32 33
__alt_mark_hold()
{
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    # TODO: do more long checking via apt
    local pkg
    local i
    __alt_test_glob "$*"
    for i in "$@" ; do
        if __is_wildcard "$i" ; then
            local pkglist
            pkglist="$(epm qp --short "^$i")" || continue
            for pkg in $pkglist ; do
                __alt_mark_hold_package $pkg
            done
            return
        else
            pkg="$(epm query --short "$i")" || continue
        fi
        __alt_mark_hold_package $pkg
    done
51 52 53 54
}

__alt_mark_unhold()
{
55 56 57 58 59 60 61 62
    # TODO: do more long checking via apt
    local pkg
    local i
    __alt_test_glob "$*"
    for i in "$@" ; do
        pkg="$(epm query --short "$i")" || pkg="$i"
        sudocmd rm -fv /etc/apt/apt.conf.d/hold-$pkg.conf
    done
63 64
}

65 66
__alt_mark_showhold()
{
67
    grep -h "RPM::Hold" /etc/apt/apt.conf.d/hold-*.conf 2>/dev/null | sed -e 's|RPM::Hold {"^\(.*\)";};|\1|'
68 69
}

70 71
__dnf_assure_versionlock()
{
72
    epm assure /etc/dnf/plugins/versionlock.conf 'dnf-command(versionlock)'
73
}
74

75 76 77 78 79
__dnf_is_supported_versionlock()
{
    [ -f /etc/dnf/plugins/versionlock.conf ]
}

80
epm_mark_hold()
81 82
{

83
case $BASEDISTRNAME in
84 85 86 87
    "alt")
        __alt_mark_hold "$@"
        exit
        ;;
88 89
esac

90
case $PMTYPE in
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    apt-dpkg)
        sudocmd apt-mark hold "$@"
        ;;
    dnf-rpm)
        __dnf_assure_versionlock
        sudocmd dnf versionlock add "$@"
        ;;
    zypper-rpm)
        sudocmd zypper al "$@"
        ;;
    emerge)
        info "Check /etc/portage/package.mask"
        ;;
    pacman)
        info "Manually: edit /etc/pacman.conf modifying IgnorePkg array"
        ;;
    *)
108
        fatal 'Have no suitable command for $PMTYPE'
109
        ;;
110 111 112 113 114 115 116 117
esac

}


epm_mark_unhold()
{

118
case $BASEDISTRNAME in
119 120 121 122
    "alt")
        __alt_mark_unhold "$@"
        exit
        ;;
123 124 125
esac

case $PMTYPE in
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    apt-dpkg)
        sudocmd apt-mark unhold "$@"
        ;;
    dnf-rpm)
        __dnf_assure_versionlock
        sudocmd dnf versionlock delete "$@"
        ;;
    zypper-rpm)
        sudocmd zypper rl "$@"
        ;;
    emerge)
        info "Check /etc/portage/package.mask (package.unmask)"
        ;;
    pacman)
        info "Manually: edit /etc/pacman.conf removing package from IgnorePkg line"
        ;;
    *)
143
        fatal 'Have no suitable command for $PMTYPE'
144
        ;;
145 146 147 148 149 150 151 152
esac

}


epm_mark_showhold()
{

153
case $BASEDISTRNAME in
154 155 156 157
    "alt")
        __alt_mark_showhold "$@"
        exit
        ;;
158 159 160
esac

case $PMTYPE in
161
    apt-dpkg)
162
        docmd apt-mark showhold "$@"
163 164
        ;;
    dnf-rpm)
165 166
        # there is no hold entries without versionlock
        __dnf_is_supported_versionlock || return 0
167
        __dnf_assure_versionlock
168 169 170 171 172 173
        if [ -n "$short" ] ; then
            load_helper epm-query
            docmd dnf versionlock list "$@" | sed -e 's|\.\*$||' | grep -v " " | filter_pkgnames_to_short
        else
            docmd dnf versionlock list "$@"
        fi
174 175
        ;;
    zypper-rpm)
176
        docmd zypper ll "$@"
177 178 179 180 181 182 183 184
        ;;
    emerge)
        cat /etc/portage/package.mask
        ;;
    pacman)
        cat /etc/pacman.conf
        ;;
    *)
185
        fatal 'Have no suitable command for $PMTYPE'
186
        ;;
187 188 189 190
esac

}

191 192 193 194 195
epm_mark_checkhold()
{
# workaround against epm assure questions
case $PMTYPE in
    dnf-rpm)
196 197
        # there is no hold entries without versionlock
        __dnf_is_supported_versionlock || return 1
198 199 200 201 202 203 204 205 206 207 208
        __dnf_assure_versionlock
        load_helper epm-query
        docmd dnf versionlock list | grep "^$1" | sed -e 's|\.\*$||' | grep -v " " | filter_pkgnames_to_short | grep -q "^$1$"
        return
        ;;
esac

epm_mark_showhold | grep -q "^$1$"

}

209 210 211 212

epm_mark_auto()
{

213
case $BASEDISTRNAME in
214 215 216 217
    "alt")
        sudocmd apt-mark auto "$@"
        exit
        ;;
218 219 220
esac

case $PMTYPE in
221 222 223 224 225 226 227 228 229 230 231 232 233
    apt-dpkg)
        sudocmd apt-mark auto "$@"
        ;;
    dnf-rpm)
        sudocmd dnf mark remove "$@"
        ;;
    pacman)
            sudocmd pacman -D --asdeps "$@"
        ;;
    emerge)
            sudocmd emerge --oneshot "$@"
        ;;
    *)
234
        fatal 'Have no suitable command for $PMTYPE'
235
        ;;
236 237 238 239 240 241 242 243
esac

}


epm_mark_manual()
{

244
case $BASEDISTRNAME in
245 246 247 248
    "alt")
        sudocmd apt-mark manual "$@"
        exit
        ;;
249 250 251
esac

case $PMTYPE in
252 253 254 255 256 257 258 259 260 261 262 263 264
    apt-dpkg)
        sudocmd apt-mark manual "$@"
        ;;
    dnf-rpm)
        sudocmd dnf mark install "$@"
        ;;
    pacman)
            sudocmd pacman -D --asexplicit "$@"
        ;;
    emerge)
            sudocmd emerge --select "$@"
        ;;
    *)
265
        fatal 'Have no suitable command for $PMTYPE'
266
        ;;
267 268 269
esac

}
270 271 272 273 274


epm_mark_showauto()
{

275
case $BASEDISTRNAME in
276 277 278 279
    "alt")
        sudocmd apt-mark showauto "$@"
        exit
        ;;
280 281 282
esac

case $PMTYPE in
283 284 285 286 287 288 289
    apt-dpkg)
        sudocmd apt-mark showauto "$@"
        ;;
    dnf-rpm)
        sudocmd dnf repoquery --unneeded
        ;;
    *)
290
        fatal 'Have no suitable command for $PMTYPE'
291
        ;;
292 293 294 295 296 297 298
esac

}

epm_mark_showmanual()
{

299
case $BASEDISTRNAME in
300 301 302 303
    "alt")
        sudocmd apt-mark showmanual "$@"
        exit
        ;;
304 305 306
esac

case $PMTYPE in
307 308 309 310 311 312 313
    apt-dpkg)
        sudocmd apt-mark showmanual "$@"
        ;;
    dnf-rpm)
        sudocmd dnf repoquery --userinstalled
        ;;
    *)
314
        fatal 'Have no suitable command for $PMTYPE'
315
        ;;
316 317 318 319
esac

}

320 321
epm_mark_help()
{
322
    message "mark is the interface for marking packages"
323
            get_help HELPCMD $SHAREDIR/epm-mark
324
    message '
325 326 327
Examples:
  epm mark hold mc
  epm manual mc
328
'
329
}
330 331 332

epm_mark()
{
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
    local CMD="$1"
    [ -n "$CMD" ] && shift
    case "$CMD" in
    ""|"-h"|"--help"|help)               # HELPCMD: help
        epm_mark_help
        ;;
    hold)                             # HELPCMD: mark the given package(s) as held back
        epm_mark_hold "$@"
        ;;
    unhold)                           # HELPCMD: unset the given package(s) as held back
        epm_mark_unhold "$@"
        ;;
    showhold)                         # HELPCMD: print the list of packages on hold
        epm_mark_showhold "$@"
        ;;
348
    checkhold)                        # HELPCMD: return true if the package is on hold
349 350
        epm_mark_checkhold "$@"
        ;;
351
    auto|remove)                      # HELPCMD: mark the given package(s) as automatically installed
352 353
        epm_mark_auto "$@"
        ;;
354
    manual|install)                   # HELPCMD: mark the given package(s) as manually installed
355 356 357 358 359 360 361 362 363
        epm_mark_manual "$@"
        ;;
    showauto)                         # HELPCMD: print the list of automatically installed packages
        epm_mark_showauto "$@"
        ;;
    showmanual)                       # HELPCMD: print the list of manually installed packages
        epm_mark_showmanual "$@"
        ;;
    *)
364
        fatal 'Unknown command $ epm repo $CMD'
365
        ;;
366 367 368
esac

}