Commit a49cbdce authored by Vitaly Lipatov's avatar Vitaly Lipatov

commit packed files

parent 2e8094cb
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PROGDIR=$(dirname $0)
# will replaced to /usr/share/eepm during install
SHAREDIR=$(dirname $0)
load_helper()
{
local CMD="$SHAREDIR/$1"
# do not use fatal() here, it can be initial state
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
. $CMD
}
# File bin/epm-sh-functions:
isatty()
{
# Set a sane TERM required for tput
[ -n "$TERM" ] || TERM=dumb
export TERM
test -t 1
}
check_tty()
{
isatty || return
which tput >/dev/null 2>/dev/null || return
# FreeBSD does not support tput -S
echo | tput -S >/dev/null 2>/dev/null || return
[ -z "$USETTY" ] || return
export USETTY=1
}
: ${BLACK:=0} ${RED:=1} ${GREEN:=2} ${YELLOW:=3} ${BLUE:=4} ${MAGENTA:=5} ${CYAN:=6} ${WHITE:=7}
set_boldcolor()
{
[ "$USETTY" = "1" ] || return
{
echo bold
echo setaf $1
} |tput -S
}
restore_color()
{
[ "$USETTY" = "1" ] || return
{
echo op; # set Original color Pair.
echo sgr0; # turn off all special graphics mode (bold in our case).
} |tput -S
}
echover()
{
[ -n "$verbose" ] || return
echo "$*" >&2
}
set_target_pkg_env()
{
[ -n "$DISTRNAME" ] || fatal "Run set_target_pkg_env without DISTRNAME"
PKGFORMAT=$($DISTRVENDOR -p "$DISTRNAME")
PKGVENDOR=$($DISTRVENDOR -s "$DISTRNAME")
RPMVENDOR=$($DISTRVENDOR -n "$DISTRNAME")
}
realpath()
{
readlink -f "$@"
}
showcmd()
{
if [ -z "$quiet" ] ; then
set_boldcolor $GREEN
local PROMTSIG="\$"
[ "$UID" = 0 ] && PROMTSIG="#"
echo " $PROMTSIG $@"
restore_color
fi >&2
}
docmd()
{
showcmd "$@"
"$@"
}
docmd_foreach()
{
local cmd
cmd="$1"
#showcmd "$@"
shift
for pkg in "$@" ; do
docmd $cmd $pkg
done
}
sudocmd()
{
showcmd "$SUDO $@"
$SUDO "$@"
}
filter_strip_spaces()
{
# possible use just
#xargs echo
sed -e "s| \+| |g" | \
sed -e "s|^ ||" | sed -e "s| \$||"
}
filter_pkg_verel()
{
case $PKGFORMAT in
*)
cat
;;
esac
}
strip_spaces()
{
echo "$*" | filter_strip_spaces
}
fatal()
{
if [ -z "$TEXTDOMAIN" ] ; then
echo "Error: $@" >&2
fi
exit 1
}
set_sudo()
{
SUDO=""
# skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return
# set SUDO not for root user
[ -n "$UID" ] || UID=`id -u`
# do not need sudo
[ $UID = "0" ] && return
# use sudo if possible
which sudo >/dev/null 2>/dev/null && SUDO="sudo" && return
SUDO="fatal 'Can't find sudo. Please install sudo or run epm under root.'"
}
get_help()
{
grep -- "# $1" $0 | while read n ; do
opt=$(echo $n | sed -e "s|) # $1:.*||g")
desc=$(echo $n | sed -e "s|.*) # $1:||g")
printf " %-20s %s\n" $opt "$desc"
done
}
set_pm_type()
{
local CMD
# Fill for use: PMTYPE, DISTRNAME, DISTRVERSION, PKGFORMAT, PKGVENDOR, RPMVENDOR
DISTRVENDOR=internal_distr_info
[ -n "$DISTRNAME" ] || DISTRNAME=$($DISTRVENDOR -d)
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
set_target_pkg_env
if [ -n "$FORCEPM" ] ; then
PMTYPE=$FORCEPM
return
fi
case $DISTRNAME in
ALTLinux|PCLinux)
CMD="apt-rpm"
#which deepsolver 2>/dev/null >/dev/null && CMD=deepsolver-rpm
;;
PCLinux)
CMD="apt-rpm"
;;
Ubuntu|Debian|Mint)
CMD="apt-dpkg"
;;
Mandriva|ROSA)
CMD="urpm-rpm"
;;
FreeBSD|NetBSD|OpenBSD|Solaris)
CMD="pkgsrc"
;;
Gentoo)
CMD="emerge"
;;
ArchLinux)
CMD="pacman"
;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific)
CMD="yum-rpm"
;;
Slackware)
CMD="slackpkg"
;;
SUSE|SLED|SLES)
CMD="zypper-rpm"
;;
Windows)
CMD="chocolatey"
;;
*)
fatal "Do not known DISTRNAME $DISTRNAME"
;;
esac
PMTYPE=$CMD
}
# File bin/epm-addrepo:
epm_addrepo()
{
case $PMTYPE in
apt-rpm)
sudocmd apt-repo add $pkg_filenames
;;
apt-dpkg)
echo "You need manually add repo to /etc/apt/sources.list"
;;
yum-rpm)
echo "You need manually add repo to /etc/yum.repos.d/"
;;
urpm-rpm)
sudocmd urpmi.addmedia $pkg_filenames
;;
zypper-rpm)
sudocmd zypper ar $pkg_filenames
;;
emerge)
sudocmd layman -a $pkg_filenames
;;
pacman)
echo "You need manually add repo to /etc/pacman.conf"
;;
npackd)
docmd npackdcl add-repo --url=$pkg_filenames
;;
slackpkg)
echo "You need manually add repo to /etc/slackpkg/mirrors"
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-autoremove:
epm_autoremove()
{
case $PMTYPE in
#apt-rpm)
# sudocmd apt-get autoclean
# ;;
apt-dpkg)
sudocmd apt-get autoremove
;;
#yum-rpm)
# sudocmd yum clean all
# ;;
#urpm-rpm)
# sudocmd urpmi --clean
# ;;
#zypper-rpm)
# sudocmd zypper clean
# ;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-changelog:
__epm_changelog_files()
{
[ -z "$*" ] && return
case $PMTYPE in
apt-rpm|yum-rpm|zypper-rpm|urpm-rpm)
docmd_foreach "rpm -p --changelog" $@ | less
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
__epm_changelog_local_names()
{
[ -z "$*" ] && return
case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm)
docmd_foreach "rpm --changelog" $@ | less
;;
apt-dpkg)
# FIXME: only first pkg
docmd zcat /usr/share/doc/$1/changelog.Debian.gz | less
;;
emerge)
docmd view /usr/portage/category/$1/ChangeLog | less
;;
pacman)
docmd pacman -Qc package | less
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
__epm_changelog_unlocal_names()
{
[ -z "$*" ] && return
case $PMTYPE in
#apt-rpm)
# docmd_foreach "rpm --changelog" $@ | less
# ;;
#apt-dpkg)
# # FIXME: only first pkg
# docmd zcat /usr/share/doc/$1/changelog.Debian.gz | less
# ;;
#yum-rpm)
# sudocmd yum clean all
# ;;
#urpm-rpm)
# sudocmd urpmi --clean
# ;;
#zypper-rpm)
# sudocmd zypper clean
# ;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
epm_changelog()
{
[ -n "$pkg_filenames" ] || fatal "Run changelog without params"
__epm_changelog_files $pkg_files
local pkg
for pkg in $pkg_names ; do
if is_installed $pkg ; then
__epm_changelog_local_names $pkg
else
__epm_changelog_unlocal_names $pkg
fi
done
}
# File bin/epm-check:
epm_check()
{
case $PMTYPE in
apt-rpm|apt-dpkg)
#sudocmd apt-get check || exit
#sudocmd apt-get update || exit
sudocmd apt-get -f install || exit
;;
apt-dpkg)
#sudocmd apt-get update || exit
#sudocmd apt-get check || exit
sudocmd apt-get -f install || exit
sudocmd apt-get autoremove
;;
yum-rpm)
docmd yum check
docmd package-cleanup --problems
#docmd package-cleanup --dupes
sudocmd package-cleanup --cleandupes
# cleanup orphanes?
while true ; do
docmd package-cleanup --leaves
# FIXME: package-cleanup have to use stderr for errors
local PKGLIST=$(package-cleanup --leaves | grep -v "Loaded plugins" | grep -v "Unable to")
[ -n "$PKGLIST" ] || break
sudocmd yum remove $PKGLIST
done
docmd rpm -Va --nofiles --nodigest
;;
urpm-rpm)
sudocmd urpme --auto-orphans
;;
zypper-rpm)
sudocmd zypper verify || exit
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-checkpkg:
check_rpm_integrity()
{
docmd rpm --checksig $@
}
check_deb_integrity()
{
# FIXME: debsums -ca package ?
docmd dpkg --contents $@
}
check_bz2_integrity()
{
docmd bunzip -t $1
}
check_tbz_integrity()
{
check_bz2_integrity $@
}
check_gz_integrity()
{
docmd gunzip -t $1
}
check_tgz_integrity()
{
check_gz_integrity $@
}
check_zip_integrity()
{
docmd unzip -t $@
}
check_rar_integrity()
{
docmd unrar t $@
}
check_xz_integrity()
{
docmd xz -t $1
}
check_7z_integrity()
{
docmd 7z t $1
}
check_exe_integrity()
{
# skip
true
}
check_ebuild_integrity()
{
# skip
true
}
check_pkg_integrity()
{
local EXT=`echo "$1" | sed -e "s|.*\.\([a-z0-9]*\)\$|\1|g"`
local PKG="$1"
local RET
check_${EXT}_integrity "$PKG" || fatal "Unknown package extension '$EXT' in $PKG package"
}
epm_checkpkg()
{
[ -n "$pkg_files" ] || fatal "Run without names"
local pkg
for pkg in $pkg_files ; do
check_pkg_integrity $pkg || fatal "Broken package $pkg"
done
}
# File bin/epm-clean:
epm_clean()
{
case $PMTYPE in
apt-rpm|apt-dpkg)
sudocmd apt-get clean
;;
yum-rpm)
sudocmd yum clean all
sudocmd yum makecache
;;
dnf-rpm)
sudocmd dnf clean all
;;
urpm-rpm)
sudocmd urpmi --clean
;;
zypper-rpm)
sudocmd zypper clean
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-filelist:
__epm_filelist_file()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm)
CMD="rpm -qlp"
;;
apt-dpkg)
CMD="dpkg --contents"
;;
*)
fatal "Do not known query command for $PMTYPE"
;;
esac
docmd $CMD $@
}
__epm_filelist_name()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
apt-rpm)
CMD="rpm -ql"
;;
apt-dpkg)
CMD="dpkg -L"
;;
yum-rpm)
CMD="rpm -ql"
;;
urpm-rpm)
CMD="rpm -ql"
;;
zypper-rpm)
CMD="rpm -ql"
;;
pacman)
CMD="pacman -Ql"
;;
slackpkg)
is_installed $pkg_names || fatal "Query filelist for non installed packages does not realized"
docmd awk 'BEGIN{desk=1}{if(/^FILE LIST:$/){desk=0} else if (desk==0) {print}}' /var/log/packages/${pkg_filenames}*
return
;;
*)
fatal "Do not known query command for $PMTYPE"
;;
esac
docmd $CMD $pkg_names && return
is_installed $pkg_names || fatal "Query filelist for non installed packages does not realized"
}
epm_filelist()
{
[ -n "$pkg_filenames" ] || fatal "Run query without names"
__epm_filelist_file $pkg_files || return
__epm_filelist_name $pkg_names || return
}
# File bin/epm-info:
__epm_info_rpm_low()
{
if [ -n "$pkg_files" ] ; then
docmd rpm -qip $pkg_files
fi
[ -z "$pkg_names" ] && return
is_installed $pkg_names && docmd rpm -qi $pkg_names && return
}
epm_info()
{
case $PMTYPE in
apt-rpm)
__epm_info_rpm_low && return
docmd apt-cache show $pkg_names
;;
apt-dpkg)
if [ -n "$pkg_files" ] ; then
docmd dpkg -I $pkg_files
fi
[ -z "$pkg_names" ] && return
is_installed $pkg_names && docmd dpkg -p $pkg_names && return
docmd apt-cache show $pkg_names
;;
yum-rpm)
__epm_info_rpm_low && return
docmd yum info $pkg_names
;;
dnf-rpm)
__epm_info_rpm_low && return
docmd dnf info $pkg_names
;;
zypper-rpm)
__epm_info_rpm_low && return
docmd zypper info $pkg_names
;;
pacman)
docmd pacman -Si $pkg_names
;;
npackd)
# FIXME: --version=
docmd npackdcl info --package=$pkg_names
;;
slackpkg)
docmd /usr/sbin/slackpkg info $pkg_names
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-install:
filter_out_installed_packages()
{
[ -z "$skip_installed" ] && cat && return
# TODO: rewrite with use is_installed
# TODO: use this more effectively way
#for i in $(cat) ; do
# rpm -q $i >/dev/null && continue
# echo $i
#done |
case $PKGFORMAT in
"rpm")
LANG=C LC_ALL=C xargs -n1 rpm -q 2>&1 | grep 'is not installed' |
sed -e 's|^.*package \(.*\) is not installed.*|\1|g'
;;
"deb")
LANG=C LC_ALL=C xargs -n1 dpkg -l 2>&1 | grep 'no packages found matching' |
sed -e 's|^.*no packages found matching \(.*\)|\1|g'
;;
*)
cat
;;
esac | sed -e "s|rpm-build-altlinux-compat[^ ]*||g" | filter_strip_spaces
}
epm_install_names()
{
if [ -n "$non_interactive" ] ; then
epm_ni_install_names "$@"
return
fi
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm|apt-dpkg)
sudocmd apt-get $APTOPTIONS install $@
return ;;
deepsolver-rpm)
sudocmd ds-install $@
return ;;
urpm-rpm)
sudocmd urpmi $URPMOPTIONS $@
return ;;
pkgsrc)
sudocmd pkg_add -r $@
return ;;
emerge)
sudocmd emerge -uD $@
return ;;
pacman)
sudocmd pacman -S $@
return ;;
yum-rpm)
sudocmd yum $YUMOPTIONS install $@
return ;;
dnf-rpm)
sudocmd dnf install $@
return ;;
zypper-rpm)
sudocmd zypper install $ZYPPEROPTIONS $@
return ;;
mpkg)
sudocmd mpkg install $@
return ;;
slackpkg)
# TODO: use upgrade if package is already installed
sudocmd /usr/sbin/slackpkg install $@
return ;;
*)
fatal "Do not known install command for $PMTYPE"
;;
esac
}
epm_ni_install_names()
{
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm|apt-dpkg)
sudocmd apt-get -y --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $APTOPTIONS install $@
return ;;
yum-rpm)
sudocmd yum -y $YUMOPTIONS install $@
return ;;
urpm-rpm)
sudocmd urpmi --auto $URPMOPTIONS $@
return ;;
zypper-rpm)
# FIXME: returns true ever no package found, need check for "no found", "Nothing to do."
yes | sudocmd zypper --non-interactive $ZYPPEROPTIONS install $@
return ;;
pkgsrc)
sudocmd pkg_add -r $@
return ;;
pacman)
sudocmd pacman -S --noconfirm $@
return ;;
npackd)
# npackdcl update --package=<package> (remove old and install new)
docmd npackdcl add --package=$@
return ;;
chocolatey)
docmd chocolatey install $@
return ;;
slackpkg)
# TODO: use upgrade if package is already installed
sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes install $@
return ;;
*)
fatal "Do not known appropriate install command for $PMTYPE"
;;
esac
}
epm_install_files()
{
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm)
sudocmd rpm -Uvh $force $nodeps $@ && return
# TODO: check for "is already installed"
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return
# use install_names
;;
apt-dpkg)
# the new version of the conf. file is installed with a .dpkg-dist suffix
if [ -n "$non_interactive" ] ; then
DPKGOPTIONS="--force-confdef --force-confold"
fi
sudocmd dpkg $DPKGOPTIONS -i $@
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return
# fall to apt-get -f install for fix deps
APTOPTIONS="-f"
;;
yum-rpm|dnf-rpm)
sudocmd rpm -Uvh $force $nodeps $@ && return
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return
YUMOPTIONS=--nogpgcheck
# use install_names
;;
zypper-rpm)
sudocmd rpm -Uvh $force $nodeps $@ && return
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return
ZYPPEROPTIONS=--no-gpg-checks
# use install_names
;;
urpm-rpm)
sudocmd rpm -Uvh $force $nodeps $@ && return
# if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return
URPMOPTIONS=--no-verify-rpm
# use install_names
;;
pkgsrc)
sudocmd pkg_add $@
return ;;
pacman)
sudocmd pacman -U --noconfirm $@
return ;;
slackpkg)
sudocmd /sbin/installpkg $@
return ;;
esac
# other systems can install file package via ordinary command
epm_install_names "$@"
}
epm_print_install_command()
{
case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
echo "rpm -Uvh --force $nodeps $@"
;;
apt-dpkg)
echo "dpkg -i $@"
;;
pkgsrc)
echo "pkg_add $@"
;;
pacman)
echo "pacman -U --noconfirm $@"
;;
slackpkg)
echo "/sbin/installpkg $@"
;;
npackd)
echo "npackdcl add --package=$@"
;;
*)
fatal "Do not known appropriate install command for $PMTYPE"
;;
esac
}
epm_install()
{
if [ -n "$show_command_only" ] ; then
epm_print_install_command $pkg_filenames
return
fi
[ -n "$pkg_files$pkg_names" ] || fatal "Run install without packages"
local names="$(echo $pkg_names | filter_out_installed_packages)"
local files="$(echo $pkg_files | filter_out_installed_packages)"
[ -z "$files$names" ] && echo "Skip empty install list" && return 22
epm_install_names $names || return
epm_install_files $files
}
# File bin/epm-packages:
epm_packages()
{
local CMD
case $PMTYPE in
apt-rpm)
CMD="rpm -qa $pkg_filenames"
[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
;;
apt-dpkg)
CMD="dpkg -l $pkg_filenames"
;;
yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
CMD="rpm -qa $pkg_filenames"
;;
emerge)
CMD="qlist -I"
;;
pkgsrc)
CMD="pkg_info"
;;
pacman)
CMD="pacman -Qs"
;;
npackd)
CMD="npackdcl list"
;;
slackpkg)
CMD="ls -1 /var/log/packages/"
;;
*)
fatal "Do not known query command for $PMTYPE"
;;
esac
docmd $CMD
}
# File bin/epm-programs:
epm_programs()
{
local DESKTOPDIR=/usr/share/applications
[ -d "$DESKTOPDIR" ] || fatal "There is no $DESKTOPDIR dir on the system."
#find /usr/share/applications -type f -name "*.desktop" | while read f; do pkg_files="$f" quiet=1 short=1 epm_query_file ; done | sort -u
find /usr/share/applications -type f -name "*.desktop" | \
xargs $0 -qf --quiet --short | sort -u
}
# File bin/epm-query:
_query_via_packages_list()
{
local res=0
local firstpkg=$1
shift
epm_packages | grep -- "$firstpkg-" || res=1
for pkg in "$@" ; do
epm_packages 2>/dev/null | grep -- "$pkg-" || res=1
done
return $res
}
__epm_query_file()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm)
CMD="rpm -qp"
;;
apt-dpkg)
CMD="dpkg-deb --show"
# TODO: make rpm-like output
#showcmd dpkg -l $pkg_filenames
#dpkg -l $pkg_filenames | grep "^ii"
#return
;;
*)
fatal "Do not know command for query file package"
;;
esac
docmd $CMD $@
}
__epm_query_name()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm)
CMD="rpm -q"
;;
apt-dpkg)
CMD="dpkg -l"
# TODO: make rpm-like output
#showcmd dpkg -l $pkg_filenames
#dpkg -l $pkg_filenames | grep "^ii"
#return
;;
npackd)
CMD="npackdcl path --package=$@"
;;
*)
_query_via_packages_list $@
return
;;
esac
docmd $CMD $@
}
is_installed()
{
pkg_filenames="$@" epm_query >/dev/null
}
epm_query()
{
[ -n "$pkg_filenames" ] || fatal "Run query without names"
__epm_query_file $pkg_files || return
__epm_query_name $pkg_names || return
}
# File bin/epm-query_file:
__do_query_real_file()
{
local LINKTO1 LINKTO
local TOFILE
# get canonical path
if [ -e "$1" ] ; then
TOFILE=$1
else
TOFILE=`which $1 2>/dev/null || echo $1`
if [ "$TOFILE" != "$1" ] ; then
echo "Note: $1 is placed as $TOFILE"
fi
fi
# get value of symbolic link
if [ -L "$TOFILE" ] ; then
__do_query $TOFILE
LINKTO=`readlink "$TOFILE"`
echo "Note: $TOFILE is link to $LINKTO"
__do_query_real_file "$LINKTO"
fi
FULLFILEPATH=`realpath $TOFILE`
}
dpkg_print_name_version()
{
local ver i
for i in $* ; do
ver=$(dpkg -s $i 2>/dev/null | grep "Version:" | sed -e "s|Version: ||g")
if [ -z "$ver" ] ; then
echo "$i"
else
echo "$i-$ver"
fi
done
}
__do_query()
{
local CMD
case $PMTYPE in
apt-rpm)
CMD="rpm -qf"
;;
apt-dpkg)
showcmd dpkg -S $1
dpkg_print_name_version $(dpkg -S $1 | sed -e "s|:.*||")
return ;;
yum-rpm|urpm-rpm)
CMD="rpm -qf"
;;
zypper-rpm)
CMD="rpm -qf"
;;
emerge)
CMD="equery belongs"
;;
pacman)
CMD="pacman -Qo"
;;
slackpkg)
# note: need remove leading slash for grep
docmd grep -R -- "$(echo $@ | sed -e 's|^/\+||g')" /var/log/packages | sed -e "s|/var/log/packages/||g"
return
;;
*)
fatal "Do not known query command for $PMTYPE"
;;
esac
docmd $CMD $@
}
__do_short_query()
{
local CMD
case $PMTYPE in
*-rpm)
CMD="rpm -qf --queryformat %{NAME}\n"
;;
NOapt-dpkg)
showcmd dpkg -S $1
dpkg_print_name_version $(dpkg -S $1 | sed -e "s|:.*||")
return ;;
NOemerge)
CMD="equery belongs"
;;
NOpacman)
CMD="pacman -Qo"
;;
NOslackpkg)
# note: need remove leading slash for grep
docmd grep -R "$(echo $@ | sed -e 's|^/\+||g')" /var/log/packages | sed -e "s|/var/log/packages/||g"
return
;;
*)
fatal "Do not known query command for $PMTYPE"
;;
esac
docmd $CMD $@
}
epm_query_file()
{
# in short mode print handle only real names and do short output
# TODO: move to separate command?
if [ -n "$short" ] ; then
[ -n "$pkg_files" ] || fatal "Run query without file names (needed path to files)"
__do_short_query $pkg_files
return
fi
# file can exists or not
[ -n "$pkg_filenames" ] || fatal "Run query without file names"
for pkg in $pkg_filenames ; do
__do_query_real_file "$pkg"
__do_query $FULLFILEPATH || pkg_filenames=$pkg epm_search_file
done
}
# File bin/epm-query_package:
epm_query_package()
{
#showcmd grep --color "$pkg_filenames"
pkg_filenames= epm_packages | grep --color -- "$pkg_filenames"
}
# File bin/epm-reinstall:
epm_reinstall_names()
{
[ -n "$1" ] || return
case $PMTYPE in
apt-rpm|apt-dpkg)
sudocmd apt-get --reinstall install $@
return ;;
yum-rpm)
sudocmd yum install $@
return ;;
dnf-rpm)
sudocmd dnf reinstall $@
return ;;
urpm-rpm)
sudocmd urpmi $@
return ;;
zypper-rpm)
sudocmd zypper install $@
return ;;
pkgsrc)
sudocmd pkg_add -r $@
return ;;
pacman)
sudocmd pacman -U $@
return ;;
slackpkg)
sudocmd /usr/sbin/slackpkg reinstall $@
return ;;
*)
fatal "Do not known install command for $PMTYPE"
;;
esac
}
epm_reinstall_files()
{
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm)
sudocmd rpm -Uvh --force $@ && return
sudocmd apt-get --reinstall install $@
return ;;
apt-pkg)
sudocmd dpkg -i $@
return ;;
slackpkg)
sudocmd /sbin/installpkg $@
return ;;
esac
# other systems can install file package via ordinary command
epm_reinstall_names $@
}
epm_reinstall()
{
[ -n "$pkg_filenames" ] || fatal "Run install without packages"
epm_reinstall_names $pkg_names
epm_reinstall_files $pkg_files
}
# File bin/epm-remove:
epm_remove_low()
{
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm)
sudocmd rpm -ev $nodeps $@
return ;;
apt-dpkg)
sudocmd dpkg -P $@
return ;;
pkgsrc)
sudocmd pkg_delete -r $@
return ;;
emerge)
sudocmd emerge --unmerge $@
return ;;
slackpkg)
sudocmd /sbin/removepkg $@
return ;;
esac
return 1
}
epm_remove_names()
{
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm|apt-dpkg)
sudocmd apt-get remove --purge $@
return ;;
deepsolver-rpm)
sudocmd ds-remove $@
return ;;
urpm-rpm)
sudocmd urpme $@
return ;;
pkgsrc) # without dependencies
sudocmd pkg_delete $@
return ;;
emerge)
#sudocmd emerge --unmerge $@
sudocmd emerge -aC $@
return ;;
pacman)
sudocmd pacman -R $@
return ;;
yum-rpm)
sudocmd yum remove $@
return ;;
dnf-rpm)
sudocmd dnf remove $@
return ;;
zypper-rpm)
sudocmd zypper remove $@
return ;;
mpkg)
sudocmd mpkg remove $@
return ;;
npackd)
docmd npackdcl remove --package=$@
return ;;
chocolatey)
docmd chocolatey uninstall $@
return ;;
slackpkg)
sudocmd /usr/sbin/slackpkg remove $@
return ;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
epm_remove_nonint()
{
case $PMTYPE in
apt-rpm|apt-dpkg)
sudocmd apt-get -y --force-yes remove --purge $@
return ;;
urpm-rpm)
sudocmd urpme --auto $@
return ;;
pacman)
sudocmd pacman -R --noconfirm $@
return ;;
yum-rpm)
sudocmd yum -y remove $@
return ;;
zypper-rpm)
sudocmd zypper --non-interactive remove $@
return ;;
slackpkg)
sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes remove $@
return ;;
esac
return 5
}
epm_print_remove_command()
{
case $PMTYPE in
apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm)
echo "rpm -ev $nodeps $@"
;;
apt-dpkg)
echo "dpkg -P $@"
;;
pkgsrc)
echo "pkg_delete -r $@"
;;
emerge)
echo "emerge --unmerge $@"
;;
slackpkg)
echo "/sbin/removepkg $@"
;;
*)
fatal "Do not known appropriate remove command for $PMTYPE"
;;
esac
}
epm_remove()
{
if [ -n "$show_command_only" ] ; then
epm_print_remove_command $pkg_filenames
return
fi
[ -n "$pkg_files" ] && fatal "FIXME: remove by package file is not supported yet"
[ -n "$pkg_filenames" ] || fatal "Run remove without args"
epm_remove_low $pkg_filenames && return
# FIXME: needs only for apt
pkg_filenames=$(echo $pkg_filenames | filter_pkg_verel)
if [ -n "$non_interactive" ] ; then
epm_remove_nonint $pkg_filenames
local RET=$?
# if not separate command, use usual command
[ "$RET" = "5" ] || return $RET
fi
epm_remove_names $pkg_filenames
}
# File bin/epm-removerepo:
epm_removerepo()
{
case $PMTYPE in
apt-rpm)
sudocmd apt-repo rm $pkg_filenames
;;
apt-dpkg)
echo "You need remove repo from /etc/apt/sources.list"
;;
yum-rpm)
echo "You need remove repo from /etc/yum.repos.d/"
;;
urpm-rpm)
sudocmd urpmi.removemedia $pkg_filenames
;;
zypper-rpm)
sudocmd zypper removerepo $pkg_filenames
;;
emerge)
sudocmd layman -d$pkg_filenames
;;
pacman)
echo "You need remove repo from /etc/pacman.conf"
;;
npackd)
docmd npackdcl remove-repo --url=$pkg_filenames
;;
slackpkg)
echo "You need remove repo from /etc/slackpkg/mirrors"
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-repolist:
print_apt_sources_list()
{
local i
for i in $@ ; do
test -r "$i" || continue
#echo
#echo "$i:"
grep -v -- "^#" $i
done | grep -v -- "^ *\$"
}
epm_repolist()
{
case $PMTYPE in
apt-rpm)
docmd apt-repo list
;;
deepsolver-rpm)
docmd ds-conf
;;
apt-dpkg)
showcmd cat /etc/apt/sources.list*
print_apt_sources_list /etc/apt/sources.list /etc/apt/sources.list.d/*.list
;;
yum-rpm)
docmd yum repolist
;;
dnf-rpm)
docmd dnf repolist -v
;;
urpm-rpm)
docmd urpmq --list-url
;;
zypper-rpm)
docmd zypper sl -d
;;
emerge)
docmd layman -L
;;
pacman)
docmd grep -v -- "^#\|^$" /etc/pacman.conf
;;
slackpkg)
docmd grep -v -- "^#\|^$" /etc/slackpkg/mirrors
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
}
# File bin/epm-requires:
epm_requires()
{
local CMD
[ -n "$pkg_filenames" ] || fatal "Run query without names"
case $PMTYPE in
apt-rpm|urpm-rpm|zypper-rpm|yum-rpm)
CMD="rpm -q --requires -p"
;;
apt-dpkg)
showcmd dpkg -s $pkg_files
a= dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
return
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
[ -n "$pkg_files" ] && docmd $CMD $pkg_files
case $PMTYPE in
apt-rpm|urpm-rpm|zypper-rpm)
# FIXME: use hi level commands
CMD="rpm -q --requires"
;;
yum-rpm)
CMD="yum deplist"
;;
apt-dpkg)
CMD="apt-cache depends"
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
[ -n "$pkg_names" ] && docmd $CMD $pkg_names
}
# File bin/epm-search:
epm_search()
{
local CMD
[ -n "$pkg_filenames" ] || fatal "Run search without names"
case $PMTYPE in
apt-rpm|apt-dpkg)
CMD="apt-cache search"
;;
urpm-rpm)
CMD="urpmq -y"
;;
pkgsrc)
CMD="pkg_info -x"
;;
emerge)
CMD="emerge --search"
;;
pacman)
CMD="pacman -Ss"
;;
yum-rpm)
CMD="yum search"
;;
dnf-rpm)
CMD="dnf search"
;;
zypper-rpm)
CMD="zypper search"
;;
mpkg)
CMD="mpkg search"
;;
npackd)
fatal "FIXME: Have not idea for search with npackdcl list"
;;
chocolatey)
CMD="chocolatey list"
;;
slackpkg)
# FIXME
echo "FIXME: need case insensitive search"
docmd_foreach "/usr/sbin/slackpkg search" $pkg_filenames
return
;;
*)
fatal "Do not known search command for $PMTYPE"
;;
esac
docmd $CMD $pkg_filenames
}
# File bin/epm-search_file:
local_content_search()
{
local SYSARCH
SYSARCH=$(uname -m)
[ "$SYSARCH" = "x86_64" ] || SYSARCH=i586
local REPODIR=/var/ftp/pub/ALTLinux/Sisyphus
local CI=$REPODIR/$SYSARCH/base/contents_index
local CINOA=$REPODIR/noarch/base/contents_index
#local OUTCMD="less"
#[ -n "$USETTY" ] || OUTCMD="cat"
OUTCMD="cat"
test -r $CI && test -r $CINOA || fatal "Can't locate $CI or $CINOA"
{
[ -n "$USETTY" ] && echo "Search in $CI and $CINOA for $1..."
grep -h -- ".*$1.*\t" $CI $CINOA | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g"
} | $OUTCMD
}
epm_search_file()
{
local CMD
[ -n "$pkg_filenames" ] || fatal "Run search without names"
case $PMTYPE in
apt-rpm)
local_content_search $pkg_filenames
return ;;
apt-dpkg)
sudocmd apt-file update
docmd apt-file search $pkg_filenames
return ;;
yum-rpm)
CMD="yum provides"
;;
dnf-rpm)
CMD="dnf provides"
;;
urpm-rpm)
CMD="urpmf"
;;
zypper-rpm)
CMD="zypper wp vi"
;;
pacman)
CMD="pacman -Qo"
;;
slackpkg)
CMD="/usr/sbin/slackpkg file-search"
;;
*)
fatal "Do not known search file command for $PMTYPE"
;;
esac
docmd $CMD $pkg_filenames
}
# File bin/epm-simulate:
__use_zypper_dry_run()
{
a= zypper install --help 2>&1 | grep -q -- "--dry-run" && echo "--dry-run"
}
_epm_do_simulate()
{
local CMD
local filenames=$@
case $PMTYPE in
apt-rpm|apt-dpkg)
CMD="apt-get --simulate install"
;;
yum-rpm)
LC_ALL=C sudocmd yum --assumeno install $filenames
# FIXME: check only error output
LC_ALL=C sudocmd yum --assumeno install $filenames 2>&1 | grep "^No package" && return 1
return 0 ;;
urpm-rpm)
CMD="urpmi --test --auto"
;;
zypper-rpm)
if ! __use_zypper_dry_run >/dev/null ; then
echo "zypper is too old: does not support --dry-run"
return
fi
CMD="zypper --non-interactive install"
;;
emerge)
echo "FIXME: Skip with emerge"
return ;;
pacman)
showcmd $SUDO pacman -v -S $filenames
echo no | $SUDO pacman -v -S $filenames
return ;;
slackpkg)
#docmd /usr/sbin/slackpkg -batch=on -default_answer=yes download
# just try search every package
# FIXME: epm_search have to return false status code if the package does not found
local pkg res
res=0
for pkg in $filenames ; do
pkg_filenames="$pkg-[0-9]" epm_search | grep -E "(installed|upgrade)" && continue
pkg_filenames="$pkg" epm_search | grep -E "(installed|upgrade)" && continue
res=1
echo "Does not found in repository."
done
return $res ;;
*)
fatal "Do not known simulate command for $PMTYPE"
;;
esac
sudocmd $CMD $filenames
}
epm_simulate()
{
[ -z "$pkg_filenames" ] && echo "Skip empty list" && return 22
local filenames="$(echo $pkg_filenames | filter_out_installed_packages)"
[ -z "$filenames" ] && echo "All packages are already installed" && return 0
_epm_do_simulate $filenames
local RES=$?
if [ -z "$quiet" ] ; then
[ "$RES" = 0 ] && echo "Result: $filenames package(s) CAN BE installed" || echo "Result: There are PROBLEMS with install some package(s)"
fi
return $RES
}
# File bin/epm-update:
epm_update()
{
echo "Run command for update remote package repository database"
case $PMTYPE in
apt-rpm)
sudocmd apt-get update || exit
#sudocmd apt-get -f install || exit
;;
apt-dpkg)
sudocmd apt-get update || exit
#sudocmd apt-get -f install || exit
#sudocmd apt-get autoremove
;;
yum-rpm)
sudocmd yum check-update
;;
urpm-rpm)
sudocmd urpmi.update -a
;;
pacman)
sudocmd pacman -S -y
;;
zypper-rpm)
sudocmd zypper refresh
;;
emerge)
sudocmd emerge --sync
;;
slackpkg)
sudocmd /usr/sbin/slackpkg update
;;
deepsolver-rpm)
sudocmd ds-update
;;
*)
fatal "Do not known update command for $PMTYPE"
;;
esac
}
# File bin/epm-upgrade:
epm_upgrade()
{
local CMD
echo "Run command for upgrade packages"
case $PMTYPE in
apt-rpm|apt-dpkg)
# FIXME: apt-get update before
CMD="apt-get dist-upgrade"
;;
yum-rpm)
CMD="yum update"
;;
dnf-rpm)
CMD="dnf update"
;;
urpm-rpm)
# or --auto-select --replace-files
CMD="urpmi --auto-update"
;;
zypper-rpm)
CMD="zypper dist-upgrade"
;;
pacman)
CMD="pacman -S -u"
;;
emerge)
CMD="emerge -NuDa world"
;;
pkgsrc)
CMD="freebsd-update fetch install"
;;
chocolatey)
CMD="chocolatey update all"
;;
slackpkg)
CMD="/usr/sbin/slackpkg upgrade-all"
;;
*)
fatal "Do not known command for $PMTYPE"
;;
esac
sudocmd $CMD $pkg_filenames
}
# File bin/epm-Upgrade:
epm_Upgrade()
{
case $PMTYPE in
yum-rpm)
;;
*)
epm_update || return
;;
esac
epm_upgrade $pkg_filenames
}
internal_distr_info()
{
#!/bin/sh
# Author: Vitaly Lipatov <lav@etersoft.ru>
# 2007, 2009, 2010, 2012 (c) Etersoft
# 2007 Public domain
# Detect the distro and version
# Welcome to send updates!
# You can set ROOTDIR to root system dir
#ROOTDIR=
# Check for DISTRO specific file in /etc
distro()
{
#[ -n "$ROOTDIR" ] || return
# fill global DISTROFILE
DISTROFILE="$ROOTDIR/etc/$1"
[ -f "$DISTROFILE" ]
}
# Has a distro file the specified word?
has()
{
[ -n "$DISTROFILE" ] || exit 1
grep "$*" "$DISTROFILE" >/dev/null 2>&1
}
# Translate DISTRIB_ID to vendor name (like %_vendor does)
rpmvendor()
{
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
echo "$DISTRIB_ID" | tr "[A-Z]" "[a-z]"
}
# Translate DISTRIB_ID name to package manner (like in the package release name)
pkgvendor()
{
[ "$DISTRIB_ID" = "Mandriva" ] && echo "mdv" && return
rpmvendor
}
# Print pkgtype (need DISTRIB_ID var)
pkgtype()
{
case `pkgvendor` in
freebsd) echo "tbz" ;;
sunos) echo "pkg.gz" ;;
slackware|mopslinux) echo "tgz" ;;
archlinux) echo "tar.xz" ;;
gentoo) echo "tbz2" ;;
windows) echo "exe" ;;
debian|ubuntu|mint|runtu) echo "deb" ;;
alt|asplinux|suse|mandriva|rosa|mandrake|pclinux|sled|sles)
echo "rpm" ;;
fedora|redhat|scientific|centos|rhel)
echo "rpm" ;;
*) echo "rpm" ;;
esac
}
get_var()
{
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//"
}
# 2010.1 -> 2010
get_major_version()
{
echo "$1" | sed -e "s/\..*//g"
}
# Default values
DISTRIB_ID="Generic"
DISTRIB_RELEASE=""
# Default with LSB
if distro lsb-release ; then
DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID`
DISTRIB_RELEASE=`cat $DISTROFILE | get_var DISTRIB_RELEASE`
fi
# ALT Linux based
if distro altlinux-release ; then
DISTRIB_ID="ALTLinux"
if has Strawberry ; then DISTRIB_RELEASE="2.3"
elif has Citron ; then DISTRIB_RELEASE="2.4"
elif has 20050723 ; then DISTRIB_RELEASE="3.0"
elif has Ajuga ; then DISTRIB_RELEASE="4.0"
elif has 20070810 ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
elif has Walnut ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7"
elif has 6.0 ; then DISTRIB_RELEASE="p6"
elif has Centaurea ; then DISTRIB_RELEASE="p6"
elif has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
fi
elif distro gentoo-release ; then
DISTRIB_ID="Gentoo"
DISTRIB_RELEASE=`basename $(readlink $ROOTDIR/etc/make.profile)`
# Slackware based
elif distro mopslinux-version ; then
DISTRIB_ID="MOPSLinux"
if has 4.0 ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has 6.0 ; then DISTRIB_RELEASE="6.0"
elif has 6.1 ; then DISTRIB_RELEASE="6.1"
fi
elif distro slackware-version ; then
DISTRIB_ID="Slackware"
DISTRIB_RELEASE="$(grep -Eo [0-9]+\.[0-9]+ $DISTROFILE)"
elif distro arch-release ; then
DISTRIB_ID="ArchLinux"
DISTRIB_RELEASE="2010"
if grep 2011 -q $ROOTDIR/etc/pacman.d/mirrorlist ; then
DISTRIB_RELEASE="2011"
fi
# for Ubuntu use standard LSB info
elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB version
true
# Debian based
elif distro debian_version ; then
DISTRIB_ID="Debian"
DISTRIB_RELEASE=`cat $DISTROFILE`
# Mandriva based
elif distro pclinuxos-release ; then
DISTRIB_ID="PCLinux"
if has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
elif has "2010" ; then DISTRIB_RELEASE="2010"
fi
elif distro mandriva-release || distro mandrake-release ; then
DISTRIB_ID="Mandriva"
if has 2005 ; then DISTRIB_RELEASE="2005"
elif has 2006 ; then DISTRIB_RELEASE="2006"
elif has 2007 ; then DISTRIB_RELEASE="2007"
elif has 2008 ; then DISTRIB_RELEASE="2008"
elif has 2009.0 ; then DISTRIB_RELEASE="2009.0"
elif has 2009.1 ; then DISTRIB_RELEASE="2009.1"
else
# use /etc/lsb-release info by default
if has ROSA ; then
DISTRIB_ID="ROSA"
fi
fi
# Fedora based
elif distro linux-xp-release || distro lxp-release; then
DISTRIB_ID="LinuxXP"
if has "Attack of the Clones" ; then DISTRIB_RELEASE="2006"
elif has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
elif has "2009" ; then DISTRIB_RELEASE="2009"
fi
elif distro asplinux-release ; then
DISTRIB_ID="ASPLinux"
if has Karelia ; then DISTRIB_RELEASE="10"
elif has Seliger ; then DISTRIB_RELEASE="11"
elif has "11.1" ; then DISTRIB_RELEASE="11.1"
elif has Ladoga ; then DISTRIB_RELEASE="11.2"
elif has "11.2" ; then DISTRIB_RELEASE="11.2"
elif has "12" ; then DISTRIB_RELEASE="12"
elif has "13" ; then DISTRIB_RELEASE="13"
elif has "14" ; then DISTRIB_RELEASE="14"
elif has "15" ; then DISTRIB_RELEASE="15"
fi
elif distro MCBC-release ; then
DISTRIB_ID="MCBC"
if has 3.0 ; then DISTRIB_RELEASE="3.0"
elif has 3.1 ; then DISTRIB_RELEASE="3.1"
fi
elif distro fedora-release ; then
DISTRIB_ID="Fedora"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g")
elif distro redhat-release ; then
# FIXME if need
# actually in the original RHEL: Red Hat Enterprise Linux .. release N
DISTRIB_ID="RHEL"
if has CentOS ; then
DISTRIB_ID="CentOS"
elif has Scientific ; then
DISTRIB_ID="Scientific"
fi
if has Beryllium ; then
DISTRIB_ID="Scientific"
DISTRIB_RELEASE="4.1"
elif has Shrike ; then
DISTRIB_ID="RedHat"
DISTRIB_RELEASE="9"
elif has Taroon ; then DISTRIB_RELEASE="3"
elif has "release 4" ; then DISTRIB_RELEASE="4"
elif has "release 5" ; then DISTRIB_RELEASE="5"
elif has "release 6" ; then DISTRIB_RELEASE="6"
elif has "release 7" ; then DISTRIB_RELEASE="7"
fi
# SUSE based
elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SUSE"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "VERSION" | sed -e "s|^VERSION = ||g")
if has "SUSE Linux Enterprise Desktop" ; then
DISTRIB_ID="SLED"
elif has "SUSE Linux Enterprise Server" ; then
DISTRIB_ID="SLES"
fi
# fixme: can we detect by some file?
elif [ `uname` = "FreeBSD" ] ; then
DISTRIB_ID="FreeBSD"
UNAME=$(uname -r)
DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g")
# fixme: can we detect by some file?
elif [ `uname` = "SunOS" ] ; then
DISTRIB_ID="SunOS"
DISTRIB_RELEASE=$(uname -r)
# try use standart LSB info by default
elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB
true
fi
case $1 in
-p)
# override DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
pkgtype
exit 0
;;
-h)
echo "distr_vendor - system name and version detection"
echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name"
echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)"
echo "-s [SystemName] - print name of distro for build system (like in the package release name)"
echo "-n [SystemName] - print vendor name (as _vendor macros in rpm)"
echo "-V - print the version of $0"
echo "-h - this help"
exit 0
;;
-d)
echo $DISTRIB_ID
;;
-v)
echo $DISTRIB_RELEASE
;;
-s)
# override DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
pkgvendor
exit 0
;;
-n)
# override DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
rpmvendor
exit 0
;;
-V)
echo "20120519"
exit 0
;;
*)
# if run without args, just printout Name/Version of the current system
[ -n "$DISTRIB_RELEASE" ] && echo $DISTRIB_ID/$DISTRIB_RELEASE || echo $DISTRIB_ID
;;
esac
}
#PATH=$PATH:/sbin:/usr/sbin
set_sudo
check_tty
#############################
phelp()
{
echo "$Descr
$Usage
Commands:
$(get_help HELPCMD)
Options:
$(get_help HELPOPT)
"
}
print_version()
{
echo "EPM package manager version 1.1.8"
echo "Running on $($DISTRVENDOR) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)"
echo "Copyright (c) Etersoft 2012-2013"
echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
}
Usage="Usage: epm [options] <command> [package name(s), package files]..."
Descr="epm - EPM package manager"
set_pm_type
verbose=
quiet=
nodeps=
force=
short=
non_interactive=
skip_installed=
show_command_only=
epm_cmd=
pkg_files=
pkg_names=
progname="${0##*/}"
case $progname in
epmi)
epm_cmd=install
;;
epme)
epm_cmd=remove
;;
epmcl)
epm_cmd=changelog
;;
epms)
epm_cmd=search
;;
epmq)
epm_cmd=query
;;
epmqi)
epm_cmd=info
;;
epmqf)
epm_cmd=query_file
;;
epmqa)
epm_cmd=packages
;;
epmqp)
epm_cmd=query_package
;;
epm|upm|eepm)
;;
*)
# epm by default
# fatal "Unknown command: $progname"
;;
esac
check_command()
{
# do not override command
[ -z "$epm_cmd" ] || return
# Base commands
case $1 in
-i|install|add) # HELPCMD: install package(s) from remote repositories or from local file
epm_cmd=install
;;
-e|-P|remove|delete) # HELPCMD: remove (delete) package(s) from the database and the system
epm_cmd=remove
;;
-s|search) # HELPCMD: search in remote package repositories
epm_cmd=search
;;
-qp|query_package) # HELPCMD: search in the list of installed packages
epm_cmd=query_package
;;
-qf|which|belongs) # HELPCMD: query package(s) owning file
epm_cmd=query_file
;;
# Useful commands
reinstall) # HELPCMD: reinstall package(s) from remote repositories or from local file
epm_cmd=reinstall
;;
-q|installed) # HELPCMD: check presence of package(s)
epm_cmd=query
;;
-sf|sf|filesearch) # HELPCMD: search in which package a file is included
epm_cmd=search_file
;;
-ql|filelist) # HELPCMD: print package file list
epm_cmd=filelist
;;
check|fix|verify) # HELPCMD: check local package base integrity and fix it
epm_cmd=check
;;
changelog|cl) # HELPCMD: show changelog for package
epm_cmd=changelog
;;
-qi|info|show) # HELPCMD: print package detail info
epm_cmd=info
;;
requires|deplist) # HELPCMD: print package requires
epm_cmd=requires
;;
-qa|list|packages|-l) # HELPCMD: list of installed package(s)
epm_cmd=packages
;;
programs) # HELPCMD: list of installed program(s)
epm_cmd=programs
;;
# Repository control
update) # HELPCMD: update remote package repository databases
epm_cmd=update
;;
addrepo|ar) # HELPCMD: add package repo
epm_cmd=addrepo
;;
repolist|sl|rl|listrepo) # HELPCMD: print repo list
epm_cmd=repolist
;;
removerepo|rr) # HELPCMD: remove package repo
epm_cmd=removerepo
;;
# Other commands
clean) # HELPCMD: clean local package cache
epm_cmd=clean
;;
autoremove) # HELPCMD: auto remove unneeded package(s)
epm_cmd=autoremove
;;
upgrade|dist-upgrade) # HELPCMD: performs upgrades of package software distributions
epm_cmd=upgrade
;;
Upgrade) # HELPCMD: performs update && upgrade command
epm_cmd=Upgrade
;;
simulate) # HELPCMD: simulate install (it does check requires, minimally)
epm_cmd=simulate
;;
checkpkg|integrity) # HELPCMD: check package integrity
epm_cmd=checkpkg
;;
*)
return 1
;;
esac
return 0
}
check_option()
{
case $1 in
-h|--help|help) # HELPOPT: this help
phelp
exit 0
;;
-v|--version) # HELPOPT: print version
print_version
exit 0
;;
--verbose) # HELPOPT: verbose mode
verbose=1
;;
--skip-installed) # HELPOPT: skip already install during install
skip_installed=1
;;
--show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY)
show_command_only=1
;;
--quiet) # HELPOPT: quiet mode (do not print commands before exec)
quiet=1
;;
--nodeps) # HELPOPT: skip dependency check (during install/simulate and so on)
nodeps="--nodeps"
;;
--force) # HELPOPT: force install/remove package (f.i., override)
force="--force"
;;
--short) # HELPOPT: short output (package instead package-version-release)
short="--short"
;;
--auto) # HELPOPT: non interactive mode
non_interactive=1
;;
*)
return 1
;;
esac
return 0
}
for opt in "$@" ; do
check_command $opt && continue
check_option $opt && continue
if [ -f "$opt" ] ; then
pkg_files="$pkg_files $opt"
else
pkg_names="$pkg_names $opt"
fi
done
pkg_files=$(strip_spaces "$pkg_files")
pkg_names=$(strip_spaces "$pkg_names")
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
# Just debug
#echover "command: $epm_cmd"
#echover "pkg_files=$pkg_files"
#echover "pkg_names=$pkg_names"
# Just printout help if run without args
if [ -z "$epm_cmd" ] ; then
print_version
echo
fatal "Run $ epm --help for get help"
fi
# Run helper for command
epm_$epm_cmd
# return last error code (from subroutine)
#!/bin/sh
#
# Copyright (C) 2012-2013 Etersoft
# Copyright (C) 2012-2013 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
PROGDIR=$(dirname $0)
# will replaced to /usr/share/eepm during install
SHAREDIR=$(dirname $0)
load_helper()
{
local CMD="$SHAREDIR/$1"
[ -r "$CMD" ] || fatal "Have no $CMD helper file"
. $CMD
}
# File bin/epm-sh-functions:
isatty()
{
# Set a sane TERM required for tput
[ -n "$TERM" ] || TERM=dumb
export TERM
test -t 1
}
check_tty()
{
isatty || return
which tput >/dev/null 2>/dev/null || return
# FreeBSD does not support tput -S
echo | tput -S >/dev/null 2>/dev/null || return
[ -z "$USETTY" ] || return
export USETTY=1
}
: ${BLACK:=0} ${RED:=1} ${GREEN:=2} ${YELLOW:=3} ${BLUE:=4} ${MAGENTA:=5} ${CYAN:=6} ${WHITE:=7}
set_boldcolor()
{
[ "$USETTY" = "1" ] || return
{
echo bold
echo setaf $1
} |tput -S
}
restore_color()
{
[ "$USETTY" = "1" ] || return
{
echo op; # set Original color Pair.
echo sgr0; # turn off all special graphics mode (bold in our case).
} |tput -S
}
echover()
{
[ -n "$verbose" ] || return
echo "$*" >&2
}
set_target_pkg_env()
{
[ -n "$DISTRNAME" ] || fatal "Run set_target_pkg_env without DISTRNAME"
PKGFORMAT=$($DISTRVENDOR -p "$DISTRNAME")
PKGVENDOR=$($DISTRVENDOR -s "$DISTRNAME")
RPMVENDOR=$($DISTRVENDOR -n "$DISTRNAME")
}
realpath()
{
readlink -f "$@"
}
showcmd()
{
if [ -z "$quiet" ] ; then
set_boldcolor $GREEN
local PROMTSIG="\$"
[ "$UID" = 0 ] && PROMTSIG="#"
echo " $PROMTSIG $@"
restore_color
fi >&2
}
docmd()
{
showcmd "$@"
"$@"
}
docmd_foreach()
{
local cmd
cmd="$1"
#showcmd "$@"
shift
for pkg in "$@" ; do
docmd $cmd $pkg
done
}
sudocmd()
{
showcmd "$SUDO $@"
$SUDO "$@"
}
filter_strip_spaces()
{
# possible use just
#xargs echo
sed -e "s| \+| |g" | \
sed -e "s|^ ||" | sed -e "s| \$||"
}
filter_pkg_verel()
{
case $PKGFORMAT in
*)
cat
;;
esac
}
strip_spaces()
{
echo "$*" | filter_strip_spaces
}
fatal()
{
if [ -z "$TEXTDOMAIN" ] ; then
echo "Error: $@" >&2
fi
exit 1
}
set_sudo()
{
SUDO=""
# skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return
# set SUDO not for root user
[ -n "$UID" ] || UID=`id -u`
# do not need sudo
[ $UID = "0" ] && return
# use sudo if possible
which sudo >/dev/null 2>/dev/null && SUDO="sudo" && return
SUDO="fatal 'Can't find sudo. Please install sudo or run epm under root.'"
}
get_help()
{
grep -- "# $1" $0 | while read n ; do
opt=$(echo $n | sed -e "s|) # $1:.*||g")
desc=$(echo $n | sed -e "s|.*) # $1:||g")
printf " %-20s %s\n" $opt "$desc"
done
}
set_pm_type()
{
local CMD
# Fill for use: PMTYPE, DISTRNAME, DISTRVERSION, PKGFORMAT, PKGVENDOR, RPMVENDOR
DISTRVENDOR=internal_distr_info
[ -n "$DISTRNAME" ] || DISTRNAME=$($DISTRVENDOR -d)
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
set_target_pkg_env
if [ -n "$FORCEPM" ] ; then
PMTYPE=$FORCEPM
return
fi
case $DISTRNAME in
ALTLinux|PCLinux)
CMD="apt-rpm"
#which deepsolver 2>/dev/null >/dev/null && CMD=deepsolver-rpm
;;
PCLinux)
CMD="apt-rpm"
;;
Ubuntu|Debian|Mint)
CMD="apt-dpkg"
;;
Mandriva|ROSA)
CMD="urpm-rpm"
;;
FreeBSD|NetBSD|OpenBSD|Solaris)
CMD="pkgsrc"
;;
Gentoo)
CMD="emerge"
;;
ArchLinux)
CMD="pacman"
;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific)
CMD="yum-rpm"
;;
Slackware)
CMD="slackpkg"
;;
SUSE|SLED|SLES)
CMD="zypper-rpm"
;;
Windows)
CMD="chocolatey"
;;
*)
fatal "Do not known DISTRNAME $DISTRNAME"
;;
esac
PMTYPE=$CMD
}
# File bin/serv-common:
serv_common()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
sudocmd service $SERVICE "$@"
;;
service-initd|service-update)
sudocmd /etc/init.d/$SERVICE "$@"
;;
systemd)
sudocmd systemctl "$@" $SERVICE
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-disable:
serv_disable()
{
is_service_running $1 && { serv_stop $1 || return ; }
is_service_autostart $1 || { echo "Service $1 already disabled for startup" && return ; }
case $SERVICETYPE in
service-chkconfig|service-upstart)
sudocmd chkconfig $1 off
;;
service-initd|service-update)
sudocmd update-rc.d $1 remove
;;
systemd)
sudocmd systemctl disable $1
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-enable:
serv_enable()
{
is_service_running $1 || serv_start $1 || return
is_service_autostart $1 && echo "Service $1 already enabled for startup" && return
case $SERVICETYPE in
service-chkconfig|service-upstart)
sudocmd chkconfig $1 on
;;
service-initd|service-update)
sudocmd update-rc.d $1 defaults
;;
systemd)
sudocmd systemctl enable $1
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-list:
serv_list()
{
case $SERVICETYPE in
service-upstart)
sudocmd initctl list
;;
service-update)
sudocmd service --status-all
;;
systemd)
sudocmd systemctl list-units
;;
*)
load_helper serv-list_all
load_helper serv-status
for i in $(serv_list_all) ; do
is_service_running $i && echo $i
done
;;
esac
}
# File bin/serv-list_all:
serv_list_all()
{
case $SERVICETYPE in
service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1
;;
service-initd|service-update)
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
;;
systemd)
sudocmd systemctl list-unit-files
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-list_startup:
serv_list_startup()
{
case $SERVICETYPE in
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-start:
serv_start()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
sudocmd service $SERVICE start "$@"
;;
service-initd|service-update)
sudocmd /etc/init.d/$SERVICE start "$@"
;;
systemd)
sudocmd systemctl start "$SERVICE" "$@"
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-status:
is_service_running()
{
case $SERVICETYPE in
service-chkconfig|service-upstart)
$SUDO service $1 status >/dev/null
;;
service-initd|service-update)
$SUDO /etc/init.d/$1 status >/dev/null
;;
systemd)
#sudocmd systemctl is-enabled $1
fatal "FIXME: don't know how detect current startup state"
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
is_service_autostart()
{
case $SERVICETYPE in
service-chkconfig|service-upstart)
LANG=C $SUDO chkconfig $1 --list | grep -q "5:on"
;;
service-initd|service-update)
fatal "FIXME: don't know how detect current startup state"
;;
systemd)
sudocmd systemctl is-enabled $1.service
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
serv_status()
{
is_service_autostart $1 && echo "Service $1 is sheduled to run on startup" || echo "Service $1 will NOT run on startup"
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
sudocmd service $SERVICE status "$@"
;;
service-update)
sudocmd /etc/init.d/$SERVICE status "$@"
;;
systemd)
sudocmd systemctl status $SERVICE.service "$@"
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-stop:
serv_stop()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
sudocmd service $SERVICE stop "$@"
;;
service-initd|service-update)
sudocmd /etc/init.d/$SERVICE stop "$@"
;;
systemd)
sudocmd systemctl stop $SERVICE "$@"
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-try_restart:
serv_try_restart()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
is_service_running $SERVICE || return 0
sudocmd service $SERVICE restart "$@"
;;
service-initd|service-update)
is_service_running $SERVICE || return 0
sudocmd /etc/init.d/$SERVICE restart "$@"
;;
systemd)
sudocmd systemctl try-restart $SERVICE "$@"
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
}
# File bin/serv-usage:
_print_additional_usage()
{
echo "serv addition usage: {on|off|try-restart|usage}"
}
serv_usage()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
# CHECKME: many services print out usage in stderr, it conflicts with printout command
#sudocmd service $SERVICE 2>&1
$SUDO service $SERVICE 2>&1
;;
service-initd|service-update)
#sudocmd /etc/init.d/$SERVICE 2>&1
$SUDO service $SERVICE 2>&1
;;
systemd)
sudocmd systemctl $SERVICE 2>&1
;;
*)
fatal "Do not known command for $SERVICETYPE"
;;
esac
_print_additional_usage
}
internal_distr_info()
{
#!/bin/sh
# Author: Vitaly Lipatov <lav@etersoft.ru>
# 2007, 2009, 2010, 2012 (c) Etersoft
# 2007 Public domain
# Detect the distro and version
# Welcome to send updates!
# You can set ROOTDIR to root system dir
#ROOTDIR=
# Check for DISTRO specific file in /etc
distro()
{
#[ -n "$ROOTDIR" ] || return
# fill global DISTROFILE
DISTROFILE="$ROOTDIR/etc/$1"
[ -f "$DISTROFILE" ]
}
# Has a distro file the specified word?
has()
{
[ -n "$DISTROFILE" ] || exit 1
grep "$*" "$DISTROFILE" >/dev/null 2>&1
}
# Translate DISTRIB_ID to vendor name (like %_vendor does)
rpmvendor()
{
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
echo "$DISTRIB_ID" | tr "[A-Z]" "[a-z]"
}
# Translate DISTRIB_ID name to package manner (like in the package release name)
pkgvendor()
{
[ "$DISTRIB_ID" = "Mandriva" ] && echo "mdv" && return
rpmvendor
}
# Print pkgtype (need DISTRIB_ID var)
pkgtype()
{
case `pkgvendor` in
freebsd) echo "tbz" ;;
sunos) echo "pkg.gz" ;;
slackware|mopslinux) echo "tgz" ;;
archlinux) echo "tar.xz" ;;
gentoo) echo "tbz2" ;;
windows) echo "exe" ;;
debian|ubuntu|mint|runtu) echo "deb" ;;
alt|asplinux|suse|mandriva|rosa|mandrake|pclinux|sled|sles)
echo "rpm" ;;
fedora|redhat|scientific|centos|rhel)
echo "rpm" ;;
*) echo "rpm" ;;
esac
}
get_var()
{
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//"
}
# 2010.1 -> 2010
get_major_version()
{
echo "$1" | sed -e "s/\..*//g"
}
# Default values
DISTRIB_ID="Generic"
DISTRIB_RELEASE=""
# Default with LSB
if distro lsb-release ; then
DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID`
DISTRIB_RELEASE=`cat $DISTROFILE | get_var DISTRIB_RELEASE`
fi
# ALT Linux based
if distro altlinux-release ; then
DISTRIB_ID="ALTLinux"
if has Strawberry ; then DISTRIB_RELEASE="2.3"
elif has Citron ; then DISTRIB_RELEASE="2.4"
elif has 20050723 ; then DISTRIB_RELEASE="3.0"
elif has Ajuga ; then DISTRIB_RELEASE="4.0"
elif has 20070810 ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
elif has Walnut ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7"
elif has 6.0 ; then DISTRIB_RELEASE="p6"
elif has Centaurea ; then DISTRIB_RELEASE="p6"
elif has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
fi
elif distro gentoo-release ; then
DISTRIB_ID="Gentoo"
DISTRIB_RELEASE=`basename $(readlink $ROOTDIR/etc/make.profile)`
# Slackware based
elif distro mopslinux-version ; then
DISTRIB_ID="MOPSLinux"
if has 4.0 ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has 6.0 ; then DISTRIB_RELEASE="6.0"
elif has 6.1 ; then DISTRIB_RELEASE="6.1"
fi
elif distro slackware-version ; then
DISTRIB_ID="Slackware"
DISTRIB_RELEASE="$(grep -Eo [0-9]+\.[0-9]+ $DISTROFILE)"
elif distro arch-release ; then
DISTRIB_ID="ArchLinux"
DISTRIB_RELEASE="2010"
if grep 2011 -q $ROOTDIR/etc/pacman.d/mirrorlist ; then
DISTRIB_RELEASE="2011"
fi
# for Ubuntu use standard LSB info
elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB version
true
# Debian based
elif distro debian_version ; then
DISTRIB_ID="Debian"
DISTRIB_RELEASE=`cat $DISTROFILE`
# Mandriva based
elif distro pclinuxos-release ; then
DISTRIB_ID="PCLinux"
if has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
elif has "2010" ; then DISTRIB_RELEASE="2010"
fi
elif distro mandriva-release || distro mandrake-release ; then
DISTRIB_ID="Mandriva"
if has 2005 ; then DISTRIB_RELEASE="2005"
elif has 2006 ; then DISTRIB_RELEASE="2006"
elif has 2007 ; then DISTRIB_RELEASE="2007"
elif has 2008 ; then DISTRIB_RELEASE="2008"
elif has 2009.0 ; then DISTRIB_RELEASE="2009.0"
elif has 2009.1 ; then DISTRIB_RELEASE="2009.1"
else
# use /etc/lsb-release info by default
if has ROSA ; then
DISTRIB_ID="ROSA"
fi
fi
# Fedora based
elif distro linux-xp-release || distro lxp-release; then
DISTRIB_ID="LinuxXP"
if has "Attack of the Clones" ; then DISTRIB_RELEASE="2006"
elif has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
elif has "2009" ; then DISTRIB_RELEASE="2009"
fi
elif distro asplinux-release ; then
DISTRIB_ID="ASPLinux"
if has Karelia ; then DISTRIB_RELEASE="10"
elif has Seliger ; then DISTRIB_RELEASE="11"
elif has "11.1" ; then DISTRIB_RELEASE="11.1"
elif has Ladoga ; then DISTRIB_RELEASE="11.2"
elif has "11.2" ; then DISTRIB_RELEASE="11.2"
elif has "12" ; then DISTRIB_RELEASE="12"
elif has "13" ; then DISTRIB_RELEASE="13"
elif has "14" ; then DISTRIB_RELEASE="14"
elif has "15" ; then DISTRIB_RELEASE="15"
fi
elif distro MCBC-release ; then
DISTRIB_ID="MCBC"
if has 3.0 ; then DISTRIB_RELEASE="3.0"
elif has 3.1 ; then DISTRIB_RELEASE="3.1"
fi
elif distro fedora-release ; then
DISTRIB_ID="Fedora"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g")
elif distro redhat-release ; then
# FIXME if need
# actually in the original RHEL: Red Hat Enterprise Linux .. release N
DISTRIB_ID="RHEL"
if has CentOS ; then
DISTRIB_ID="CentOS"
elif has Scientific ; then
DISTRIB_ID="Scientific"
fi
if has Beryllium ; then
DISTRIB_ID="Scientific"
DISTRIB_RELEASE="4.1"
elif has Shrike ; then
DISTRIB_ID="RedHat"
DISTRIB_RELEASE="9"
elif has Taroon ; then DISTRIB_RELEASE="3"
elif has "release 4" ; then DISTRIB_RELEASE="4"
elif has "release 5" ; then DISTRIB_RELEASE="5"
elif has "release 6" ; then DISTRIB_RELEASE="6"
elif has "release 7" ; then DISTRIB_RELEASE="7"
fi
# SUSE based
elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SUSE"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "VERSION" | sed -e "s|^VERSION = ||g")
if has "SUSE Linux Enterprise Desktop" ; then
DISTRIB_ID="SLED"
elif has "SUSE Linux Enterprise Server" ; then
DISTRIB_ID="SLES"
fi
# fixme: can we detect by some file?
elif [ `uname` = "FreeBSD" ] ; then
DISTRIB_ID="FreeBSD"
UNAME=$(uname -r)
DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g")
# fixme: can we detect by some file?
elif [ `uname` = "SunOS" ] ; then
DISTRIB_ID="SunOS"
DISTRIB_RELEASE=$(uname -r)
# try use standart LSB info by default
elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB
true
fi
case $1 in
-p)
# override DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
pkgtype
exit 0
;;
-h)
echo "distr_vendor - system name and version detection"
echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name"
echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)"
echo "-s [SystemName] - print name of distro for build system (like in the package release name)"
echo "-n [SystemName] - print vendor name (as _vendor macros in rpm)"
echo "-V - print the version of $0"
echo "-h - this help"
exit 0
;;
-d)
echo $DISTRIB_ID
;;
-v)
echo $DISTRIB_RELEASE
;;
-s)
# override DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
pkgvendor
exit 0
;;
-n)
# override DISTRIB_ID
test -n "$2" && DISTRIB_ID="$2"
rpmvendor
exit 0
;;
-V)
echo "20120519"
exit 0
;;
*)
# if run without args, just printout Name/Version of the current system
[ -n "$DISTRIB_RELEASE" ] && echo $DISTRIB_ID/$DISTRIB_RELEASE || echo $DISTRIB_ID
;;
esac
}
PATH=$PATH:/sbin:/usr/sbin
set_sudo
check_tty
#############################
# FIXME: detect by real init system
# FIXME: add upstart support (Ubuntu?)
set_service_type()
{
local CMD
# Fill for use: PMTYPE, DISTRNAME, DISTRVERSION, PKGFORMAT, PKGVENDOR, RPMVENDOR
DISTRVENDOR=internal_distr_info
[ -n "$DISTRNAME" ] || DISTRNAME=$($DISTRVENDOR -d)
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
set_target_pkg_env
is_active_systemd()
{
SYSTEMCTL=/bin/systemctl
SYSTEMD_CGROUP_DIR=/sys/fs/cgroup/systemd
[ -x "$SYSTEMCTL" ] && [ -d "$SYSTEMD_CGROUP_DIR" ] && mountpoint -q "$SYSTEMD_CGROUP_DIR"
}
case $DISTRNAME in
ALTLinux)
CMD="service-chkconfig"
;;
Ubuntu|Debian|Mint)
CMD="service-update"
;;
Mandriva|ROSA)
CMD="service-chkconfig"
;;
# FreeBSD)
# CMD="pkg_add"
# ;;
# Gentoo)
# CMD="emerge"
# ;;
# ArchLinux)
# CMD="pacman"
# ;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific)
CMD="service-chkconfig"
;;
Slackware)
CMD="service-initd"
;;
SUSE|SLED|SLES)
CMD="service-chkconfig"
;;
# Windows)
# CMD="chocolatey"
# ;;
*)
fatal "Do not known DISTRNAME $DISTRNAME yet"
;;
esac
# Note: force systemd using if active
is_active_systemd && CMD="systemd"
# override system control detection result
[ -n "$FORCESERVICE" ] && CMD=$FORCESERVICE
SERVICETYPE=$CMD
}
phelp()
{
echo "$Descr
$Usage
Commands:
$(get_help HELPCMD)
Options:
$(get_help HELPOPT)
"
}
print_version()
{
echo "Service manager version 1.1.8"
echo "Running on $($DISTRVENDOR)"
echo "Copyright (c) Etersoft 2012, 2013"
echo "This program may be freely redistributed under the terms of the GNU AGPLv3."
}
Usage="Usage: serv [options] [<service>] [<command>] [params]..."
Descr="serv - Service manager"
set_service_type
verbose=
quiet=
non_interactive=
show_command_only=
serv_cmd=
service_name=
params=
check_command()
{
# do not override command
[ -z "$serv_cmd" ] || return
case $1 in
status) # HELPCMD: show service status
serv_cmd=status
;;
usage) # HELPCMD: print out usage of the service
serv_cmd=usage
;;
#restart) # HELPCMD: restart service
#reload) # HELPCMD: reload service
start) # HELPCMD: start service
serv_cmd=start
;;
try-restart|condrestart) # HELPCMD: Restart service if running
serv_cmd=try_restart
;;
stop) # HELPCMD: stop service
serv_cmd=stop
;;
list) # HELPCMD: list running services
serv_cmd=list
;;
list-all) # HELPCMD: list all available services
serv_cmd=list_all
;;
list-startup) # HELPCMD: list all services to run on startup
serv_cmd=list_startup
;;
on|enable) # HELPCMD: add service to run on startup and start it now
serv_cmd=enable
;;
off|disable) # HELPCMD: remove service to run on startup and stop it now
serv_cmd=disable
;;
*)
return 1
;;
esac
return 0
}
check_option()
{
case $1 in
-h|--help|help) # HELPOPT: this help
phelp
exit 0
;;
-v|--version) # HELPOPT: print version
print_version
exit 0
;;
--verbose) # HELPOPT: verbose mode
verbose=1
;;
--show-command-only) # HELPOPT: show command only, do not any action
show_command_only=1
;;
--quiet) # HELPOPT: quiet mode (do not print commands before exec)
quiet=1
;;
--auto) # HELPOPT: non interactive mode
non_interactive=1
;;
*)
return 1
;;
esac
return 0
}
for opt in "$@" ; do
check_command $opt && continue
check_option $opt && continue
[ -z "$service_name" ] && service_name=$opt && continue
params="$params $opt"
done
echover "service: $service_name"
echover "command: $serv_cmd"
# Just printout help if run without args
if [ "$serv_cmd" != "list" ] && [ "$serv_cmd" != "list_all" ] && [ -z "$service_name" ] ; then
print_version
echo
fatal "Run $ serv --help for get help"
fi
if [ -z "$serv_cmd" ] ; then
serv_cmd=common
fi
# Run helper for command
serv_$serv_cmd $service_name $params
# return last error code (from subroutine)
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