epm-mark 5.97 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 86 87 88 89 90
case $DISTRNAME in
	ALTLinux|ALTServer)
		__alt_mark_hold "$@"
		exit
		;;
esac

91
case $PMTYPE in
92 93 94 95
	apt-dpkg)
		sudocmd apt-mark hold "$@"
		;;
	yum-rpm|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 119 120 121 122 123 124 125 126 127 128 129 130
		;;
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}


epm_mark_unhold()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		__alt_mark_unhold "$@"
		exit
		;;
esac

case $PMTYPE in
	apt-dpkg)
		sudocmd apt-mark unhold "$@"
		;;
	yum-rpm|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 154 155 156 157 158 159 160 161 162 163 164
		;;
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}


epm_mark_showhold()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		__alt_mark_showhold "$@"
		exit
		;;
esac

case $PMTYPE in
	apt-dpkg)
		sudocmd apt-mark showhold "$@"
		;;
165 166 167 168 169 170 171 172 173 174 175 176 177
	yum-rpm|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
		;;
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}


epm_mark_auto()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		sudocmd apt-mark auto "$@"
		exit
		;;
esac

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

}


epm_mark_manual()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		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
#	yum-rpm|dnf-rpm)
#		sudocmd dnf mark install "$@"
#		;;
234 235 236 237 238 239
		pacman)
			sudocmd pacman -D --asexplicit "$@"
		;;
		emerge)
			sudocmd emerge --select "$@"
		;;
240 241 242 243 244 245
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 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


epm_mark_showauto()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		sudocmd apt-mark showauto "$@"
		exit
		;;
esac

case $PMTYPE in
	apt-dpkg)
		sudocmd apt-mark showauto "$@"
		;;
#	yum-rpm|dnf-rpm)
#		sudocmd dnf mark remove "$@"
#		;;
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}

epm_mark_showmanual()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		sudocmd apt-mark showmanual "$@"
		exit
		;;
esac

case $PMTYPE in
	apt-dpkg)
		sudocmd apt-mark showmanual "$@"
		;;
#	yum-rpm|dnf-rpm)
#		sudocmd dnf mark install "$@"
#		;;
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}


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

}