Commit db3edf22 authored by Vitaly Lipatov's avatar Vitaly Lipatov

commit packed 3.50.0

parent 714d5b32
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -37,71 +37,71 @@ load_helper() ...@@ -37,71 +37,71 @@ load_helper()
inputisatty() inputisatty()
{ {
# check stdin # check stdin
#tty -s 2>/dev/null #tty -s 2>/dev/null
test -t 0 test -t 0
} }
isatty() isatty()
{ {
# check stdout # check stdout
test -t 1 test -t 1
} }
isatty2() isatty2()
{ {
# check stderr # check stderr
test -t 2 test -t 2
} }
check_tty() check_tty()
{ {
isatty2 || return isatty2 || return
# Set a sane TERM required for tput # Set a sane TERM required for tput
[ -n "$TERM" ] || TERM=dumb [ -n "$TERM" ] || TERM=dumb
export TERM export TERM
check_core_commands check_core_commands
# grep -E from busybox may not --color # grep -E from busybox may not --color
# grep -E from MacOS print help to stderr # grep -E from MacOS print help to stderr
if grep -E --help 2>&1 | grep -q -- "--color" ; then if grep -E --help 2>&1 | grep -q -- "--color" ; then
export EGREPCOLOR="--color" export EGREPCOLOR="--color"
fi fi
is_command tput || return is_command tput || return
# FreeBSD does not support tput -S # FreeBSD does not support tput -S
echo | a= tput -S >/dev/null 2>/dev/null || return echo | a= tput -S >/dev/null 2>/dev/null || return
USETTY="tput -S" USETTY="tput -S"
} }
: ${BLACK:=0} ${RED:=1} ${GREEN:=2} ${YELLOW:=3} ${BLUE:=4} ${MAGENTA:=5} ${CYAN:=6} ${WHITE:=7} : ${BLACK:=0} ${RED:=1} ${GREEN:=2} ${YELLOW:=3} ${BLUE:=4} ${MAGENTA:=5} ${CYAN:=6} ${WHITE:=7}
set_boldcolor() set_boldcolor()
{ {
[ -n "$USETTY" ] || return [ -n "$USETTY" ] || return
{ {
echo bold echo bold
echo setaf $1 echo setaf $1
} | $USETTY } | $USETTY
} }
set_color() set_color()
{ {
[ -n "$USETTY" ] || return [ -n "$USETTY" ] || return
{ {
echo setaf $1 echo setaf $1
} | $USETTY } | $USETTY
} }
restore_color() restore_color()
{ {
[ -n "$USETTY" ] || return [ -n "$USETTY" ] || return
{ {
echo op; # set Original color Pair. echo op; # set Original color Pair.
echo sgr0; # turn off all special graphics mode (bold in our case). echo sgr0; # turn off all special graphics mode (bold in our case).
} | $USETTY } | $USETTY
} }
echover() echover()
...@@ -112,117 +112,117 @@ echover() ...@@ -112,117 +112,117 @@ echover()
echon() echon()
{ {
# default /bin/sh on MacOS does not recognize -n # default /bin/sh on MacOS does not recognize -n
echo -n "$*" 2>/dev/null || a= /bin/echo -n "$*" echo -n "$*" 2>/dev/null || a= /bin/echo -n "$*"
} }
set_target_pkg_env() set_target_pkg_env()
{ {
[ -n "$DISTRNAME" ] || fatal "Missing DISTRNAME in set_target_pkg_env." [ -n "$DISTRNAME" ] || fatal "Missing DISTRNAME in set_target_pkg_env."
local ver="$DISTRVERSION" local ver="$DISTRVERSION"
[ -n "$ver" ] && ver="/$ver" [ -n "$ver" ] && ver="/$ver"
PKGFORMAT=$($DISTRVENDOR -p "$DISTRNAME$ver") PKGFORMAT=$($DISTRVENDOR -p "$DISTRNAME$ver")
PKGVENDOR=$($DISTRVENDOR -s "$DISTRNAME$ver") PKGVENDOR=$($DISTRVENDOR -s "$DISTRNAME$ver")
RPMVENDOR=$($DISTRVENDOR -n "$DISTRNAME$ver") RPMVENDOR=$($DISTRVENDOR -n "$DISTRNAME$ver")
} }
showcmd() showcmd()
{ {
if [ -z "$quiet" ] ; then if [ -z "$quiet" ] ; then
set_boldcolor $GREEN set_boldcolor $GREEN
local PROMTSIG="\$" local PROMTSIG="\$"
is_root && PROMTSIG="#" is_root && PROMTSIG="#"
echo " $PROMTSIG $*" echo " $PROMTSIG $*"
restore_color restore_color
fi >&2 fi >&2
} }
echocmd() echocmd()
{ {
set_boldcolor $GREEN set_boldcolor $GREEN
local PROMTSIG="\$" local PROMTSIG="\$"
is_root && PROMTSIG="#" is_root && PROMTSIG="#"
echo -n "$PROMTSIG $*" echo -n "$PROMTSIG $*"
restore_color restore_color
} }
docmd() docmd()
{ {
showcmd "$*$EXTRA_SHOWDOCMD" showcmd "$*$EXTRA_SHOWDOCMD"
"$@" "$@"
} }
docmd_foreach() docmd_foreach()
{ {
local cmd pkg local cmd pkg
cmd="$1" cmd="$1"
#showcmd "$@" #showcmd "$@"
shift shift
for pkg in "$@" ; do for pkg in "$@" ; do
docmd $cmd $pkg docmd $cmd $pkg
done done
} }
sudorun() sudorun()
{ {
set_sudo set_sudo
if [ -z "$SUDO" ] ; then if [ -z "$SUDO" ] ; then
"$@" "$@"
return return
fi fi
$SUDO "$@" $SUDO "$@"
} }
sudocmd() sudocmd()
{ {
set_sudo set_sudo
[ -n "$SUDO" ] && showcmd "$SUDO $*" || showcmd "$*" [ -n "$SUDO" ] && showcmd "$SUDO $*" || showcmd "$*"
sudorun "$@" sudorun "$@"
} }
sudocmd_foreach() sudocmd_foreach()
{ {
local cmd pkg local cmd pkg
cmd="$1" cmd="$1"
#showcmd "$@" #showcmd "$@"
shift shift
for pkg in "$@" ; do for pkg in "$@" ; do
# don't quote $cmd here: it can be a command with an args # don't quote $cmd here: it can be a command with an args
sudocmd $cmd $pkg || return sudocmd $cmd $pkg || return
done done
} }
make_filepath() make_filepath()
{ {
local i local i
for i in "$@" ; do for i in "$@" ; do
[ -f "$i" ] || continue [ -f "$i" ] || continue
echo "$i" | grep -q "/" && echo "$i" && continue echo "$i" | grep -q "/" && echo "$i" && continue
echo "./$i" echo "./$i"
done done
} }
get_firstarg() get_firstarg()
{ {
echon "$1" echon "$1"
} }
get_lastarg() get_lastarg()
{ {
local lastarg local lastarg
eval "lastarg=\${$#}" eval "lastarg=\${$#}"
echon "$lastarg" echon "$lastarg"
} }
isnumber() isnumber()
{ {
echo "$*" | filter_strip_spaces | grep -q "^[0-9]\+$" echo "$*" | filter_strip_spaces | grep -q "^[0-9]\+$"
} }
rhas() rhas()
{ {
echo "$1" | grep -E -q -- "$2" echo "$1" | grep -E -q -- "$2"
} }
is_dirpath() is_dirpath()
...@@ -247,13 +247,13 @@ strip_spaces() ...@@ -247,13 +247,13 @@ strip_spaces()
sed_escape() sed_escape()
{ {
echo "$*" | sed -e 's/[]()$*.^|[]/\\&/g' echo "$*" | sed -e 's/[]()$*.^|[]/\\&/g'
} }
subst_option() subst_option()
{ {
eval "[ -n \"\$$1\" ]" && echo "$2" || echo "$3" eval "[ -n \"\$$1\" ]" && echo "$2" || echo "$3"
} }
store_output() store_output()
...@@ -283,150 +283,150 @@ clean_store_output() ...@@ -283,150 +283,150 @@ clean_store_output()
epm() epm()
{ {
if [ -n "$PROGNAME" ] ; then if [ -n "$PROGNAME" ] ; then
local bashopt='' local bashopt=''
[ -n "$verbose" ] && bashopt='-x' [ -n "$verbose" ] && bashopt='-x'
$CMDSHELL $bashopt $PROGDIR/$PROGNAME --inscript "$@" $CMDSHELL $bashopt $PROGDIR/$PROGNAME --inscript "$@"
else else
epm_main --inscript "$@" epm_main --inscript "$@"
fi fi
} }
sudoepm() sudoepm()
{ {
[ -n "$PROGNAME" ] || fatal "Can't use sudo epm call from the piped script" [ -n "$PROGNAME" ] || fatal "Can't use sudo epm call from the piped script"
local bashopt='' local bashopt=''
[ -n "$verbose" ] && bashopt='-x' [ -n "$verbose" ] && bashopt='-x'
sudorun $CMDSHELL $bashopt $PROGDIR/$PROGNAME --inscript "$@" sudorun $CMDSHELL $bashopt $PROGDIR/$PROGNAME --inscript "$@"
} }
fatal() fatal()
{ {
if [ -z "$TEXTDOMAIN" ] ; then if [ -z "$TEXTDOMAIN" ] ; then
echo "Error: $* (you can discuss the problem in Telegram: https://t.me/useepm)" >&2 echo "Error: $* (you can discuss the problem in Telegram: https://t.me/useepm)" >&2
fi fi
exit 1 exit 1
} }
warning() warning()
{ {
if [ -z "$TEXTDOMAIN" ] ; then if [ -z "$TEXTDOMAIN" ] ; then
echo "Warning: $*" >&2 echo "Warning: $*" >&2
fi fi
} }
info() info()
{ {
[ -n "$quiet" ] && return [ -n "$quiet" ] && return
# print message to stderr if stderr forwarded to (a file) # print message to stderr if stderr forwarded to (a file)
if isatty2 ; then if isatty2 ; then
isatty || return 0 isatty || return 0
echo "$*" echo "$*"
else else
echo "$*" >&2 echo "$*" >&2
fi fi
} }
SUDO_TESTED='' SUDO_TESTED=''
SUDO_CMD='sudo' SUDO_CMD='sudo'
set_sudo() set_sudo()
{ {
local nofail="$1" local nofail="$1"
# cache the result # cache the result
[ -n "$SUDO_TESTED" ] && return "$SUDO_TESTED" [ -n "$SUDO_TESTED" ] && return "$SUDO_TESTED"
SUDO_TESTED="0" SUDO_TESTED="0"
SUDO="" SUDO=""
# skip SUDO if disabled # skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return [ -n "$EPMNOSUDO" ] && return
if [ "$DISTRNAME" = "Cygwin" ] || [ "$DISTRNAME" = "Windows" ] ; then if [ "$DISTRNAME" = "Cygwin" ] || [ "$DISTRNAME" = "Windows" ] ; then
# skip sudo using on Windows # skip sudo using on Windows
return return
fi fi
# if we are root, do not need sudo # if we are root, do not need sudo
is_root && return is_root && return
# start error section # start error section
SUDO_TESTED="1" SUDO_TESTED="1"
if ! is_command $SUDO_CMD ; then if ! is_command $SUDO_CMD ; then
[ "$nofail" = "nofail" ] || 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 "$SUDO_TESTED" 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
[ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only passwordless sudo is supported in non interactive using). Please run epm under root.'" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only passwordless sudo is supported in non interactive using). Please run epm under root.'"
return "$SUDO_TESTED" 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
[ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only passwordless sudo is supported). Please run epm under root or check http://altlinux.org/sudo '" [ "$nofail" = "nofail" ] || SUDO="fatal 'Can't use sudo (only passwordless sudo is supported). Please run epm under root or check http://altlinux.org/sudo '"
return "$SUDO_TESTED" return "$SUDO_TESTED"
fi fi
fi fi
SUDO_TESTED="0" SUDO_TESTED="0"
# FIXME: does not work: sudo -- VARIABLE=some command # FIXME: does not work: sudo -- VARIABLE=some command
SUDO="$SUDO_CMD" SUDO="$SUDO_CMD"
#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"
} }
sudo_allowed() sudo_allowed()
{ {
set_sudo nofail set_sudo nofail
} }
withtimeout() withtimeout()
{ {
local TO=$(print_command_path timeout || print_command_path gtimeout) local TO=$(print_command_path timeout || print_command_path gtimeout)
if [ -x "$TO" ] ; then if [ -x "$TO" ] ; then
$TO "$@" $TO "$@"
return return
fi fi
fatal "Possible indefinite wait due timeout command is missed" fatal "Possible indefinite wait due timeout command is missed"
# fallback: drop time arg and run without timeout # fallback: drop time arg and run without timeout
#shift #shift
#"$@" #"$@"
} }
set_eatmydata() set_eatmydata()
{ {
# don't use eatmydata (useless) # don't use eatmydata (useless)
return 0 return 0
# skip if disabled # skip if disabled
[ -n "$EPMNOEATMYDATA" ] && return [ -n "$EPMNOEATMYDATA" ] && return
# use if possible # use if possible
is_command eatmydata || return is_command eatmydata || return
set_sudo set_sudo
# FIXME: check if SUDO already has eatmydata # FIXME: check if SUDO already has eatmydata
[ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata" [ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata"
[ -n "$verbose" ] && info "Uwaga! eatmydata is installed, we will use it for disable all sync operations." [ -n "$verbose" ] && info "Uwaga! eatmydata is installed, we will use it for disable all sync operations."
return 0 return 0
} }
__get_package_for_command() __get_package_for_command()
{ {
case "$1" in case "$1" in
equery|revdep-rebuild) equery|revdep-rebuild)
echo 'gentoolkit' echo 'gentoolkit'
;; ;;
update-kernel|remove-old-kernels) update-kernel|remove-old-kernels)
echo 'update-kernel' echo 'update-kernel'
;; ;;
esac esac
} }
confirm() { confirm() {
...@@ -446,160 +446,160 @@ confirm() { ...@@ -446,160 +446,160 @@ confirm() {
confirm_info() confirm_info()
{ {
info "$*" info "$*"
if [ -z "$non_interactive" ] ; then if [ -z "$non_interactive" ] ; then
confirm "Are you sure? [y/N]" || fatal "Exiting" confirm "Are you sure? [y/N]" || fatal "Exiting"
fi fi
} }
is_root() is_root()
{ {
local EFFUID="$(id -u)" local EFFUID="$(id -u)"
[ "$EFFUID" = "0" ] [ "$EFFUID" = "0" ]
} }
assure_root() assure_root()
{ {
is_root || fatal "run me only under root" is_root || fatal "run me only under root"
} }
regexp_subst() regexp_subst()
{ {
local expression="$1" local expression="$1"
shift shift
sed -i -r -e "$expression" "$@" sed -i -r -e "$expression" "$@"
} }
assure_exists() assure_exists()
{ {
local package="$2" local package="$2"
local textpackage= local textpackage=
[ -n "$package" ] || package="$(__get_package_for_command "$1")" [ -n "$package" ] || package="$(__get_package_for_command "$1")"
[ -n "$3" ] && textpackage=" >= $3" [ -n "$3" ] && textpackage=" >= $3"
( direct='' epm_assure "$1" $package $3 ) || fatal "Can't assure in '$1' command from $package$textpackage package" ( direct='' epm_assure "$1" $package $3 ) || fatal "Can't assure in '$1' command from $package$textpackage package"
} }
assure_exists_erc() assure_exists_erc()
{ {
local package="erc" local package="erc"
( direct='' epm_assure "$package" ) || epm ei erc || fatal "erc is not available to install." ( direct='' epm_assure "$package" ) || epm ei erc || fatal "erc is not available to install."
} }
disabled_eget() disabled_eget()
{ {
local EGET local EGET
# use internal eget only if exists # use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@" ( EGET_BACKEND=$eget_backend $SHAREDIR/tools_eget "$@" )
return return
fi fi
fatal "Internal error: missed tools_eget" fatal "Internal error: missed tools_eget"
# FIXME: we need disable output here, eget can be used for get output # FIXME: we need disable output here, eget can be used for get output
assure_exists eget eget 3.3 >/dev/null assure_exists eget eget 3.3 >/dev/null
# run external command, not the function # run external command, not the function
EGET=$(print_command_path eget) || fatal "Missed command eget from installed package eget" EGET=$(print_command_path eget) || fatal "Missed command eget from installed package eget"
$EGET "$@" $EGET "$@"
} }
disabled_erc() disabled_erc()
{ {
local ERC local ERC
# use internal eget only if exists # use internal eget only if exists
if [ -s $SHAREDIR/tools_erc ] ; then if [ -s $SHAREDIR/tools_erc ] ; then
$SHAREDIR/tools_erc "$@" $SHAREDIR/tools_erc "$@"
return return
fi fi
fatal "Internal error: missed tools_erc" fatal "Internal error: missed tools_erc"
# FIXME: we need disable output here, ercat can be used for get output # FIXME: we need disable output here, ercat can be used for get output
assure_exists_erc >/dev/null assure_exists_erc >/dev/null
# run external command, not the function # run external command, not the function
ERC=$(print_command_path erc) || fatal "Missed command erc from installed package erc" ERC=$(print_command_path erc) || fatal "Missed command erc from installed package erc"
$ERC "$@" $ERC "$@"
} }
disabled_ercat() disabled_ercat()
{ {
local ERCAT local ERCAT
# use internal eget only if exists # use internal eget only if exists
if [ -s $SHAREDIR/tools_ercat ] ; then if [ -s $SHAREDIR/tools_ercat ] ; then
$SHAREDIR/tools_ercat "$@" $SHAREDIR/tools_ercat "$@"
return return
fi fi
fatal "Internal error: missed tools_ercat" fatal "Internal error: missed tools_ercat"
# FIXME: we need disable output here, ercat can be used for get output # FIXME: we need disable output here, ercat can be used for get output
assure_exists_erc >/dev/null assure_exists_erc >/dev/null
# run external command, not the function # run external command, not the function
ERCAT=$(print_command_path ercat) || fatal "Missed command ercat from installed package erc" ERCAT=$(print_command_path ercat) || fatal "Missed command ercat from installed package erc"
$ERCAT "$@" $ERCAT "$@"
} }
disabled_estrlist() disabled_estrlist()
{ {
if [ -s $SHAREDIR/tools_estrlist ] ; then if [ -s $SHAREDIR/tools_estrlist ] ; then
$SHAREDIR/tools_estrlist "$@" $SHAREDIR/tools_estrlist "$@"
return return
fi fi
fatal "missed tools_estrlist" fatal "missed tools_estrlist"
} }
estrlist() estrlist()
{ {
internal_tools_estrlist "$@" internal_tools_estrlist "$@"
} }
eget() eget()
{ {
# check for both # check for both
# we really need that cross here, # we really need that cross here,
is_command curl || assure_exists wget is_command curl || assure_exists wget
is_command wget || assure_exists curl is_command wget || assure_exists curl
internal_tools_eget "$@" internal_tools_eget "$@"
} }
get_package_type() get_package_type()
{ {
local i local i
case $1 in case $1 in
*.deb) *.deb)
echo "deb" echo "deb"
return return
;; ;;
*.rpm) *.rpm)
echo "rpm" echo "rpm"
return return
;; ;;
*.txz) *.txz)
echo "txz" echo "txz"
return return
;; ;;
*.tbz) *.tbz)
echo "tbz" echo "tbz"
return return
;; ;;
*.exe) *.exe)
echo "exe" echo "exe"
return return
;; ;;
*.msi) *.msi)
echo "msi" echo "msi"
return return
;; ;;
*.AppImage) *.AppImage)
echo "AppImage" echo "AppImage"
return return
;; ;;
*) *)
#fatal "Don't know type of $1" #fatal "Don't know type of $1"
# return package name for info # return package name for info
echo "$1" echo "$1"
return 1 return 1
;; ;;
esac esac
} }
...@@ -628,50 +628,50 @@ get_help() ...@@ -628,50 +628,50 @@ get_help()
set_distro_info() set_distro_info()
{ {
# use external distro_info if internal one is missed # use external distro_info if internal one is missed
DISTRVENDOR=internal_distr_info DISTRVENDOR=internal_distr_info
[ -x $DISTRVENDOR ] || DISTRVENDOR=internal_distr_info [ -x $DISTRVENDOR ] || DISTRVENDOR=internal_distr_info
export DISTRVENDOR export DISTRVENDOR
[ -n "$DISTRNAME" ] || DISTRNAME=$($DISTRVENDOR -d) || fatal "Can't get distro name." [ -n "$DISTRNAME" ] || DISTRNAME=$($DISTRVENDOR -d) || fatal "Can't get distro name."
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v) [ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
if [ -z "$DISTRARCH" ] ; then if [ -z "$DISTRARCH" ] ; then
DISTRARCH=$($DISTRVENDOR --distro-arch) DISTRARCH=$($DISTRVENDOR --distro-arch)
fi fi
DISTRCONTROL="$($DISTRVENDOR -y)" DISTRCONTROL="$($DISTRVENDOR -y)"
[ -n "$BASEDISTRNAME" ] || BASEDISTRNAME=$($DISTRVENDOR -s) [ -n "$BASEDISTRNAME" ] || BASEDISTRNAME=$($DISTRVENDOR -s)
# TODO: improve BIGTMPDIR conception # TODO: improve BIGTMPDIR conception
# https://bugzilla.mozilla.org/show_bug.cgi?id=69938 # https://bugzilla.mozilla.org/show_bug.cgi?id=69938
# https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s15.html # https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch05s15.html
# https://geekpeach.net/ru/%D0%BA%D0%B0%D0%BA-systemd-tmpfiles-%D0%BE%D1%87%D0%B8%D1%89%D0%B0%D0%B5%D1%82-tmp-%D0%B8%D0%BB%D0%B8-var-tmp-%D0%B7%D0%B0%D0%BC%D0%B5%D0%BD%D0%B0-tmpwatch-%D0%B2-centos-rhel-7 # https://geekpeach.net/ru/%D0%BA%D0%B0%D0%BA-systemd-tmpfiles-%D0%BE%D1%87%D0%B8%D1%89%D0%B0%D0%B5%D1%82-tmp-%D0%B8%D0%BB%D0%B8-var-tmp-%D0%B7%D0%B0%D0%BC%D0%B5%D0%BD%D0%B0-tmpwatch-%D0%B2-centos-rhel-7
[ -n "$BIGTMPDIR" ] || [ -d "/var/tmp" ] && BIGTMPDIR="/var/tmp" || BIGTMPDIR="/tmp" [ -n "$BIGTMPDIR" ] || [ -d "/var/tmp" ] && BIGTMPDIR="/var/tmp" || BIGTMPDIR="/tmp"
} }
set_pm_type() set_pm_type()
{ {
local CMD local CMD
set_distro_info set_distro_info
set_target_pkg_env set_target_pkg_env
if [ -n "$FORCEPM" ] ; then if [ -n "$FORCEPM" ] ; then
PMTYPE=$FORCEPM PMTYPE=$FORCEPM
return return
fi fi
PMTYPE="$($DISTRVENDOR -g $DISTRNAME/$DISTRVERSION)" PMTYPE="$($DISTRVENDOR -g $DISTRNAME/$DISTRVERSION)"
} }
is_active_systemd() is_active_systemd()
{ {
[ "$DISTRCONTROL" = "systemd" ] [ "$DISTRCONTROL" = "systemd" ]
} }
assure_distr() assure_distr()
{ {
local TEXT="this option" local TEXT="this option"
[ -n "$2" ] && TEXT="$2" [ -n "$2" ] && TEXT="$2"
[ "$DISTRNAME" = "$1" ] || fatal "$TEXT supported only for $1 distro" [ "$DISTRNAME" = "$1" ] || fatal "$TEXT supported only for $1 distro"
} }
get_pkg_name_delimiter() get_pkg_name_delimiter()
...@@ -762,9 +762,9 @@ fi ...@@ -762,9 +762,9 @@ fi
check_core_commands() check_core_commands()
{ {
#which which >/dev/null || fatal "Can't find which command (which or debianutils package is missed?)" #which which >/dev/null || fatal "Can't find which command (which or debianutils package is missed?)"
is_command grep || fatal "Can't find grep command (coreutils package is missed?)" is_command grep || fatal "Can't find grep command (coreutils package is missed?)"
is_command sed || fatal "Can't find sed command (sed package is missed?)" is_command sed || fatal "Can't find sed command (sed package is missed?)"
} }
...@@ -772,58 +772,58 @@ check_core_commands() ...@@ -772,58 +772,58 @@ check_core_commands()
serv_cat() serv_cat()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
docmd systemctl cat "$SERVICE" "$@" docmd systemctl cat "$SERVICE" "$@"
;; ;;
*) *)
case $BASEDISTRNAME in case $BASEDISTRNAME in
"alt") "alt")
local INITFILE=/etc/init.d/$SERVICE local INITFILE=/etc/init.d/$SERVICE
[ -r "$INITFILE" ] || fatal "Can't find init file $INITFILE" [ -r "$INITFILE" ] || fatal "Can't find init file $INITFILE"
docmd cat $INITFILE docmd cat $INITFILE
return ;; return ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
esac esac
} }
# File bin/serv-common: # File bin/serv-common:
serv_common() serv_common()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
fatal "Have no idea how to call anyservice service with args" fatal "Have no idea how to call anyservice service with args"
fi fi
sudocmd service $SERVICE "$@" sudocmd service $SERVICE "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE "$@" sudocmd $INITDIR/$SERVICE "$@"
;; ;;
systemd) systemd)
# run init script directly (for nonstandart commands) # run init script directly (for nonstandart commands)
if [ -x $INITDIR/$SERVICE ] ; then if [ -x $INITDIR/$SERVICE ] ; then
sudocmd $INITDIR/$SERVICE "$@" sudocmd $INITDIR/$SERVICE "$@"
else else
sudocmd systemctl "$@" $SERVICE sudocmd systemctl "$@" $SERVICE
fi fi
;; ;;
runit) runit)
sudocmd sv $SERVICE "$@" sudocmd sv $SERVICE "$@"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-disable: # File bin/serv-disable:
...@@ -831,51 +831,51 @@ serv_common() ...@@ -831,51 +831,51 @@ serv_common()
serv_disable() serv_disable()
{ {
local SERVICE="$1" local SERVICE="$1"
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
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE off sudocmd anyservice $SERVICE off
return return
fi fi
sudocmd chkconfig $1 off sudocmd chkconfig $1 off
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd update-rc.d $1 remove sudocmd update-rc.d $1 remove
;; ;;
systemd) systemd)
sudocmd systemctl disable $1 sudocmd systemctl disable $1
;; ;;
openrc) openrc)
sudocmd rc-update del $1 default sudocmd rc-update del $1 default
;; ;;
runit) runit)
sudocmd rm -fv /var/service/$SERVICE sudocmd rm -fv /var/service/$SERVICE
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-edit: # File bin/serv-edit:
serv_edit() serv_edit()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd systemctl edit "$@" "$SERVICE" sudocmd systemctl edit "$@" "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-enable: # File bin/serv-enable:
...@@ -883,234 +883,234 @@ serv_edit() ...@@ -883,234 +883,234 @@ serv_edit()
serv_enable() serv_enable()
{ {
local SERVICE="$1" local SERVICE="$1"
is_service_autostart $1 && info "Service $1 is already enabled for startup" && return is_service_autostart $1 && info "Service $1 is already enabled for startup" && return
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig) service-chkconfig)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE on sudocmd anyservice $SERVICE on
return return
fi fi
sudocmd chkconfig --add $1 || return sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
service-upstart) service-upstart)
sudocmd chkconfig --add $1 || return sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd update-rc.d $1 defaults sudocmd update-rc.d $1 defaults
;; ;;
systemd) systemd)
sudocmd systemctl enable $1 sudocmd systemctl enable $1
;; ;;
openrc) openrc)
sudocmd rc-update add $1 default sudocmd rc-update add $1 default
;; ;;
runit) runit)
assure_exists $SERVICE assure_exists $SERVICE
[ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE" [ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE"
sudocmd ln -s /etc/sv/$SERVICE /var/service/ sudocmd ln -s /etc/sv/$SERVICE /var/service/
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-exists: # File bin/serv-exists:
serv_exists() serv_exists()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
# too direct way: test -s /lib/systemd/system/dm.service # too direct way: test -s /lib/systemd/system/dm.service
docmd systemctl cat "$SERVICE" "$@" >/dev/null 2>/dev/null docmd systemctl cat "$SERVICE" "$@" >/dev/null 2>/dev/null
;; ;;
*) *)
case $BASEDISTRNAME in case $BASEDISTRNAME in
"alt") "alt")
local INITFILE=/etc/init.d/$SERVICE local INITFILE=/etc/init.d/$SERVICE
[ -r "$INITFILE" ] || return [ -r "$INITFILE" ] || return
return ;; return ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
esac esac
} }
# File bin/serv-list: # File bin/serv-list:
serv_list() serv_list()
{ {
[ -n "$short" ] || info "Running services:" [ -n "$short" ] || info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
service-upstart) service-upstart)
sudocmd initctl list sudocmd initctl list
;; ;;
service-update) service-update)
sudocmd service --status-all sudocmd service --status-all
;; ;;
systemd) systemd)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
docmd systemctl list-units --type=service "$@" | grep '\.service' | sed -e 's|\.service.*||' -e 's|^ *||' docmd systemctl list-units --type=service "$@" | grep '\.service' | sed -e 's|\.service.*||' -e 's|^ *||'
else else
docmd systemctl list-units --type=service "$@" docmd systemctl list-units --type=service "$@"
fi fi
;; ;;
openrc) openrc)
sudocmd rc-status sudocmd rc-status
;; ;;
*) *)
# hack to improve list speed # hack to improve list speed
[ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; } [ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; }
for i in $(quiet=1 serv_list_all) ; do for i in $(quiet=1 serv_list_all) ; do
is_service_running $i >/dev/null && echo $i is_service_running $i >/dev/null && echo $i
done done
;; ;;
esac esac
} }
# File bin/serv-list_all: # File bin/serv-list_all:
serv_list_all() serv_list_all()
{ {
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
# service --status-all for Ubuntu/Fedora # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" | cut -f 1 -d" " sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" | cut -f 1 -d" "
else else
# service --status-all for Ubuntu/Fedora # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$" sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$"
fi fi
if [ -n "$ANYSERVICE" ] ; then if [ -n "$ANYSERVICE" ] ; then
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
sudocmd anyservice --quiet list | cut -f 1 -d" " sudocmd anyservice --quiet list | cut -f 1 -d" "
else else
sudocmd anyservice --quiet list sudocmd anyservice --quiet list
fi fi
return return
fi fi
;; ;;
service-initd|service-update) service-initd|service-update)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
sudocmd ls $INITDIR/ | grep -v README | cut -f 1 -d" " sudocmd ls $INITDIR/ | grep -v README | cut -f 1 -d" "
else else
sudocmd ls $INITDIR/ | grep -v README sudocmd ls $INITDIR/ | grep -v README
fi fi
;; ;;
systemd) systemd)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
docmd systemctl list-unit-files --type=service "$@" | sed -e 's|\.service.*||' | grep -v 'unit files listed' | grep -v '^$' docmd systemctl list-unit-files --type=service "$@" | sed -e 's|\.service.*||' | grep -v 'unit files listed' | grep -v '^$'
else else
docmd systemctl list-unit-files --type=service "$@" docmd systemctl list-unit-files --type=service "$@"
fi fi
;; ;;
openrc) openrc)
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
sudocmd rc-service -l | cut -f 1 -d" " sudocmd rc-service -l | cut -f 1 -d" "
else else
sudocmd rc-service -l sudocmd rc-service -l
fi fi
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-list_failed: # File bin/serv-list_failed:
serv_list_failed() serv_list_failed()
{ {
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd systemctl --failed sudocmd systemctl --failed
;; ;;
*) *)
for i in $(short=1 serv_list_startup) ; 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
} }
# File bin/serv-list_startup: # File bin/serv-list_startup:
serv_list_startup() serv_list_startup()
{ {
case $SERVICETYPE in case $SERVICETYPE in
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 $(short=1 serv_list_all) ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null 2>/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
*) *)
for i in $(short=1 serv_list_all) ; do for i in $(short=1 serv_list_all) ; do
is_service_autostart >/dev/null 2>/dev/null $i && echo $i is_service_autostart >/dev/null 2>/dev/null $i && echo $i
done done
;; ;;
esac esac
} }
# File bin/serv-log: # File bin/serv-log:
__serv_log_altlinux() __serv_log_altlinux()
{ {
local SERVICE="$1" local SERVICE="$1"
local PRG="less" local PRG="less"
[ "$2" = "-f" ] && PRG="tail -f" [ "$2" = "-f" ] && PRG="tail -f"
case "$SERVICE" in case "$SERVICE" in
postfix) postfix)
sudocmd $PRG /var/log/mail/all /var/log/mail/errors sudocmd $PRG /var/log/mail/all /var/log/mail/errors
;; ;;
sshd) sshd)
sudocmd $PRG /var/log/auth/all sudocmd $PRG /var/log/auth/all
;; ;;
cups) cups)
sudocmd $PRG /var/log/cups/access_log /var/log/cups/error_log sudocmd $PRG /var/log/cups/access_log /var/log/cups/error_log
;; ;;
fail2ban) fail2ban)
sudocmd $PRG /var/log/$SERVICE.log sudocmd $PRG /var/log/$SERVICE.log
;; ;;
*) *)
fatal "Have no suitable for $SERVICE service" fatal "Have no suitable for $SERVICE service"
;; ;;
esac esac
} }
serv_log() serv_log()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd journalctl -b -u "$SERVICE" "$@" sudocmd journalctl -b -u "$SERVICE" "$@"
;; ;;
*) *)
case $BASEDISTRNAME in case $BASEDISTRNAME in
"alt") "alt")
FF="" ; [ "$1" = "-f" ] && FF="-f" FF="" ; [ "$1" = "-f" ] && FF="-f"
__serv_log_altlinux "$SERVICE" $FF __serv_log_altlinux "$SERVICE" $FF
return ;; return ;;
*) *)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE" fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;; ;;
esac esac
esac esac
} }
# File bin/serv-off: # File bin/serv-off:
...@@ -1118,11 +1118,11 @@ serv_log() ...@@ -1118,11 +1118,11 @@ serv_log()
serv_off() serv_off()
{ {
local SERVICE="$1" local SERVICE="$1"
is_service_running $1 && { serv_stop $1 || return ; } 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 ; }
serv_disable $SERVICE serv_disable $SERVICE
} }
# File bin/serv-on: # File bin/serv-on:
...@@ -1130,18 +1130,18 @@ serv_off() ...@@ -1130,18 +1130,18 @@ serv_off()
serv_on() serv_on()
{ {
serv_enable "$1" || return serv_enable "$1" || return
# start if need # start if need
is_service_running $1 && info "Service $1 is already running" && return is_service_running $1 && info "Service $1 is already running" && return
serv_start $1 serv_start $1
} }
# File bin/serv-print: # File bin/serv-print:
serv_print() serv_print()
{ {
echo "Detected init system: $SERVICETYPE" echo "Detected init system: $SERVICETYPE"
[ -n "$ANYSERVICE" ] && echo "anyservice is detected too" [ -n "$ANYSERVICE" ] && echo "anyservice is detected too"
} }
# File bin/serv-reload: # File bin/serv-reload:
...@@ -1149,28 +1149,28 @@ serv_print() ...@@ -1149,28 +1149,28 @@ serv_print()
serv_reload() serv_reload()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE reload sudocmd anyservice $SERVICE reload
return return
fi fi
sudocmd service $SERVICE reload "$@" sudocmd service $SERVICE reload "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE reload "$@" sudocmd $INITDIR/$SERVICE reload "$@"
;; ;;
systemd) systemd)
sudocmd systemctl reload $SERVICE "$@" sudocmd systemctl reload $SERVICE "$@"
;; ;;
*) *)
info "Fallback to restart..." info "Fallback to restart..."
serv_restart "$SERVICE" "$@" serv_restart "$SERVICE" "$@"
;; ;;
esac esac
} }
# File bin/serv-restart: # File bin/serv-restart:
...@@ -1178,224 +1178,224 @@ serv_reload() ...@@ -1178,224 +1178,224 @@ serv_reload()
serv_restart() serv_restart()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE restart sudocmd anyservice $SERVICE restart
return return
fi fi
sudocmd service $SERVICE restart "$@" sudocmd service $SERVICE restart "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE restart "$@" sudocmd $INITDIR/$SERVICE restart "$@"
;; ;;
systemd) systemd)
sudocmd systemctl restart $SERVICE "$@" sudocmd systemctl restart $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv restart "$SERVICE" sudocmd sv restart "$SERVICE"
;; ;;
openrc) openrc)
sudocmd rc-service restart "$SERVICE" sudocmd rc-service restart "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-start: # File bin/serv-start:
serv_start() serv_start()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE start sudocmd anyservice $SERVICE start
return return
fi fi
sudocmd service $SERVICE start "$@" sudocmd service $SERVICE start "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE start "$@" sudocmd $INITDIR/$SERVICE start "$@"
;; ;;
systemd) systemd)
sudocmd systemctl start "$SERVICE" "$@" sudocmd systemctl start "$SERVICE" "$@"
;; ;;
runit) runit)
sudocmd sv up "$SERVICE" sudocmd sv up "$SERVICE"
;; ;;
openrc) openrc)
sudocmd rc-service start "$SERVICE" sudocmd rc-service start "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-status: # File bin/serv-status:
is_service_running() is_service_running()
{ {
local SERVICE="$1" local SERVICE="$1"
local OUTPUT local OUTPUT
# TODO: real status can be checked only with grep output # TODO: real status can be checked only with grep output
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $1 ; then if is_anyservice $1 ; then
OUTPUT="$(sudorun anyservice $1 status 2>/dev/null)" || return 1 OUTPUT="$(sudorun anyservice $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1 echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0 return 0
fi fi
OUTPUT="$(sudorun service $1 status 2>/dev/null)" || return 1 OUTPUT="$(sudorun service $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1 echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0 return 0
;; ;;
service-initd|service-update) service-initd|service-update)
sudorun $INITDIR/$1 status >/dev/null 2>/dev/null sudorun $INITDIR/$1 status >/dev/null 2>/dev/null
;; ;;
systemd) systemd)
a='' 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
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
is_service_autostart() is_service_autostart()
{ {
local SERVICE="$1" local SERVICE="$1"
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE; then if is_anyservice $SERVICE; then
$ANYSERVICE $SERVICE isautostarted $ANYSERVICE $SERVICE isautostarted
return return
fi fi
# FIXME: check for current runlevel # FIXME: check for current runlevel
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)
a='' systemctl is-enabled $1 a='' systemctl is-enabled $1
;; ;;
runit) runit)
test -L "/var/service/$SERVICE" test -L "/var/service/$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
serv_status() serv_status()
{ {
is_service_autostart $1 && echo "Service $1 is scheduled to run on startup" || echo "Service $1 will NOT run on startup" is_service_autostart $1 && echo "Service $1 is scheduled to run on startup" || echo "Service $1 will NOT run on startup"
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE status sudocmd anyservice $SERVICE status
return return
fi fi
sudocmd service $SERVICE status "$@" sudocmd service $SERVICE status "$@"
;; ;;
service-update) service-update)
sudocmd $INITDIR/$SERVICE status "$@" sudocmd $INITDIR/$SERVICE status "$@"
;; ;;
systemd) systemd)
docmd systemctl -l status $SERVICE "$@" docmd systemctl -l status $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv status "$SERVICE" sudocmd sv status "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-stop: # File bin/serv-stop:
serv_stop() serv_stop()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE stop sudocmd anyservice $SERVICE stop
return return
fi fi
sudocmd service $SERVICE stop "$@" sudocmd service $SERVICE stop "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd $INITDIR/$SERVICE stop "$@" sudocmd $INITDIR/$SERVICE stop "$@"
;; ;;
systemd) systemd)
sudocmd systemctl stop $SERVICE "$@" sudocmd systemctl stop $SERVICE "$@"
;; ;;
runit) runit)
sudocmd sv down "$SERVICE" sudocmd sv down "$SERVICE"
;; ;;
openrc) openrc)
sudocmd rc-service stop "$SERVICE" sudocmd rc-service stop "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-test: # File bin/serv-test:
serv_test() serv_test()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICE in case $SERVICE in
cups|cupsd) cups|cupsd)
docmd cupsd -t docmd cupsd -t
;; ;;
nginx) nginx)
docmd nginx -t docmd nginx -t
;; ;;
sshd) sshd)
docmd sshd -t docmd sshd -t
;; ;;
httpd2|httpd|apache|apache2) httpd2|httpd|apache|apache2)
if is_command httpd2 ; then if is_command httpd2 ; then
docmd httpd2 -t docmd httpd2 -t
elif is_command apache2 ; then elif is_command apache2 ; then
docmd apache2 -t docmd apache2 -t
fi fi
;; ;;
postfix) postfix)
docmd /etc/init.d/postfix check docmd /etc/init.d/postfix check
;; ;;
*) *)
fatal "$SERVICE is not supported yet. Please report if you know how to test" fatal "$SERVICE is not supported yet. Please report if you know how to test"
;; ;;
esac esac
} }
# File bin/serv-try_restart: # File bin/serv-try_restart:
...@@ -1403,49 +1403,49 @@ serv_test() ...@@ -1403,49 +1403,49 @@ serv_test()
serv_try_restart() serv_try_restart()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
systemd) systemd)
sudocmd systemctl try-restart $SERVICE "$@" sudocmd systemctl try-restart $SERVICE "$@"
;; ;;
*) *)
info "Fallback to restart..." info "Fallback to restart..."
is_service_running $SERVICE || { info "Service $SERVICE is not running, restart skipping…" ; return 0 ; } is_service_running $SERVICE || { info "Service $SERVICE is not running, restart skipping…" ; return 0 ; }
serv_restart "$SERVICE" "$@" serv_restart "$SERVICE" "$@"
;; ;;
esac esac
} }
# File bin/serv-usage: # File bin/serv-usage:
_print_additional_usage() _print_additional_usage()
{ {
echo "serv addition usage: {on|off|try-restart|usage}" echo "serv addition usage: {on|off|try-restart|usage}"
} }
serv_usage() serv_usage()
{ {
local SERVICE="$1" local SERVICE="$1"
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# CHECKME: many services print out usage in stderr, it conflicts with printout command # CHECKME: many services print out usage in stderr, it conflicts with printout command
#sudocmd service $SERVICE 2>&1 #sudocmd service $SERVICE 2>&1
sudorun service $SERVICE 2>&1 sudorun service $SERVICE 2>&1
;; ;;
service-initd|service-update) service-initd|service-update)
#sudocmd /etc/init.d/$SERVICE 2>&1 #sudocmd /etc/init.d/$SERVICE 2>&1
sudorun service $SERVICE 2>&1 sudorun service $SERVICE 2>&1
;; ;;
systemd) systemd)
sudocmd systemctl $SERVICE 2>&1 sudocmd systemctl $SERVICE 2>&1
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
_print_additional_usage _print_additional_usage
...@@ -1468,17 +1468,17 @@ PROGVERSION="20230406" ...@@ -1468,17 +1468,17 @@ PROGVERSION="20230406"
# Check for DISTRO specific file in /etc # Check for DISTRO specific file in /etc
distro() distro()
{ {
#[ -n "$ROOTDIR" ] || return #[ -n "$ROOTDIR" ] || return
# fill global DISTROFILE # fill global DISTROFILE
DISTROFILE="$ROOTDIR/etc/$1" DISTROFILE="$ROOTDIR/etc/$1"
[ -f "$DISTROFILE" ] [ -f "$DISTROFILE" ]
} }
# Has a distro file the specified word? # Has a distro file the specified word?
has() has()
{ {
[ -n "$DISTROFILE" ] || exit 1 [ -n "$DISTROFILE" ] || exit 1
grep "$*" "$DISTROFILE" >/dev/null 2>&1 grep "$*" "$DISTROFILE" >/dev/null 2>&1
} }
# copied from epm-sh-functions # copied from epm-sh-functions
...@@ -1512,58 +1512,59 @@ is_command() ...@@ -1512,58 +1512,59 @@ is_command()
firstupper() firstupper()
{ {
echo "$*" | sed 's/.*/\u&/' # FIXME: works with GNU sed only
echo "$*" | sed 's/.*/\u&/'
} }
tolower() tolower()
{ {
# tr is broken in busybox (checked with OpenWrt) # tr is broken in busybox (checked with OpenWrt)
#echo "$*" | tr "[:upper:]" "[:lower:]" #echo "$*" | tr "[:upper:]" "[:lower:]"
echo "$*" | awk '{print tolower($0)}' echo "$*" | awk '{print tolower($0)}'
} }
print_bug_report_url() print_bug_report_url()
{ {
echo "$BUG_REPORT_URL" echo "$BUG_REPORT_URL"
} }
override_distrib() override_distrib()
{ {
[ -n "$1" ] || return [ -n "$1" ] || return
VENDOR_ID='' VENDOR_ID=''
PRETTY_NAME='' PRETTY_NAME=''
local name="$(echo "$1" | sed -e 's|x86_64/||')" local name="$(echo "$1" | sed -e 's|x86_64/||')"
[ "$name" = "$1" ] && DIST_ARCH="x86" || DIST_ARCH="x86_64" [ "$name" = "$1" ] && DIST_ARCH="x86" || DIST_ARCH="x86_64"
DISTRIB_ID="$(echo "$name" | sed -e 's|/.*||')" DISTRIB_ID="$(echo "$name" | sed -e 's|/.*||')"
DISTRO_NAME="$DISTRIB_ID" DISTRO_NAME="$DISTRIB_ID"
DISTRIB_RELEASE="$(echo "$name" | sed -e 's|.*/||')" DISTRIB_RELEASE="$(echo "$name" | sed -e 's|.*/||')"
[ "$DISTRIB_ID" = "$DISTRIB_RELEASE" ] && DISTRIB_RELEASE='' [ "$DISTRIB_ID" = "$DISTRIB_RELEASE" ] && DISTRIB_RELEASE=''
DISTRIB_CODENAME="$DISTRIB_RELEASE" DISTRIB_CODENAME="$DISTRIB_RELEASE"
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE" DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
} }
# Translate DISTRIB_ID to vendor name (like %_vendor does or package release name uses), uses VENDOR_ID by default # Translate DISTRIB_ID to vendor name (like %_vendor does or package release name uses), uses VENDOR_ID by default
pkgvendor() pkgvendor()
{ {
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return [ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
[ "$DISTRIB_ID" = "ALTServer" ] && echo "alt" && return [ "$DISTRIB_ID" = "ALTServer" ] && echo "alt" && return
[ "$DISTRIB_ID" = "MOC" ] && echo "alt" && return [ "$DISTRIB_ID" = "MOC" ] && echo "alt" && return
[ "$DISTRIB_ID" = "MESh" ] && echo "alt" && return [ "$DISTRIB_ID" = "MESh" ] && echo "alt" && return
[ "$DISTRIB_ID" = "AstraLinuxSE" ] && echo "astra" && return [ "$DISTRIB_ID" = "AstraLinuxSE" ] && echo "astra" && return
[ "$DISTRIB_ID" = "AstraLinuxCE" ] && echo "astra" && return [ "$DISTRIB_ID" = "AstraLinuxCE" ] && echo "astra" && return
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return [ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
[ "$DISTRIB_ID" = "TinyCoreLinux" ] && echo "tcl" && return [ "$DISTRIB_ID" = "TinyCoreLinux" ] && echo "tcl" && return
[ "$DISTRIB_ID" = "VoidLinux" ] && echo "void" && return [ "$DISTRIB_ID" = "VoidLinux" ] && echo "void" && return
[ "$DISTRIB_ID" = "OpenSUSE" ] && echo "suse" && return [ "$DISTRIB_ID" = "OpenSUSE" ] && echo "suse" && return
[ "$DISTRIB_ID" = "openSUSETumbleweed" ] && echo "suse" && return [ "$DISTRIB_ID" = "openSUSETumbleweed" ] && echo "suse" && return
[ "$DISTRIB_ID" = "openSUSELeap" ] && echo "suse" && return [ "$DISTRIB_ID" = "openSUSELeap" ] && echo "suse" && return
if [ -n "$VENDOR_ID" ] ; then if [ -n "$VENDOR_ID" ] ; then
[ "$VENDOR_ID" = "altlinux" ] && echo "alt" && return [ "$VENDOR_ID" = "altlinux" ] && echo "alt" && return
echo "$VENDOR_ID" echo "$VENDOR_ID"
return return
fi fi
tolower "$DISTRIB_ID" tolower "$DISTRIB_ID"
} }
# TODO: in more appropriate way # TODO: in more appropriate way
...@@ -1575,109 +1576,109 @@ pkgmanager() ...@@ -1575,109 +1576,109 @@ pkgmanager()
local CMD local CMD
# FIXME: some problems with multibased distros (Server Edition on CentOS and Desktop Edition on Ubuntu) # FIXME: some problems with multibased distros (Server Edition on CentOS and Desktop Edition on Ubuntu)
case $DISTRIB_ID in case $DISTRIB_ID in
ALTLinux|ALTServer) ALTLinux|ALTServer)
#which ds-install 2>/dev/null >/dev/null && CMD=deepsolver-rpm #which ds-install 2>/dev/null >/dev/null && CMD=deepsolver-rpm
#which pkcon 2>/dev/null >/dev/null && CMD=packagekit-rpm #which pkcon 2>/dev/null >/dev/null && CMD=packagekit-rpm
CMD="apt-rpm" CMD="apt-rpm"
;; ;;
ALTServer) ALTServer)
CMD="apt-rpm" CMD="apt-rpm"
;; ;;
PCLinux) PCLinux)
CMD="apt-rpm" CMD="apt-rpm"
;; ;;
Ubuntu|Debian|Mint|OSNovaLinux|AstraLinux*|Elbrus) Ubuntu|Debian|Mint|OSNovaLinux|AstraLinux*|Elbrus)
CMD="apt-dpkg" CMD="apt-dpkg"
#which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg #which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg
#is_command snappy && CMD=snappy #is_command snappy && CMD=snappy
;; ;;
Solus) Solus)
CMD="eopkg" CMD="eopkg"
;; ;;
Mandriva) Mandriva)
CMD="urpm-rpm" CMD="urpm-rpm"
;; ;;
ROSA) ROSA)
CMD="urpm-rpm" CMD="urpm-rpm"
is_command yum && CMD="yum-rpm" is_command yum && CMD="yum-rpm"
is_command dnf && CMD="dnf-rpm" is_command dnf && CMD="dnf-rpm"
# use dnf since 2020 # use dnf since 2020
#[ "$DISTRIB_ID/$DISTRIB_RELEASE" = "ROSA/2020" ] && CMD="urpm-rpm" #[ "$DISTRIB_ID/$DISTRIB_RELEASE" = "ROSA/2020" ] && CMD="urpm-rpm"
;; ;;
FreeBSD|NetBSD|OpenBSD|Solaris) FreeBSD|NetBSD|OpenBSD|Solaris)
CMD="pkgsrc" CMD="pkgsrc"
is_command pkg && CMD=pkgng is_command pkg && CMD=pkgng
;; ;;
Gentoo) Gentoo)
CMD="emerge" CMD="emerge"
;; ;;
ArchLinux) ArchLinux)
CMD="pacman" CMD="pacman"
;; ;;
Fedora|CentOS|OracleLinux|RockyLinux|AlmaLinux|RHEL|RELS|Scientific|GosLinux|Amzn|RedOS) Fedora|CentOS|OracleLinux|RockyLinux|AlmaLinux|RHEL|RELS|Scientific|GosLinux|Amzn|RedOS)
CMD="dnf-rpm" CMD="dnf-rpm"
is_command dnf || CMD="yum-rpm" is_command dnf || CMD="yum-rpm"
[ "$DISTRIB_ID/$DISTRIB_RELEASE" = "CentOS/7" ] && CMD="yum-rpm" [ "$DISTRIB_ID/$DISTRIB_RELEASE" = "CentOS/7" ] && CMD="yum-rpm"
;; ;;
Slackware) Slackware)
CMD="slackpkg" CMD="slackpkg"
;; ;;
SUSE|SLED|SLES|openSUSETumbleweed|openSUSELeap) SUSE|SLED|SLES|openSUSETumbleweed|openSUSELeap)
CMD="zypper-rpm" CMD="zypper-rpm"
;; ;;
ForesightLinux|rPathLinux) ForesightLinux|rPathLinux)
CMD="conary" CMD="conary"
;; ;;
Windows) Windows)
CMD="appget" CMD="appget"
is_command $CMD || CMD="chocolatey" is_command $CMD || CMD="chocolatey"
is_command $CMD || CMD="winget" is_command $CMD || CMD="winget"
;; ;;
MacOS) MacOS)
CMD="homebrew" CMD="homebrew"
;; ;;
OpenWrt) OpenWrt)
CMD="opkg" CMD="opkg"
;; ;;
GNU/Linux/Guix) GNU/Linux/Guix)
CMD="guix" CMD="guix"
;; ;;
Android) Android)
CMD="android" CMD="android"
;; ;;
Cygwin) Cygwin)
CMD="aptcyg" CMD="aptcyg"
;; ;;
alpine) AlpineLinux)
CMD="apk" CMD="apk"
;; ;;
TinyCoreLinux) TinyCoreLinux)
CMD="tce" CMD="tce"
;; ;;
VoidLinux) VoidLinux)
CMD="xbps" CMD="xbps"
;; ;;
*) *)
# try detect firstly # try detect firstly
if grep -q "ID_LIKE=debian" /etc/os-release 2>/dev/null ; then if grep -q "ID_LIKE=debian" /etc/os-release 2>/dev/null ; then
echo "apt-dpkg" && return echo "apt-dpkg" && return
fi fi
if is_command "rpm" && [ -s /var/lib/rpm/Name ] || [ -s /var/lib/rpm/rpmdb.sqlite ] ; then if is_command "rpm" && [ -s /var/lib/rpm/Name ] || [ -s /var/lib/rpm/rpmdb.sqlite ] ; then
is_command "zypper" && echo "zypper-rpm" && return is_command "zypper" && echo "zypper-rpm" && return
is_command "dnf" && echo "dnf-rpm" && return is_command "dnf" && echo "dnf-rpm" && return
is_command "apt-get" && echo "apt-rpm" && return is_command "apt-get" && echo "apt-rpm" && return
is_command "yum" && echo "yum-rpm" && return is_command "yum" && echo "yum-rpm" && return
is_command "urpmi" && echo "urpm-rpm" && return is_command "urpmi" && echo "urpm-rpm" && return
fi fi
if is_command "dpkg" && [ -s /var/lib/dpkg/status ] ; then if is_command "dpkg" && [ -s /var/lib/dpkg/status ] ; then
is_command "apt" && echo "apt-dpkg" && return is_command "apt" && echo "apt-dpkg" && return
is_command "apt-get" && echo "apt-dpkg" && return is_command "apt-get" && echo "apt-dpkg" && return
fi fi
echo "We don't support yet DISTRIB_ID $DISTRIB_ID" >&2 echo "We don't support yet DISTRIB_ID $DISTRIB_ID" >&2
;; ;;
esac esac
echo "$CMD" echo "$CMD"
} }
...@@ -1687,88 +1688,89 @@ pkgtype() ...@@ -1687,88 +1688,89 @@ pkgtype()
{ {
# TODO: try use generic names # TODO: try use generic names
case $(pkgvendor) in case $(pkgvendor) in
freebsd) echo "tbz" ;; freebsd) echo "tbz" ;;
sunos) echo "pkg.gz" ;; sunos) echo "pkg.gz" ;;
slackware|mopslinux) echo "tgz" ;; slackware|mopslinux) echo "tgz" ;;
archlinux|manjaro) echo "pkg.tar.xz" ;; archlinux|manjaro) echo "pkg.tar.xz" ;;
gentoo) echo "tbz2" ;; gentoo) echo "tbz2" ;;
windows) echo "exe" ;; windows) echo "exe" ;;
android) echo "apk" ;; android) echo "apk" ;;
alpine) echo "apk" ;; alpine) echo "apk" ;;
tinycorelinux) echo "tcz" ;; tinycorelinux) echo "tcz" ;;
voidlinux) echo "xbps" ;; voidlinux) echo "xbps" ;;
openwrt) echo "ipk" ;; openwrt) echo "ipk" ;;
cygwin) echo "tar.xz" ;; cygwin) echo "tar.xz" ;;
solus) echo "eopkg" ;; solus) echo "eopkg" ;;
*) *)
case $(pkgmanager) in case $(pkgmanager) in
*-dpkg) *-dpkg)
echo "deb" ;; echo "deb" ;;
*-rpm) *-rpm)
echo "rpm" ;; echo "rpm" ;;
*) *)
echo "rpm" ;; echo "rpm" ;;
esac esac
esac esac
} }
print_codename() print_codename()
{ {
echo "$DISTRIB_CODENAME" echo "$DISTRIB_CODENAME"
} }
print_repo_name() print_repo_name()
{ {
echo "$DISTRIB_CODENAME" echo "$DISTRIB_CODENAME"
} }
get_var() get_var()
{ {
# get first variable and print it out, drop quotes if exists # get first variable and print it out, drop quotes if exists
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" | sed -e "s/^[\'\"]\(.*\)[\'\"]/\1/" grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" | sed -e "s/^[\'\"]\(.*\)[\'\"]/\1/"
} }
# 2010.1 -> 2010 # 2010.1 -> 2010
get_major_version() get_major_version()
{ {
echo "$1" | sed -e "s/\..*//g" echo "$1" | sed -e "s/\..*//g"
} }
normalize_name() normalize_name()
{ {
case "$1" in case "$1" in
"RED OS") "RED OS")
echo "RedOS" echo "RedOS"
;; ;;
"Debian GNU/Linux") "Debian GNU/Linux")
echo "Debian" echo "Debian"
;; ;;
"CentOS Linux") "CentOS Linux")
echo "CentOS" echo "CentOS"
;; ;;
"Fedora Linux") "Fedora Linux")
echo "Fedora" echo "Fedora"
;; ;;
"Red Hat Enterprise Linux Server") "Red Hat Enterprise Linux Server")
echo "RHEL" echo "RHEL"
;; ;;
"ROSA Fresh"*|"ROSA Desktop Fresh"*) "ROSA Fresh"*|"ROSA Desktop Fresh"*)
echo "ROSA" echo "ROSA"
;; ;;
"ROSA Chrome Desktop") "ROSA Chrome Desktop")
echo "ROSA" echo "ROSA"
;; ;;
"ROSA Enterprise Linux Desktop") "ROSA Enterprise Linux Desktop")
echo "RELS" echo "RELS"
;; ;;
"ROSA Enterprise Linux Server") "ROSA Enterprise Linux Server")
echo "RELS" echo "RELS"
;; ;;
*) *)
#echo "${1// /}" #echo "${1// /}"
firstupper "$1" | sed -e "s/ //g" -e 's|(.*||' #firstupper "$1" | sed -e "s/ //g" -e 's|(.*||'
;; echo "$1" | sed -e "s/ //g" -e 's|(.*||'
esac ;;
esac
} }
# 1.2.3.4.5 -> 1 # 1.2.3.4.5 -> 1
...@@ -1805,101 +1807,101 @@ BUILD_ID="" ...@@ -1805,101 +1807,101 @@ BUILD_ID=""
# Default detection by /etc/os-release # Default detection by /etc/os-release
# https://www.freedesktop.org/software/systemd/man/os-release.html # https://www.freedesktop.org/software/systemd/man/os-release.html
if distro os-release ; then if distro os-release ; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $DISTROFILE . $DISTROFILE
DISTRO_NAME="$NAME" DISTRO_NAME="$NAME"
DISTRIB_ID="$(normalize_name "$NAME")" DISTRIB_ID="$(normalize_name "$NAME")"
DISTRIB_RELEASE_ORIG="$VERSION_ID" DISTRIB_RELEASE_ORIG="$VERSION_ID"
DISTRIB_RELEASE="$VERSION_ID" DISTRIB_RELEASE="$VERSION_ID"
[ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR" [ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR"
# set by os-release: # set by os-release:
#PRETTY_NAME #PRETTY_NAME
VENDOR_ID="$ID" VENDOR_ID="$ID"
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE" DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
DISTRIB_CODENAME="$VERSION_CODENAME" DISTRIB_CODENAME="$VERSION_CODENAME"
elif distro lsb-release ; then elif distro lsb-release ; then
DISTRIB_ID=$(cat $DISTROFILE | get_var DISTRIB_ID) DISTRIB_ID=$(cat $DISTROFILE | get_var DISTRIB_ID)
DISTRO_NAME=$(cat $DISTROFILE | get_var DISTRIB_ID) DISTRO_NAME=$(cat $DISTROFILE | get_var DISTRIB_ID)
DISTRIB_RELEASE="$(cat $DISTROFILE | get_var DISTRIB_RELEASE)" DISTRIB_RELEASE="$(cat $DISTROFILE | get_var DISTRIB_RELEASE)"
DISTRIB_RELEASE_ORIG="$DISTRIB_RELEASE" DISTRIB_RELEASE_ORIG="$DISTRIB_RELEASE"
DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE" DISTRIB_FULL_RELEASE="$DISTRIB_RELEASE"
DISTRIB_CODENAME=$(cat $DISTROFILE | get_var DISTRIB_CODENAME) DISTRIB_CODENAME=$(cat $DISTROFILE | get_var DISTRIB_CODENAME)
PRETTY_NAME=$(cat $DISTROFILE | get_var DISTRIB_DESCRIPTION) PRETTY_NAME=$(cat $DISTROFILE | get_var DISTRIB_DESCRIPTION)
fi fi
DISTRIB_RELEASE=$(normalize_version2 "$DISTRIB_RELEASE") DISTRIB_RELEASE=$(normalize_version2 "$DISTRIB_RELEASE")
[ -n "$DISTRIB_CODENAME" ] || DISTRIB_CODENAME=$DISTRIB_RELEASE [ -n "$DISTRIB_CODENAME" ] || DISTRIB_CODENAME=$DISTRIB_RELEASE
case "$VENDOR_ID" in case "$VENDOR_ID" in
"alt"|"altlinux") "alt"|"altlinux")
# 2.4.5.99 -> 2 # 2.4.5.99 -> 2
DISTRIB_RELEASE=$(normalize_version1 "$DISTRIB_RELEASE_ORIG") DISTRIB_RELEASE=$(normalize_version1 "$DISTRIB_RELEASE_ORIG")
case "$DISTRIB_ID" in case "$DISTRIB_ID" in
"ALTServer"|"ALTSPWorkstation"|"Sisyphus") "ALTServer"|"ALTSPWorkstation"|"Sisyphus")
;; ;;
*) *)
DISTRIB_ID="ALTLinux" DISTRIB_ID="ALTLinux"
;; ;;
esac esac
;; ;;
"astra") "astra")
DISTRIB_RELEASE=$(normalize_version2 "$DISTRIB_RELEASE_ORIG" | sed -e 's|_.*||') DISTRIB_RELEASE=$(normalize_version2 "$DISTRIB_RELEASE_ORIG" | sed -e 's|_.*||')
DISTRIB_FULL_RELEASE=$(normalize_version3 "$DISTRIB_RELEASE_ORIG" | sed -e 's|_.*||') DISTRIB_FULL_RELEASE=$(normalize_version3 "$DISTRIB_RELEASE_ORIG" | sed -e 's|_.*||')
if [ "$VARIANT" = "orel" ] || [ "$VARIANT" = "Orel" ] ; then if [ "$VARIANT" = "orel" ] || [ "$VARIANT" = "Orel" ] ; then
DISTRIB_ID="AstraLinuxCE" DISTRIB_ID="AstraLinuxCE"
else else
DISTRIB_ID="AstraLinuxSE" DISTRIB_ID="AstraLinuxSE"
fi fi
if [ "$DISTRIB_ID" = "AstraLinuxSE" ] ; then if [ "$DISTRIB_ID" = "AstraLinuxSE" ] ; then
local fr="$(cat /etc/astra_version 2>/dev/null)" local fr="$(cat /etc/astra_version 2>/dev/null)"
[ -n "$fr" ] && echo "$fr" | grep -q "$DISTRIB_RELEASE" && DISTRIB_FULL_RELEASE="$fr" [ -n "$fr" ] && echo "$fr" | grep -q "$DISTRIB_RELEASE" && DISTRIB_FULL_RELEASE="$fr"
fi fi
;; ;;
esac esac
case "$DISTRIB_ID" in case "$DISTRIB_ID" in
"ALTLinux") "ALTLinux")
echo "$VERSION" | grep -q "c9.* branch" && DISTRIB_RELEASE="c9" echo "$VERSION" | grep -q "c9.* branch" && DISTRIB_RELEASE="c9"
echo "$VERSION" | grep -q "c9f1 branch" && DISTRIB_RELEASE="c9f1" echo "$VERSION" | grep -q "c9f1 branch" && DISTRIB_RELEASE="c9f1"
echo "$VERSION" | grep -q "c9f2 branch" && DISTRIB_RELEASE="c9f2" echo "$VERSION" | grep -q "c9f2 branch" && DISTRIB_RELEASE="c9f2"
DISTRIB_CODENAME="$DISTRIB_RELEASE" DISTRIB_CODENAME="$DISTRIB_RELEASE"
# FIXME: fast hack for fallback: 10.1 -> p10 for /etc/os-release # FIXME: fast hack for fallback: 10.1 -> p10 for /etc/os-release
if echo "$DISTRIB_RELEASE" | grep -q "^[0-9]" && echo "$DISTRIB_RELEASE" | grep -q -v "[0-9][0-9][0-9]" ; then if echo "$DISTRIB_RELEASE" | grep -q "^[0-9]" && echo "$DISTRIB_RELEASE" | grep -q -v "[0-9][0-9][0-9]" ; then
DISTRIB_RELEASE="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||')" DISTRIB_RELEASE="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||')"
DISTRIB_CODENAME="$DISTRIB_RELEASE" DISTRIB_CODENAME="$DISTRIB_RELEASE"
fi fi
;; ;;
"ALTServer") "ALTServer")
DISTRIB_CODENAME="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||')" DISTRIB_CODENAME="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||')"
;; ;;
"ALTSPWorkstation") "ALTSPWorkstation")
DISTRIB_ID="ALTLinux" DISTRIB_ID="ALTLinux"
case "$DISTRIB_RELEASE_ORIG" in case "$DISTRIB_RELEASE_ORIG" in
8.0|8.1) 8.0|8.1)
;; ;;
8.2|8.3) 8.2|8.3)
DISTRIB_RELEASE="c9f1" DISTRIB_RELEASE="c9f1"
;; ;;
8.4) 8.4)
DISTRIB_RELEASE="c9f2" DISTRIB_RELEASE="c9f2"
;; ;;
8.*) 8.*)
DISTRIB_RELEASE="c9f3" DISTRIB_RELEASE="c9f3"
;; ;;
esac esac
DISTRIB_CODENAME="$DISTRIB_RELEASE" DISTRIB_CODENAME="$DISTRIB_RELEASE"
# DISTRIB_RELEASE=$(echo $DISTRIB_RELEASE | sed -e "s/\..*//g") # DISTRIB_RELEASE=$(echo $DISTRIB_RELEASE | sed -e "s/\..*//g")
;; ;;
"Sisyphus") "Sisyphus")
DISTRIB_ID="ALTLinux" DISTRIB_ID="ALTLinux"
DISTRIB_RELEASE="Sisyphus" DISTRIB_RELEASE="Sisyphus"
DISTRIB_CODENAME="$DISTRIB_RELEASE" DISTRIB_CODENAME="$DISTRIB_RELEASE"
;; ;;
"ROSA") "ROSA")
DISTRIB_FULL_RELEASE="$DISTRIB_CODENAME" DISTRIB_FULL_RELEASE="$DISTRIB_CODENAME"
DISTRIB_CODENAME="$DISTRIB_RELEASE" DISTRIB_CODENAME="$DISTRIB_RELEASE"
;; ;;
esac esac
...@@ -1910,123 +1912,123 @@ esac ...@@ -1910,123 +1912,123 @@ esac
# ALT Linux based # ALT Linux based
if distro altlinux-release ; then if distro altlinux-release ; then
DISTRIB_ID="ALTLinux" DISTRIB_ID="ALTLinux"
# FIXME: fast hack for fallback: 10 -> p10 for /etc/os-release # FIXME: fast hack for fallback: 10 -> p10 for /etc/os-release
DISTRIB_RELEASE="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||' -e 's|^pp|p|')" DISTRIB_RELEASE="$(echo p$DISTRIB_RELEASE | sed -e 's|\..*||' -e 's|^pp|p|')"
if has Sisyphus ; then DISTRIB_RELEASE="Sisyphus" if has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
elif has "ALT p10.* p10 " ; then DISTRIB_RELEASE="p10" elif has "ALT p10.* p10 " ; then DISTRIB_RELEASE="p10"
elif has "ALTServer 10." ; then DISTRIB_RELEASE="p10" elif has "ALTServer 10." ; then DISTRIB_RELEASE="p10"
elif has "ALTServer 9." ; then DISTRIB_RELEASE="p9" elif has "ALTServer 9." ; then DISTRIB_RELEASE="p9"
elif has "ALT c10.* c10 " ; then DISTRIB_RELEASE="c10" elif has "ALT c10.* c10 " ; then DISTRIB_RELEASE="c10"
elif has "ALT p9.* p9 " ; then DISTRIB_RELEASE="p9" elif has "ALT p9.* p9 " ; then DISTRIB_RELEASE="p9"
elif has "ALT 9 SP " ; then DISTRIB_RELEASE="c9" elif has "ALT 9 SP " ; then DISTRIB_RELEASE="c9"
elif has "ALT c9f1" ; then DISTRIB_RELEASE="c9f1" elif has "ALT c9f1" ; then DISTRIB_RELEASE="c9f1"
elif has "ALT MED72 " ; then DISTRIB_RELEASE="p8" elif has "ALT MED72 " ; then DISTRIB_RELEASE="p8"
elif has "ALT 8 SP " ; then DISTRIB_RELEASE="c8" elif has "ALT 8 SP " ; then DISTRIB_RELEASE="c8"
elif has "ALT c8.2 " ; then DISTRIB_RELEASE="c8.2" elif has "ALT c8.2 " ; then DISTRIB_RELEASE="c8.2"
elif has "ALT c8.1 " ; then DISTRIB_RELEASE="c8.1" elif has "ALT c8.1 " ; then DISTRIB_RELEASE="c8.1"
elif has "ALT c8 " ; then DISTRIB_RELEASE="c8" elif has "ALT c8 " ; then DISTRIB_RELEASE="c8"
elif has "ALT .*8.[0-9]" ; then DISTRIB_RELEASE="p8" elif has "ALT .*8.[0-9]" ; then DISTRIB_RELEASE="p8"
elif has "Simply Linux 10." ; then DISTRIB_RELEASE="p10" elif has "Simply Linux 10." ; then DISTRIB_RELEASE="p10"
elif has "Simply Linux 9." ; then DISTRIB_RELEASE="p9" elif has "Simply Linux 9." ; then DISTRIB_RELEASE="p9"
elif has "Simply Linux 8." ; then DISTRIB_RELEASE="p8" elif has "Simply Linux 8." ; then DISTRIB_RELEASE="p8"
elif has "Simply Linux 7." ; then DISTRIB_RELEASE="p7" elif has "Simply Linux 7." ; then DISTRIB_RELEASE="p7"
elif has "Simply Linux 6." ; then DISTRIB_RELEASE="p6" elif has "Simply Linux 6." ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p8" ; then DISTRIB_RELEASE="p8" elif has "ALT Linux p8" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux 8." ; then DISTRIB_RELEASE="p8" elif has "ALT Linux 8." ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7" elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7"
elif has "ALT Linux 7." ; then DISTRIB_RELEASE="p7" elif has "ALT Linux 7." ; then DISTRIB_RELEASE="p7"
elif has "ALT Linux t7." ; then DISTRIB_RELEASE="t7" elif has "ALT Linux t7." ; then DISTRIB_RELEASE="t7"
elif has "ALT Linux 6." ; then DISTRIB_RELEASE="p6" elif has "ALT Linux 6." ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6" elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5" elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5"
elif has "ALT Linux 5.1" ; then DISTRIB_RELEASE="5.1" elif has "ALT Linux 5.1" ; then DISTRIB_RELEASE="5.1"
elif has "ALT Linux 5.0" ; then DISTRIB_RELEASE="5.0" elif has "ALT Linux 5.0" ; then DISTRIB_RELEASE="5.0"
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1" elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0" elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
elif has "starter kit" ; then DISTRIB_RELEASE="Sisyphus" elif has "starter kit" ; then DISTRIB_RELEASE="Sisyphus"
elif has Citron ; then DISTRIB_RELEASE="2.4" elif has Citron ; then DISTRIB_RELEASE="2.4"
fi fi
PRETTY_NAME="$(cat /etc/altlinux-release)" PRETTY_NAME="$(cat /etc/altlinux-release)"
elif distro gentoo-release ; then elif distro gentoo-release ; then
DISTRIB_ID="Gentoo" DISTRIB_ID="Gentoo"
MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile) MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile)
DISTRIB_RELEASE=$(basename $MAKEPROFILE) DISTRIB_RELEASE=$(basename $MAKEPROFILE)
echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=$(basename "$(dirname $MAKEPROFILE)") #" echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=$(basename "$(dirname $MAKEPROFILE)") #"
elif distro slackware-version ; then elif distro slackware-version ; then
DISTRIB_ID="Slackware" DISTRIB_ID="Slackware"
DISTRIB_RELEASE="$(grep -Eo '[0-9]+\.[0-9]+' $DISTROFILE)" DISTRIB_RELEASE="$(grep -Eo '[0-9]+\.[0-9]+' $DISTROFILE)"
elif distro os-release && is_command tce-ab ; then elif distro os-release && is_command tce-ab ; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $ROOTDIR/etc/os-release . $ROOTDIR/etc/os-release
DISTRIB_ID="TinyCoreLinux" DISTRIB_ID="TinyCoreLinux"
DISTRIB_RELEASE="$VERSION_ID" DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && is_command xbps-query ; then elif distro os-release && is_command xbps-query ; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $ROOTDIR/etc/os-release . $ROOTDIR/etc/os-release
DISTRIB_ID="VoidLinux" DISTRIB_ID="VoidLinux"
DISTRIB_RELEASE="Live" DISTRIB_RELEASE="Live"
# TODO: use standart /etc/os-release or lsb # TODO: use standart /etc/os-release or lsb
elif distro arch-release ; then elif distro arch-release ; then
DISTRIB_ID="ArchLinux" DISTRIB_ID="ArchLinux"
DISTRIB_RELEASE="rolling" DISTRIB_RELEASE="rolling"
# Elbrus # Elbrus
elif distro mcst_version ; then elif distro mcst_version ; then
DISTRIB_ID="MCST" DISTRIB_ID="MCST"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") #" DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") #"
# OpenWrt # OpenWrt
elif distro openwrt_release ; then elif distro openwrt_release ; then
. $DISTROFILE . $DISTROFILE
DISTRIB_RELEASE=$(cat $ROOTDIR/etc/openwrt_version) DISTRIB_RELEASE=$(cat $ROOTDIR/etc/openwrt_version)
# Debian based # Debian based
elif distro debian_version ; then elif distro debian_version ; then
DISTRIB_ID="Debian" DISTRIB_ID="Debian"
DISTRIB_RELEASE=$(cat $DISTROFILE | sed -e "s/\..*//g") DISTRIB_RELEASE=$(cat $DISTROFILE | sed -e "s/\..*//g")
# SUSE based # SUSE based
elif distro SuSe-release || distro SuSE-release ; then elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SUSE" DISTRIB_ID="SUSE"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "VERSION" | sed -e "s|^VERSION = ||g") DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "VERSION" | sed -e "s|^VERSION = ||g")
if has "SUSE Linux Enterprise Desktop" ; then if has "SUSE Linux Enterprise Desktop" ; then
DISTRIB_ID="SLED" DISTRIB_ID="SLED"
elif has "SUSE Linux Enterprise Server" ; then elif has "SUSE Linux Enterprise Server" ; then
DISTRIB_ID="SLES" DISTRIB_ID="SLES"
fi fi
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ "$(uname)" = "FreeBSD" ] ; then elif [ "$(uname)" = "FreeBSD" ] ; then
DISTRIB_ID="FreeBSD" DISTRIB_ID="FreeBSD"
UNAME=$(uname -r) UNAME=$(uname -r)
DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g") #" DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g") #"
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ "$(uname)" = "SunOS" ] ; then elif [ "$(uname)" = "SunOS" ] ; then
DISTRIB_ID="SunOS" DISTRIB_ID="SunOS"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ "$(uname -s 2>/dev/null)" = "Darwin" ] ; then elif [ "$(uname -s 2>/dev/null)" = "Darwin" ] ; then
DISTRIB_ID="MacOS" DISTRIB_ID="MacOS"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: move to up # fixme: move to up
elif [ "$(uname)" = "Linux" ] && is_command guix ; then elif [ "$(uname)" = "Linux" ] && is_command guix ; then
DISTRIB_ID="GNU/Linux/Guix" DISTRIB_ID="GNU/Linux/Guix"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: move to up # fixme: move to up
elif [ "$(uname)" = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then elif [ "$(uname)" = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then
DISTRIB_ID="Android" DISTRIB_ID="Android"
DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]') DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]')
elif [ "$(uname -o 2>/dev/null)" = "Cygwin" ] ; then elif [ "$(uname -o 2>/dev/null)" = "Cygwin" ] ; then
DISTRIB_ID="Cygwin" DISTRIB_ID="Cygwin"
...@@ -2341,154 +2343,154 @@ EOF ...@@ -2341,154 +2343,154 @@ EOF
} }
case "$2" in case "$2" in
-*) -*)
echo "Unsupported option $2" >&2 echo "Unsupported option $2" >&2
exit 1 exit 1
;; ;;
esac esac
case "$1" in case "$1" in
-h|--help) -h|--help)
echo "distro_info v$PROGVERSION - distro information retriever" echo "distro_info v$PROGVERSION - distro information retriever"
echo "Usage: distro_info [options] [SystemName/Version]" echo "Usage: distro_info [options] [SystemName/Version]"
echo "Options:" echo "Options:"
echo " -h | --help - this help" echo " -h | --help - this help"
echo " -a - print hardware architecture (--distro-arch for distro depended name)" echo " -a - print hardware architecture (--distro-arch for distro depended name)"
echo " -b - print size of arch bit (32/64)" echo " -b - print size of arch bit (32/64)"
echo " -c - print number of CPU cores" echo " -c - print number of CPU cores"
echo " -i - print virtualization type" echo " -i - print virtualization type"
echo " -m - print system memory size (in MB)" echo " -m - print system memory size (in MB)"
echo " -y|--service-manager - print running service manager" echo " -y|--service-manager - print running service manager"
echo " -z - print current CPU MHz" echo " -z - print current CPU MHz"
echo " --glibc-version - print system glibc version" echo " --glibc-version - print system glibc version"
echo echo
echo " -d|--base-distro-name - print distro id (short distro name)" echo " -d|--base-distro-name - print distro id (short distro name)"
echo " -e - print full name of distro with version" echo " -e - print full name of distro with version"
echo " -o | --os-name - print base OS name" echo " -o | --os-name - print base OS name"
echo " -p | package-type - print type of the packaging system" echo " -p | package-type - print type of the packaging system"
echo " -g - print name of the packaging system" echo " -g - print name of the packaging system"
echo " -s|-n|--vendor-name - print name of the distro family (vendor name) (ubuntu for all Ubuntu family, alt for all ALT family) (see _vendor macros in rpm)" echo " -s|-n|--vendor-name - print name of the distro family (vendor name) (ubuntu for all Ubuntu family, alt for all ALT family) (see _vendor macros in rpm)"
echo " --pretty|--pretty-name - print pretty distro name" echo " --pretty|--pretty-name - print pretty distro name"
echo " -v | --base-version - print version of the distro" echo " -v | --base-version - print version of the distro"
echo " --distro-name - print distro name" echo " --distro-name - print distro name"
echo " --distro-version - print full version of the distro" echo " --distro-version - print full version of the distro"
echo " --full-version - print full version of the distro" echo " --full-version - print full version of the distro"
echo " --codename (obsoleted) - print distro codename (focal for Ubuntu 20.04)" echo " --codename (obsoleted) - print distro codename (focal for Ubuntu 20.04)"
echo " -r|--repo-name - print repository name (focal for Ubuntu 20.04)" echo " -r|--repo-name - print repository name (focal for Ubuntu 20.04)"
echo " --build-id - print a string uniquely identifying the system image originally used as the installation base" echo " --build-id - print a string uniquely identifying the system image originally used as the installation base"
echo " -V - print the utility version" echo " -V - print the utility version"
echo "Run without args to print all information." echo "Run without args to print all information."
exit 0 exit 0
;; ;;
-p|--package-type) -p|--package-type)
override_distrib "$2" override_distrib "$2"
pkgtype pkgtype
exit 0 exit 0
;; ;;
-g) -g)
override_distrib "$2" override_distrib "$2"
pkgmanager pkgmanager
exit 0 exit 0
;; ;;
--pretty|--pretty-name) --pretty|--pretty-name)
override_distrib "$2" override_distrib "$2"
print_pretty_name print_pretty_name
;; ;;
--distro-arch) --distro-arch)
override_distrib "$2" override_distrib "$2"
get_distro_arch get_distro_arch
exit 0 exit 0
;; ;;
--debian-arch) --debian-arch)
override_distrib "$2" override_distrib "$2"
get_debian_arch get_debian_arch
exit 0 exit 0
;; ;;
--glibc-version) --glibc-version)
override_distrib "$2" override_distrib "$2"
get_glibc_version get_glibc_version
exit 0 exit 0
;; ;;
-d|--base-distro-name) -d|--base-distro-name)
override_distrib "$2" override_distrib "$2"
echo $DISTRIB_ID echo $DISTRIB_ID
;; ;;
--distro-name) --distro-name)
override_distrib "$2" override_distrib "$2"
echo $DISTRO_NAME echo $DISTRO_NAME
;; ;;
--codename) --codename)
override_distrib "$2" override_distrib "$2"
print_codename print_codename
;; ;;
-a) -a)
override_distrib "$2" override_distrib "$2"
[ -n "$DIST_ARCH" ] && echo "$DIST_ARCH" && exit 0 [ -n "$DIST_ARCH" ] && echo "$DIST_ARCH" && exit 0
get_arch get_arch
;; ;;
-b) -b)
get_bit_size get_bit_size
;; ;;
-c) -c)
get_core_count get_core_count
;; ;;
-z) -z)
get_core_mhz get_core_mhz
;; ;;
-i) -i)
get_virt get_virt
;; ;;
-m) -m)
get_memory_size get_memory_size
;; ;;
-o|--os-name) -o|--os-name)
override_distrib "$2" override_distrib "$2"
get_base_os_name get_base_os_name
;; ;;
-r|--repo-name) -r|--repo-name)
override_distrib "$2" override_distrib "$2"
print_repo_name print_repo_name
;; ;;
--build-id) --build-id)
echo "$BUILD_ID" echo "$BUILD_ID"
;; ;;
-v|--base-version) -v|--base-version)
override_distrib "$2" override_distrib "$2"
echo "$DISTRIB_RELEASE" echo "$DISTRIB_RELEASE"
;; ;;
--full-version|--distro-version) --full-version|--distro-version)
override_distrib "$2" override_distrib "$2"
echo "$DISTRIB_FULL_RELEASE" echo "$DISTRIB_FULL_RELEASE"
;; ;;
--bug-report-url) --bug-report-url)
print_bug_report_url print_bug_report_url
exit return
;; ;;
-s|-n|--vendor-name) -s|-n|--vendor-name)
override_distrib "$2" override_distrib "$2"
pkgvendor pkgvendor
exit 0 exit 0
;; ;;
-y|--service-manager) -y|--service-manager)
override_distrib "$2" override_distrib "$2"
get_service_manager get_service_manager
;; ;;
-V) -V)
echo "$PROGVERSION" echo "$PROGVERSION"
exit 0 exit 0
;; ;;
-e) -e)
override_distrib "$2" override_distrib "$2"
print_name_version print_name_version
;; ;;
-*) -*)
echo "Unsupported option $1" >&2 echo "Unsupported option $1" >&2
exit 1 exit 1
;; ;;
*) *)
override_distrib "$1" override_distrib "$1"
print_total_info print_total_info
;; ;;
esac esac
} }
...@@ -2512,18 +2514,18 @@ check_tty ...@@ -2512,18 +2514,18 @@ check_tty
# FIXME: add upstart support (Ubuntu?) # FIXME: add upstart support (Ubuntu?)
set_service_type() set_service_type()
{ {
local CMD local CMD
set_distro_info set_distro_info
set_target_pkg_env set_target_pkg_env
case "$DISTRCONTROL" in case "$DISTRCONTROL" in
sysvinit) sysvinit)
CMD="service-chkconfig" CMD="service-chkconfig"
;; ;;
systemd) systemd)
CMD="systemd" CMD="systemd"
;; ;;
esac esac
# override system control detection result # override system control detection result
...@@ -2538,16 +2540,16 @@ ANYSERVICE=$(print_command_path anyservice) ...@@ -2538,16 +2540,16 @@ ANYSERVICE=$(print_command_path anyservice)
# TODO: done it on anyservice part # TODO: done it on anyservice part
is_anyservice() is_anyservice()
{ {
[ -n "$ANYSERVICE" ] || return [ -n "$ANYSERVICE" ] || return
[ -n "$1" ] || return [ -n "$1" ] || return
# check if anyservice is exists and checkd returns true # check if anyservice is exists and checkd returns true
$ANYSERVICE "$1" checkd 2>/dev/null $ANYSERVICE "$1" checkd 2>/dev/null
} }
phelp() phelp()
{ {
echo "$Descr echo "$Descr
$Usage $Usage
Commands: Commands:
$(get_help HELPCMD) $(get_help HELPCMD)
...@@ -2562,7 +2564,7 @@ print_version() ...@@ -2562,7 +2564,7 @@ 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.42.0 https://wiki.etersoft.ru/Epm" echo "Service manager version 3.50.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-2021" 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."
......
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