epm-mark 5.89 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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
# TODO: move to a common place and use
__is_wildcard()
{
	echo "$1" | grep -q "[*?]"
}

__alt_mark_hold_package()
{
		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
}

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

38 39 40 41 42
__alt_mark_hold()
{
	# TODO: do more long checking via apt
	local pkg
	local i
43
	__alt_test_glob "$*"
44
	for i in "$@" ; do
45 46 47 48 49 50 51 52 53 54 55
		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
56 57 58 59 60 61 62 63
	done
}

__alt_mark_unhold()
{
	# TODO: do more long checking via apt
	local pkg
	local i
64
	__alt_test_glob "$*"
65 66 67 68 69 70
	for i in "$@" ; do
		pkg="$(epm query --short "$i")" || pkg="$i"
		sudocmd rm -fv /etc/apt/apt.conf.d/hold-$pkg.conf
	done
}

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

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

epm_mark_hold()
82 83
{

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

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

}


epm_mark_unhold()
{

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

case $PMTYPE in
	apt-dpkg)
		sudocmd apt-mark unhold "$@"
		;;
130
	dnf-rpm)
131 132 133 134 135 136 137 138 139 140 141
		__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"
142 143 144 145 146 147 148 149 150 151 152 153
		;;
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}


epm_mark_showhold()
{

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

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

}


epm_mark_auto()
{

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

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

}


epm_mark_manual()
{

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

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

}
246 247 248 249 250


epm_mark_showauto()
{

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

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

}

epm_mark_showmanual()
{

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

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

}

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

epm_mark()
{
	local CMD="$1"
	[ -n "$CMD" ] && shift
	case "$CMD" in
	""|"-h"|"--help"|help)               # HELPCMD: help
313
		epm_mark_help
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 339 340 341
		;;
	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'"
		;;
esac

}