epm-mark 6.88 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 22
# TODO: move to a common place and use
__is_wildcard()
{
23
    echo "$1" | grep -q "[*?]"
24 25 26 27
}

__alt_mark_hold_package()
{
28 29 30
        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
31 32 33 34
}

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

38 39
__alt_mark_hold()
{
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    # 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
57 58 59 60
}

__alt_mark_unhold()
{
61 62 63 64 65 66 67 68
    # 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
69 70
}

71 72
__alt_mark_showhold()
{
73
    grep -h "RPM::Hold" /etc/apt/apt.conf.d/hold-*.conf 2>/dev/null | sed -e 's|RPM::Hold {"^\(.*\)";};|\1|'
74 75
}

76 77
__dnf_assure_versionlock()
{
78
    epm assure /etc/dnf/plugins/versionlock.conf 'dnf-command(versionlock)'
79
}
80 81

epm_mark_hold()
82 83
{

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

91
case $PMTYPE in
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    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"
        ;;
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
111 112 113 114 115 116 117 118
esac

}


epm_mark_unhold()
{

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

case $PMTYPE in
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    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"
        ;;
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
146 147 148 149 150 151 152 153
esac

}


epm_mark_showhold()
{

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

case $PMTYPE in
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    apt-dpkg)
        sudocmd apt-mark showhold "$@"
        ;;
    dnf-rpm)
        __dnf_assure_versionlock
        sudocmd dnf versionlock list
        ;;
    zypper-rpm)
        sudocmd zypper ll "$@"
        ;;
    emerge)
        cat /etc/portage/package.mask
        ;;
    pacman)
        cat /etc/pacman.conf
        ;;
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
181 182 183 184 185 186 187 188
esac

}


epm_mark_auto()
{

189
case $BASEDISTRNAME in
190 191 192 193
    "alt")
        sudocmd apt-mark auto "$@"
        exit
        ;;
194 195 196
esac

case $PMTYPE in
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    apt-dpkg)
        sudocmd apt-mark auto "$@"
        ;;
    dnf-rpm)
        sudocmd dnf mark remove "$@"
        ;;
    pacman)
            sudocmd pacman -D --asdeps "$@"
        ;;
    emerge)
            sudocmd emerge --oneshot "$@"
        ;;
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
212 213 214 215 216 217 218 219
esac

}


epm_mark_manual()
{

220
case $BASEDISTRNAME in
221 222 223 224
    "alt")
        sudocmd apt-mark manual "$@"
        exit
        ;;
225 226 227
esac

case $PMTYPE in
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
    apt-dpkg)
        sudocmd apt-mark manual "$@"
        ;;
    dnf-rpm)
        sudocmd dnf mark install "$@"
        ;;
    pacman)
            sudocmd pacman -D --asexplicit "$@"
        ;;
    emerge)
            sudocmd emerge --select "$@"
        ;;
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
243 244 245
esac

}
246 247 248 249 250


epm_mark_showauto()
{

251
case $BASEDISTRNAME in
252 253 254 255
    "alt")
        sudocmd apt-mark showauto "$@"
        exit
        ;;
256 257 258
esac

case $PMTYPE in
259 260 261 262 263 264 265 266 267
    apt-dpkg)
        sudocmd apt-mark showauto "$@"
        ;;
    dnf-rpm)
        sudocmd dnf repoquery --unneeded
        ;;
    *)
        fatal "Have no suitable command for $PMTYPE"
        ;;
268 269 270 271 272 273 274
esac

}

epm_mark_showmanual()
{

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

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

}

296 297
epm_mark_help()
{
298 299 300
    echo "mark is the interface for marking packages"
            get_help HELPCMD $SHAREDIR/epm-mark
    cat <<EOF
301 302 303 304 305
Examples:
  epm mark hold mc
  epm manual mc
EOF
}
306 307 308

epm_mark()
{
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
    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 "$@"
        ;;
    auto)                             # HELPCMD: mark the given package(s) as automatically installed
        epm_mark_auto "$@"
        ;;
    manual)                           # HELPCMD: mark the given package(s) as manually installed
        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 "$@"
        ;;
    *)
        fatal "Unknown command $ epm repo '$CMD'"
        ;;
339 340 341
esac

}