Commit 285a93b1 authored by Vitaly Lipatov's avatar Vitaly Lipatov

commit packed 3.13.0

parent faed782f
...@@ -293,12 +293,16 @@ info() ...@@ -293,12 +293,16 @@ info()
fi fi
} }
SUDO_TESTED="0" SUDO_TESTED=''
SUDO_CMD="sudo" SUDO_CMD='sudo'
set_sudo() set_sudo()
{ {
[ "$SUDO_TESTED" = "1" ] && return local nofail="$1"
SUDO_TESTED="1"
# cache the result
[ -n "$SUDO_TESTED" ] && return "$SUDO_TESTED"
SUDO_TESTED="0"
SUDO="" SUDO=""
# skip SUDO if disabled # skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return [ -n "$EPMNOSUDO" ] && return
...@@ -309,28 +313,32 @@ set_sudo() ...@@ -309,28 +313,32 @@ set_sudo()
EFFUID=$(id -u) EFFUID=$(id -u)
# do not need sudo # if we are root, do not need sudo
[ $EFFUID = "0" ] && return [ $EFFUID = "0" ] && return
# start error section
SUDO_TESTED="1"
if ! which $SUDO_CMD >/dev/null 2>/dev/null ; then if ! which $SUDO_CMD >/dev/null 2>/dev/null ; then
SUDO="fatal 'Can't find sudo. Please install and tune sudo ('# epm install sudo') or run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't find sudo. Please install and tune sudo ('# epm install sudo') or run epm under root.'"
return return "$SUDO_TESTED"
fi fi
# if input is a console # if input is a console
if inputisatty && isatty && isatty2 ; then if inputisatty && isatty && isatty2 ; then
if ! $SUDO_CMD -l >/dev/null ; then if ! $SUDO_CMD -l >/dev/null ; then
SUDO="fatal 'Can't use sudo (only without password sudo is supported in non interactive using). Please run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only without password sudo is supported in non interactive using). Please run epm under root.'"
return return "$SUDO_TESTED"
fi fi
else else
# use sudo if one is tuned and tuned without password # use sudo if one is tuned and tuned without password
if ! $SUDO_CMD -l -n >/dev/null 2>/dev/null ; then if ! $SUDO_CMD -l -n >/dev/null 2>/dev/null ; then
SUDO="fatal 'Can't use sudo (only without password sudo is supported). Please run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only without password sudo is supported). Please run epm under root.'"
return return "$SUDO_TESTED"
fi fi
fi fi
SUDO_TESTED="0"
SUDO="$SUDO_CMD --" SUDO="$SUDO_CMD --"
# check for < 1.7 version which do not support -- (and --help possible too) # check for < 1.7 version which do not support -- (and --help possible too)
$SUDO_CMD -h 2>/dev/null | grep -q " --" || SUDO="$SUDO_CMD" $SUDO_CMD -h 2>/dev/null | grep -q " --" || SUDO="$SUDO_CMD"
...@@ -400,6 +408,7 @@ confirm_info() ...@@ -400,6 +408,7 @@ confirm_info()
assure_root() assure_root()
{ {
set_sudo
[ "$EFFUID" = 0 ] || fatal "run me only under root" [ "$EFFUID" = 0 ] || fatal "run me only under root"
} }
...@@ -584,7 +593,7 @@ get_pkg_name_delimiter() ...@@ -584,7 +593,7 @@ get_pkg_name_delimiter()
has_space() has_space()
{ {
estrlist has_space "$@" estrlist -- has_space "$@"
} }
# File bin/epm-addrepo: # File bin/epm-addrepo:
...@@ -708,6 +717,7 @@ __epm_addkey_deb() ...@@ -708,6 +717,7 @@ __epm_addkey_deb()
local fingerprint="$2" local fingerprint="$2"
if [ -z "$fingerprint" ] ; then if [ -z "$fingerprint" ] ; then
assure_exists curl assure_exists curl
set_sudo
showcmd "curl -fsSL '$url' | $SUDO apt-key add -" showcmd "curl -fsSL '$url' | $SUDO apt-key add -"
a= curl -fsSL "$url" | sudorun apt-key add - a= curl -fsSL "$url" | sudorun apt-key add -
return return
...@@ -929,7 +939,7 @@ __epm_orphan_altrpm() ...@@ -929,7 +939,7 @@ __epm_orphan_altrpm()
epm_autoorphans() epm_autoorphans()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" [ -z "$*" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
...@@ -1724,15 +1734,16 @@ __is_repo_info_uptodate() ...@@ -1724,15 +1734,16 @@ __is_repo_info_uptodate()
update_repo_if_needed() update_repo_if_needed()
{ {
# check if we need skip update checking # check if we need skip update checking
if [ "$1" = "soft" ] && [ -n "$SUDO" ] ; then if [ "$1" = "soft" ] && ! set_sudo nofail ; then
# if sudo requires a password, skip autoupdate # if sudo requires a password, skip autoupdate
sudorun -n true 2>/dev/null || { info "sudo requires a password, skip repo status checking" ; return 0 ; } info "can't use sudo, so skip repo status checking"
return 1
fi fi
cd / || fatal cd / || fatal
if ! __is_repo_info_downloaded || ! __is_repo_info_uptodate ; then if ! __is_repo_info_downloaded || ! __is_repo_info_uptodate ; then
# FIXME: cleans!!! # FIXME: cleans!!!
(pkg_filenames='' epm_update) epm_update
fi fi
cd - >/dev/null || fatal cd - >/dev/null || fatal
...@@ -1781,7 +1792,7 @@ __remove_deb_apt_cache_file() ...@@ -1781,7 +1792,7 @@ __remove_deb_apt_cache_file()
epm_clean() epm_clean()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" [ -z "$*" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
...@@ -2034,6 +2045,7 @@ epm_downgrade() ...@@ -2034,6 +2045,7 @@ epm_downgrade()
apt-rpm) apt-rpm)
local APTOPTIONS="$(subst_option non_interactive -y)" local APTOPTIONS="$(subst_option non_interactive -y)"
__epm_add_alt_apt_downgrade_preferences || return __epm_add_alt_apt_downgrade_preferences || return
# pass pkg_filenames too
epm_upgrade "$@" epm_upgrade "$@"
__epm_remove_apt_downgrade_preferences __epm_remove_apt_downgrade_preferences
;; ;;
...@@ -2238,40 +2250,40 @@ epm_download() ...@@ -2238,40 +2250,40 @@ epm_download()
case $DISTRNAME-$PMTYPE in case $DISTRNAME-$PMTYPE in
ALTLinux-apt-rpm) ALTLinux-apt-rpm)
__epm_download_alt $pkg_filenames __epm_download_alt $*
return return
;; ;;
esac esac
case $PMTYPE in case $PMTYPE in
dnf-rpm) dnf-rpm)
sudocmd dnf download $pkg_filenames sudocmd dnf download $*
;; ;;
aptcyg) aptcyg)
sudocmd apt-cyg download $pkg_filenames sudocmd apt-cyg download $*
;; ;;
packagekit) packagekit)
docmd pkcon download $pkg_filenames docmd pkcon download $*
;; ;;
yum-rpm) yum-rpm)
# TODO: check yum install --downloadonly --downloaddir=/tmp <package-name> # TODO: check yum install --downloadonly --downloaddir=/tmp <package-name>
assure_exists yumdownloader yum-utils assure_exists yumdownloader yum-utils
sudocmd yumdownloader $pkg_filenames sudocmd yumdownloader $*
;; ;;
dnf-rpm) dnf-rpm)
sudocmd dnf download $pkg_filenames sudocmd dnf download $*
;; ;;
urpm-rpm) urpm-rpm)
sudocmd urpmi --no-install $URPMOPTIONS $@ sudocmd urpmi --no-install $URPMOPTIONS $@
;; ;;
tce) tce)
sudocmd tce-load -w $pkg_filenames sudocmd tce-load -w $*
;; ;;
opkg) opkg)
docmd opkg $pkg_filenames docmd opkg $*
;; ;;
homebrew) homebrew)
docmd brew fetch $pkg_filenames docmd brew fetch $*
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -2502,7 +2514,7 @@ epm_filelist() ...@@ -2502,7 +2514,7 @@ epm_filelist()
epm_full_upgrade() epm_full_upgrade()
{ {
(pkg_filenames='' epm_update) || return epm_update || return
epm_upgrade || return epm_upgrade || return
...@@ -3243,7 +3255,7 @@ epm_Install() ...@@ -3243,7 +3255,7 @@ epm_Install()
[ -z "$files$names" ] && info "Install: Skip empty install list." && return 22 [ -z "$files$names" ] && info "Install: Skip empty install list." && return 22
(pkg_filenames='' epm_update) || { [ -n "$force" ] || return ; } epm_update || { [ -n "$force" ] || return ; }
epm_install_names $names || return epm_install_names $names || return
...@@ -3342,8 +3354,8 @@ epm_kernel_update() ...@@ -3342,8 +3354,8 @@ epm_kernel_update()
fi fi
assure_exists update-kernel update-kernel 0.9.9 assure_exists update-kernel update-kernel 0.9.9
update_repo_if_needed update_repo_if_needed
sudocmd update-kernel $(subst_option non_interactive -y) $pkg_filenames || return sudocmd update-kernel $(subst_option non_interactive -y) "$@" || return
docmd epm remove-old-kernels $(subst_option non_interactive -y) $pkg_filenames || fatal docmd epm remove-old-kernels $(subst_option non_interactive -y) "$@" || fatal
return ;; return ;;
esac esac
...@@ -3386,7 +3398,7 @@ __repack_rpm_base() ...@@ -3386,7 +3398,7 @@ __repack_rpm_base()
epm_optimize() epm_optimize()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" [ -z "$*" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
*-rpm) *-rpm)
...@@ -3634,6 +3646,7 @@ Options: ...@@ -3634,6 +3646,7 @@ Options:
--remove APP - remove APP --remove APP - remove APP
--list - list all installed apps --list - list all installed apps
--list-all - list all available apps --list-all - list all available apps
--short - print only names
EOF EOF
exit exit
fi fi
...@@ -3650,22 +3663,43 @@ fi ...@@ -3650,22 +3663,43 @@ fi
if [ "$1" = "--list" ] || [ "$1" = "--installed" ] ; then if [ "$1" = "--list" ] || [ "$1" = "--installed" ] ; then
shift shift
echo "Installed:"
local i local i
if [ -n "$short" ] ; then
for i in $(__list_installed_app) ; do
echo "$i"
done
exit
fi
echo "Installed:"
for i in $(__list_installed_app) ; do for i in $(__list_installed_app) ; do
printf " %-20s - %s\n" "$i" "$($psdir/$i.sh --description 2>/dev/null)" printf " %-20s - %s\n" "$i" "$($psdir/$i.sh --description 2>/dev/null)"
done done
exit exit
fi fi
[ "($DISTRVENDOR -a)" = "x86_64" ] && IGNOREi586='' || IGNOREi586=1
if [ "$1" = "--list-all" ] || [ -z "$*" ] ; then if [ "$1" = "--list-all" ] || [ -z "$*" ] ; then
echo "Run with a name of a play script to run:" echo "Run with a name of a play script to run:"
local i local i
local desc local desc
if [ -n "$short" ] ; then
for i in $psdir/*.sh ; do
# print all
#desc="$($i --description 2>/dev/null)"
#[ -z "$desc" ] && continue
local name=$(basename $i .sh)
[ -n "$IGNOREi586" ] && rhas "$name" "^i586-" && continue
echo "$name"
done
exit
fi
for i in $psdir/*.sh ; do for i in $psdir/*.sh ; do
desc="$($i --description 2>/dev/null)" desc="$($i --description 2>/dev/null)"
[ -z "$desc" ] && continue [ -z "$desc" ] && continue
printf " %-20s - %s\n" "$(basename $i .sh)" "$desc" local name=$(basename $i .sh)
[ -n "$IGNOREi586" ] && rhas "$name" "^i586-" && continue
printf " %-20s - %s\n" "$name" "$desc"
done done
echo echo
echo "run epm play --list to list installed only or --remove to remove one" echo "run epm play --list to list installed only or --remove to remove one"
...@@ -4469,7 +4503,11 @@ __do_query_real_file() ...@@ -4469,7 +4503,11 @@ __do_query_real_file()
# get value of symbolic link # get value of symbolic link
if [ -L "$TOFILE" ] ; then if [ -L "$TOFILE" ] ; then
local LINKTO local LINKTO
__do_query "$TOFILE" if [ -n "$short" ] ; then
__do_short_query "$TOFILE"
else
__do_query "$TOFILE"
fi
LINKTO=$(readlink -f -- "$TOFILE") LINKTO=$(readlink -f -- "$TOFILE")
info "Note: $TOFILE is link to $LINKTO" info "Note: $TOFILE is link to $LINKTO"
__do_query_real_file "$LINKTO" __do_query_real_file "$LINKTO"
...@@ -4577,16 +4615,6 @@ __do_short_query() ...@@ -4577,16 +4615,6 @@ __do_short_query()
epm_query_file() epm_query_file()
{ {
# И где это используется?
# in short mode print handle only real names and do short output
# TODO: move to separate command?
# FIXME: it is possible use query
if [ -n "$short" ] ; then
[ -n "$pkg_files$pkg_dirs" ] || fatal "Run query without file names (needed path to files)"
__do_short_query $pkg_files $pkg_dirs
return
fi
# file can exists or not # file can exists or not
[ -n "$pkg_filenames" ] || fatal "Run query without file names" [ -n "$pkg_filenames" ] || fatal "Run query without file names"
...@@ -4596,7 +4624,11 @@ epm_query_file() ...@@ -4596,7 +4624,11 @@ epm_query_file()
res=0 res=0
for pkg in $pkg_filenames ; do for pkg in $pkg_filenames ; do
__do_query_real_file "$pkg" __do_query_real_file "$pkg"
__do_query "$FULLFILEPATH" || res=$? if [ -n "$short" ] ; then
__do_short_query "$FULLFILEPATH" || res=$?
else
__do_query "$FULLFILEPATH" || res=$?
fi
done done
[ "$res" = "0" ] || info "Try epm sf for search file in all packages in repository" [ "$res" = "0" ] || info "Try epm sf for search file in all packages in repository"
#|| pkg_filenames="$FULLFILEPATH" epm_search_file #|| pkg_filenames="$FULLFILEPATH" epm_search_file
...@@ -4706,35 +4738,50 @@ epm_reinstall() ...@@ -4706,35 +4738,50 @@ epm_reinstall()
# File bin/epm-release_upgrade: # File bin/epm-release_upgrade:
SAVELISTDIR=/tmp/eepm-release_upgrade assure_safe_run()
__save_alt_repo_lists()
{ {
info "Creating copy of all sources lists to $SAVELISTDIR ..." if [ "$TERM" = "linux" ] ; then
local i echo "You have the best choise to run the '# epm release-upgrade' from text console."
rm -rfv $SAVELISTDIR 2>/dev/null return
mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/ fi
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do if [ "$TERM" != "screen" ] ; then
[ -s "$i" ] || continue if [ -n "$force" ] ; then
local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")" echo "You force me running not under screen (TERM=$TERM now)! You can lost your system!"
cp -af $verbose "$i" "$DD" || fatal "Can't save apt source list files to $SAVELISTDIR" return
done else
} warning "It is very dangerous to upgrade to next release from a GUI (your TERM=$TERM)."
warning "It is recommended install 'screen' and run upgrade via screen: '# screen epm release-upgrade'"
fatal "or run me with --force if you understand the risk."
fi
fi
__restore_alt_repo_lists() # run under screen, check if systemd will not kill our processes
{ local res
info "Some error. Restoring copy of all sources lists from $SAVELISTDIR ..." if ! is_active_systemd systemd ; then
local i return
[ -d "$SAVELISTDIR/apt" ] || return 0 fi
mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do res="$(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager KillUserProcesses)"
[ -s "$i" ] || continue if [ "$res" = "b false" ] ; then
local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")" echo "Good news: systemd-logind will not kill your screen processes (KillUserProcesses=false)"
# restore only if there are differences return
diff -q "$DD" "$i" >/dev/null || continue else
mv $verbose "$DD" "$i" || warning "Can't restore $i file" if [ -n "$force" ] ; then
done warning "You force runnning even if systemd-logind kills screen on disconnect"
else
docmd epm install systemd-settings-disable-kill-user-processes || fatal "Can't install the package above. Fix it or run with --force."
docmd serv systemd-logind restart || fatal "Can't restart systemd-logind service. Fix it or run with --force."
fatal "Now you need relogin to the system. In this session your screen still will be killed."
fi
fi
# check too: KillExcludeUsers
# can continue
return 0
} }
__replace_text_in_alt_repo() __replace_text_in_alt_repo()
{ {
local i local i
...@@ -4858,7 +4905,7 @@ get_fix_release_pkg() ...@@ -4858,7 +4905,7 @@ get_fix_release_pkg()
[ "$TOINSTALL" = "altlinux-release-sisyphus" ] && TOINSTALL="branding-alt-sisyphus-release" [ "$TOINSTALL" = "altlinux-release-sisyphus" ] && TOINSTALL="branding-alt-sisyphus-release"
# update if installed (just print package name here to include in the install list) # update if installed (just print package name here to include in the install list)
epm --quiet --short -q alt-gpgkeys 2>/dev/null epm --quiet --short installed alt-gpgkeys 2>/dev/null
if epm --quiet --short -q etersoft-gpgkeys 2>/dev/null >/dev/null ; then if epm --quiet --short -q etersoft-gpgkeys 2>/dev/null >/dev/null ; then
# leave etersoft-gpgkeys only we have LINUX@Etersoft repo # leave etersoft-gpgkeys only we have LINUX@Etersoft repo
epm rl | grep -q "LINUX@Etersoft" && echo etersoft-gpgkeys || echo alt-gpgkeys epm rl | grep -q "LINUX@Etersoft" && echo etersoft-gpgkeys || echo alt-gpgkeys
...@@ -4888,19 +4935,36 @@ __switch_repo_to() ...@@ -4888,19 +4935,36 @@ __switch_repo_to()
__check_system() __check_system()
{ {
local TO="$1"
shift
# sure we have systemd if systemd is running # sure we have systemd if systemd is running
if is_active_systemd systemd ; then if is_active_systemd systemd ; then
docmd epm --skip-installed install systemd || fatal docmd epm --skip-installed install systemd || fatal
fi fi
# FIXME: will GUI closed during that changes? if [ "$TO" != "Sisyphus" ] ; then
# switch from prefdm: https://bugzilla.altlinux.org/show_bug.cgi?id=26405#c52 if epm installed altlinux-release-sisyphus >/dev/null ; then
if is_active_systemd systemd && serv display-manager status >/dev/null || serv prefdm status >/dev/null ; then warning "Target distro is $TO, but altlinux-release-sisyphus package is installed."
docmd systemctl disable prefdm.service warning "Trying to replace it with altlinux-release-$TO"
docmd systemctl disable display-manager.service docmd epm install altlinux-release-$TO
docmd systemctl enable display-manager.service fi
# docmd systemctl enable sddm.service fi
# docmd systemctl enable lightdm.service
# switch from prefdm: https://bugzilla.altlinux.org/show_bug.cgi?id=26405#c47
if is_active_systemd systemd ; then
if serv display-manager exists || serv prefdm exists ; then
# don't stop running X server!
# docmd serv dm off
docmd serv disable prefdm
docmd serv disable display-manager
docmd serv enable display-manager
# enable first available DM
for i in lightdm sddm lxde-lxdm gdm ; do
serv $i exists && docmd serv enable $i && break
done
fi
fi fi
} }
...@@ -4970,7 +5034,7 @@ __switch_alt_to_distro() ...@@ -4970,7 +5034,7 @@ __switch_alt_to_distro()
__epm_ru_update || fatal __epm_ru_update || fatal
docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again"
docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again"
__check_system __check_system "$TO"
docmd epm update-kernel || fatal docmd epm update-kernel || fatal
info "Run epm release-upgrade again for update to p9" info "Run epm release-upgrade again for update to p9"
;; ;;
...@@ -4981,7 +5045,7 @@ __switch_alt_to_distro() ...@@ -4981,7 +5045,7 @@ __switch_alt_to_distro()
__epm_ru_update || fatal __epm_ru_update || fatal
docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again"
docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again"
__check_system __check_system "$TO"
docmd epm update-kernel || fatal docmd epm update-kernel || fatal
;; ;;
"p8 c8"|"p8 c8.1"|"p8 c8.2") "p8 c8"|"p8 c8.1"|"p8 c8.2")
...@@ -4996,7 +5060,7 @@ __switch_alt_to_distro() ...@@ -4996,7 +5060,7 @@ __switch_alt_to_distro()
fi fi
docmd epm downgrade docmd epm downgrade
docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again"
__check_system __check_system "$TO"
docmd epm update-kernel || fatal docmd epm update-kernel || fatal
;; ;;
"p8"|"p8 p9"|"t8 p9"|"c8 c9"|"c8 p9"|"c8.1 p9"|"c8.2 p9"|"p9 p9") "p8"|"p8 p9"|"t8 p9"|"c8 c9"|"c8 p9"|"c8.1 p9"|"c8.2 p9"|"p9 p9")
...@@ -5010,7 +5074,7 @@ __switch_alt_to_distro() ...@@ -5010,7 +5074,7 @@ __switch_alt_to_distro()
__epm_ru_update || fatal __epm_ru_update || fatal
docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again"
docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again"
__check_system __check_system "$TO"
docmd epm update-kernel || fatal docmd epm update-kernel || fatal
info "Run epm release-upgrade again for update to p10" info "Run epm release-upgrade again for update to p10"
;; ;;
...@@ -5024,7 +5088,7 @@ __switch_alt_to_distro() ...@@ -5024,7 +5088,7 @@ __switch_alt_to_distro()
__epm_ru_update || fatal __epm_ru_update || fatal
docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm upgrade || fatal "Check the errors and run '# epm release-upgrade' again"
docmd epm install rpm apt "$(get_fix_release_pkg "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm install rpm apt "$(get_fix_release_pkg "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again"
__check_system __check_system "$TO"
docmd epm update-kernel -t std-def || fatal docmd epm update-kernel -t std-def || fatal
;; ;;
"p9 p8"|"c8.1 c8"|"c8.1 p8"|"p8 p8") "p9 p8"|"c8.1 c8"|"c8.1 p8"|"p8 p8")
...@@ -5038,7 +5102,7 @@ __switch_alt_to_distro() ...@@ -5038,7 +5102,7 @@ __switch_alt_to_distro()
docmd epm downgrade apt rpm pam pam0_passwdqc glibc-core libcrypt- || fatal docmd epm downgrade apt rpm pam pam0_passwdqc glibc-core libcrypt- || fatal
fi fi
docmd epm downgrade docmd epm downgrade
__check_system __check_system "$TO"
docmd epm upgrade || fatal docmd epm upgrade || fatal
;; ;;
"p9 c8"|"p9 c8.1"|"p9 c8.2") "p9 c8"|"p9 c8.1"|"p9 c8.2")
...@@ -5052,7 +5116,7 @@ __switch_alt_to_distro() ...@@ -5052,7 +5116,7 @@ __switch_alt_to_distro()
# docmd epm downgrade apt rpm pam pam0_passwdqc glibc-core libcrypt- || fatal # docmd epm downgrade apt rpm pam pam0_passwdqc glibc-core libcrypt- || fatal
#fi #fi
docmd epm downgrade docmd epm downgrade
__check_system __check_system "$TO"
docmd epm upgrade || fatal docmd epm upgrade || fatal
;; ;;
"p10 p9") "p10 p9")
...@@ -5063,7 +5127,7 @@ __switch_alt_to_distro() ...@@ -5063,7 +5127,7 @@ __switch_alt_to_distro()
__epm_ru_update || fatal __epm_ru_update || fatal
docmd epm downgrade rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm downgrade rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again"
docmd epm downgrade docmd epm downgrade
__check_system __check_system "$TO"
docmd epm upgrade || fatal docmd epm upgrade || fatal
;; ;;
"Sisyphus p8"|"Sisyphus p9"|"Sisyphus p10"|"Sisyphus c8"|"Sisyphus c8.1") "Sisyphus p8"|"Sisyphus p9"|"Sisyphus p10"|"Sisyphus c8"|"Sisyphus c8.1")
...@@ -5074,7 +5138,7 @@ __switch_alt_to_distro() ...@@ -5074,7 +5138,7 @@ __switch_alt_to_distro()
__epm_ru_update || fatal __epm_ru_update || fatal
docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again" docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check the errors and run '# epm release-upgrade' again"
docmd epm downgrade docmd epm downgrade
__check_system __check_system "$TO"
docmd epm upgrade || fatal docmd epm upgrade || fatal
;; ;;
"p8 Sisyphus"|"p9 Sisyphus"|"p10 Sisyphus"|"Sisyphus Sisyphus") "p8 Sisyphus"|"p9 Sisyphus"|"p10 Sisyphus"|"Sisyphus Sisyphus")
...@@ -5090,7 +5154,7 @@ __switch_alt_to_distro() ...@@ -5090,7 +5154,7 @@ __switch_alt_to_distro()
#ADDPKG=$(epm -q --short make-initrd sssd-ad 2>/dev/null) #ADDPKG=$(epm -q --short make-initrd sssd-ad 2>/dev/null)
#docmd epm install librpm7 librpm rpm apt $ADDPKG "$(get_fix_release_pkg --force "$TO")" ConsoleKit2- || fatal "Check an error and run again" #docmd epm install librpm7 librpm rpm apt $ADDPKG "$(get_fix_release_pkg --force "$TO")" ConsoleKit2- || fatal "Check an error and run again"
docmd epm upgrade || fatal "Check the error and run '# epm release-upgrade' or just '# epm upgrade' again" docmd epm upgrade || fatal "Check the error and run '# epm release-upgrade' or just '# epm upgrade' again"
__check_system __check_system "$TO"
docmd epm update-kernel || fatal docmd epm update-kernel || fatal
;; ;;
*) *)
...@@ -5113,6 +5177,7 @@ __switch_alt_to_distro() ...@@ -5113,6 +5177,7 @@ __switch_alt_to_distro()
epm_release_upgrade() epm_release_upgrade()
{ {
assure_root assure_root
assure_safe_run
info "Starting upgrade/switch whole system to other release" info "Starting upgrade/switch whole system to other release"
info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux" info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
...@@ -5563,7 +5628,7 @@ epm_remove_old_kernels() ...@@ -5563,7 +5628,7 @@ epm_remove_old_kernels()
return return
fi fi
assure_exists update-kernel update-kernel 0.9.9 assure_exists update-kernel update-kernel 0.9.9
sudocmd remove-old-kernels $(subst_option non_interactive -y) $pkg_filenames sudocmd remove-old-kernels $(subst_option non_interactive -y) "$@"
return ;; return ;;
Ubuntu) Ubuntu)
if ! __epm_query_package linux-image >/dev/null ; then if ! __epm_query_package linux-image >/dev/null ; then
...@@ -5582,7 +5647,7 @@ epm_remove_old_kernels() ...@@ -5582,7 +5647,7 @@ epm_remove_old_kernels()
assure_exists purge-old-kernels byobu assure_exists purge-old-kernels byobu
;; ;;
esac esac
sudocmd purge-old-kernels $pkg_filenames sudocmd purge-old-kernels "$@"
return ;; return ;;
Gentoo) Gentoo)
sudocmd emerge -P gentoo-sources sudocmd emerge -P gentoo-sources
...@@ -5605,9 +5670,14 @@ epm_remove_old_kernels() ...@@ -5605,9 +5670,14 @@ epm_remove_old_kernels()
__epm_removerepo_alt_grepremove() __epm_removerepo_alt_grepremove()
{ {
local rl local rl
rl="$((quiet=1 epm repolist) 2>/dev/null | grep -E "$1")" if [ "$1" = "all" ] || rhas "$1" "^rpm" ; then
[ -z "$rl" ] && warning "Can't find '$1' in the repos (see '# epm repolist' output)" && return 1 rl="$1"
else
rl="$((quiet=1 epm repolist) 2>/dev/null | grep -E "$1")"
[ -z "$rl" ] && warning "Can't find '$1' in the repos (see '# epm repolist' output)" && return 1
fi
echo "$rl" | while read rp ; do echo "$rl" | while read rp ; do
# TODO: print removed lines
[ -n "$dryrun" ] && docmd apt-repo $dryrun rm "$rp" && continue [ -n "$dryrun" ] && docmd apt-repo $dryrun rm "$rp" && continue
if [ -n "$verbose" ] ; then if [ -n "$verbose" ] ; then
sudocmd apt-repo $dryrun rm "$rp" sudocmd apt-repo $dryrun rm "$rp"
...@@ -5671,10 +5741,9 @@ esac; ...@@ -5671,10 +5741,9 @@ esac;
case $PMTYPE in case $PMTYPE in
apt-dpkg) apt-dpkg)
assure_exists apt-add-repository software-properties-common assure_exists apt-add-repository software-properties-common
# FIXME: it is possible there is troubles to pass the args
showcmd apt-add-repository --remove "$*"
set_sudo set_sudo
$SUDO apt-add-repository --remove "$*" # FIXME: it is possible there is troubles to pass the args
sudocmd apt-add-repository --remove "$*"
info "Check file /etc/apt/sources.list if needed" info "Check file /etc/apt/sources.list if needed"
;; ;;
aptitude-dpkg) aptitude-dpkg)
...@@ -6269,8 +6338,6 @@ case $DISTRNAME in ...@@ -6269,8 +6338,6 @@ case $DISTRNAME in
;; ;;
esac esac
[ -z "$1" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -6330,11 +6397,14 @@ print_apt_sources_list() ...@@ -6330,11 +6397,14 @@ print_apt_sources_list()
epm_repolist() epm_repolist()
{ {
[ -z "$*" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
#assure_exists apt-repo #assure_exists apt-repo
if tasknumber "$pkg_names" >/dev/null ; then if tasknumber "$1" >/dev/null ; then
get_task_packages $pkg_names get_task_packages "$@"
else else
print_apt_sources_list print_apt_sources_list
#docmd apt-repo list #docmd apt-repo list
...@@ -6387,11 +6457,47 @@ esac ...@@ -6387,11 +6457,47 @@ esac
# File bin/epm-reposave: # File bin/epm-reposave:
SAVELISTDIR=/tmp/eepm-etc-save
__save_alt_repo_lists()
{
info "Creating copy of all sources lists to $SAVELISTDIR ..."
local i
rm -rf $verbose $SAVELISTDIR 2>/dev/null
mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
[ -s "$i" ] || continue
local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")"
cp -af $verbose "$i" "$DD" || fatal "Can't save apt source list files to $SAVELISTDIR"
done
}
__restore_alt_repo_lists()
{
info "Restoring copy of all sources lists from $SAVELISTDIR ..."
local i
[ -d "$SAVELISTDIR/apt" ] || return 0
mkdir -p $SAVELISTDIR/apt/ $SAVELISTDIR/apt/sources.list.d/
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
[ -s "$i" ] || continue
local DD="$(echo "$i" | sed -e "s|/etc|$SAVELISTDIR|")"
# restore only if there are differences
if diff -q "$DD" "$i" >/dev/null ; then
rm -f $verbose "$DD"
else
mv $verbose "$DD" "$i" || warning "Can't restore $i file"
fi
done
}
epm_reposave() epm_reposave()
{ {
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-*)
fatal "TODO" assure_root
__save_alt_repo_lists
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -6403,8 +6509,9 @@ esac ...@@ -6403,8 +6509,9 @@ esac
epm_reporestore() epm_reporestore()
{ {
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-*)
fatal "TODO" assure_root
__restore_alt_repo_lists
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -7148,6 +7255,7 @@ case $PMTYPE in ...@@ -7148,6 +7255,7 @@ case $PMTYPE in
esac esac
LANG=C docmd $CMD $string LANG=C docmd $CMD $string
epm play $short --list-all | sed -e 's|^ *||g' -e 's|[[:space:]]\+| |g' -e "s|\$| (use \'epm play\' to install it)|"
} }
__epm_search_make_grep() __epm_search_make_grep()
...@@ -7900,7 +8008,7 @@ done ...@@ -7900,7 +8008,7 @@ done
epm_update() epm_update()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" [ -z "$*" ] || fatal "No arguments are allowed here"
info "Running command for update remote package repository database" info "Running command for update remote package repository database"
warmup_hibase warmup_hibase
...@@ -7992,17 +8100,15 @@ epm_upgrade() ...@@ -7992,17 +8100,15 @@ epm_upgrade()
{ {
local CMD local CMD
#[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
# it is useful for first time running # it is useful for first time running
update_repo_if_needed update_repo_if_needed
warmup_bases warmup_bases
if [ "$DISTRNAME" = "ALTLinux" ] ; then if [ "$DISTRNAME" = "ALTLinux" ] ; then
if tasknumber "$pkg_names" >/dev/null ; then if tasknumber "$*" >/dev/null ; then
epm_addrepo "$pkg_names" epm_addrepo "$*"
local installlist="$(get_task_packages $pkg_names)" local installlist="$(get_task_packages $*)"
# hack: drop -devel packages to avoid package provided by multiple packages # hack: drop -devel packages to avoid package provided by multiple packages
installlist="$(estrlist reg_exclude ".*-devel .*-devel-static" "$installlist")" installlist="$(estrlist reg_exclude ".*-devel .*-devel-static" "$installlist")"
[ -n "$verbose" ] && info "Packages from task(s): $installlist" [ -n "$verbose" ] && info "Packages from task(s): $installlist"
...@@ -8033,18 +8139,18 @@ epm_upgrade() ...@@ -8033,18 +8139,18 @@ epm_upgrade()
yum-rpm) yum-rpm)
local OPTIONS="$(subst_option non_interactive -y)" local OPTIONS="$(subst_option non_interactive -y)"
# can do update repobase automagically # can do update repobase automagically
CMD="yum $OPTIONS update $pkg_filenames" CMD="yum $OPTIONS update $*"
;; ;;
dnf-rpm) dnf-rpm)
local OPTIONS="$(subst_option non_interactive -y)" local OPTIONS="$(subst_option non_interactive -y)"
CMD="dnf $OPTIONS distro-sync $pkg_filenames" CMD="dnf $OPTIONS distro-sync $*"
;; ;;
snappy) snappy)
CMD="snappy update" CMD="snappy update"
;; ;;
urpm-rpm) urpm-rpm)
# or --auto-select --replace-files # or --auto-select --replace-files
CMD="urpmi --update --auto-select $pkg_filenames" CMD="urpmi --update --auto-select $*"
;; ;;
zypper-rpm) zypper-rpm)
CMD="zypper dist-upgrade" CMD="zypper dist-upgrade"
...@@ -8100,7 +8206,7 @@ epm_upgrade() ...@@ -8100,7 +8206,7 @@ epm_upgrade()
;; ;;
esac esac
sudocmd $CMD $pkg_filenames sudocmd $CMD "$@"
} }
...@@ -8109,8 +8215,7 @@ epm_upgrade() ...@@ -8109,8 +8215,7 @@ epm_upgrade()
epm_Upgrade() epm_Upgrade()
{ {
(pkg_filenames='' epm_update) epm_update
epm_upgrade epm_upgrade
} }
...@@ -9566,7 +9671,12 @@ esac ...@@ -9566,7 +9671,12 @@ esac
shift shift
# FIXME: do to call function directly, use case instead? # FIXME: do to call function directly, use case instead?
if [ "$1" = "-" ] ; then if [ "$COMMAND" = "--" ] ; then
# ignore all options (-)
COMMAND="$1"
shift
"$COMMAND" "$@"
elif [ "$1" = "-" ] ; then
shift shift
"$COMMAND" "$(cat) $@" "$COMMAND" "$(cat) $@"
elif [ "$2" = "-" ] ; then elif [ "$2" = "-" ] ; then
...@@ -9825,7 +9935,7 @@ Examples: ...@@ -9825,7 +9935,7 @@ Examples:
print_version() print_version()
{ {
echo "EPM package manager version 3.11.2 https://wiki.etersoft.ru/Epm" echo "EPM package manager version 3.13.0 https://wiki.etersoft.ru/Epm"
echo "Running on $($DISTRVENDOR -e) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)" echo "Running on $($DISTRVENDOR -e) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)"
echo "Copyright (c) Etersoft 2012-2020" echo "Copyright (c) Etersoft 2012-2020"
echo "This program may be freely redistributed under the terms of the GNU AGPLv3." echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
...@@ -9835,7 +9945,7 @@ print_version() ...@@ -9835,7 +9945,7 @@ print_version()
Usage="Usage: epm [options] <command> [package name(s), package files]..." Usage="Usage: epm [options] <command> [package name(s), package files]..."
Descr="epm - EPM package manager" Descr="epm - EPM package manager"
EPMVERSION=3.11.2 EPMVERSION=3.13.0
verbose= verbose=
quiet= quiet=
nodeps= nodeps=
...@@ -9859,6 +9969,7 @@ pkg_dirs= ...@@ -9859,6 +9969,7 @@ pkg_dirs=
pkg_names= pkg_names=
pkg_urls= pkg_urls=
quoted_args= quoted_args=
direct_args=
# load system wide config # load system wide config
[ -f /etc/eepm/eepm.conf ] && . /etc/eepm/eepm.conf [ -f /etc/eepm/eepm.conf ] && . /etc/eepm/eepm.conf
...@@ -9906,9 +10017,11 @@ case $PROGNAME in ...@@ -9906,9 +10017,11 @@ case $PROGNAME in
;; ;;
epmrl) # HELPSHORT: alias for epm repo list epmrl) # HELPSHORT: alias for epm repo list
epm_cmd=repolist epm_cmd=repolist
direct_args=1
;; ;;
epmu) # HELPSHORT: alias for epm update epmu) # HELPSHORT: alias for epm update
epm_cmd=update epm_cmd=update
direct_args=1
;; ;;
epm|upm|eepm) # HELPSHORT: other aliases for epm command epm|upm|eepm) # HELPSHORT: other aliases for epm command
;; ;;
...@@ -9964,15 +10077,18 @@ check_command() ...@@ -9964,15 +10077,18 @@ check_command()
;; ;;
check|fix|verify) # HELPCMD: check local package base integrity and fix it check|fix|verify) # HELPCMD: check local package base integrity and fix it
epm_cmd=check epm_cmd=check
direct_args=1
;; ;;
dedup) # HELPCMD: remove unallowed duplicated pkgs (after upgrade crash) dedup) # HELPCMD: remove unallowed duplicated pkgs (after upgrade crash)
epm_cmd=dedup epm_cmd=dedup
direct_args=1
;; ;;
-cl|cl|changelog) # HELPCMD: show changelog for package -cl|cl|changelog) # HELPCMD: show changelog for package
epm_cmd=changelog epm_cmd=changelog
;; ;;
-qi|qi|info|show) # HELPCMD: print package detail info -qi|qi|info|show) # HELPCMD: print package detail info
epm_cmd=info epm_cmd=info
direct_args=1
;; ;;
requires|deplist|depends|req|depends-on) # HELPCMD: print package requires requires|deplist|depends|req|depends-on) # HELPCMD: print package requires
epm_cmd=requires epm_cmd=requires
...@@ -9994,6 +10110,7 @@ check_command() ...@@ -9994,6 +10110,7 @@ check_command()
;; ;;
programs) # HELPCMD: print list of installed GUI program(s) (they have .desktop files) programs) # HELPCMD: print list of installed GUI program(s) (they have .desktop files)
epm_cmd=programs epm_cmd=programs
direct_args=1
;; ;;
assure) # HELPCMD: <command> [package] [version]: install package if command does not exist assure) # HELPCMD: <command> [package] [version]: install package if command does not exist
epm_cmd=assure epm_cmd=assure
...@@ -10005,44 +10122,56 @@ check_command() ...@@ -10005,44 +10122,56 @@ check_command()
# HELPCMD: PART: Repository control: # HELPCMD: PART: Repository control:
update) # HELPCMD: update remote package repository databases update) # HELPCMD: update remote package repository databases
epm_cmd=update epm_cmd=update
direct_args=1
;; ;;
addrepo|ar) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/12/31); run with param to get list addrepo|ar) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/12/31); run with param to get list
epm_cmd=addrepo epm_cmd=addrepo
direct_args=1
;; ;;
repolist|sl|rl|listrepo|repo-list) # HELPCMD: print repo list repolist|sl|rl|listrepo|repo-list) # HELPCMD: print repo list
epm_cmd=repolist epm_cmd=repolist
direct_args=1
;; ;;
repofix) # HELPCMD: <mirror>: fix paths in sources lists (ALT Linux only). use repofix etersoft/yandex/basealt for rewrite URL to the specified server repofix) # HELPCMD: <mirror>: fix paths in sources lists (ALT Linux only). use repofix etersoft/yandex/basealt for rewrite URL to the specified server
epm_cmd=repofix epm_cmd=repofix
direct_args=1
;; ;;
removerepo|rr) # HELPCMD: remove package repo (shortcut for epm repo remove) removerepo|rr) # HELPCMD: remove package repo (shortcut for epm repo remove)
epm_cmd=removerepo epm_cmd=removerepo
direct_args=1
;; ;;
repo) # HELPCMD: manipulate with repository list (run epm repo --help to help) repo) # HELPCMD: manipulate with repository list (run epm repo --help to help)
epm_cmd=repo epm_cmd=repo
direct_args=1
;; ;;
full-upgrade) # HELPCMD: update all system packages and kernel full-upgrade) # HELPCMD: update all system packages and kernel
epm_cmd=full_upgrade epm_cmd=full_upgrade
direct_args=1
;; ;;
release-upgrade|upgrade-release|upgrade-system|release-switch|release-downgrade) # HELPCMD: upgrade/switch whole system to the release in arg (default: next (latest) release) release-upgrade|upgrade-release|upgrade-system|release-switch|release-downgrade) # HELPCMD: upgrade/switch whole system to the release in arg (default: next (latest) release)
epm_cmd=release_upgrade epm_cmd=release_upgrade
direct_args=1
;; ;;
kernel-update|kernel-upgrade|update-kernel|upgrade-kernel) # HELPCMD: update system kernel to the last repo version kernel-update|kernel-upgrade|update-kernel|upgrade-kernel) # HELPCMD: update system kernel to the last repo version
epm_cmd=kernel_update epm_cmd=kernel_update
direct_args=1
;; ;;
remove-old-kernels|remove-old-kernel) # HELPCMD: remove old system kernels (exclude current or last two kernels) remove-old-kernels|remove-old-kernel) # HELPCMD: remove old system kernels (exclude current or last two kernels)
epm_cmd=remove_old_kernels epm_cmd=remove_old_kernels
direct_args=1
;; ;;
# HELPCMD: PART: Other commands: # HELPCMD: PART: Other commands:
clean) # HELPCMD: clean local package cache clean) # HELPCMD: clean local package cache
epm_cmd=clean epm_cmd=clean
direct_args=1
;; ;;
restore) # HELPCMD: install (restore) packages need for the project (f.i. by requirements.txt) restore) # HELPCMD: install (restore) packages need for the project (f.i. by requirements.txt)
epm_cmd=restore epm_cmd=restore
;; ;;
autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [--direct [libs|python|perl|libs-devel]] autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [--direct [libs|python|perl|libs-devel]]
epm_cmd=autoremove epm_cmd=autoremove
direct_args=1
;; ;;
mark) # HELPCMD: mark package as manually or automatically installed (see epm mark --help) mark) # HELPCMD: mark package as manually or automatically installed (see epm mark --help)
epm_cmd=mark epm_cmd=mark
...@@ -10052,12 +10181,15 @@ check_command() ...@@ -10052,12 +10181,15 @@ check_command()
;; ;;
upgrade|dist-upgrade) # HELPCMD: performs upgrades of package software distributions upgrade|dist-upgrade) # HELPCMD: performs upgrades of package software distributions
epm_cmd=upgrade epm_cmd=upgrade
direct_args=1
;; ;;
Upgrade) # HELPCMD: force update package base, then run upgrade Upgrade) # HELPCMD: force update package base, then run upgrade
epm_cmd=Upgrade epm_cmd=Upgrade
direct_args=1
;; ;;
downgrade) # HELPCMD: downgrade [all] packages to the repo state downgrade) # HELPCMD: downgrade [all] packages to the repo state
epm_cmd=downgrade epm_cmd=downgrade
direct_args=1
;; ;;
download) # HELPCMD: download package(s) file to the current dir download) # HELPCMD: download package(s) file to the current dir
epm_cmd=download epm_cmd=download
...@@ -10068,9 +10200,11 @@ check_command() ...@@ -10068,9 +10200,11 @@ check_command()
;; ;;
audit) # HELPCMD: audits installed packages against known vulnerabilities audit) # HELPCMD: audits installed packages against known vulnerabilities
epm_cmd=audit epm_cmd=audit
direct_args=1
;; ;;
#checksystem) # HELPCMD: check system for known errors (package management related) #checksystem) # HELPCMD: check system for known errors (package management related)
# epm_cmd=checksystem # epm_cmd=checksystem
# direct_args=1
# ;; # ;;
site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site) site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site)
epm_cmd=site epm_cmd=site
...@@ -10080,15 +10214,18 @@ check_command() ...@@ -10080,15 +10214,18 @@ check_command()
;; ;;
print) # HELPCMD: print various info, run epm print help for details print) # HELPCMD: print various info, run epm print help for details
epm_cmd=print epm_cmd=print
direct_args=1
;; ;;
repack) # HELPCMD: repack rpm to local compatibility repack) # HELPCMD: repack rpm to local compatibility
epm_cmd=repack epm_cmd=repack
;; ;;
prescription|recipe) # HELPCMD: run prescription (a script to achieving the goal), run without args to get list prescription|recipe) # HELPCMD: run prescription (a script to achieving the goal), run without args to get list
epm_cmd=prescription epm_cmd=prescription
direct_args=1
;; ;;
play) # HELPCMD: install the application from the official site (run without args to get list) play) # HELPCMD: install the application from the official site (run without args to get list)
epm_cmd=play epm_cmd=play
direct_args=1
;; ;;
-V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum) -V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum)
epm_cmd=checkpkg epm_cmd=checkpkg
...@@ -10201,12 +10338,18 @@ for opt in $EPM_OPTIONS ; do ...@@ -10201,12 +10338,18 @@ for opt in $EPM_OPTIONS ; do
done done
FLAGENDOPTS= FLAGENDOPTS=
# NOTE: can't use while read here: set vars inside
for opt in "$@" ; do for opt in "$@" ; do
[ "$opt" = "--" ] && FLAGENDOPTS=1 && continue [ "$opt" = "--" ] && FLAGENDOPTS=1 && continue
if [ -z "$FLAGENDOPTS" ] ; then if [ -z "$FLAGENDOPTS" ] ; then
check_command "$opt" && continue check_command "$opt" && continue
check_option "$opt" && continue check_option "$opt" && continue
fi fi
if [ -n "$direct_args" ] ; then
quoted_args="$quoted_args \"$opt\""
FLAGENDOPTS=1
continue
fi
# Note: will parse all params separately (no package names with spaces!) # Note: will parse all params separately (no package names with spaces!)
check_filenames "$opt" check_filenames "$opt"
done done
......
...@@ -284,12 +284,16 @@ info() ...@@ -284,12 +284,16 @@ info()
fi fi
} }
SUDO_TESTED="0" SUDO_TESTED=''
SUDO_CMD="sudo" SUDO_CMD='sudo'
set_sudo() set_sudo()
{ {
[ "$SUDO_TESTED" = "1" ] && return local nofail="$1"
SUDO_TESTED="1"
# cache the result
[ -n "$SUDO_TESTED" ] && return "$SUDO_TESTED"
SUDO_TESTED="0"
SUDO="" SUDO=""
# skip SUDO if disabled # skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return [ -n "$EPMNOSUDO" ] && return
...@@ -300,28 +304,32 @@ set_sudo() ...@@ -300,28 +304,32 @@ set_sudo()
EFFUID=$(id -u) EFFUID=$(id -u)
# do not need sudo # if we are root, do not need sudo
[ $EFFUID = "0" ] && return [ $EFFUID = "0" ] && return
# start error section
SUDO_TESTED="1"
if ! which $SUDO_CMD >/dev/null 2>/dev/null ; then if ! which $SUDO_CMD >/dev/null 2>/dev/null ; then
SUDO="fatal 'Can't find sudo. Please install and tune sudo ('# epm install sudo') or run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't find sudo. Please install and tune sudo ('# epm install sudo') or run epm under root.'"
return return "$SUDO_TESTED"
fi fi
# if input is a console # if input is a console
if inputisatty && isatty && isatty2 ; then if inputisatty && isatty && isatty2 ; then
if ! $SUDO_CMD -l >/dev/null ; then if ! $SUDO_CMD -l >/dev/null ; then
SUDO="fatal 'Can't use sudo (only without password sudo is supported in non interactive using). Please run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only without password sudo is supported in non interactive using). Please run epm under root.'"
return return "$SUDO_TESTED"
fi fi
else else
# use sudo if one is tuned and tuned without password # use sudo if one is tuned and tuned without password
if ! $SUDO_CMD -l -n >/dev/null 2>/dev/null ; then if ! $SUDO_CMD -l -n >/dev/null 2>/dev/null ; then
SUDO="fatal 'Can't use sudo (only without password sudo is supported). Please run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only without password sudo is supported). Please run epm under root.'"
return return "$SUDO_TESTED"
fi fi
fi fi
SUDO_TESTED="0"
SUDO="$SUDO_CMD --" SUDO="$SUDO_CMD --"
# check for < 1.7 version which do not support -- (and --help possible too) # check for < 1.7 version which do not support -- (and --help possible too)
$SUDO_CMD -h 2>/dev/null | grep -q " --" || SUDO="$SUDO_CMD" $SUDO_CMD -h 2>/dev/null | grep -q " --" || SUDO="$SUDO_CMD"
...@@ -391,6 +399,7 @@ confirm_info() ...@@ -391,6 +399,7 @@ confirm_info()
assure_root() assure_root()
{ {
set_sudo
[ "$EFFUID" = 0 ] || fatal "run me only under root" [ "$EFFUID" = 0 ] || fatal "run me only under root"
} }
...@@ -575,7 +584,7 @@ get_pkg_name_delimiter() ...@@ -575,7 +584,7 @@ get_pkg_name_delimiter()
has_space() has_space()
{ {
estrlist has_space "$@" estrlist -- has_space "$@"
} }
# File bin/serv-cat: # File bin/serv-cat:
...@@ -587,7 +596,7 @@ serv_cat() ...@@ -587,7 +596,7 @@ serv_cat()
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd systemctl cat "$SERVICE" "$@" docmd systemctl cat "$SERVICE" "$@"
;; ;;
*) *)
case $DISTRNAME in case $DISTRNAME in
...@@ -643,7 +652,6 @@ serv_disable() ...@@ -643,7 +652,6 @@ serv_disable()
{ {
local SERVICE="$1" local SERVICE="$1"
is_service_running $1 && { serv_stop $1 || return ; }
is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; } is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; }
case $SERVICETYPE in case $SERVICETYPE in
...@@ -692,7 +700,7 @@ serv_edit() ...@@ -692,7 +700,7 @@ serv_edit()
# File bin/serv-enable: # File bin/serv-enable:
__serv_enable() serv_enable()
{ {
local SERVICE="$1" local SERVICE="$1"
...@@ -729,22 +737,38 @@ __serv_enable() ...@@ -729,22 +737,38 @@ __serv_enable()
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
serv_enable() # File bin/serv-exists:
serv_exists()
{ {
__serv_enable "$1" || return local SERVICE="$1"
# start if need shift
is_service_running $1 && info "Service $1 is already running" && return
serv_start $1 case $SERVICETYPE in
systemd)
# too direct way: test -s /lib/systemd/system/dm.service
docmd systemctl cat "$SERVICE" "$@" >/dev/null 2>/dev/null
;;
*)
case $DISTRNAME in
ALTLinux)
local INITFILE=/etc/init.d/$SERVICE
[ -r "$INITFILE" ] || return
return ;;
*)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;;
esac
esac
} }
# File bin/serv-list: # File bin/serv-list:
serv_list() serv_list()
{ {
info "Running services:" [ -n "$short" ] || info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
service-upstart) service-upstart)
sudocmd initctl list sudocmd initctl list
...@@ -753,7 +777,11 @@ serv_list() ...@@ -753,7 +777,11 @@ serv_list()
sudocmd service --status-all sudocmd service --status-all
;; ;;
systemd) systemd)
sudocmd systemctl list-units $@ if [ -n "$short" ] ; then
docmd systemctl list-units --type=service "$@" | grep '\.service' | sed -e 's|\.service.*||' -e 's|^ *||'
else
docmd systemctl list-units --type=service "$@"
fi
;; ;;
openrc) openrc)
sudocmd rc-status sudocmd rc-status
...@@ -774,22 +802,42 @@ serv_list_all() ...@@ -774,22 +802,42 @@ serv_list_all()
{ {
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora if [ -n "$short" ] ; then
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" | cut -f 1 -d" "
else
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$"
fi
if [ -n "$ANYSERVICE" ] ; then if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice --quiet list if [ -n "$short" ] ; then
sudocmd anyservice --quiet list | cut -f 1 -d" "
else
sudocmd anyservice --quiet list
fi
return return
fi fi
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd ls $INITDIR/ | grep -v README if [ -n "$short" ] ; then
sudocmd ls $INITDIR/ | grep -v README | cut -f 1 -d" "
else
sudocmd ls $INITDIR/ | grep -v README
fi
;; ;;
systemd) systemd)
sudocmd systemctl list-unit-files $@ if [ -n "$short" ] ; then
docmd systemctl list-unit-files --type=service "$@" | sed -e 's|\.service.*||' | grep -v 'unit files listed' | grep -v '^$'
else
docmd systemctl list-unit-files --type=service "$@"
fi
;; ;;
openrc) openrc)
sudocmd rc-service -l if [ -n "$short" ] ; then
sudocmd rc-service -l | cut -f 1 -d" "
else
sudocmd rc-service -l
fi
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
...@@ -806,13 +854,12 @@ serv_list_failed() ...@@ -806,13 +854,12 @@ serv_list_failed()
sudocmd systemctl --failed sudocmd systemctl --failed
;; ;;
*) *)
for i in $(serv_list_startup | cut -f 1 -d" ") ; do for i in $(short=1 serv_list_startup) ; do
is_service_running >/dev/null $i && continue is_service_running >/dev/null $i && continue
echo ; echo $i echo ; echo $i
serv_status $i serv_status $i
done done
;; ;;
esac esac
} }
...@@ -824,16 +871,15 @@ serv_list_startup() ...@@ -824,16 +871,15 @@ serv_list_startup()
systemd) systemd)
#sudocmd systemctl list-unit-files #sudocmd systemctl list-unit-files
# TODO: native command? implement --short for list (only names) # TODO: native command? implement --short for list (only names)
for i in $(serv_list_all | cut -f 1 -d" " | grep "\.service$") ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
*) *)
for i in $(serv_list_all | cut -f 1 -d" ") ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
esac esac
} }
...@@ -886,6 +932,29 @@ serv_log() ...@@ -886,6 +932,29 @@ serv_log()
esac esac
} }
# File bin/serv-off:
serv_off()
{
local SERVICE="$1"
is_service_running $1 && { serv_stop $1 || return ; }
is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; }
serv_disable $SERVICE
}
# File bin/serv-on:
serv_on()
{
serv_enable "$1" || return
# start if need
is_service_running $1 && info "Service $1 is already running" && return
serv_start $1
}
# File bin/serv-print: # File bin/serv-print:
serv_print() serv_print()
...@@ -1012,7 +1081,7 @@ is_service_running() ...@@ -1012,7 +1081,7 @@ is_service_running()
sudorun $INITDIR/$1 status >/dev/null 2>/dev/null sudorun $INITDIR/$1 status >/dev/null 2>/dev/null
;; ;;
systemd) systemd)
sudorun systemctl status $1 >/dev/null 2>/dev/null a='' systemctl status $1 >/dev/null 2>/dev/null
;; ;;
runit) runit)
sudorun sv status "$SERVICE" >/dev/null 2>/dev/null sudorun sv status "$SERVICE" >/dev/null 2>/dev/null
...@@ -1038,10 +1107,10 @@ is_service_autostart() ...@@ -1038,10 +1107,10 @@ is_service_autostart()
LANG=C sudorun chkconfig $1 --list | grep -q "[35]:on" LANG=C sudorun chkconfig $1 --list | grep -q "[35]:on"
;; ;;
service-initd|service-update) service-initd|service-update)
test -L "$(echo /etc/rc5.d/S??$1)" test -L "$(echo /etc/rc5.d/S??$1)"
;; ;;
systemd) systemd)
sudorun systemctl is-enabled $1 a='' systemctl is-enabled $1
;; ;;
runit) runit)
test -L "/var/service/$SERVICE" test -L "/var/service/$SERVICE"
...@@ -1071,7 +1140,7 @@ serv_status() ...@@ -1071,7 +1140,7 @@ serv_status()
sudocmd $INITDIR/$SERVICE status "$@" sudocmd $INITDIR/$SERVICE status "$@"
;; ;;
systemd) systemd)
sudocmd systemctl -l status $SERVICE "$@" docmd systemctl -l status $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv status "$SERVICE" sudocmd sv status "$SERVICE"
...@@ -2540,7 +2609,12 @@ esac ...@@ -2540,7 +2609,12 @@ esac
shift shift
# FIXME: do to call function directly, use case instead? # FIXME: do to call function directly, use case instead?
if [ "$1" = "-" ] ; then if [ "$COMMAND" = "--" ] ; then
# ignore all options (-)
COMMAND="$1"
shift
"$COMMAND" "$@"
elif [ "$1" = "-" ] ; then
shift shift
"$COMMAND" "$(cat) $@" "$COMMAND" "$(cat) $@"
elif [ "$2" = "-" ] ; then elif [ "$2" = "-" ] ; then
...@@ -2867,9 +2941,9 @@ print_version() ...@@ -2867,9 +2941,9 @@ print_version()
local on_text="(host system)" local on_text="(host system)"
local virt="$($DISTRVENDOR -i)" local virt="$($DISTRVENDOR -i)"
[ "$virt" = "(unknown)" ] || [ "$virt" = "(host system)" ] || on_text="(under $virt)" [ "$virt" = "(unknown)" ] || [ "$virt" = "(host system)" ] || on_text="(under $virt)"
echo "Service manager version 3.11.2 https://wiki.etersoft.ru/Epm" echo "Service manager version 3.13.0 https://wiki.etersoft.ru/Epm"
echo "Running on $($DISTRVENDOR -e) $on_text with $SERVICETYPE" echo "Running on $($DISTRVENDOR -e) $on_text with $SERVICETYPE"
echo "Copyright (c) Etersoft 2012-2019" echo "Copyright (c) Etersoft 2012-2021"
echo "This program may be freely redistributed under the terms of the GNU AGPLv3." echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
} }
...@@ -2882,6 +2956,7 @@ set_service_type ...@@ -2882,6 +2956,7 @@ set_service_type
verbose= verbose=
quiet= quiet=
short=
non_interactive= non_interactive=
show_command_only= show_command_only=
serv_cmd= serv_cmd=
...@@ -2913,10 +2988,16 @@ check_command() ...@@ -2913,10 +2988,16 @@ check_command()
stop) # HELPCMD: stop service stop) # HELPCMD: stop service
serv_cmd=stop serv_cmd=stop
;; ;;
on|enable) # HELPCMD: add service to run on startup and start it now on) # HELPCMD: add service to run on startup and start it now
serv_cmd=on
;;
off) # HELPCMD: remove service to run on startup and stop it now
serv_cmd=off
;;
enable) # HELPCMD: add service to run on startup (see 'on' also)
serv_cmd=enable serv_cmd=enable
;; ;;
off|disable) # HELPCMD: remove service to run on startup and stop it now disable) # HELPCMD: remove service to run on startup (see 'off' also)
serv_cmd=disable serv_cmd=disable
;; ;;
log|journal) # HELPCMD: print log for the service (-f - follow, -r - reverse order) log|journal) # HELPCMD: print log for the service (-f - follow, -r - reverse order)
...@@ -2925,6 +3006,9 @@ check_command() ...@@ -2925,6 +3006,9 @@ check_command()
cat) # HELPCMD: print out service file for the service cat) # HELPCMD: print out service file for the service
serv_cmd=cat serv_cmd=cat
;; ;;
exists) # HELPCMD: check if the service is installed on the system
serv_cmd=exists
;;
edit) # HELPCMD: edit service file overload (use --full to edit full file) edit) # HELPCMD: edit service file overload (use --full to edit full file)
serv_cmd=edit serv_cmd=edit
;; ;;
...@@ -2979,6 +3063,9 @@ check_option() ...@@ -2979,6 +3063,9 @@ check_option()
--verbose) # HELPOPT: verbose mode --verbose) # HELPOPT: verbose mode
verbose=1 verbose=1
;; ;;
--short) # HELPOPT: short mode
short=1
;;
--show-command-only) # HELPOPT: show command only, do not any action --show-command-only) # HELPOPT: show command only, do not any action
show_command_only=1 show_command_only=1
;; ;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment