Commit c375c438 authored by Vitaly Lipatov's avatar Vitaly Lipatov

packed files

parent 53d3a6ed
...@@ -152,7 +152,7 @@ docmd_foreach() ...@@ -152,7 +152,7 @@ docmd_foreach()
sudocmd() sudocmd()
{ {
showcmd "$SUDO $*" [ -n "$SUDO" ] && showcmd "$SUDO $*" || showcmd "$*"
$SUDO $@ $SUDO $@
} }
...@@ -186,6 +186,11 @@ get_lastarg() ...@@ -186,6 +186,11 @@ get_lastarg()
echon "$lastarg" echon "$lastarg"
} }
isnumber()
{
echo "$*" | filter_strip_spaces | grep -q "^[0-9]\+$"
}
filter_strip_spaces() filter_strip_spaces()
{ {
# possible use just # possible use just
...@@ -293,12 +298,12 @@ withtimeout() ...@@ -293,12 +298,12 @@ withtimeout()
{ {
local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null) local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null)
if [ -x "$TO" ] ; then if [ -x "$TO" ] ; then
$TO $@ $TO "$@"
return return
fi fi
# fallback: drop time arg and run without timeout # fallback: drop time arg and run without timeout
shift shift
$@ "$@"
} }
set_eatmydata() set_eatmydata()
...@@ -307,7 +312,7 @@ set_eatmydata() ...@@ -307,7 +312,7 @@ set_eatmydata()
[ -n "$EPMNOEATMYDATA" ] && return [ -n "$EPMNOEATMYDATA" ] && return
# use if possible # use if possible
which eatmydata >/dev/null 2>/dev/null || return which eatmydata >/dev/null 2>/dev/null || return
SUDO="$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
} }
...@@ -359,6 +364,20 @@ assure_exists() ...@@ -359,6 +364,20 @@ assure_exists()
__epm_assure "$1" $package $3 || fatal "Can't assure in '$1' command from $package$textpackage package" __epm_assure "$1" $package $3 || fatal "Can't assure in '$1' command from $package$textpackage package"
} }
disabled_eget()
{
# use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@"
return
fi
assure_exists eget
# run external command, not the function
EGET=$(which eget) || fatal "Missed command eget from installed package eget"
$EGET "$@"
}
eget() eget()
{ {
assure_exists wget assure_exists wget
...@@ -522,22 +541,23 @@ is_active_systemd() ...@@ -522,22 +541,23 @@ is_active_systemd()
# File bin/epm-addrepo: # File bin/epm-addrepo:
epm_addrepo()
{
local repo="$(eval echo "$quoted_args")"
case $DISTRNAME in __epm_addrepo_altlinux()
ALTLinux) {
case "$repo" in local repo="$@"
case "$1" in
etersoft) etersoft)
info "add etersoft repo" info "add Etersoft's addon repo"
epm install --skip-installed apt-conf-etersoft-common apt-conf-etersoft-hold || fatal epm install --skip-installed apt-conf-etersoft-common apt-conf-etersoft-hold
# TODO: ignore only error code 22 (skipped) || fatal
local branch="$DISTRVERSION/branch" local branch="$DISTRVERSION/branch"
[ "$DISTRVERSION" = "Sisyphus" ] && branch="$DISTRVERSION" [ "$DISTRVERSION" = "Sisyphus" ] && branch="$DISTRVERSION"
# FIXME # FIXME
[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION" [ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
# TODO: func?
local arch=$(uname -m) local arch=$(uname -m)
[ "$arch" = "i686" ] && arch="i586" [ "$arch" = "i686" ] && arch="i586"
# TODO: use apt-repo add ?
echo "" | sudocmd tee -a /etc/apt/sources.list echo "" | sudocmd tee -a /etc/apt/sources.list
echo "# added with eepm addrepo etersoft" | sudocmd tee -a /etc/apt/sources.list echo "# added with eepm addrepo etersoft" | sudocmd tee -a /etc/apt/sources.list
echo "rpm [etersoft] http://download.etersoft.ru/pub/Etersoft LINUX@Etersoft/$branch/$arch addon" | sudocmd tee -a /etc/apt/sources.list echo "rpm [etersoft] http://download.etersoft.ru/pub/Etersoft LINUX@Etersoft/$branch/$arch addon" | sudocmd tee -a /etc/apt/sources.list
...@@ -551,23 +571,54 @@ case $DISTRNAME in ...@@ -551,23 +571,54 @@ case $DISTRNAME in
autoimports) autoimports)
[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION" [ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")" repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
;;
archive)
datestr="$2"
echo "$datestr" | grep -Eq "^20[0-2][0-9]/[01][0-9]/[0-3][0-9]$" || fatal "use follow date format: 2017/12/31"
# TODO: func?
local arch=$(uname -m)
[ "$arch" = "i686" ] && arch="i586"
echo "" | sudocmd tee -a /etc/apt/sources.list
echo "rpm [alt] http://ftp.altlinux.org/pub/distributions archive/sisyphus/date/$datestr/$arch classic" | sudocmd tee -a /etc/apt/sources.list
if [ "$arch" = "x86_64" ] ; then
echo "rpm [alt] http://ftp.altlinux.org/pub/distributions archive/sisyphus/date/$datestr/$arch-i586 classic" | sudocmd tee -a /etc/apt/sources.list
fi
echo "rpm [alt] http://ftp.altlinux.org/pub/distributions archive/sisyphus/date/$datestr/noarch classic" | sudocmd tee -a /etc/apt/sources.list
return 0
;;
esac esac
assure_exists apt-repo assure_exists apt-repo
if tasknumber "$repo" >/dev/null ; then
sudocmd apt-repo add $(tasknumber "$repo")
return
fi
if [ -z "$repo" ] ; then if [ -z "$repo" ] ; then
docmd apt-repo add branch info "Add branch repo. TODO?"
echo "etersoft" sudocmd apt-repo add branch
return return
fi fi
sudocmd apt-repo add "$repo" sudocmd apt-repo add "$repo"
}
epm_addrepo()
{
local repo="$(eval echo "$quoted_args")"
case $DISTRNAME in
ALTLinux)
__epm_addrepo_altlinux $repo
return return
;; ;;
esac esac
case $PMTYPE in case $PMTYPE in
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
info "You need manually add repo to /etc/apt/sources.list" info "You need manually add repo to /etc/apt/sources.list (TODO)"
;; ;;
yum-rpm) yum-rpm)
assure_exists yum-utils assure_exists yum-utils
...@@ -736,18 +787,25 @@ case $PMTYPE in ...@@ -736,18 +787,25 @@ case $PMTYPE in
apt-rpm) apt-rpm)
# ALT Linux only # ALT Linux only
assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts
if [ -z "$dryrun" ] ; then
echo "We will try remove all installed packages which are missed in repositories" echo "We will try remove all installed packages which are missed in repositories"
warning "Use with caution!" warning "Use with caution!"
fi
local PKGLIST=$(__epm_orphan_altrpm \ local PKGLIST=$(__epm_orphan_altrpm \
| sed -e "s/\.32bit//g" \ | sed -e "s/\.32bit//g" \
| grep -v -- "^eepm$" \ | grep -v -- "^eepm$" \
| grep -v -- "^kernel") | grep -v -- "^kernel")
docmd epm remove $PKGLIST
if [ -n "$quiet" ] ; then
echo "$PKGLIST"
else
docmd epm remove $dryrun $PKGLIST
fi
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
assure_exists deborphan assure_exists deborphan
showcmd deborphan showcmd deborphan
a='' deborphan | docmd epm remove a='' deborphan | docmd epm remove $dryrun
;; ;;
#aura) #aura)
# sudocmd aura -Oj # sudocmd aura -Oj
...@@ -755,18 +813,22 @@ case $PMTYPE in ...@@ -755,18 +813,22 @@ case $PMTYPE in
yum-rpm) yum-rpm)
showcmd package-cleanup --orphans showcmd package-cleanup --orphans
local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-") local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
docmd epm remove $PKGLIST docmd epm remove $dryrun $PKGLIST
;; ;;
dnf-rpm) dnf-rpm)
# TODO: dnf list extras # TODO: dnf list extras
# TODO: Yum-utils package has been deprecated, use dnf instead. # TODO: Yum-utils package has been deprecated, use dnf instead.
showcmd package-cleanup --orphans showcmd package-cleanup --orphans
local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-") local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
docmd epm remove $PKGLIST docmd epm remove $dryrun $PKGLIST
;; ;;
urpm-rpm) urpm-rpm)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
else
showcmd urpme --report-orphans showcmd urpme --report-orphans
sudocmd urpme --auto-orphans sudocmd urpme --auto-orphans
fi
;; ;;
#emerge) #emerge)
# sudocmd emerge --depclean # sudocmd emerge --depclean
...@@ -774,12 +836,17 @@ case $PMTYPE in ...@@ -774,12 +836,17 @@ case $PMTYPE in
# sudocmd revdep-rebuild # sudocmd revdep-rebuild
# ;; # ;;
pacman) pacman)
if [ -n "$dryrun" ] ; then
info "Autoorphans packages list:"
sudocmd pacman -Qdtq
else
sudocmd pacman -Qdtq | sudocmd pacman -Rs - sudocmd pacman -Qdtq | sudocmd pacman -Rs -
fi
;; ;;
#slackpkg) slackpkg)
# clean-system removes non official packages # clean-system removes non official packages
#sudocmd slackpkg clean-system sudocmd slackpkg clean-system
# ;; ;;
#guix) #guix)
# sudocmd guix gc # sudocmd guix gc
# ;; # ;;
...@@ -793,10 +860,14 @@ case $PMTYPE in ...@@ -793,10 +860,14 @@ case $PMTYPE in
sudocmd zypper packages --orphaned sudocmd zypper packages --orphaned
# FIXME: x86_64/i586 are duplicated # FIXME: x86_64/i586 are duplicated
local PKGLIST=$(zypper packages --orphaned | tail -n +5 | cut -d \| -f 3 | sort -u) local PKGLIST=$(zypper packages --orphaned | tail -n +5 | cut -d \| -f 3 | sort -u)
sudocmd zypper remove --clean-deps $PKGLIST docmd epm remove $dryrun --clean-deps $PKGLIST
;; ;;
xbps) xbps)
CMD="xbps-remove -o" if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
else
sudocmd xbps-remove -o
fi
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -815,19 +886,27 @@ __epm_autoremove_altrpm_pp() ...@@ -815,19 +886,27 @@ __epm_autoremove_altrpm_pp()
#[ -n "$force" ] || info "You can run with --force for more deep removing" #[ -n "$force" ] || info "You can run with --force for more deep removing"
local force=force local force=force
local libexclude="$1"
local flag= local flag=
[ -n "$force" ] || libexclude=$libexclude'[^-]*$'
libexclude='^(python-module-|python3-module-|python-modules-|python3-modules|perl-)'
[ -n "$force" ] || libexclude=$libexclude'[^-]*$' [ -n "$force" ] || libexclude=$libexclude'[^-]*$'
showcmd "apt-cache list-nodeps | grep -E -- \"$libexclude\"" showcmd "apt-cache list-nodeps | grep -E -- \"$libexclude\""
pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" ) pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" )
if [ -n "$dryrun" ] ; then
info "Packages for autoremoving:"
echo "$pkgs"
return 0
fi
[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1 [ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1
if [ -n "$flag" ] ; then if [ -n "$flag" ] ; then
info "" info ""
info "call again for next cycle until all modules will be removed" info "call again for next cycle until all modules will be removed"
__epm_autoremove_altrpm_pp __epm_autoremove_altrpm_pp "$libexclude"
fi fi
return 0 return 0
...@@ -837,28 +916,51 @@ __epm_autoremove_altrpm_lib() ...@@ -837,28 +916,51 @@ __epm_autoremove_altrpm_lib()
{ {
local pkgs local pkgs
local nodevel="$1"
info info
if [ "$nodevel" = "nodevel" ] ; then
info "Removing all non -devel/-debuginfo libs packages not need by anything..." info "Removing all non -devel/-debuginfo libs packages not need by anything..."
local develrule='-(devel|devel-static)$'
else
info "Removing all non -debuginfo libs packages (-devel too) not need by anything..."
local develrule='-(NONONO)$'
fi
#[ -n "$force" ] || info "You can run with --force for more deep removing" #[ -n "$force" ] || info "You can run with --force for more deep removing"
local force=force local force=force
local flag= local flag=
local libexclude='^(lib|i586-lib)' local libgrep='^(lib|i586-lib|bzlib|zlib)'
[ -n "$force" ] || libexclude=$libexclude'[^-]*$' [ -n "$force" ] || libexclude=$libgrep'[^-]*$'
# https://www.altlinux.org/APT_в_ALT_Linux/Советы_по_использованию#apt-cache_list-nodeps # https://www.altlinux.org/APT_в_ALT_Linux/Советы_по_использованию#apt-cache_list-nodeps
showcmd "apt-cache list-nodeps | grep -- \"$libexclude\"" showcmd "apt-cache list-nodeps | grep -E -- \"$libgrep\""
pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" \ pkgs=$(apt-cache list-nodeps | grep -E -- "$libgrep" \
| sed -e "s/[-\.]32bit$//g" \ | sed -e "s/[-\.]32bit$//g" \
| grep -E -v -- "-(devel|devel-static|debuginfo)$" \ | grep -E -v -- "$develrule" \
| grep -E -v -- "-(debuginfo)$" \
| grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \ | grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \
| grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm)" ) | grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm)" )
if [ -n "$dryrun" ] ; then
info "Packages for autoremoving:"
echo "$pkgs"
return 0
fi
# commented, with hi probability user install i586- manually
# workaround against missed i586- handling in apt-cache list-nodeps
if epmqp i586-lib >/dev/null ; then
info "You can try removing i586- with follow command"
showcmd rpm -v -e $(epmqp i586-lib)
fi
[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1 [ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1
if [ -n "$flag" ] ; then if [ -n "$flag" ] ; then
info "" info ""
info "call again for next cycle until all libs will be removed" info "call again for next cycle until all libs will be removed"
__epm_autoremove_altrpm_lib __epm_autoremove_altrpm_lib $nodevel
fi fi
return 0 return 0
...@@ -867,11 +969,34 @@ __epm_autoremove_altrpm_lib() ...@@ -867,11 +969,34 @@ __epm_autoremove_altrpm_lib()
__epm_autoremove_altrpm() __epm_autoremove_altrpm()
{ {
local pkg local i
assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts
__epm_autoremove_altrpm_pp if [ -z "$pkg_names" ] ; then
__epm_autoremove_altrpm_pp '^(python-module-|python3-module-|python-modules-|python3-modules|perl-)'
__epm_autoremove_altrpm_lib nodevel
return 0
fi
for i in $pkg_names ; do
case $i in
libs)
__epm_autoremove_altrpm_lib nodevel
;;
python)
__epm_autoremove_altrpm_pp '^(python-module-|python3-module-|python-modules-|python3-modules)'
;;
perl)
__epm_autoremove_altrpm_pp '^(perl-)'
;;
libs-devel)
__epm_autoremove_altrpm_lib __epm_autoremove_altrpm_lib
;;
*)
fatal "autoremove: unsupported '$i'. Use libs, python, perl, libs-devel."
;;
esac
done
return 0 return 0
} }
...@@ -879,11 +1004,12 @@ __epm_autoremove_altrpm() ...@@ -879,11 +1004,12 @@ __epm_autoremove_altrpm()
epm_autoremove() epm_autoremove()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
__epm_autoremove_altrpm __epm_autoremove_altrpm
[ -n "$dryrun" ] && return
docmd epm remove-old-kernels docmd epm remove-old-kernels
if which nvidia-clean-driver 2>/dev/null ; then if which nvidia-clean-driver 2>/dev/null ; then
...@@ -896,11 +1022,16 @@ case $DISTRNAME in ...@@ -896,11 +1022,16 @@ case $DISTRNAME in
;; ;;
esac esac
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
sudocmd apt-get autoremove sudocmd apt-get autoremove $dryrun
;; ;;
aura) aura)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd aura -Oj sudocmd aura -Oj
;; ;;
yum-rpm) yum-rpm)
...@@ -911,10 +1042,13 @@ case $PMTYPE in ...@@ -911,10 +1042,13 @@ case $PMTYPE in
# FIXME: package-cleanup have to use stderr for errors # FIXME: package-cleanup have to use stderr for errors
local PKGLIST=$(package-cleanup -q --leaves | grep -v "^eepm-") local PKGLIST=$(package-cleanup -q --leaves | grep -v "^eepm-")
[ -n "$PKGLIST" ] || break [ -n "$PKGLIST" ] || break
sudocmd yum remove $PKGLIST showcmd epm remove $PKGLIST
done done
;; ;;
dnf-rpm) dnf-rpm)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd dnf autoremove sudocmd dnf autoremove
;; ;;
# see autoorhans # see autoorhans
...@@ -922,6 +1056,9 @@ case $PMTYPE in ...@@ -922,6 +1056,9 @@ case $PMTYPE in
# sudocmd urpme --auto-orphans # sudocmd urpme --auto-orphans
# ;; # ;;
emerge) emerge)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd emerge --depclean sudocmd emerge --depclean
assure_exists revdep-rebuild assure_exists revdep-rebuild
sudocmd revdep-rebuild sudocmd revdep-rebuild
...@@ -946,10 +1083,13 @@ case $PMTYPE in ...@@ -946,10 +1083,13 @@ case $PMTYPE in
sudocmd zypper packages --unneeded sudocmd zypper packages --unneeded
# FIXME: x86_64/i586 are duplicated # FIXME: x86_64/i586 are duplicated
local PKGLIST=$(zypper packages --unneeded | tail -n +5 | cut -d \| -f 3 | sort -u) local PKGLIST=$(zypper packages --unneeded | tail -n +5 | cut -d \| -f 3 | sort -u)
sudocmd zypper remove --clean-deps $PKGLIST showcmd epm remove --clean-deps $PKGLIST
;; ;;
xbps) xbps)
CMD="xbps-remove -O" if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd xbps-remove -O
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -1158,6 +1298,7 @@ case $PMTYPE in ...@@ -1158,6 +1298,7 @@ case $PMTYPE in
docmd rpm -V $@ docmd rpm -V $@
;; ;;
*-dpkg) *-dpkg)
assure_exists debsums
docmd debsums $@ docmd debsums $@
;; ;;
emerge) emerge)
...@@ -1197,6 +1338,7 @@ epm_checkpkg() ...@@ -1197,6 +1338,7 @@ epm_checkpkg()
# TODO: reinvent # TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files [ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
#fatal "Broken package $pkg" #fatal "Broken package $pkg"
return $RETVAL return $RETVAL
...@@ -1344,7 +1486,7 @@ case $PMTYPE in ...@@ -1344,7 +1486,7 @@ case $PMTYPE in
sudocmd urpmi --clean sudocmd urpmi --clean
;; ;;
pacman) pacman)
sudocmd pacman -Sc sudocmd pacman -Sc --noconfirm
;; ;;
zypper-rpm) zypper-rpm)
sudocmd zypper clean sudocmd zypper clean
...@@ -1551,12 +1693,16 @@ epm_downgrade() ...@@ -1551,12 +1693,16 @@ epm_downgrade()
# File bin/epm-download: # File bin/epm-download:
alt_base_dist_url="http://ftp.basealt.ru/pub/distributions"
__use_url_install() __use_url_install()
{ {
case $DISTRNAME in case $DISTRNAME in
"ALTLinux") "ALTLinux")
# not for https # do not support https yet
echo "$pkg_urls" | grep -q "https://" && return 1 echo "$pkg_urls" | grep -q "https://" && return 1
# force download if wildcard is used
echo "$pkg_urls" | grep -q "[?*]" && return 1
pkg_names="$pkg_names $pkg_urls" pkg_names="$pkg_names $pkg_urls"
return 0 return 0
;; ;;
...@@ -1593,16 +1739,21 @@ __download_pkg_urls() ...@@ -1593,16 +1739,21 @@ __download_pkg_urls()
local url local url
[ -z "$pkg_urls" ] && return [ -z "$pkg_urls" ] && return
for url in $pkg_urls ; do for url in $pkg_urls ; do
# TODO: use some individual tmp dir local tmppkg=$(mktemp -d) || fatal "failed mktemp -d"
local new_file=/tmp/$(basename "$url") cd $tmppkg || fatal
if docmd eget -O $new_file $url && [ -s "$new_file" ] ; then if docmd eget "$url" ; then
pkg_files="$pkg_files $new_file" local i
to_remove_pkg_files="$to_remove_pkg_files $new_file" for i in $(basename $url) ; do
[ -s "$tmppkg/$i" ] || continue
pkg_files="$pkg_files $tmppkg/$i"
to_remove_pkg_files="$to_remove_pkg_files $tmppkg/$i"
done
else else
warning "Failed to download $url, ignoring" warning "Failed to download $url, ignoring"
fi fi
cd - >/dev/null
done done
# restore # reconstruct
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names") pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
} }
...@@ -1647,7 +1798,53 @@ __epm_get_altpkg_url() ...@@ -1647,7 +1798,53 @@ __epm_get_altpkg_url()
# fixme: get from /branches # fixme: get from /branches
local dv=$DISTRNAME/$DISTRVERSION/branch local dv=$DISTRNAME/$DISTRVERSION/branch
[ "$DISTRVERSION" = "Sisyphus" ] && dv=$DISTRNAME/$DISTRVERSION [ "$DISTRVERSION" = "Sisyphus" ] && dv=$DISTRNAME/$DISTRVERSION
echo "http://ftp.basealt.ru/pub/distributions/$dv/$arch/RPMS.classic/$filename" echo "$alt_base_dist_url/$dv/$arch/RPMS.classic/$filename"
}
__epm_print_url_alt()
{
local url="$1"
echo "$url"
echo "$url" | sed -e "s|$alt_base_dist_url/$DISTRNAME|http://mirror.yandex.ru/altlinux|g"
echo "$url" | sed -e "s|$alt_base_dist_url/$DISTRNAME|http://download.etersoft.ru/pub/ALTLinux|g"
}
__epm_print_url_alt_check()
{
local pkg=$1
shift
local tm=$(mktemp)
epm assure curl
quiet=1
local buildtime=$(paoapi packages/$pkg | get_pao_var buildtime)
echo
echo "Latest release: $(paoapi packages/$pkg | get_pao_var sourcepackage) $buildtime"
__epm_print_url_alt "$1" | while read url ; do
curl -s --head $url >$tm || { echo "$url: missed" ; continue ; }
local http=$(cat $tm | grep "^HTTP" | sed -e "s|\r||g")
local lastdate=$(cat $tm | grep "^Last-Modified:" | sed -e "s|\r||g")
local size=$(cat $tm | grep "^Content-Length:" | sed -e "s|^Content-Length: ||g" | sed -e "s|\r||g")
echo "$url ($http $lastdate) Size: $size"
done
rm -f $tm
}
__epm_download_alt()
{
local pkg
if [ "$1" = "--check" ] ; then
local checkflag="$1"
shift
fi
for pkg in "$@" ; do
local url=$(__epm_get_altpkg_url $pkg)
[ -n "$url" ] || warning "Can't get URL for $pkg"
if [ -n "$checkflag" ] ; then
__epm_print_url_alt_check "$pkg" "$url"
else
docmd eget $url || return
fi
done
} }
epm_download() epm_download()
...@@ -1656,12 +1853,7 @@ epm_download() ...@@ -1656,12 +1853,7 @@ epm_download()
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
local pkg __epm_download_alt $pkg_filenames
for pkg in $pkg_filenames ; do
local url=$(__epm_get_altpkg_url $pkg)
[ -n "$url" ] || warning "Can't get url for $pkg"
docmd eget $url
done
return return
;; ;;
esac esac
...@@ -1795,6 +1987,8 @@ __epm_filelist_name() ...@@ -1795,6 +1987,8 @@ __epm_filelist_name()
[ -z "$*" ] && return [ -z "$*" ] && return
warmup_lowbase
case $PMTYPE in case $PMTYPE in
*-rpm) *-rpm)
CMD="rpm -ql" CMD="rpm -ql"
...@@ -1986,6 +2180,7 @@ __epm_info_by_pkgtype || __epm_info_by_pmtype ...@@ -1986,6 +2180,7 @@ __epm_info_by_pkgtype || __epm_info_by_pmtype
local RETVAL=$? local RETVAL=$?
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files [ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
return $RETVAL return $RETVAL
} }
...@@ -2053,15 +2248,19 @@ __separate_sudocmd() ...@@ -2053,15 +2248,19 @@ __separate_sudocmd()
epm_install_names() epm_install_names()
{ {
[ -z "$1" ] && return
warmup_hibase
if [ -n "$non_interactive" ] ; then if [ -n "$non_interactive" ] ; then
epm_ni_install_names "$@" epm_ni_install_names "$@"
return return
fi fi
[ -z "$1" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
sudocmd apt-get -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS $noremove install $@ APTOPTIONS="$APTOPTIONS $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
sudocmd apt-get $APTOPTIONS $noremove install $@
return ;; return ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude install $@ sudocmd aptitude install $@
...@@ -2150,6 +2349,7 @@ epm_install_names() ...@@ -2150,6 +2349,7 @@ epm_install_names()
epm_ni_install_names() epm_ni_install_names()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
...@@ -2433,7 +2633,9 @@ epm_install_files() ...@@ -2433,7 +2633,9 @@ epm_install_files()
epm_print_install_command() epm_print_install_command()
{ {
[ -z "$1" ] && return # print out low level command by default (wait --low-level for control it)
#[ -z "$1" ] && return
[ -z "$1" ] && [ -n "$pkg_names" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm) apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
echo "rpm -Uvh --force $nodeps $*" echo "rpm -Uvh --force $nodeps $*"
...@@ -2488,6 +2690,8 @@ epm_print_install_command() ...@@ -2488,6 +2690,8 @@ epm_print_install_command()
epm_print_install_names_command() epm_print_install_names_command()
{ {
# check for pkg_files to support print out command without pkg names in args
#[ -z "$1" ] && [ -n "$pkg_files" ] && return
[ -z "$1" ] && return [ -z "$1" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
...@@ -2526,6 +2730,12 @@ epm_print_install_names_command() ...@@ -2526,6 +2730,12 @@ epm_print_install_names_command()
epm_install() epm_install()
{ {
if tasknumber "$pkg_names" >/dev/null ; then
assure_exists apt-repo
sudocmd apt-repo test $(tasknumber "$pkg_names")
return
fi
if [ -n "$show_command_only" ] ; then if [ -n "$show_command_only" ] ; then
epm_print_install_command $pkg_files epm_print_install_command $pkg_files
epm_print_install_names_command $pkg_names epm_print_install_names_command $pkg_names
...@@ -2543,10 +2753,18 @@ epm_install() ...@@ -2543,10 +2753,18 @@ epm_install()
[ -z "$pkg_files$pkg_names" ] && info "Skip empty install list" && return 22 [ -z "$pkg_files$pkg_names" ] && info "Skip empty install list" && return 22
# to be filter happy
warmup_lowbase
local names="$(echo $pkg_names | filter_out_installed_packages)" local names="$(echo $pkg_names | filter_out_installed_packages)"
local files="$(echo $pkg_files | filter_out_installed_packages)" local files="$(echo $pkg_files | filter_out_installed_packages)"
[ -z "$files$names" ] && info "Skip empty install list" && return 22 # can be empty only after skip installed
if [ -z "$files$names" ] ; then
# TODO: assert $skip_installed
[ -n "$verbose" ] && info "Skip empty install list"
return 22
fi
if [ -z "$files" ] && [ -z "$direct" ] ; then if [ -z "$files" ] && [ -z "$direct" ] ; then
# it is useful for first time running # it is useful for first time running
...@@ -2559,6 +2777,7 @@ epm_install() ...@@ -2559,6 +2777,7 @@ epm_install()
# TODO: reinvent # TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files [ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
return $RETVAL return $RETVAL
} }
...@@ -2665,9 +2884,12 @@ epm_install_emerge() ...@@ -2665,9 +2884,12 @@ epm_install_emerge()
# File bin/epm-kernel_update: # File bin/epm-kernel_update:
epm_kernel_update() epm_kernel_update()
{ {
info "Starting update system kernel to the latest version" warmup_bases
info "Updating system kernel to the latest version..."
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
...@@ -2676,6 +2898,7 @@ epm_kernel_update() ...@@ -2676,6 +2898,7 @@ epm_kernel_update()
return return
fi fi
assure_exists update-kernel update-kernel 0.9.9 assure_exists update-kernel update-kernel 0.9.9
update_repo_if_needed
sudocmd update-kernel $pkg_filenames || return sudocmd update-kernel $pkg_filenames || return
docmd epm remove-old-kernels $pkg_filenames || fatal docmd epm remove-old-kernels $pkg_filenames || fatal
return ;; return ;;
...@@ -2721,14 +2944,17 @@ esac ...@@ -2721,14 +2944,17 @@ esac
# File bin/epm-packages: # File bin/epm-packages:
__epm_packages_sort() __epm_packages_sort()
{ {
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm) apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
# FIXME: space with quotes problems, use point instead # FIXME: space with quotes problems, use point instead
warmup_rpmbase
docmd rpm -qa --queryformat "%{size}@%{name}-%{version}-%{release}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1 docmd rpm -qa --queryformat "%{size}@%{name}-%{version}-%{release}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
;; ;;
apt-dpkg) apt-dpkg)
warmup_dpkgbase
docmd dpkg-query -W --showformat="\${Installed-Size}@\${Package}-\${Version}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1 docmd dpkg-query -W --showformat="\${Installed-Size}@\${Package}-\${Version}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
;; ;;
*) *)
...@@ -2756,12 +2982,14 @@ epm_packages() ...@@ -2756,12 +2982,14 @@ epm_packages()
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
warmup_rpmbase
# FIXME: strong equal # FIXME: strong equal
CMD="rpm -qa $pkg_filenames" CMD="rpm -qa $pkg_filenames"
[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames" [ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
docmd $CMD docmd $CMD
return ;; return ;;
*-dpkg) *-dpkg)
warmup_dpkgbase
# FIXME: strong equal # FIXME: strong equal
#CMD="dpkg -l $pkg_filenames" #CMD="dpkg -l $pkg_filenames"
CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}-\${Version}\n $pkg_filenames" CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}-\${Version}\n $pkg_filenames"
...@@ -2773,6 +3001,7 @@ case $PMTYPE in ...@@ -2773,6 +3001,7 @@ case $PMTYPE in
CMD="snappy info" CMD="snappy info"
;; ;;
yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm) yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
warmup_rpmbase
# FIXME: strong equal # FIXME: strong equal
CMD="rpm -qa $pkg_filenames" CMD="rpm -qa $pkg_filenames"
[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames" [ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
...@@ -2888,6 +3117,8 @@ epm_policy() ...@@ -2888,6 +3117,8 @@ epm_policy()
[ -n "$pkg_names" ] || fatal "Info: missing package(s) name" [ -n "$pkg_names" ] || fatal "Info: missing package(s) name"
warmup_bases
pkg_names=$(__epm_get_hilevel_name $pkg_names) pkg_names=$(__epm_get_hilevel_name $pkg_names)
case $PMTYPE in case $PMTYPE in
...@@ -3677,6 +3908,7 @@ epm_query_package() ...@@ -3677,6 +3908,7 @@ epm_query_package()
epm_reinstall_names() epm_reinstall_names()
{ {
[ -n "$1" ] || return [ -n "$1" ] || return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
local APTOPTIONS="$(subst_option non_interactive -y)" local APTOPTIONS="$(subst_option non_interactive -y)"
...@@ -3729,9 +3961,13 @@ epm_reinstall() ...@@ -3729,9 +3961,13 @@ epm_reinstall()
{ {
[ -n "$pkg_filenames" ] || fatal "Reinstall: missing package(s) name." [ -n "$pkg_filenames" ] || fatal "Reinstall: missing package(s) name."
warmup_lowbase
# get package name for hi level package management command (with version if supported and if possible) # get package name for hi level package management command (with version if supported and if possible)
pkg_names=$(__epm_get_hilevel_name $pkg_names) pkg_names=$(__epm_get_hilevel_name $pkg_names)
warmup_hibase
epm_reinstall_names $pkg_names epm_reinstall_names $pkg_names
epm_reinstall_files $pkg_files epm_reinstall_files $pkg_files
} }
...@@ -3797,14 +4033,57 @@ __alt_repofix() ...@@ -3797,14 +4033,57 @@ __alt_repofix()
{ {
showcmd epm repofix showcmd epm repofix
quiet=1 pkg_filenames='' epm_repofix >/dev/null quiet=1 pkg_filenames='' epm_repofix >/dev/null
__replace_text_in_alt_repo "/^ *#/! s!\[[tp][6-9]\]![updates]!g" __replace_text_in_alt_repo "/^ *#/! s!\[[tpc][6-9]\]![updates]!g"
}
__get_conflict_release_pkg()
{
epmqf --quiet --short /etc/fedora-release | head -n1
} }
get_fix_release_pkg() get_fix_release_pkg()
{ {
# TODO: check for version incompatibilities local TOINSTALL=''
if epmqf /etc/altlinux-release | grep -q sisyphus ; then
echo altlinux-release-$1 local FORCE=''
if [ "$1" == "--force" ] ; then
FORCE="$1"
shift
fi
local TO="$1"
echo "rpm apt"
if [ "$TO" = "Sisyphus" ] ; then
TO="sisyphus"
echo "apt-conf-$TO"
else
echo "apt-conf-branch"
fi
if [ "$FORCE" == "--force" ] ; then
# assure we have set needed release
TOINSTALL="altlinux-release-$TO"
else
# just assure we have /etc/altlinux-release and switched from sisyphus
if [ ! -s /etc/altlinux-release ] || epmqf /etc/altlinux-release | grep -q sisyphus ; then
TOINSTALL="altlinux-release-$TO"
fi
fi
# workaround against obsoleted altlinux-release-sisyphus package from 2008 year
[ "$TOINSTALL" = "altlinux-release-sisyphus" ] && TOINSTALL="branding-alt-sisyphus-release"
if [ -n "$TOINSTALL" ] ; then
echo "$TOINSTALL"
# workaround against
# file /etc/fedora-release from install of altlinux-release-p8-20160414-alt1 conflicts with file from package branding-simply-linux-release-8.2.0-alt1
# problem
if __get_conflict_release_pkg | grep -q -v "^altlinux-release" && [ "$TOINSTALL" != "$(__get_conflict_release_pkg)" ] ; then
echo $(__get_conflict_release_pkg)-
fi
fi fi
} }
...@@ -3815,7 +4094,7 @@ __update_to_the_distro() ...@@ -3815,7 +4094,7 @@ __update_to_the_distro()
case "$TO" in case "$TO" in
p7) p7)
docmd epm update || fatal docmd epm update || fatal
docmd epm install apt rpm apt-conf-branch "$(get_fix_release_pkg "$TO")" || fatal "Check an error and run epm release-upgrade again" docmd epm install "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
__alt_repofix __alt_repofix
__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g" __replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
docmd epm update || fatal docmd epm update || fatal
...@@ -3823,14 +4102,11 @@ __update_to_the_distro() ...@@ -3823,14 +4102,11 @@ __update_to_the_distro()
;; ;;
p8) p8)
docmd epm update || fatal docmd epm update || fatal
if ! docmd epm install apt rpm apt-conf-branch "$(get_fix_release_pkg "$TO")" ; then docmd epm install "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
# Hack for error: execution of %post scriptlet from glibc-core-2.23-alt1.eter1
docmd rpm -ev glibc-core-2.17 || fatal "Check an error and run epm release-upgrade again"
docmd epm install apt rpm apt-conf-branch "$(get_fix_release_pkg "$TO")" || fatal "Check an error and run epm release-upgrade again"
fi
__alt_repofix __alt_repofix
__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g" __replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
docmd epm update || fatal docmd epm update || fatal
# sure we have systemd if systemd is running
if is_installed systemd && is_active_systemd systemd ; then if is_installed systemd && is_active_systemd systemd ; then
docmd epm install systemd || fatal docmd epm install systemd || fatal
fi fi
...@@ -3838,33 +4114,35 @@ __update_to_the_distro() ...@@ -3838,33 +4114,35 @@ __update_to_the_distro()
;; ;;
Sisyphus) Sisyphus)
docmd epm update || fatal docmd epm update || fatal
docmd epm install apt rpm librpm7 librpm apt-conf-sisyphus altlinux-release-sisyphus || fatal "Check an error and run again" docmd epm install librpm7 librpm "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run again"
docmd epm upgrade || fatal "Check an error and run epm release-upgrade again" docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
;; ;;
*) *)
esac esac
} }
__update_alt_to_next_distro() __update_alt_to_next_distro()
{ {
local TO="" local TO="$2"
local FROM="$1" local FROM="$1"
[ -n "$TO" ] || TO="$FROM"
info info
case "$*" in case "$*" in
"p6"|"p6 p7"|"t6 p7") "p6"|"p6 p7"|"t6 p7"|"c6 c7")
TO="p7" TO="p7"
info "Upgrade $DISTRNAME from $FROM to $TO ..." info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install apt-conf-branch || fatal docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo "$FROM/branch/" "$TO/branch/" __replace_alt_version_in_repo "$FROM/branch/" "$TO/branch/"
__update_to_the_distro "$TO" __update_to_the_distro "$TO"
docmd epm update-kernel docmd epm update-kernel
info "Done." info "Done."
info "Run epm release-upgrade again for update to p8" info "Run epm release-upgrade again for update to p8"
;; ;;
"p7"|"p7 p8"|"t7 p8") "p7"|"p7 p8"|"t7 p8"|"c7 c8"|"p8 p8")
TO="p8" TO="p8"
info "Upgrade $DISTRNAME from $FROM to $TO ..." info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install apt-conf-branch "$(get_fix_release_pkg "$FROM")" || fatal docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo $FROM/branch/ $TO/branch/ __replace_alt_version_in_repo $FROM/branch/ $TO/branch/
__update_to_the_distro $TO __update_to_the_distro $TO
docmd epm update-kernel || fatal docmd epm update-kernel || fatal
...@@ -3873,17 +4151,17 @@ __update_alt_to_next_distro() ...@@ -3873,17 +4151,17 @@ __update_alt_to_next_distro()
"Sisyphus p8") "Sisyphus p8")
TO="p8" TO="p8"
info "Downgrade $DISTRNAME from $FROM to $TO ..." info "Downgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install apt-conf-branch || fatal docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo "$FROM/" "$FROM/branch/" __replace_alt_version_in_repo "$FROM/" "$FROM/branch/"
__replace_text_in_alt_repo "/^ *#/! s!\[alt\]![$TO]!g" __replace_text_in_alt_repo "/^ *#/! s!\[alt\]![$TO]!g"
__update_to_the_distro $TO __update_to_the_distro $TO
docmd epm downgrade || fatal docmd epm downgrade || fatal
info "Done." info "Done."
;; ;;
"p8 Sisyphus") "p8 Sisyphus"|"Sisyphus Sisyphus")
TO="Sisyphus" TO="Sisyphus"
info "Upgrade $DISTRNAME from $FROM to $TO ..." info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install apt-conf-branch || fatal docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
docmd epm upgrade || fatal docmd epm upgrade || fatal
__replace_alt_version_in_repo "$FROM/branch/" "$TO/" __replace_alt_version_in_repo "$FROM/branch/" "$TO/"
__alt_repofix __alt_repofix
...@@ -3893,7 +4171,11 @@ __update_alt_to_next_distro() ...@@ -3893,7 +4171,11 @@ __update_alt_to_next_distro()
info "Done." info "Done."
;; ;;
*) *)
if [ "$FROM" = "$TO" ] ; then
info "It seems your system is already updated to newest $DISTRNAME $TO"
else
warning "Have no idea how to update from $DISTRNAME $FROM to $DISTRNAME $TO." warning "Have no idea how to update from $DISTRNAME $FROM to $DISTRNAME $TO."
fi
info "Try run f.i. # epm release-upgrade p8 or # epm release-upgrade Sisyphus" info "Try run f.i. # epm release-upgrade p8 or # epm release-upgrade Sisyphus"
info "Also possible you need install altlinux-release-p? package for correct distro version detecting" info "Also possible you need install altlinux-release-p? package for correct distro version detecting"
return 1 return 1
...@@ -3906,10 +4188,12 @@ epm_release_upgrade() ...@@ -3906,10 +4188,12 @@ epm_release_upgrade()
info "Starting upgrade whole system to the next release" info "Starting upgrade whole system to the next release"
info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux" info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
# TODO: it is possible eatmydata does not do his work
export EPMNOEATMYDATA=1
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
docmd epm update docmd epm update
docmd epm install apt rpm
# try to detect current release by repo # try to detect current release by repo
if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then
...@@ -3928,6 +4212,7 @@ epm_release_upgrade() ...@@ -3928,6 +4212,7 @@ epm_release_upgrade()
[ "$(__wcount $pkg_filenames)" = "1" ] || fatal "Too many args: $pkg_filenames" [ "$(__wcount $pkg_filenames)" = "1" ] || fatal "Too many args: $pkg_filenames"
fi fi
# TODO: ask before upgrade
__update_alt_to_next_distro $DISTRVERSION $pkg_filenames __update_alt_to_next_distro $DISTRVERSION $pkg_filenames
return return
;; ;;
...@@ -4007,6 +4292,9 @@ epm_release_upgrade() ...@@ -4007,6 +4292,9 @@ epm_release_upgrade()
epm_remove_low() epm_remove_low()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
warmup_lowbase
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm) apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm)
sudocmd rpm -ev $nodeps $@ sudocmd rpm -ev $nodeps $@
...@@ -4038,15 +4326,17 @@ epm_remove_names() ...@@ -4038,15 +4326,17 @@ epm_remove_names()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
warmup_bases
case $PMTYPE in case $PMTYPE in
apt-dpkg) apt-dpkg)
sudocmd apt-get remove --purge $@ sudocmd apt-get remove --purge $APTOPTIONS $@
return ;; return ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude purge $@ sudocmd aptitude purge $@
return ;; return ;;
apt-rpm) apt-rpm)
sudocmd apt-get remove $@ sudocmd apt-get remove $APTOPTIONS $@
return ;; return ;;
deepsolver-rpm) deepsolver-rpm)
sudocmd ds-remove $@ sudocmd ds-remove $@
...@@ -4127,6 +4417,8 @@ epm_remove_names() ...@@ -4127,6 +4417,8 @@ epm_remove_names()
epm_remove_nonint() epm_remove_nonint()
{ {
warmup_bases
case $PMTYPE in case $PMTYPE in
apt-dpkg) apt-dpkg)
sudocmd apt-get -y --force-yes remove --purge $@ sudocmd apt-get -y --force-yes remove --purge $@
...@@ -4212,11 +4504,39 @@ epm_remove() ...@@ -4212,11 +4504,39 @@ epm_remove()
return return
fi fi
local tn=$(tasknumber "$pkg_names")
if [ -n "$tn" ] ; then
assure_exists apt-repo
pkg_names=$(showcmd apt-repo list $tn)
#docmd epm remove $dryrun
return
fi
# get full package name(s) from the package file(s) # get full package name(s) from the package file(s)
[ -n "$pkg_files" ] && pkg_names="$pkg_names $(epm query $pkg_files)" [ -n "$pkg_files" ] && pkg_names="$pkg_names $(epm query $pkg_files)"
[ -n "$pkg_names" ] || fatal "Remove: missing package(s) name." [ -n "$pkg_names" ] || fatal "Remove: missing package(s) name."
if [ -n "$dryrun" ] ; then
info "Packages for removing:"
echo "$pkg_names"
case $PMTYPE in
apt-rpm)
nodeps="--test"
APTOPTIONS="--simulate"
;;
*
return
;;
esac
fi
epm_remove_low $pkg_names && return epm_remove_low $pkg_names && return
local STATUS=$?
if [ -n "$direct" ] ; then
return $STATUS
fi
# get package name for hi level package management command (with version if supported and if possible) # get package name for hi level package management command (with version if supported and if possible)
pkg_names=$(__epm_get_hilevel_name $pkg_names) pkg_names=$(__epm_get_hilevel_name $pkg_names)
...@@ -4234,8 +4554,12 @@ epm_remove() ...@@ -4234,8 +4554,12 @@ epm_remove()
# File bin/epm-remove_old_kernels: # File bin/epm-remove_old_kernels:
epm_remove_old_kernels() epm_remove_old_kernels()
{ {
warmup_bases
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
if ! __epm_query_package kernel-image >/dev/null ; then if ! __epm_query_package kernel-image >/dev/null ; then
...@@ -4281,6 +4605,7 @@ epm_remove_old_kernels() ...@@ -4281,6 +4605,7 @@ epm_remove_old_kernels()
# File bin/epm-removerepo: # File bin/epm-removerepo:
epm_removerepo() epm_removerepo()
{ {
local repo="$(eval echo $quoted_args)" local repo="$(eval echo $quoted_args)"
...@@ -4293,8 +4618,31 @@ case $DISTRNAME in ...@@ -4293,8 +4618,31 @@ case $DISTRNAME in
[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION" [ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")" repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
;; ;;
archive)
info "remove archive repos"
assure_exists apt-repo
epm repolist | grep "archive/" | while read repo ; do
sudocmd apt-repo rm "$repo"
done
return 0
;;
tasks)
info "remove task repos"
assure_exists apt-repo
epm repolist | grep "/repo/" | while read repo ; do
sudocmd apt-repo rm "$repo"
done
return 0
;;
*)
if tasknumber "$repo" >/dev/null ; then
repo="$(epm repolist | grep "repo/$(tasknumber "$repo")" | line)"
# "
fi
;;
esac esac
[ -n "$repo" ] || fatal "No such repo or task. Use epm remove repo [autoimports|archive|TASK]"
assure_exists apt-repo assure_exists apt-repo
sudocmd apt-repo rm "$repo" sudocmd apt-repo rm "$repo"
return return
...@@ -4377,6 +4725,7 @@ __fix_apt_sources_list() ...@@ -4377,6 +4725,7 @@ __fix_apt_sources_list()
# Sisyphus uses 'alt' vendor key # Sisyphus uses 'alt' vendor key
__try_fix_apt_source_list $i alt "ALTLinux\/Sisyphus" __try_fix_apt_source_list $i alt "ALTLinux\/Sisyphus"
__try_fix_apt_source_list $i etersoft "Etersoft\/Sisyphus"
# skip branch replacement for ALT Linux Sisyphus # skip branch replacement for ALT Linux Sisyphus
[ "$DISTRVERSION" = "Sisyphus" ] && continue [ "$DISTRVERSION" = "Sisyphus" ] && continue
...@@ -4693,8 +5042,8 @@ __epm_search_make_grep() ...@@ -4693,8 +5042,8 @@ __epm_search_make_grep()
local listN= local listN=
for i in $@ ; do for i in $@ ; do
case "$i" in case "$i" in
^*) ~*)
# will clean from ^ later (and have the bug here with empty arg if run with one ^ only) # will clean from ~ later (and have the bug here with empty arg if run with one ~ only)
listN="$listN $i" listN="$listN $i"
;; ;;
*) *)
...@@ -4704,7 +5053,7 @@ __epm_search_make_grep() ...@@ -4704,7 +5053,7 @@ __epm_search_make_grep()
done done
#list=$(strip_spaces $list | sed -e "s/ /|/g") #list=$(strip_spaces $list | sed -e "s/ /|/g")
listN=$(strip_spaces $listN | sed -e "s/ /|/g" | sed -e "s/\^//g") listN=$(strip_spaces $listN | sed -e "s/ /|/g" | sed -e "s/~//g")
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
echon " | sed -e \"s| .*||g\"" echon " | sed -e \"s| .*||g\""
...@@ -4749,6 +5098,8 @@ epm_search() ...@@ -4749,6 +5098,8 @@ epm_search()
# it is useful for first time running # it is useful for first time running
update_repo_if_needed soft update_repo_if_needed soft
warmup_bases
# FIXME: do it better # FIXME: do it better
local MGS local MGS
MGS=$(eval __epm_search_make_grep $quoted_args) MGS=$(eval __epm_search_make_grep $quoted_args)
...@@ -4931,6 +5282,83 @@ get_local_alt_contents_index() ...@@ -4931,6 +5282,83 @@ get_local_alt_contents_index()
} }
tasknumber()
{
local num="$(echo "$*" | sed -e "s| *#*||g")"
isnumber "$num" && echo "$num"
}
# File bin/epm-sh-warmup:
is_warmup_allowed()
{
local MEM
MEM=$($DISTRVENDOR -m)
# disable warm if have no enough memory
[ $MEM -le 1024 ] && return 1
return 0
}
__warmup_files()
{
local D="$1"
shift
#showcmd "$*"
[ -n "$D" ] && info "Warming up $D ..."
# TODO: use progress, calc files size before
docmd cat $* >/dev/null 2>/dev/null
}
warmup_rpmbase()
{
is_warmup_allowed || return
__warmup_files "rpm" "/var/lib/rpm/*"
}
warmup_dpkgbase()
{
is_warmup_allowed || { warning "Skipping warmup bases due low memory size" ; return ; }
__warmup_files "dpkg" "/var/lib/dpkg/*"
}
warmup_lowbase()
{
case $PKGFORMAT in
"rpm")
warmup_rpmbase "$@"
;;
"dpkg")
warmup_dpkgbase "$@"
;;
*)
;;
esac
}
warmup_aptbase()
{
is_warmup_allowed || return
__warmup_files "apt" "/var/lib/apt/lists/* /var/cache/apt/*.bin"
}
warmup_hibase()
{
case $PMTYPE in
"apt-rpm"|"apt-dpkg")
warmup_aptbase "$@"
;;
*)
;;
esac
}
warmup_bases()
{
DISquiet=1 warmup_lowbase
DISquiet=1 warmup_hibase
}
# File bin/epm-simulate: # File bin/epm-simulate:
...@@ -5194,11 +5622,14 @@ done ...@@ -5194,11 +5622,14 @@ done
# File bin/epm-update: # File bin/epm-update:
epm_update() epm_update()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" [ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
info "Running command for update remote package repository database" info "Running command for update remote package repository database"
warmup_hibase
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
sudocmd apt-get update || return sudocmd apt-get update || return
...@@ -5287,11 +5718,12 @@ epm_upgrade() ...@@ -5287,11 +5718,12 @@ epm_upgrade()
# it is useful for first time running # it is useful for first time running
update_repo_if_needed update_repo_if_needed
warmup_bases
info "Running command for upgrade packages" info "Running command for upgrade packages"
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
local APTOPTIONS="$(subst_option non_interactive -y)" local APTOPTIONS="$(subst_option non_interactive -y) $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
# Функцию добавления параметра при условии # Функцию добавления параметра при условии
CMD="apt-get $APTOPTIONS dist-upgrade $noremove" CMD="apt-get $APTOPTIONS dist-upgrade $noremove"
;; ;;
...@@ -5476,6 +5908,7 @@ docmd $CMD $pkg ...@@ -5476,6 +5908,7 @@ docmd $CMD $pkg
} }
################# incorporate bin/distr_info #################
internal_distr_info() internal_distr_info()
{ {
# Author: Vitaly Lipatov <lav@etersoft.ru> # Author: Vitaly Lipatov <lav@etersoft.ru>
...@@ -5504,6 +5937,11 @@ has() ...@@ -5504,6 +5937,11 @@ has()
grep "$*" "$DISTROFILE" >/dev/null 2>&1 grep "$*" "$DISTROFILE" >/dev/null 2>&1
} }
firstupper()
{
echo "$*" | sed 's/.*/\u&/'
}
# Translate DISTRIB_ID to vendor name (like %_vendor does) # Translate DISTRIB_ID to vendor name (like %_vendor does)
rpmvendor() rpmvendor()
{ {
...@@ -5525,11 +5963,12 @@ pkgvendor() ...@@ -5525,11 +5963,12 @@ pkgvendor()
# Print pkgtype (need DISTRIB_ID var) # Print pkgtype (need DISTRIB_ID var)
pkgtype() pkgtype()
{ {
# 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) 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" ;;
...@@ -5619,7 +6058,7 @@ elif distro slackware-version ; then ...@@ -5619,7 +6058,7 @@ elif distro slackware-version ; then
elif distro os-release && which apk 2>/dev/null >/dev/null ; then elif distro os-release && which apk 2>/dev/null >/dev/null ; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $ROOTDIR/etc/os-release . $ROOTDIR/etc/os-release
DISTRIB_ID="$ID" DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID" DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && which tce-ab 2>/dev/null >/dev/null ; then elif distro os-release && which tce-ab 2>/dev/null >/dev/null ; then
...@@ -5641,6 +6080,7 @@ elif distro arch-release ; then ...@@ -5641,6 +6080,7 @@ elif distro arch-release ; then
DISTRIB_RELEASE="2011" DISTRIB_RELEASE="2011"
fi fi
# 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")
...@@ -5751,6 +6191,14 @@ elif distro SuSe-release || distro SuSE-release ; then ...@@ -5751,6 +6191,14 @@ elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SLES" DISTRIB_ID="SLES"
fi fi
# https://www.freedesktop.org/software/systemd/man/os-release.html
elif distro os-release ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID"
[ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR"
# 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"
...@@ -5793,6 +6241,112 @@ elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then ...@@ -5793,6 +6241,112 @@ elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
esac esac
fi fi
get_base_os_name()
{
local DIST_OS
# Resolve the os
DIST_OS=`uname -s | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_OS" in
'sunos')
DIST_OS="solaris"
;;
'hp-ux' | 'hp-ux64')
DIST_OS="hpux"
;;
'darwin' | 'oarwin')
DIST_OS="macosx"
;;
'unix_sv')
DIST_OS="unixware"
;;
'freebsd' | 'openbsd' | 'netbsd')
DIST_OS="freebsd"
;;
esac
echo "$DIST_OS"
}
get_arch()
{
local DIST_ARCH
# Resolve the architecture
DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_ARCH" in
'amd64' | 'ia32' | 'i386' | 'i486' | 'i586' | 'i686' | 'x86_64')
DIST_ARCH="x86"
;;
'ia64' | 'ia-64')
DIST_ARCH="ia64"
;;
'ip27' | 'mips')
DIST_ARCH="mips"
;;
'powermacintosh' | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
DIST_ARCH="ppc"
;;
'pa_risc' | 'pa-risc')
DIST_ARCH="parisc"
;;
'sun4u' | 'sparcv9')
DIST_ARCH="sparc"
;;
'9000/800')
DIST_ARCH="parisc"
;;
armv*)
if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then
DIST_ARCH="armel"
else
DIST_ARCH="armhf"
fi
;;
esac
echo "$DIST_ARCH"
}
get_bit_size()
{
local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now...
DIST_BIT=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64"
;;
# 'pa_risc' | 'pa-risc') # Are some of these 64bit? Least not all...
# BIT="64"
# ;;
'sun4u' | 'sparcv9') # Are all sparcs 64?
DIST_BIT="64"
;;
# '9000/800')
# DIST_BIT="64"
# ;;
*) # In any other case default to 32
DIST_BIT="32"
;;
esac
echo "$DIST_BIT"
}
get_memory_size() {
local detected=0
local DIST_OS=$(get_base_os_name)
if [ $DIST_OS = "macosx" ]
then
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
elif [ $DIST_OS = "freebsd" ]
then
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
elif [ $DIST_OS = "linux" ]
then
detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
fi
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected
}
case $1 in case $1 in
-p) -p)
# override DISTRIB_ID # override DISTRIB_ID
...@@ -5805,6 +6359,10 @@ case $1 in ...@@ -5805,6 +6359,10 @@ case $1 in
echo "Usage: distr_vendor [options] [args]" echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system" echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name" echo "-d - print distro name"
echo "-a - print hardware architecture"
echo "-b - print size of arch bit (32/64)"
echo "-m - print system memory size (in MB)"
echo "-o - print base os name"
echo "-v - print version of distro" echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)" 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 "-s [SystemName] - print name of distro for build system (like in the package release name)"
...@@ -5816,6 +6374,18 @@ case $1 in ...@@ -5816,6 +6374,18 @@ case $1 in
-d) -d)
echo $DISTRIB_ID echo $DISTRIB_ID
;; ;;
-a)
get_arch
;;
-b)
get_bit_size
;;
-m)
get_memory_size
;;
-o)
get_base_os_name
;;
-v) -v)
echo $DISTRIB_RELEASE echo $DISTRIB_RELEASE
;; ;;
...@@ -5842,16 +6412,19 @@ case $1 in ...@@ -5842,16 +6412,19 @@ case $1 in
esac esac
} }
################# end of incorporated bin/distr_info #################
################# incorporate bin/tools_eget #################
internal_tools_eget() internal_tools_eget()
{ {
# eget - simply shell on wget for loading directories over http # eget - simply shell on wget for loading directories over http (wget does not support wildcard for http)
# Example use: # Example use:
# eget ftp://ftp.altlinux.ru/pub/security/ssl/* # eget http://ftp.altlinux.ru/pub/security/ssl/*
# #
# Copyright (C) 2014-2014, 2016 Etersoft # Copyright (C) 2014-2014, 2016 Etersoft
# Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru> # Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -5886,29 +6459,39 @@ fi ...@@ -5886,29 +6459,39 @@ fi
# TODO: # TODO:
# -P support # -P support
# If ftp protocol or have no asterisk, just download if [ -z "$1" ] ; then
# TODO: use has() echo "eget - wget wrapper" >&2
if echo "$1" | grep -q "\(^ftp://\|[^*]\)" ; then echo "Run with URL, like http://somesite.ru/dir/*.log" >&2
exit 1
fi
# If ftp protocol, just download
if echo "$1" | grep -q "^ftp://" ; then
$WGET $WGET_OPTION_TARGET "$1"
return
fi
# drop mask part (if has /$, not changed)
URL=$(echo "$1" | grep "/$" || dirname "$1")
# If have no wildcard symbol like asterisk and no / at the end, just download
if [ "$URL" != "$1" ] && echo "$1" | grep -qv "[*?]" ; then
$WGET $WGET_OPTION_TARGET "$1" $WGET $WGET_OPTION_TARGET "$1"
return return
fi fi
echo "Fall to http workaround" echo "Fall to http workaround"
URL=$(echo "$1" | grep "/$" || dirname "$1")
# mask allowed only in last part of path # mask allowed only in last part of path
MASK=$(basename "$1") MASK=$(basename "$1")
# TODO: skip create_fake_files for full dir
get_index() # add * if full dir
{ #[ "$URL" != "$1" ] && MASK="*"
MYTMPDIR="$(mktemp -d)"
INDEX=$MYTMPDIR/index
$WGET $URL -O $INDEX
}
print_files() print_files()
{ {
cat $INDEX | grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2 $WGET -O- $URL | \
grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
} }
create_fake_files() create_fake_files()
...@@ -5924,18 +6507,23 @@ create_fake_files() ...@@ -5924,18 +6507,23 @@ create_fake_files()
download_files() download_files()
{ {
ERROR=0 ERROR=0
# TODO: test fix / at the end
for line in $DIRALLFILES/$MASK ; do for line in $DIRALLFILES/$MASK ; do
[ -r "$line" ] || { ERROR=1 ; break ; }
$WGET $URL/$(basename "$line") || ERROR=1 $WGET $URL/$(basename "$line") || ERROR=1
done done
return $ERROR return $ERROR
} }
get_index || return MYTMPDIR="$(mktemp -d)"
create_fake_files create_fake_files
download_files || echo "There was some download errors" >&2 download_files || echo "There was some download errors" >&2
rm -rf "$MYTMPDIR" rm -rf "$MYTMPDIR"
} }
################# end of incorporated bin/tools_eget #################
################# incorporate bin/tools_json #################
internal_tools_json() internal_tools_json()
{ {
...@@ -6149,6 +6737,8 @@ fi ...@@ -6149,6 +6737,8 @@ fi
# vi: expandtab sw=2 ts=2 # vi: expandtab sw=2 ts=2
} }
################# end of incorporated bin/tools_json #################
#PATH=$PATH:/sbin:/usr/sbin #PATH=$PATH:/sbin:/usr/sbin
...@@ -6174,7 +6764,7 @@ $(get_help HELPOPT) ...@@ -6174,7 +6764,7 @@ $(get_help HELPOPT)
print_version() print_version()
{ {
echo "EPM package manager version 2.1.1" echo "EPM package manager version 2.3.0"
echo "Running on $($DISTRVENDOR) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)" echo "Running on $($DISTRVENDOR) ('$PMTYPE' package manager uses '$PKGFORMAT' package format)"
echo "Copyright (c) Etersoft 2012-2017" echo "Copyright (c) Etersoft 2012-2017"
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."
...@@ -6189,6 +6779,7 @@ verbose= ...@@ -6189,6 +6779,7 @@ verbose=
quiet= quiet=
nodeps= nodeps=
noremove= noremove=
dryrun=
force= force=
short= short=
direct= direct=
...@@ -6313,7 +6904,7 @@ check_command() ...@@ -6313,7 +6904,7 @@ check_command()
provides|prov) # HELPCMD: print package provides provides|prov) # HELPCMD: print package provides
epm_cmd=provides epm_cmd=provides
;; ;;
whatdepends) # HELPCMD: print packages dependences on that whatdepends|wd) # HELPCMD: print packages dependences on that
epm_cmd=whatdepends epm_cmd=whatdepends
;; ;;
whatprovides) # HELPCMD: print packages provides that target whatprovides) # HELPCMD: print packages provides that target
...@@ -6365,7 +6956,7 @@ check_command() ...@@ -6365,7 +6956,7 @@ check_command()
clean) # HELPCMD: clean local package cache clean) # HELPCMD: clean local package cache
epm_cmd=clean epm_cmd=clean
;; ;;
autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [libs|python|perl|libs-devel]
epm_cmd=autoremove epm_cmd=autoremove
;; ;;
autoorphans|--orphans) # HELPCMD: remove all packages not from the repository autoorphans|--orphans) # HELPCMD: remove all packages not from the repository
...@@ -6383,6 +6974,7 @@ check_command() ...@@ -6383,6 +6974,7 @@ check_command()
download) # HELPCMD: download package(s) file to the current dir download) # HELPCMD: download package(s) file to the current dir
epm_cmd=download epm_cmd=download
;; ;;
# TODO: replace with install --simulate
simulate) # HELPCMD: simulate install with check requires simulate) # HELPCMD: simulate install with check requires
epm_cmd=simulate epm_cmd=simulate
;; ;;
...@@ -6432,7 +7024,7 @@ check_option() ...@@ -6432,7 +7024,7 @@ check_option()
--show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY) --show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY)
show_command_only=1 show_command_only=1
;; ;;
--quiet) # HELPOPT: quiet mode (do not print commands before exec) --quiet|--silent) # HELPOPT: quiet mode (do not print commands before exec)
quiet=1 quiet=1
;; ;;
--nodeps) # HELPOPT: skip dependency check (during install/simulate and so on) --nodeps) # HELPOPT: skip dependency check (during install/simulate and so on)
...@@ -6444,6 +7036,9 @@ check_option() ...@@ -6444,6 +7036,9 @@ check_option()
--noremove|--no-remove) # HELPOPT: exit if any packages are to be removed during upgrade --noremove|--no-remove) # HELPOPT: exit if any packages are to be removed during upgrade
noremove="--no-remove" noremove="--no-remove"
;; ;;
--dry-run|--simulate|--just-print|-recon--no-act) # HELPOPT: print only (autoremove/autoorphans/remove only)
dryrun="--dry-run"
;;
--short) # HELPOPT: short output (just 'package' instead 'package-version-release') --short) # HELPOPT: short output (just 'package' instead 'package-version-release')
short="--short" short="--short"
;; ;;
...@@ -6496,6 +7091,10 @@ done ...@@ -6496,6 +7091,10 @@ done
# if input is not console and run script from file, get pkgs from stdin too # if input is not console and run script from file, get pkgs from stdin too
if ! inputisatty && [ -n "$PROGDIR" ] ; then if ! inputisatty && [ -n "$PROGDIR" ] ; then
for opt in $(withtimeout 1 cat) ; do for opt in $(withtimeout 1 cat) ; do
# FIXME: do not work
# workaround against # yes | epme
[ "$opt" = "y" ] && break;
[ "$opt" = "yes" ] && break;
check_filenames $opt check_filenames $opt
done done
fi fi
......
...@@ -144,7 +144,7 @@ docmd_foreach() ...@@ -144,7 +144,7 @@ docmd_foreach()
sudocmd() sudocmd()
{ {
showcmd "$SUDO $*" [ -n "$SUDO" ] && showcmd "$SUDO $*" || showcmd "$*"
$SUDO $@ $SUDO $@
} }
...@@ -178,6 +178,11 @@ get_lastarg() ...@@ -178,6 +178,11 @@ get_lastarg()
echon "$lastarg" echon "$lastarg"
} }
isnumber()
{
echo "$*" | filter_strip_spaces | grep -q "^[0-9]\+$"
}
filter_strip_spaces() filter_strip_spaces()
{ {
# possible use just # possible use just
...@@ -285,12 +290,12 @@ withtimeout() ...@@ -285,12 +290,12 @@ withtimeout()
{ {
local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null) local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null)
if [ -x "$TO" ] ; then if [ -x "$TO" ] ; then
$TO $@ $TO "$@"
return return
fi fi
# fallback: drop time arg and run without timeout # fallback: drop time arg and run without timeout
shift shift
$@ "$@"
} }
set_eatmydata() set_eatmydata()
...@@ -299,7 +304,7 @@ set_eatmydata() ...@@ -299,7 +304,7 @@ set_eatmydata()
[ -n "$EPMNOEATMYDATA" ] && return [ -n "$EPMNOEATMYDATA" ] && return
# use if possible # use if possible
which eatmydata >/dev/null 2>/dev/null || return which eatmydata >/dev/null 2>/dev/null || return
SUDO="$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
} }
...@@ -351,6 +356,20 @@ assure_exists() ...@@ -351,6 +356,20 @@ assure_exists()
__epm_assure "$1" $package $3 || fatal "Can't assure in '$1' command from $package$textpackage package" __epm_assure "$1" $package $3 || fatal "Can't assure in '$1' command from $package$textpackage package"
} }
disabled_eget()
{
# use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@"
return
fi
assure_exists eget
# run external command, not the function
EGET=$(which eget) || fatal "Missed command eget from installed package eget"
$EGET "$@"
}
eget() eget()
{ {
assure_exists wget assure_exists wget
...@@ -1000,6 +1019,7 @@ _print_additional_usage ...@@ -1000,6 +1019,7 @@ _print_additional_usage
} }
################# incorporate bin/distr_info #################
internal_distr_info() internal_distr_info()
{ {
# Author: Vitaly Lipatov <lav@etersoft.ru> # Author: Vitaly Lipatov <lav@etersoft.ru>
...@@ -1028,6 +1048,11 @@ has() ...@@ -1028,6 +1048,11 @@ has()
grep "$*" "$DISTROFILE" >/dev/null 2>&1 grep "$*" "$DISTROFILE" >/dev/null 2>&1
} }
firstupper()
{
echo "$*" | sed 's/.*/\u&/'
}
# Translate DISTRIB_ID to vendor name (like %_vendor does) # Translate DISTRIB_ID to vendor name (like %_vendor does)
rpmvendor() rpmvendor()
{ {
...@@ -1049,11 +1074,12 @@ pkgvendor() ...@@ -1049,11 +1074,12 @@ pkgvendor()
# Print pkgtype (need DISTRIB_ID var) # Print pkgtype (need DISTRIB_ID var)
pkgtype() pkgtype()
{ {
# 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) 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" ;;
...@@ -1143,7 +1169,7 @@ elif distro slackware-version ; then ...@@ -1143,7 +1169,7 @@ elif distro slackware-version ; then
elif distro os-release && which apk 2>/dev/null >/dev/null ; then elif distro os-release && which apk 2>/dev/null >/dev/null ; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $ROOTDIR/etc/os-release . $ROOTDIR/etc/os-release
DISTRIB_ID="$ID" DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID" DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && which tce-ab 2>/dev/null >/dev/null ; then elif distro os-release && which tce-ab 2>/dev/null >/dev/null ; then
...@@ -1165,6 +1191,7 @@ elif distro arch-release ; then ...@@ -1165,6 +1191,7 @@ elif distro arch-release ; then
DISTRIB_RELEASE="2011" DISTRIB_RELEASE="2011"
fi fi
# 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")
...@@ -1275,6 +1302,14 @@ elif distro SuSe-release || distro SuSE-release ; then ...@@ -1275,6 +1302,14 @@ elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SLES" DISTRIB_ID="SLES"
fi fi
# https://www.freedesktop.org/software/systemd/man/os-release.html
elif distro os-release ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID"
[ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR"
# 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"
...@@ -1317,6 +1352,112 @@ elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then ...@@ -1317,6 +1352,112 @@ elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
esac esac
fi fi
get_base_os_name()
{
local DIST_OS
# Resolve the os
DIST_OS=`uname -s | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_OS" in
'sunos')
DIST_OS="solaris"
;;
'hp-ux' | 'hp-ux64')
DIST_OS="hpux"
;;
'darwin' | 'oarwin')
DIST_OS="macosx"
;;
'unix_sv')
DIST_OS="unixware"
;;
'freebsd' | 'openbsd' | 'netbsd')
DIST_OS="freebsd"
;;
esac
echo "$DIST_OS"
}
get_arch()
{
local DIST_ARCH
# Resolve the architecture
DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_ARCH" in
'amd64' | 'ia32' | 'i386' | 'i486' | 'i586' | 'i686' | 'x86_64')
DIST_ARCH="x86"
;;
'ia64' | 'ia-64')
DIST_ARCH="ia64"
;;
'ip27' | 'mips')
DIST_ARCH="mips"
;;
'powermacintosh' | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
DIST_ARCH="ppc"
;;
'pa_risc' | 'pa-risc')
DIST_ARCH="parisc"
;;
'sun4u' | 'sparcv9')
DIST_ARCH="sparc"
;;
'9000/800')
DIST_ARCH="parisc"
;;
armv*)
if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then
DIST_ARCH="armel"
else
DIST_ARCH="armhf"
fi
;;
esac
echo "$DIST_ARCH"
}
get_bit_size()
{
local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now...
DIST_BIT=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"`
case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64"
;;
# 'pa_risc' | 'pa-risc') # Are some of these 64bit? Least not all...
# BIT="64"
# ;;
'sun4u' | 'sparcv9') # Are all sparcs 64?
DIST_BIT="64"
;;
# '9000/800')
# DIST_BIT="64"
# ;;
*) # In any other case default to 32
DIST_BIT="32"
;;
esac
echo "$DIST_BIT"
}
get_memory_size() {
local detected=0
local DIST_OS=$(get_base_os_name)
if [ $DIST_OS = "macosx" ]
then
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
elif [ $DIST_OS = "freebsd" ]
then
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
elif [ $DIST_OS = "linux" ]
then
detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
fi
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected
}
case $1 in case $1 in
-p) -p)
# override DISTRIB_ID # override DISTRIB_ID
...@@ -1329,6 +1470,10 @@ case $1 in ...@@ -1329,6 +1470,10 @@ case $1 in
echo "Usage: distr_vendor [options] [args]" echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system" echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name" echo "-d - print distro name"
echo "-a - print hardware architecture"
echo "-b - print size of arch bit (32/64)"
echo "-m - print system memory size (in MB)"
echo "-o - print base os name"
echo "-v - print version of distro" echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)" 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 "-s [SystemName] - print name of distro for build system (like in the package release name)"
...@@ -1340,6 +1485,18 @@ case $1 in ...@@ -1340,6 +1485,18 @@ case $1 in
-d) -d)
echo $DISTRIB_ID echo $DISTRIB_ID
;; ;;
-a)
get_arch
;;
-b)
get_bit_size
;;
-m)
get_memory_size
;;
-o)
get_base_os_name
;;
-v) -v)
echo $DISTRIB_RELEASE echo $DISTRIB_RELEASE
;; ;;
...@@ -1366,16 +1523,19 @@ case $1 in ...@@ -1366,16 +1523,19 @@ case $1 in
esac esac
} }
################# end of incorporated bin/distr_info #################
################# incorporate bin/tools_eget #################
internal_tools_eget() internal_tools_eget()
{ {
# eget - simply shell on wget for loading directories over http # eget - simply shell on wget for loading directories over http (wget does not support wildcard for http)
# Example use: # Example use:
# eget ftp://ftp.altlinux.ru/pub/security/ssl/* # eget http://ftp.altlinux.ru/pub/security/ssl/*
# #
# Copyright (C) 2014-2014, 2016 Etersoft # Copyright (C) 2014-2014, 2016 Etersoft
# Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru> # Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -1410,29 +1570,39 @@ fi ...@@ -1410,29 +1570,39 @@ fi
# TODO: # TODO:
# -P support # -P support
# If ftp protocol or have no asterisk, just download if [ -z "$1" ] ; then
# TODO: use has() echo "eget - wget wrapper" >&2
if echo "$1" | grep -q "\(^ftp://\|[^*]\)" ; then echo "Run with URL, like http://somesite.ru/dir/*.log" >&2
exit 1
fi
# If ftp protocol, just download
if echo "$1" | grep -q "^ftp://" ; then
$WGET $WGET_OPTION_TARGET "$1"
return
fi
# drop mask part (if has /$, not changed)
URL=$(echo "$1" | grep "/$" || dirname "$1")
# If have no wildcard symbol like asterisk and no / at the end, just download
if [ "$URL" != "$1" ] && echo "$1" | grep -qv "[*?]" ; then
$WGET $WGET_OPTION_TARGET "$1" $WGET $WGET_OPTION_TARGET "$1"
return return
fi fi
echo "Fall to http workaround" echo "Fall to http workaround"
URL=$(echo "$1" | grep "/$" || dirname "$1")
# mask allowed only in last part of path # mask allowed only in last part of path
MASK=$(basename "$1") MASK=$(basename "$1")
# TODO: skip create_fake_files for full dir
get_index() # add * if full dir
{ #[ "$URL" != "$1" ] && MASK="*"
MYTMPDIR="$(mktemp -d)"
INDEX=$MYTMPDIR/index
$WGET $URL -O $INDEX
}
print_files() print_files()
{ {
cat $INDEX | grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2 $WGET -O- $URL | \
grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
} }
create_fake_files() create_fake_files()
...@@ -1448,18 +1618,23 @@ create_fake_files() ...@@ -1448,18 +1618,23 @@ create_fake_files()
download_files() download_files()
{ {
ERROR=0 ERROR=0
# TODO: test fix / at the end
for line in $DIRALLFILES/$MASK ; do for line in $DIRALLFILES/$MASK ; do
[ -r "$line" ] || { ERROR=1 ; break ; }
$WGET $URL/$(basename "$line") || ERROR=1 $WGET $URL/$(basename "$line") || ERROR=1
done done
return $ERROR return $ERROR
} }
get_index || return MYTMPDIR="$(mktemp -d)"
create_fake_files create_fake_files
download_files || echo "There was some download errors" >&2 download_files || echo "There was some download errors" >&2
rm -rf "$MYTMPDIR" rm -rf "$MYTMPDIR"
} }
################# end of incorporated bin/tools_eget #################
################# incorporate bin/tools_json #################
internal_tools_json() internal_tools_json()
{ {
...@@ -1673,6 +1848,8 @@ fi ...@@ -1673,6 +1848,8 @@ fi
# vi: expandtab sw=2 ts=2 # vi: expandtab sw=2 ts=2
} }
################# end of incorporated bin/tools_json #################
INITDIR=/etc/init.d INITDIR=/etc/init.d
...@@ -1771,7 +1948,7 @@ $(get_help HELPOPT) ...@@ -1771,7 +1948,7 @@ $(get_help HELPOPT)
print_version() print_version()
{ {
echo "Service manager version 2.1.1" echo "Service manager version 2.3.0"
echo "Running on $($DISTRVENDOR) with $SERVICETYPE" echo "Running on $($DISTRVENDOR) with $SERVICETYPE"
echo "Copyright (c) Etersoft 2012, 2013, 2016" echo "Copyright (c) Etersoft 2012, 2013, 2016"
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