Commit 1de2e43b authored by Vitaly Lipatov's avatar Vitaly Lipatov

backported to p8 as 2.4.9-alt0.M80P.1 (with rpmbph script)

parents 58f00307 1720f2c7
на p8, если в sources.list спереди стоит пробел
" rpm http://"
то имеем
# epm -sf /etc/fstab
Locate contents index file(s) ...
# apt-repo list
# eget -O /tmp/eepm/http:/10.10.19.99/altrepos/contents_index rpm/http://10.10.19.99/altrepos//base/contents_index
epm hs поиск с историей какой версией и changelog
https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks_(Русский) https://wiki.archlinux.org/index.php/Pacman/Tips_and_tricks_(Русский)
systemctl edit юнит systemctl edit юнит
......
...@@ -118,6 +118,8 @@ if distro altlinux-release ; then ...@@ -118,6 +118,8 @@ if distro altlinux-release ; then
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1" elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0" elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
elif has Walnut ; then DISTRIB_RELEASE="4.0" elif has Walnut ; then DISTRIB_RELEASE="4.0"
elif has Hypericum ; then DISTRIB_RELEASE="p8"
elif has "starter kit" ; then DISTRIB_RELEASE="p8"
elif has 20070810 ; then DISTRIB_RELEASE="4.0" elif has 20070810 ; then DISTRIB_RELEASE="4.0"
elif has Ajuga ; then DISTRIB_RELEASE="4.0" elif has Ajuga ; then DISTRIB_RELEASE="4.0"
elif has 20050723 ; then DISTRIB_RELEASE="3.0" elif has 20050723 ; then DISTRIB_RELEASE="3.0"
...@@ -354,11 +356,16 @@ esac ...@@ -354,11 +356,16 @@ esac
echo "$DIST_OS" echo "$DIST_OS"
} }
get_uname_m()
{
uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"
}
get_arch() get_arch()
{ {
local DIST_ARCH local DIST_ARCH
# Resolve the architecture # Resolve the architecture
DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"` DIST_ARCH="$(get_uname_m)"
case "$DIST_ARCH" in case "$DIST_ARCH" in
'ia32' | 'i386' | 'i486' | 'i586' | 'i686') 'ia32' | 'i386' | 'i486' | 'i586' | 'i686')
DIST_ARCH="x86" DIST_ARCH="x86"
...@@ -385,7 +392,7 @@ case "$DIST_ARCH" in ...@@ -385,7 +392,7 @@ case "$DIST_ARCH" in
DIST_ARCH="parisc" DIST_ARCH="parisc"
;; ;;
armv*) armv*)
if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then if [ -z "$(readelf -A /proc/self/exe | grep Tag_ABI_VFP_args)" ] ; then
DIST_ARCH="armel" DIST_ARCH="armel"
else else
DIST_ARCH="armhf" DIST_ARCH="armhf"
...@@ -399,7 +406,7 @@ get_bit_size() ...@@ -399,7 +406,7 @@ get_bit_size()
{ {
local DIST_BIT local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now... # 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"` DIST_BIT="$(get_uname_m)"
case "$DIST_BIT" in case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64') 'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64" DIST_BIT="64"
...@@ -423,18 +430,20 @@ echo "$DIST_BIT" ...@@ -423,18 +430,20 @@ echo "$DIST_BIT"
# TODO: check before calc # TODO: check before calc
get_memory_size() { get_memory_size() {
local detected=0 local detected=0
local DIST_OS=$(get_base_os_name) local DIST_OS="$(get_base_os_name)"
if [ $DIST_OS = "macosx" ] case "$DIST_OS" in
then macosx)
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024)) detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
elif [ $DIST_OS = "freebsd" ] ;;
then freebsd)
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024)) detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
elif [ $DIST_OS = "linux" ] ;;
then linux)
[ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024)) [ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
fi ;;
# Exit codes only support values between 0 and 255. So use stdout. esac
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected echo $detected
} }
......
...@@ -236,7 +236,7 @@ check_command() ...@@ -236,7 +236,7 @@ check_command()
update) # HELPCMD: update remote package repository databases update) # HELPCMD: update remote package repository databases
epm_cmd=update epm_cmd=update
;; ;;
addrepo|ar) # HELPCMD: add package repo addrepo|ar) # HELPCMD: add package repo (etersoft, autoimports, archive 2017/12/31); run with param to get list
epm_cmd=addrepo epm_cmd=addrepo
;; ;;
repolist|sl|rl|listrepo|repo) # HELPCMD: print repo list repolist|sl|rl|listrepo|repo) # HELPCMD: print repo list
...@@ -248,7 +248,7 @@ check_command() ...@@ -248,7 +248,7 @@ check_command()
removerepo|rr) # HELPCMD: remove package repo removerepo|rr) # HELPCMD: remove package repo
epm_cmd=removerepo epm_cmd=removerepo
;; ;;
release-upgrade|upgrade-release) # HELPCMD: update whole system to the next release release-upgrade|upgrade-release) # HELPCMD: update whole system to the release in arg (default: next (latest) release)
epm_cmd=release_upgrade epm_cmd=release_upgrade
;; ;;
kernel-update|kernel-upgrade|update-kernel|upgrade-kernel) # HELPCMD: update system kernel to the last repo version kernel-update|kernel-upgrade|update-kernel|upgrade-kernel) # HELPCMD: update system kernel to the last repo version
......
...@@ -57,11 +57,14 @@ __epm_addrepo_altlinux() ...@@ -57,11 +57,14 @@ __epm_addrepo_altlinux()
local arch=$(uname -m) local arch=$(uname -m)
[ "$arch" = "i686" ] && arch="i586" [ "$arch" = "i686" ] && arch="i586"
echo "" | sudocmd tee -a /etc/apt/sources.list 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 local distrversion="$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
local rpmsign='[alt]'
[ "$distrversion" != "sisyphus" ] && rpmsign="[$distrversion]"
echo "rpm $rpmsign http://ftp.altlinux.org/pub/distributions archive/$distrversion/date/$datestr/$arch classic" | sudocmd tee -a /etc/apt/sources.list
if [ "$arch" = "x86_64" ] ; then 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 echo "rpm $rpmsign http://ftp.altlinux.org/pub/distributions archive/$distrversion/date/$datestr/$arch-i586 classic" | sudocmd tee -a /etc/apt/sources.list
fi fi
echo "rpm [alt] http://ftp.altlinux.org/pub/distributions archive/sisyphus/date/$datestr/noarch classic" | sudocmd tee -a /etc/apt/sources.list echo "rpm $rpmsign http://ftp.altlinux.org/pub/distributions archive/$distrversion/date/$datestr/noarch classic" | sudocmd tee -a /etc/apt/sources.list
return 0 return 0
;; ;;
esac esac
...@@ -74,8 +77,10 @@ __epm_addrepo_altlinux() ...@@ -74,8 +77,10 @@ __epm_addrepo_altlinux()
fi fi
if [ -z "$repo" ] ; then if [ -z "$repo" ] ; then
info "Add branch repo. TODO?" info "Add branch repo. Use follow params:"
sudocmd apt-repo add branch sudocmd apt-repo add branch
echo "etersoft (for LINUX@Etersoft repo)"
echo "archive 2018/02/09 (for archive from that date)"
return return
fi fi
...@@ -95,7 +100,15 @@ case $DISTRNAME in ...@@ -95,7 +100,15 @@ case $DISTRNAME in
esac esac
case $PMTYPE in case $PMTYPE in
apt-dpkg|aptitude-dpkg) apt-dpkg)
assure_exists apt-add-repository software-properties-common
if echo "$repo" | grep -q "https://" ; then
assure_exists apt-transport-https
fi
apt-add-repository "$repo"
info "Check file /etc/apt/sources.list if needed"
;;
aptitude-dpkg)
info "You need manually add repo to /etc/apt/sources.list (TODO)" info "You need manually add repo to /etc/apt/sources.list (TODO)"
;; ;;
yum-rpm) yum-rpm)
......
...@@ -56,13 +56,16 @@ case $PMTYPE in ...@@ -56,13 +56,16 @@ case $PMTYPE in
# sudocmd aura -Oj # sudocmd aura -Oj
# ;; # ;;
yum-rpm) yum-rpm)
docmd epm upgrade
assure_exists package-cleanup yum-utils
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 $dryrun $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. docmd epm upgrade
assure_exists package-cleanup dnf-utils
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 $dryrun $PKGLIST docmd epm remove $dryrun $PKGLIST
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2009, 2012, 2013, 2014, 2016 Etersoft # Copyright (C) 2009, 2012, 2013, 2014, 2016, 2018 Etersoft
# Copyright (C) 2009, 2012, 2013, 2014, 2016 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2009, 2012, 2013, 2014, 2016, 2018 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
...@@ -17,15 +17,23 @@ ...@@ -17,15 +17,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# changed since rpm 4.0.4
__rpm_allows_nosignature()
{
a= rpm --help | grep -q -- "--nosignature"
}
check_pkg_integrity() check_pkg_integrity()
{ {
local PKG="$1" local PKG="$1"
local RET local RET
local NOSIGNATURE
case $(get_package_type $PKG) in case $(get_package_type $PKG) in
rpm) rpm)
assure_exists rpm assure_exists rpm
docmd rpm --checksig $PKG __rpm_allows_nosignature && NOSIGNATURE="--nosignature" || NOSIGNATURE="--nogpg"
docmd rpm --checksig $NOSIGNATURE $PKG
;; ;;
deb) deb)
assure_exists dpkg assure_exists dpkg
......
...@@ -318,6 +318,7 @@ epm_install_files() ...@@ -318,6 +318,7 @@ epm_install_files()
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
# TODO: replace with name changed function
__epm_check_if_try_install_deb $@ && return __epm_check_if_try_install_deb $@ && return
# do not using low-level for install by file path (FIXME: reasons?) # do not using low-level for install by file path (FIXME: reasons?)
...@@ -571,6 +572,7 @@ epm_install() ...@@ -571,6 +572,7 @@ epm_install()
if [ -z "$files$names" ] ; then if [ -z "$files$names" ] ; then
# TODO: assert $skip_installed # TODO: assert $skip_installed
[ -n "$verbose" ] && info "Skip empty install list" [ -n "$verbose" ] && info "Skip empty install list"
# FIXME: see to_remove below
return 22 return 22
fi fi
...@@ -579,10 +581,12 @@ epm_install() ...@@ -579,10 +581,12 @@ epm_install()
update_repo_if_needed update_repo_if_needed
fi fi
# FIXME: see to_remove below
epm_install_names $names || return epm_install_names $names || return
# repack binary files # repack binary files
if [ -n "$repack" ] ; then if [ -n "$repack" ] ; then
# FIXME: see to_remove below
__epm_repack_rpm $files || fatal __epm_repack_rpm $files || fatal
files="$repacked_rpms" files="$repacked_rpms"
fi fi
......
...@@ -30,7 +30,7 @@ case $PMTYPE in ...@@ -30,7 +30,7 @@ case $PMTYPE in
;; ;;
apt-dpkg) apt-dpkg)
warmup_dpkgbase 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}:\${Architecture}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
;; ;;
*) *)
fatal "Sorted package list function is not implemented for $PMTYPE" fatal "Sorted package list function is not implemented for $PMTYPE"
...@@ -68,7 +68,8 @@ case $PMTYPE in ...@@ -68,7 +68,8 @@ case $PMTYPE in
warmup_dpkgbase 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}:\${Architecture}\n $pkg_filenames"
# TODO: ${Architecture}
[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}\n $pkg_filenames" [ -n "$short" ] && CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}\n $pkg_filenames"
showcmd $CMD showcmd $CMD
$CMD | grep "^i" | sed -e "s|.* ||g" | __fo_pfn $CMD | grep "^i" | sed -e "s|.* ||g" | __fo_pfn
......
...@@ -54,8 +54,9 @@ exp_with_arch_suffix() ...@@ -54,8 +54,9 @@ exp_with_arch_suffix()
# TODO: use estrlist or some function to do it # TODO: use estrlist or some function to do it
local pkg local pkg
for pkg in $(cat) ; do for pkg in $(cat) ; do
local p
# check only packages without arch # check only packages without arch
local p="$(__print_with_arch_suffix "$pkg" .i686)" || { echo "$pkg" ; continue ; } p="$(__print_with_arch_suffix "$pkg" .i686)" || { echo "$pkg" ; continue ; }
# add arch suffix only if arch package already installed (otherwise we don't know package arch) # add arch suffix only if arch package already installed (otherwise we don't know package arch)
is_installed "$p" || { echo "$pkg" ; continue ; } is_installed "$p" || { echo "$pkg" ; continue ; }
echo "$pkg.x86_64" echo "$pkg.x86_64"
......
...@@ -165,7 +165,8 @@ __update_to_the_distro() ...@@ -165,7 +165,8 @@ __update_to_the_distro()
Sisyphus) Sisyphus)
docmd epm update || fatal docmd epm update || fatal
docmd epm install librpm7 librpm rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run again" docmd epm install librpm7 librpm rpm apt "$(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 apt-get upgrade || fatal "Check an error and run epm release-upgrade or just epm upgrade again"
docmd epm upgrade || fatal "Check an error and run epm release-upgrade or just epm upgrade again"
;; ;;
*) *)
esac esac
...@@ -277,7 +278,7 @@ epm_release_upgrade() ...@@ -277,7 +278,7 @@ epm_release_upgrade()
;; ;;
*-dpkg) *-dpkg)
assure_exists do-release-upgrade update-manager-core assure_exists do-release-upgrade update-manager-core
sudocmd do-release-upgrade -d sudocmd do-release-upgrade
;; ;;
yum-rpm) yum-rpm)
docmd epm install rpm yum docmd epm install rpm yum
...@@ -289,6 +290,7 @@ epm_release_upgrade() ...@@ -289,6 +290,7 @@ epm_release_upgrade()
dnf-rpm) dnf-rpm)
info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info" info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info"
docmd epm install dnf docmd epm install dnf
sudocmd dnf --refresh upgrade
sudocmd dnf clean all sudocmd dnf clean all
assure_exists dnf-plugin-system-upgrade assure_exists dnf-plugin-system-upgrade
sudocmd dnf upgrade --refresh sudocmd dnf upgrade --refresh
......
...@@ -63,7 +63,12 @@ case $DISTRNAME in ...@@ -63,7 +63,12 @@ case $DISTRNAME in
esac; esac;
case $PMTYPE in case $PMTYPE in
apt-dpkg|aptitude-dpkg) apt-dpkg)
assure_exists apt-add-repository software-properties-common
apt-add-repository --remove "$repo"
info "Check file /etc/apt/sources.list if needed"
;;
aptitude-dpkg)
info "You need remove repo from /etc/apt/sources.list" info "You need remove repo from /etc/apt/sources.list"
;; ;;
yum-rpm) yum-rpm)
......
...@@ -20,65 +20,97 @@ ...@@ -20,65 +20,97 @@
load_helper epm-sh-altlinux load_helper epm-sh-altlinux
load_helper epm-assure load_helper epm-assure
# arg: rpm or deb
# TODO: rewrite to convert (get some code from Korinf?) # fills split_replaced_pkgs with packages of that type
__epm_check_if_try_install_deb() __epm_split_by_pkg_type()
{ {
local pkg local type="$1"
local debpkgs="" shift
for pkg in $@ ; do
[ "$(get_package_type "$pkg")" = "deb" ] || return 1 split_replaced_pkgs=''
for pkg in "$@" ; do
[ "$(get_package_type "$pkg")" = "$type" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg" [ -e "$pkg" ] || fatal "Can't read $pkg"
debpkgs="$debpkgs $(realpath $pkg)" split_replaced_pkgs="$split_target_pkgs $(realpath "$pkg")"
done done
[ -n "$debpkgs" ] || return 1
[ -n "$split_replaced_pkgs" ]
}
# fills repacked_rpms
__epm_repack_deb_to_rpm()
{
local pkg
assure_exists alien assure_exists alien
assure_exists dpkg assure_exists dpkg
# TODO: Для установки требует: /usr/share/debconf/confmodule но пакет не может быть установлен # TODO: Для установки требует: /usr/share/debconf/confmodule но пакет не может быть установлен
# assure_exists debconf # assure_exists debconf
repacked_rpms=''
local TDIR=$(mktemp -d) local TDIR=$(mktemp -d)
cd $TDIR || fatal cd $TDIR || fatal
for pkg in $debpkgs ; do for pkg in "$@" ; do
# TODO: fakeroot for non ALT? # TODO: fakeroot for non ALT?
showcmd_store_output alien -r -k $scripts "$pkg" || fatal showcmd_store_output alien -r -k $scripts "$pkg" || fatal
local RPMCONVERTED=$(grep "rpm generated" $RC_STDOUT | sed -e "s| generated||g") local RPMCONVERTED=$(grep "rpm generated" $RC_STDOUT | sed -e "s| generated||g")
repacked_rpms="$repacked_rpms $(realpath $RPMCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $RPMCONVERTED)"
clean_store_output clean_store_output
docmd epm install $force $nodeps $RPMCONVERTED
done done
rm -f $TDIR/*
rmdir $TDIR/
cd - >/dev/null
return 0 return 0
} }
# TODO: rewrite to convert (get some code from Korinf?) __epm_check_if_try_install_deb()
__epm_check_if_try_install_rpm() {
__epm_split_by_pkg_type deb "$@" || return 1
__epm_repack_deb_to_rpm "$@"
# TODO: move to install
docmd epm install $force $nodeps $repacked_rpms
return 0
}
# fills repacked_debs
__epm_repack_rpm_to_deb()
{ {
local pkg local pkg
local rpmpkgs=""
for pkg in $@ ; do
[ "$(get_package_type "$pkg")" = "rpm" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg"
rpmpkgs="$rpmpkgs $(realpath $pkg)"
done
[ -n "$rpmpkgs" ] || return 1
assure_exists alien assure_exists alien
assure_exists fakeroot assure_exists fakeroot
assure_exists rpm assure_exists rpm
repacked_debs=''
local TDIR=$(mktemp -d) local TDIR=$(mktemp -d)
cd $TDIR || fatal cd $TDIR || fatal
for pkg in $rpmpkgs ; do for pkg in $rpmpkgs ; do
showcmd_store_output fakeroot alien -d -k $scripts "$pkg" showcmd_store_output fakeroot alien -d -k $scripts "$pkg"
local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g") local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
repacked_debs="$repacked_rpms $(realpath $DEBCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $DEBCONVERTED)"
clean_store_output clean_store_output
docmd epm install $force $nodeps $DEBCONVERTED
done done
rm -f $TDIR/*
rmdir $TDIR/ cd - >/dev/null
return 0
}
# TODO: rewrite to convert (get some code from Korinf?)
__epm_check_if_try_install_rpm()
{
__epm_split_by_pkg_type rpm "$@" || return 1
__epm_repack_rpm_to_deb "$@"
# TODO: move to install
docmd epm install $force $nodeps $repacked_debs
return 0 return 0
} }
...@@ -110,6 +142,17 @@ __apply_fix_code() ...@@ -110,6 +142,17 @@ __apply_fix_code()
docmd $repackcode "$1" "$2" || warning "There was errors with $repackcode script" docmd $repackcode "$1" "$2" || warning "There was errors with $repackcode script"
} }
__create_rpmmacros()
{
cat <<EOF >$HOME/.rpmmacros
%_topdir $HOME/RPM
%_tmppath $TMPDIR
%packager EPM <support@etersoft.ru>
%_gpg_name support@etersoft.ru
EOF
}
# will fill repacked_rpms var # will fill repacked_rpms var
__epm_repack_rpm() __epm_repack_rpm()
{ {
...@@ -120,8 +163,10 @@ __epm_repack_rpm() ...@@ -120,8 +163,10 @@ __epm_repack_rpm()
assure_exists rpmbuild rpm-build || fatal assure_exists rpmbuild rpm-build || fatal
local pkg local pkg
local tmpbuilddir=$(mktemp -d)/repack export HOME=$(mktemp -d)
local tmpbuilddir=$HOME/repack
mkdir $tmpbuilddir mkdir $tmpbuilddir
__create_rpmmacros
local abspkg local abspkg
repacked_rpms='' repacked_rpms=''
...@@ -144,9 +189,9 @@ __epm_repack_rpm() ...@@ -144,9 +189,9 @@ __epm_repack_rpm()
__apply_fix_code $pkgname $tmpbuilddir/$subdir $spec __apply_fix_code $pkgname $tmpbuilddir/$subdir $spec
showcmd fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec showcmd fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec
if [ -n "$verbose" ] ; then if [ -n "$verbose" ] ; then
a='' fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec || fatal a='' fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec || fatal
else else
a='' fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec >/dev/null || fatal a='' fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec >/dev/null || fatal
fi fi
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)" local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
if [ -s "$repacked_rpm" ] ; then if [ -s "$repacked_rpm" ] ; then
...@@ -175,8 +220,32 @@ epm_repack() ...@@ -175,8 +220,32 @@ epm_repack()
[ -z "$pkg_files" ] && info "Skip empty repack list" && return 22 [ -z "$pkg_files" ] && info "Skip empty repack list" && return 22
__epm_repack_rpm $pkg_files || fatal # TODO: если у нас rpm, а пакет - deb и наоборот
cp -v $repacked_rpms . case $PKGFORMAT in
rpm)
if __epm_split_by_pkg_type deb $pkg_files ; then
__epm_repack_deb_to_rpm $split_replaced_pkgs
cp -v $repacked_rpms .
pkg_files="$(estrlist exclude $split_replaced_pkgs $pkg_files)"
fi
if [ -n "$pkg_files" ] ; then
__epm_repack_rpm $pkg_files || fatal
cp -v $repacked_rpms .
fi
;;
deb)
if __epm_split_by_pkg_type rpm $pkg_files ; then
__epm_repack_rpm_to_deb $split_replaced_pkgs
cp -v $repacked_debs .
pkg_files="$(estrlist exclude $split_replaced_pkgs $pkg_files)"
fi
;;
*)
fatal "$PKGFORMAT is not supported for repack yet"
;;
esac
# TODO: move it to exit handler # TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then if [ -z "$DEBUG" ] ; then
......
...@@ -39,7 +39,7 @@ case $PMTYPE in ...@@ -39,7 +39,7 @@ case $PMTYPE in
docmd ds-conf docmd ds-conf
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
showcmd cat /etc/apt/sources.list* showcmd cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list
print_apt_sources_list /etc/apt/sources.list /etc/apt/sources.list.d/*.list print_apt_sources_list /etc/apt/sources.list /etc/apt/sources.list.d/*.list
;; ;;
yum-rpm) yum-rpm)
......
...@@ -382,6 +382,20 @@ eget() ...@@ -382,6 +382,20 @@ eget()
$EGET "$@" $EGET "$@"
} }
estrlist()
{
if [ -s $SHAREDIR/tools_estrlist ] ; then
$SHAREDIR/tools_estrlist "$@"
return
fi
fatal "missed tools_estrlist"
}
onefile_estrlist()
{
internal_tools_estrlist "$@"
}
# will replaced within eget() in packed version # will replaced within eget() in packed version
onefile_eget() onefile_eget()
{ {
......
...@@ -64,6 +64,16 @@ if [ -z "$1" ] ; then ...@@ -64,6 +64,16 @@ if [ -z "$1" ] ; then
fatal "Run with URL, like http://somesite.ru/dir/*.log" fatal "Run with URL, like http://somesite.ru/dir/*.log"
fi fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "eget - wget wrapper, with support"
echo "Usage: eget [-O target file] [--list] http://somesite.ru/dir/na*.log"
echo "Options:"
echo " --list - print files frm url with mask"
echo
wget --help
exit
fi
# do not support / # do not support /
if echo "$1" | grep -q "/$" ; then if echo "$1" | grep -q "/$" ; then
fatal "Use http://example.com/e/* to download all files in dir" fatal "Use http://example.com/e/* to download all files in dir"
......
#!/bin/bash
# 2009-2010, 2012, 2017 Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# TODO: rewrite with shell commands, perl or C
# Python - http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch16s03.html
# Shell - http://linux.byexamples.com/archives/127/uniq-and-basic-set-theory/
# - http://maiaco.com/articles/shellSetOperations.php
# Perl - http://docstore.mik.ua/orelly/perl/cookbook/ch04_09.htm
# - http://blogs.perl.org/users/polettix/2012/03/sets-operations.html
# http://rosettacode.org/wiki/Symmetric_difference
# TODO: add unit tests
# http://ru.wikipedia.org/wiki/Операции_над_множествами
# Base set operations:
# * union
# "1 2 3" "3 4 5" -> "1 2 3 4 5"
# * intersection
# "1 2 3" "3 4 5" -> "3"
# * relative complement (substracted, difference) ( A ? B – members in A but not in B )
# http://en.wikipedia.org/wiki/Complement_%28set_theory%29
# "1 3" "1 2 3 4" -> "2 4"
# * symmetric difference (симметричная разность) ( A ^ B – members in A or B but not both )
# http://en.wikipedia.org/wiki/Symmetric_difference
# "1 2 3" "3 4 5" -> "1 2 4 5"
filter_strip_spaces()
{
# possible use just
#xargs echo
sed -e "s| \+| |g" -e "s|^ ||" -e "s| \$||"
}
strip_spaces()
{
echo "$*" | filter_strip_spaces
}
isempty()
{
[ "$(strip_spaces "$*")" = "" ]
}
list()
{
local i
for i in $@ ; do
echo "$i"
done
}
count()
{
list $@ | wc -l
}
union()
{
strip_spaces $(list $@ | sort -u)
}
uniq()
{
union $@
}
has()
{
local wd="$1"
shift
echo "$*" | grep -q -- "$wd"
}
# Note: used egrep! write '[0-9]+(first|two)', not '[0-9]\+...'
match()
{
local wd="$1"
shift
echo "$*" | egrep -q -- "$wd"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_remove()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q "$1" || RES="$RES $i"
done
strip_spaces "$RES"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_wordremove()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q -w "$1" || RES="$RES $i"
done
strip_spaces "$RES"
}
# Args: LIST1 LIST2
# do_exclude_list print LIST2 list exclude fields contains also in LIST1
# Example: exclude "1 3" "1 2 3 4" -> "2 4"
exclude()
{
local i
local RES=
for i in $2 ; do
echo "$1" | grep -q -w "$i" || RES="$RES $i"
done
strip_spaces "$RES"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_exclude()
{
local i
local RES="$2"
for i in $1 ; do
RES=$(reg_remove "$i" "$RES")
done
strip_spaces "$RES"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_wordexclude()
{
local i
local RES="$2"
for i in $1 ; do
RES=$(reg_wordremove "$i" "$RES")
done
strip_spaces "$RES"
}
# FIXME:
# reg_include "1." "11 12 21 22" -> "11 12"
reg_include()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q -w "$1" && RES="$RES $i"
done
strip_spaces "$RES"
}
example()
{
local CMD="$1"
local ARG1="$2"
shift 2
echo "\$ $0 $CMD \"$ARG1\" \"$@\""
$0 $CMD "$ARG1" "$@"
}
example_res()
{
example "$@" && echo TRUE || echo FALSE
}
help()
{
echo "estrlist developed for string list operations. See also cut, join, paste..."
echo "Usage: $0 <command> [args]"
echo "Commands:"
echo " strip_spaces [args] - remove spaces between words"
echo " filter_strip_spaces - remove spaces from words from standart input"
echo " reg_remove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep notation)"
echo " reg_wordremove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep -w notation)"
echo " exclude <list1> <list2> - print list2 words exclude list1 items"
echo " reg_exclude <PATTERN> [word list] - print only words do not matched with PATTERN"
echo " reg_wordexclude <PATTERN> [word list] - print only words do not matched with PATTERN"
echo " has <PATTERN> string - check the string for a match to the regular expression given in PATTERN (grep notation)"
echo " match <PATTERN> string - check the string for a match to the regular expression given in PATTERN (egrep notation)"
echo " isempty [string] - true if string has no any symbols (only zero or more spaces)"
echo " union [word list] - sort and remove duplicates"
echo " uniq [word list] - alias for union"
echo " list [word list] - just list words line by line"
echo " count [word list] - print word count"
echo
echo "Examples:"
example reg_remove "1." "11 12 21 22"
example reg_wordremove "1." "11 12 21 22"
example exclude "1 3" "1 2 3 4"
example reg_exclude "22 1." "11 12 21 22"
example reg_wordexclude "wo.* er" "work were more else"
example union "1 2 2 3 3"
example count "1 2 3 4 10"
example_res isempty " "
#example_res isempty " 1 "
example_res has ex "exactly"
example_res has exo "exactly"
example_res match "M[0-9]+" "M250"
example_res match "M[0-9]+" "MI"
}
COMMAND="$1"
if [ -z "$COMMAND" ] ; then
echo "Run with --help for get command description."
exit 1
fi
if [ "$COMMAND" = "-h" ] || [ "$COMMAND" = "--help" ] ; then
COMMAND="help"
fi
shift
# FIXME: do to call function directly, use case instead?
if [ "$1" = "-" ] ; then
shift
"$COMMAND" "$(cat) $@"
elif [ "$2" = "-" ] ; then
"$COMMAND" "$1" "$(cat)"
else
"$COMMAND" "$@"
fi
# This spec is backported to ALTLinux p8 automatically by rpmbph script from etersoft-build-utils. # This spec is backported to ALTLinux p8 automatically by rpmbph script from etersoft-build-utils.
# #
Name: eepm Name: eepm
Version: 2.4.5 Version: 2.4.9
Release: alt0.M80P.1 Release: alt0.M80P.1
Summary: Etersoft EPM package manager Summary: Etersoft EPM package manager
...@@ -90,9 +90,28 @@ rm -f %buildroot%_datadir/%name/tools_eget ...@@ -90,9 +90,28 @@ rm -f %buildroot%_datadir/%name/tools_eget
%_sysconfdir/bash_completion.d/cerv %_sysconfdir/bash_completion.d/cerv
%changelog %changelog
* Sun Feb 04 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.5-alt0.M80P.1 * Mon Jun 18 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.9-alt0.M80P.1
- backport to ALTLinux p8 (by rpmbph script) - backport to ALTLinux p8 (by rpmbph script)
* Mon Jun 18 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.9-alt1
- repack: run independently to user's .rpmmacros
* Thu Jun 07 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.8-alt1
- autoorphans: assure for package-cleanup for yum/dnf
- apt-dpkg: implement addrepo/removerepo
- addrepo: add ALT branch support
- distr_info: support ALT starter kits
- epm-packages: add arch on deb
* Mon Mar 19 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.7-alt1
- checkpkg: detect rpm --nosignature/--nogpg
- epm-query: fix check only names without arch
* Mon Feb 26 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.6-alt1
- distr_info: cleanup code, fix quotes
- checkpkg: check only md5 (skip gpg)
- implement repack for rpm to deb and deb to rpm conversion
* Sun Feb 04 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.5-alt1 * Sun Feb 04 2018 Vitaly Lipatov <lav@altlinux.ru> 2.4.5-alt1
- implement assure_distr and use it - implement assure_distr and use it
- add repack command and move all repack code to a separate module - add repack command and move all repack code to a separate module
......
...@@ -48,6 +48,8 @@ filter_out() ...@@ -48,6 +48,8 @@ filter_out()
grep -v "^[ ]*load_helper " | \ grep -v "^[ ]*load_helper " | \
sed -e 's|^eget()|disabled_eget()|g' | \ sed -e 's|^eget()|disabled_eget()|g' | \
sed -e 's|^onefile_eget()|eget()|g' | \ sed -e 's|^onefile_eget()|eget()|g' | \
sed -e 's|^estrlist()|disabled_estrlist()|g' | \
sed -e 's|^onefile_estrlist()|estrlist()|g' | \
sed -e 's|$SHAREDIR/tools_json|internal_tools_json|g' | \ sed -e 's|$SHAREDIR/tools_json|internal_tools_json|g' | \
sed -e 's|DISTRVENDOR=$PROGDIR/distr_info|DISTRVENDOR=internal_distr_info|g' | \ sed -e 's|DISTRVENDOR=$PROGDIR/distr_info|DISTRVENDOR=internal_distr_info|g' | \
sed -e "s|@VERSION@|$(get_version)|g" sed -e "s|@VERSION@|$(get_version)|g"
...@@ -70,6 +72,7 @@ done | filter_out >>$OUTPUT ...@@ -70,6 +72,7 @@ done | filter_out >>$OUTPUT
incorporate_subfile bin/distr_info incorporate_subfile bin/distr_info
#incorporate_subfile /usr/bin/eget #incorporate_subfile /usr/bin/eget
incorporate_subfile bin/tools_eget incorporate_subfile bin/tools_eget
incorporate_subfile bin/tools_estrlist
incorporate_subfile bin/tools_json incorporate_subfile bin/tools_json
awk 'BEGIN{desk=0}{if(desk>0) {print} ; if(/^load_helper epm-sh-functions/){desk++}}' <bin/$PACKCOMMAND | filter_out >>$OUTPUT awk 'BEGIN{desk=0}{if(desk>0) {print} ; if(/^load_helper epm-sh-functions/){desk++}}' <bin/$PACKCOMMAND | filter_out >>$OUTPUT
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2016 Etersoft # Copyright (C) 2012-2018 Etersoft
# Copyright (C) 2012-2016 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2018 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
...@@ -378,6 +378,20 @@ disabled_eget() ...@@ -378,6 +378,20 @@ disabled_eget()
$EGET "$@" $EGET "$@"
} }
disabled_estrlist()
{
if [ -s $SHAREDIR/tools_estrlist ] ; then
$SHAREDIR/tools_estrlist "$@"
return
fi
fatal "missed tools_estrlist"
}
estrlist()
{
internal_tools_estrlist "$@"
}
eget() eget()
{ {
assure_exists wget assure_exists wget
...@@ -539,6 +553,13 @@ is_active_systemd() ...@@ -539,6 +553,13 @@ is_active_systemd()
ps ax | grep '[s]ystemd' | grep -q -v 'systemd-udev' ps ax | grep '[s]ystemd' | grep -q -v 'systemd-udev'
} }
assure_distr()
{
local TEXT="this option"
[ -n "$2" ] && TEXT="$2"
[ "$DISTRNAME" = "$1" ] || fatal "$TEXT supported only for $1 distro"
}
# File bin/epm-addrepo: # File bin/epm-addrepo:
...@@ -1265,7 +1286,7 @@ check_pkg_integrity() ...@@ -1265,7 +1286,7 @@ check_pkg_integrity()
case $(get_package_type $PKG) in case $(get_package_type $PKG) in
rpm) rpm)
assure_exists rpm assure_exists rpm
docmd rpm --checksig $PKG docmd rpm --checksig --nogpg $PKG
;; ;;
deb) deb)
assure_exists dpkg assure_exists dpkg
...@@ -1820,7 +1841,7 @@ __epm_print_url_alt_check() ...@@ -1820,7 +1841,7 @@ __epm_print_url_alt_check()
echo echo
echo "Latest release: $(paoapi packages/$pkg | get_pao_var sourcepackage) $buildtime" echo "Latest release: $(paoapi packages/$pkg | get_pao_var sourcepackage) $buildtime"
__epm_print_url_alt "$1" | while read url ; do __epm_print_url_alt "$1" | while read url ; do
curl -s --head $url >$tm || { echo "$url: missed" ; continue ; } a='' curl -s --head $url >$tm || { echo "$url: missed" ; continue ; }
local http=$(cat $tm | grep "^HTTP" | sed -e "s|\r||g") local http=$(cat $tm | grep "^HTTP" | sed -e "s|\r||g")
local lastdate=$(cat $tm | grep "^Last-Modified:" | 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") local size=$(cat $tm | grep "^Content-Length:" | sed -e "s|^Content-Length: ||g" | sed -e "s|\r||g")
...@@ -1889,15 +1910,50 @@ epm_download() ...@@ -1889,15 +1910,50 @@ epm_download()
epm_epm_install(){ __epm_korinf_site() {
assure_exists wget local archprefix=""
local etersoft_updates_site="http://updates.etersoft.ru/pub/Korinf/$($DISTRVENDOR -e)" [ "$($DISTRVENDOR -a)" = "x86_64" ] && archprefix="x86_64/"
# FIXME: some way to get latest package local aftername="-"
local download_link=$etersoft_updates_site/$(wget -qO- $etersoft_updates_site/ | grep -m1 -Eo "eepm[^\"]+\.$($DISTRVENDOR -p)" | tail -n1) #" [ "$($DISTRVENDOR -p)" = "deb" ] && aftername="_"
echo "http://updates.etersoft.ru/pub/Korinf/$archprefix$($DISTRVENDOR -e)"
}
__epm_korinf_list() {
[ "$1" = "--list" ] && shift
local MASK="$1"
showcmd eget --list "$(__epm_korinf_site)/$MASK*.$($DISTRVENDOR -p)"
eget --list "$(__epm_korinf_site)/$MASK*.$($DISTRVENDOR -p)" | sort
}
__epm_korinf_install(){
local PACKAGE="$1"
# FIXME: some way to get latest package
local fn="$(__epm_korinf_list $PACKAGE$aftername | tail -n1)"
[ -n "$fn" ] || fatal "Can't find package file for $PACKAGE"
local download_link=$(__epm_korinf_site)/$fn
#info "Install $download_link ..."
pkg_names='' pkg_files='' pkg_urls="$download_link" epm_install pkg_names='' pkg_files='' pkg_urls="$download_link" epm_install
} }
epm_epm_install(){
local i
local pkglist="$pkg_filenames"
# install epm by default
[ -n "$pkglist" ] || pkglist="eepm"
case "$pkglist" in
--list*)
__epm_korinf_list $pkglist
return
;;
esac
for i in $pkglist ; do
__epm_korinf_install $i
done
}
# File bin/epm-filelist: # File bin/epm-filelist:
...@@ -2188,14 +2244,31 @@ return $RETVAL ...@@ -2188,14 +2244,31 @@ return $RETVAL
# File bin/epm-install: # File bin/epm-install:
__fast_hack_for_filter_out_installed_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'
}
filter_out_installed_packages() filter_out_installed_packages()
{ {
[ -z "$skip_installed" ] && cat && return [ -z "$skip_installed" ] && cat && return
case $PKGFORMAT in case $PMTYPE in
"rpm") yum-rpm|dnf-rpm)
LANG=C LC_ALL=C xargs -n1 rpm -q 2>&1 | grep 'is not installed' | if [ "$($DISTRVENDOR -a)" = "x86_64" ] ; then
sed -e 's|^.*package \(.*\) is not installed.*|\1|g' # shellcheck disable=SC2013
for i in $(cat) ; do
is_installed "$(__print_with_arch_suffix $i .x86_64)" && continue
is_installed "$(__print_with_arch_suffix $i .noarch)" && continue
echo $i
done
else
__fast_hack_for_filter_out_installed_rpm
fi
;;
*-rpm)
__fast_hack_for_filter_out_installed_rpm
;; ;;
# dpkg -l lists some non ii status (un, etc) # dpkg -l lists some non ii status (un, etc)
#"deb") #"deb")
...@@ -2287,10 +2360,10 @@ epm_install_names() ...@@ -2287,10 +2360,10 @@ epm_install_names()
sudocmd aura -A $force $nodeps $@ sudocmd aura -A $force $nodeps $@
return ;; return ;;
yum-rpm) yum-rpm)
sudocmd yum $YUMOPTIONS install $@ sudocmd yum $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
return ;; return ;;
dnf-rpm) dnf-rpm)
sudocmd dnf install $@ sudocmd dnf install $(echo "$*" | exp_with_arch_suffix)
return ;; return ;;
snappy) snappy)
sudocmd snappy install $@ sudocmd snappy install $@
...@@ -2359,10 +2432,10 @@ epm_ni_install_names() ...@@ -2359,10 +2432,10 @@ epm_ni_install_names()
sudocmd aptitude -y install $@ sudocmd aptitude -y install $@
return ;; return ;;
yum-rpm) yum-rpm)
sudocmd yum -y $YUMOPTIONS install $@ sudocmd yum -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
return ;; return ;;
dnf-rpm) dnf-rpm)
sudocmd dnf -y $YUMOPTIONS install $@ sudocmd dnf -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
return ;; return ;;
urpm-rpm) urpm-rpm)
sudocmd urpmi --auto $URPMOPTIONS $@ sudocmd urpmi --auto $URPMOPTIONS $@
...@@ -2431,62 +2504,6 @@ __epm_check_if_rpm_already_installed() ...@@ -2431,62 +2504,6 @@ __epm_check_if_rpm_already_installed()
LANG=C $SUDO rpm -Uvh $force $nodeps $@ 2>&1 | grep -q "is already installed" LANG=C $SUDO rpm -Uvh $force $nodeps $@ 2>&1 | grep -q "is already installed"
} }
__epm_check_if_try_install_deb()
{
local pkg
local debpkgs=""
for pkg in $@ ; do
[ "$(get_package_type "$pkg")" = "deb" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg"
debpkgs="$debpkgs $(realpath $pkg)"
done
[ -n "$debpkgs" ] || return 1
assure_exists alien
local TDIR=$(mktemp -d)
cd $TDIR || fatal
for pkg in $debpkgs ; do
# TODO: fakeroot for non ALT?
showcmd_store_output alien -r -k --scripts "$pkg" || fatal
local RPMCONVERTED=$(grep "rpm generated" $RC_STDOUT | sed -e "s| generated||g")
clean_store_output
epm install $RPMCONVERTED
done
rm -f $TDIR/*
rmdir $TDIR/
return 0
}
__epm_check_if_try_install_rpm()
{
local pkg
local rpmpkgs=""
for pkg in $@ ; do
[ "$(get_package_type "$pkg")" = "rpm" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg"
rpmpkgs="$rpmpkgs $(realpath $pkg)"
done
[ -n "$rpmpkgs" ] || return 1
assure_exists alien
assure_exists fakeroot
local TDIR=$(mktemp -d)
cd $TDIR || fatal
for pkg in $rpmpkgs ; do
showcmd_store_output fakeroot alien -d -k --scripts "$pkg"
local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
clean_store_output
epm install $DEBCONVERTED
done
rm -f $TDIR/*
rmdir $TDIR/
return 0
}
__handle_direct_install() __handle_direct_install()
{ {
case "$DISTRNAME" in case "$DISTRNAME" in
...@@ -2514,9 +2531,10 @@ epm_install_files() ...@@ -2514,9 +2531,10 @@ epm_install_files()
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
# TODO: replace with name changed function
__epm_check_if_try_install_deb $@ && return __epm_check_if_try_install_deb $@ && return
# do not use low-level for install by file path # do not using low-level for install by file path (FIXME: reasons?)
if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then
sudocmd rpm -Uvh $force $nodeps $@ && return sudocmd rpm -Uvh $force $nodeps $@ && return
local RES=$? local RES=$?
...@@ -2731,6 +2749,7 @@ epm_print_install_names_command() ...@@ -2731,6 +2749,7 @@ epm_print_install_names_command()
epm_install() epm_install()
{ {
if tasknumber "$pkg_names" >/dev/null ; then if tasknumber "$pkg_names" >/dev/null ; then
assure_distr ALTLinux "install with task number"
assure_exists apt-repo assure_exists apt-repo
sudocmd apt-repo test $(tasknumber "$pkg_names") sudocmd apt-repo test $(tasknumber "$pkg_names")
return return
...@@ -2742,11 +2761,11 @@ epm_install() ...@@ -2742,11 +2761,11 @@ epm_install()
return return
fi fi
if [ -n "$direct" ] ; then if [ -n "$direct" ] && [ -z "$repack" ] ; then
__handle_direct_install __handle_direct_install
fi fi
# if possible, it will put pkg_urls into pkg_files or pkg_names # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
if [ -n "$pkg_urls" ] ; then if [ -n "$pkg_urls" ] ; then
__handle_pkg_urls_to_install __handle_pkg_urls_to_install
fi fi
...@@ -2757,12 +2776,14 @@ epm_install() ...@@ -2757,12 +2776,14 @@ epm_install()
warmup_lowbase warmup_lowbase
local names="$(echo $pkg_names | filter_out_installed_packages)" local names="$(echo $pkg_names | filter_out_installed_packages)"
#local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
local files="$(echo $pkg_files | filter_out_installed_packages)" local files="$(echo $pkg_files | filter_out_installed_packages)"
# can be empty only after skip installed # can be empty only after skip installed
if [ -z "$files$names" ] ; then if [ -z "$files$names" ] ; then
# TODO: assert $skip_installed # TODO: assert $skip_installed
[ -n "$verbose" ] && info "Skip empty install list" [ -n "$verbose" ] && info "Skip empty install list"
# FIXME: see to_remove below
return 22 return 22
fi fi
...@@ -2771,13 +2792,25 @@ epm_install() ...@@ -2771,13 +2792,25 @@ epm_install()
update_repo_if_needed update_repo_if_needed
fi fi
# FIXME: see to_remove below
epm_install_names $names || return epm_install_names $names || return
# repack binary files
if [ -n "$repack" ] ; then
# FIXME: see to_remove below
__epm_repack_rpm $files || fatal
files="$repacked_rpms"
fi
epm_install_files $files epm_install_files $files
local RETVAL=$? local RETVAL=$?
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# 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 [ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
fi
return $RETVAL return $RETVAL
} }
...@@ -3453,6 +3486,46 @@ epm_provides() ...@@ -3453,6 +3486,46 @@ epm_provides()
# File bin/epm-query: # File bin/epm-query:
__print_with_arch_suffix()
{
local pkg="$1"
local suffix="$2"
# do not change if some suffix already exists
echo "$pkg" | grep -q "(x86-32)$" && echo "$pkg" | sed -e "s|(x86-32)$|.i686|" && return 1
echo "$pkg" | grep "\.x86_64$" && return 1
echo "$pkg" | grep "\.noarch$" && return 1
echo "$pkg" | grep "\.i[56]86$" && return 1
echo "$pkg$suffix"
}
exp_with_arch_suffix()
{
local suffix
[ "$($DISTRVENDOR -a)" = "x86_64" ] || { cat ; return ; }
# TODO: it is ok for ALT rpm to remove with this suffix
# TODO: separate install and remove?
case $PMTYPE in
yum-rpm|dnf-rpm)
suffix=".x86_64"
;;
*)
cat
return
;;
esac
# TODO: use estrlist or some function to do it
local pkg
for pkg in $(cat) ; do
# check only packages without arch
local p="$(__print_with_arch_suffix "$pkg" .i686)" || { echo "$pkg" ; continue ; }
# add arch suffix only if arch package already installed (otherwise we don't know package arch)
is_installed "$p" || { echo "$pkg" ; continue ; }
echo "$pkg.x86_64"
done
}
_get_grep_exp() _get_grep_exp()
{ {
...@@ -3484,6 +3557,7 @@ _shortquery_via_packages_list() ...@@ -3484,6 +3557,7 @@ _shortquery_via_packages_list()
short=1 pkg_filenames=$pkg epm_packages 2>/dev/null | grep -- "$grepexp" || res=1 short=1 pkg_filenames=$pkg epm_packages 2>/dev/null | grep -- "$grepexp" || res=1
done done
# TODO: print in query (for user): 'warning: package $pkg is not installed'
return $res return $res
} }
...@@ -3875,10 +3949,11 @@ epm_query_file() ...@@ -3875,10 +3949,11 @@ epm_query_file()
[ -n "$pkg_filenames" ] || fatal "Run query without file names" [ -n "$pkg_filenames" ] || fatal "Run query without file names"
#load_helper epm-search_file
for pkg in $pkg_filenames ; do for pkg in $pkg_filenames ; do
__do_query_real_file "$pkg" __do_query_real_file "$pkg"
__do_query "$FULLFILEPATH" || pkg_filenames="$FULLFILEPATH" epm_search_file __do_query "$FULLFILEPATH" || info "Try epm sf for search file in all packages in repository" #|| pkg_filenames="$FULLFILEPATH" epm_search_file
done done
} }
...@@ -3976,6 +4051,15 @@ epm_reinstall() ...@@ -3976,6 +4051,15 @@ epm_reinstall()
# File bin/epm-release_upgrade: # File bin/epm-release_upgrade:
confirm_info()
{
info "$*"
if [ -z "$non_interactive" ] ; then
confirm "Are you sure? [y/N]" || fatal "Exiting"
fi
}
__replace_text_in_alt_repo() __replace_text_in_alt_repo()
{ {
local i local i
...@@ -4023,7 +4107,6 @@ __replace_alt_version_in_repo() ...@@ -4023,7 +4107,6 @@ __replace_alt_version_in_repo()
docmd apt-repo list | sed -e "s|\($1\)|{\1}->{$2}|g" | grep -E --color -- "$1" docmd apt-repo list | sed -e "s|\($1\)|{\1}->{$2}|g" | grep -E --color -- "$1"
# ask and replace only we will have changes # ask and replace only we will have changes
if a='' apt-repo list | grep -E -q -- "$1" ; then if a='' apt-repo list | grep -E -q -- "$1" ; then
confirm "Are these correct changes? [y/N]" || fatal "Exiting"
__replace_text_in_alt_repo "/^ *#/! s!$1!$2!g" __replace_text_in_alt_repo "/^ *#/! s!$1!$2!g"
fi fi
docmd apt-repo list docmd apt-repo list
...@@ -4053,8 +4136,6 @@ get_fix_release_pkg() ...@@ -4053,8 +4136,6 @@ get_fix_release_pkg()
local TO="$1" local TO="$1"
echo "rpm apt"
if [ "$TO" = "Sisyphus" ] ; then if [ "$TO" = "Sisyphus" ] ; then
TO="sisyphus" TO="sisyphus"
echo "apt-conf-$TO" echo "apt-conf-$TO"
...@@ -4094,7 +4175,7 @@ __update_to_the_distro() ...@@ -4094,7 +4175,7 @@ __update_to_the_distro()
case "$TO" in case "$TO" in
p7) p7)
docmd epm update || fatal docmd epm update || fatal
docmd epm install "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again" docmd epm install rpm apt "$(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
...@@ -4102,7 +4183,7 @@ __update_to_the_distro() ...@@ -4102,7 +4183,7 @@ __update_to_the_distro()
;; ;;
p8) p8)
docmd epm update || fatal docmd epm update || fatal
docmd epm install "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again" docmd epm install rpm apt "$(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
...@@ -4114,7 +4195,7 @@ __update_to_the_distro() ...@@ -4114,7 +4195,7 @@ __update_to_the_distro()
;; ;;
Sisyphus) Sisyphus)
docmd epm update || fatal docmd epm update || fatal
docmd epm install librpm7 librpm "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run again" docmd epm install librpm7 librpm rpm apt "$(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"
;; ;;
*) *)
...@@ -4131,8 +4212,8 @@ __update_alt_to_next_distro() ...@@ -4131,8 +4212,8 @@ __update_alt_to_next_distro()
case "$*" in case "$*" in
"p6"|"p6 p7"|"t6 p7"|"c6 c7") "p6"|"p6 p7"|"t6 p7"|"c6 c7")
TO="p7" TO="p7"
info "Upgrade $DISTRNAME from $FROM to $TO ..." confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal docmd epm install rpm apt "$(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
...@@ -4141,8 +4222,8 @@ __update_alt_to_next_distro() ...@@ -4141,8 +4222,8 @@ __update_alt_to_next_distro()
;; ;;
"p7"|"p7 p8"|"t7 p8"|"c7 c8"|"p8 p8") "p7"|"p7 p8"|"t7 p8"|"c7 c8"|"p8 p8")
TO="p8" TO="p8"
info "Upgrade $DISTRNAME from $FROM to $TO ..." confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal docmd epm install rpm apt "$(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
...@@ -4150,9 +4231,9 @@ __update_alt_to_next_distro() ...@@ -4150,9 +4231,9 @@ __update_alt_to_next_distro()
;; ;;
"Sisyphus p8") "Sisyphus p8")
TO="p8" TO="p8"
info "Downgrade $DISTRNAME from $FROM to $TO ..." confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo "$FROM/" "$FROM/branch/" __replace_alt_version_in_repo "$FROM/" "$TO/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
...@@ -4160,8 +4241,8 @@ __update_alt_to_next_distro() ...@@ -4160,8 +4241,8 @@ __update_alt_to_next_distro()
;; ;;
"p8 Sisyphus"|"Sisyphus Sisyphus") "p8 Sisyphus"|"Sisyphus Sisyphus")
TO="Sisyphus" TO="Sisyphus"
info "Upgrade $DISTRNAME from $FROM to $TO ..." confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal docmd epm install rpm apt "$(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
...@@ -4193,7 +4274,7 @@ epm_release_upgrade() ...@@ -4193,7 +4274,7 @@ epm_release_upgrade()
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
docmd epm update docmd epm update || fatal
# 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
...@@ -4241,12 +4322,15 @@ epm_release_upgrade() ...@@ -4241,12 +4322,15 @@ epm_release_upgrade()
docmd epm install dnf docmd epm install dnf
sudocmd dnf clean all sudocmd dnf clean all
assure_exists dnf-plugin-system-upgrade assure_exists dnf-plugin-system-upgrade
sudocmd dnf system-upgrade sudocmd dnf upgrade --refresh
local RELEASEVER="$pkg_filenames" local RELEASEVER="$pkg_filenames"
[ -n "$RELEASEVER" ] || RELEASEVER=$(($DISTRVERSION + 1)) [ -n "$RELEASEVER" ] || RELEASEVER=$(($DISTRVERSION + 1))
#[ -n "$RELEASEVER" ] || fatal "Run me with new version" #[ -n "$RELEASEVER" ] || fatal "Run me with new version"
info "Upgrate to $DISTRNAME/$RELEASEVER" confirm_info "Upgrade to $DISTRNAME/$RELEASEVER"
sudocmd dnf system-upgrade download --refresh --releasever=$RELEASEVER sudocmd dnf system-upgrade download --refresh --releasever=$RELEASEVER
# TODO: from docs:
# dnf system-upgrade reboot
# FIXME: download all packages again
sudocmd dnf distro-sync --releasever=$RELEASEVER sudocmd dnf distro-sync --releasever=$RELEASEVER
info "Run epm autoorphans to remove orphaned packages" info "Run epm autoorphans to remove orphaned packages"
;; ;;
...@@ -4438,6 +4522,9 @@ epm_remove_nonint() ...@@ -4438,6 +4522,9 @@ epm_remove_nonint()
yum-rpm) yum-rpm)
sudocmd yum -y remove $@ sudocmd yum -y remove $@
return ;; return ;;
dnf-rpm)
sudocmd dnf remove --assumeyes $@
return ;;
zypper-rpm) zypper-rpm)
sudocmd zypper --non-interactive remove --clean-deps $@ sudocmd zypper --non-interactive remove --clean-deps $@
return ;; return ;;
...@@ -4506,16 +4593,21 @@ epm_remove() ...@@ -4506,16 +4593,21 @@ epm_remove()
local tn=$(tasknumber "$pkg_names") local tn=$(tasknumber "$pkg_names")
if [ -n "$tn" ] ; then if [ -n "$tn" ] ; then
assure_distr ALTLinux "remove with task number"
assure_exists apt-repo assure_exists apt-repo
pkg_names=$(showcmd apt-repo list $tn) pkg_names=$(showcmd apt-repo list $tn)
#docmd epm remove $dryrun #docmd epm remove $dryrun
return return
fi fi
# TODO: fix pkg_names override
# 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)"
pkg_files=''
[ -n "$pkg_names" ] || fatal "Remove: missing package(s) name." [ -n "$pkg_names" ] || fatal "Remove: missing package(s) name."
# remove according current arch (if x86_64) by default
pkg_names="$(echo $pkg_names | exp_with_arch_suffix)"
if [ -n "$dryrun" ] ; then if [ -n "$dryrun" ] ; then
info "Packages for removing:" info "Packages for removing:"
...@@ -4683,6 +4775,224 @@ esac ...@@ -4683,6 +4775,224 @@ esac
} }
# File bin/epm-repack:
__epm_split_by_pkg_type()
{
local type="$1"
shift
split_replaced_pkgs=''
for pkg in "$@" ; do
[ "$(get_package_type "$pkg")" = "$type" ] || return 1
[ -e "$pkg" ] || fatal "Can't read $pkg"
split_replaced_pkgs="$split_target_pkgs $(realpath "$pkg")"
done
[ -n "$split_replaced_pkgs" ]
}
__epm_repack_deb_to_rpm()
{
local pkg
assure_exists alien
assure_exists dpkg
# TODO: Для установки требует: /usr/share/debconf/confmodule но пакет не может быть установлен
# assure_exists debconf
repacked_rpms=''
local TDIR=$(mktemp -d)
cd $TDIR || fatal
for pkg in "$@" ; do
# TODO: fakeroot for non ALT?
showcmd_store_output alien -r -k $scripts "$pkg" || fatal
local RPMCONVERTED=$(grep "rpm generated" $RC_STDOUT | sed -e "s| generated||g")
repacked_rpms="$repacked_rpms $(realpath $RPMCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $RPMCONVERTED)"
clean_store_output
done
cd - >/dev/null
return 0
}
__epm_check_if_try_install_deb()
{
__epm_split_by_pkg_type deb "$@" || return 1
__epm_repack_deb_to_rpm "$@"
# TODO: move to install
docmd epm install $force $nodeps $repacked_rpms
return 0
}
__epm_repack_rpm_to_deb()
{
local pkg
assure_exists alien
assure_exists fakeroot
assure_exists rpm
repacked_debs=''
local TDIR=$(mktemp -d)
cd $TDIR || fatal
for pkg in $rpmpkgs ; do
showcmd_store_output fakeroot alien -d -k $scripts "$pkg"
local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
repacked_debs="$repacked_rpms $(realpath $DEBCONVERTED)"
to_remove_pkg_files="$to_remove_pkg_files $(realpath $DEBCONVERTED)"
clean_store_output
done
cd - >/dev/null
return 0
}
__epm_check_if_try_install_rpm()
{
__epm_split_by_pkg_type rpm "$@" || return 1
__epm_repack_rpm_to_deb "$@"
# TODO: move to install
docmd epm install $force $nodeps $repacked_debs
return 0
}
__fix_spec()
{
local buildroot="$1"
local spec="$2"
local i
for i in $(grep '^"/' $spec | sed -e 's|^"\(.*\)"$|\1|') ; do
#' hack for highlight
# add %dir to dir in list
if [ -d "$buildroot$i" ] ; then
subst 's|^\("'$i'"\)$|%dir \1|' $spec
fi
done
subst "s|^Release: |Release: alt1.repacked.with.epm.|" $spec
subst "s|^\((Converted from a rpm package.*\)|(Repacked from binary rpm with epm $EPMVERSION)\n\1|" $spec
#" hack for highlight
}
__apply_fix_code()
{
local repackcode="/etc/eepm/repack.d/$1.sh"
[ -x "$repackcode" ] || return
shift
docmd $repackcode "$1" "$2" || warning "There was errors with $repackcode script"
}
__epm_repack_rpm()
{
assure_distr ALTLinux "install --repack"
assure_exists fakeroot || fatal
assure_exists alien || fatal
assure_exists rpmbuild rpm-build || fatal
local pkg
local tmpbuilddir=$(mktemp -d)/repack
mkdir $tmpbuilddir
local abspkg
repacked_rpms=''
for pkg in $* ; do
abspkg=$(realpath $pkg)
info "Repacking $abspkg to local rpm format ..."
cd $tmpbuilddir || fatal
docmd fakeroot alien --generate --to-rpm $verbose $scripts $abspkg || fatal
local subdir="$(echo *)"
[ -d "$subdir" ] || fatal "can't find subdir"
# detect spec and move to prev dir
local spec="$(echo $tmpbuilddir/$subdir/*.spec)"
[ -s "$spec" ] || fatal "can't find spec"
mv $spec $tmpbuilddir || fatal
spec="$tmpbuilddir/$(basename "$spec")"
__fix_spec $tmpbuilddir/$subdir $spec
local pkgname="$(grep "^Name: " $spec | sed -e "s|Name: ||g" | head -n1)"
__apply_fix_code $pkgname $tmpbuilddir/$subdir $spec
showcmd fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec
if [ -n "$verbose" ] ; then
a='' fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec || fatal
else
a='' fakeroot rpmbuild --buildroot $tmpbuilddir/$subdir --define='_allow_root_build 1' -bb $spec >/dev/null || fatal
fi
local repacked_rpm="$(realpath $tmpbuilddir/../*.rpm)"
if [ -s "$repacked_rpm" ] ; then
repacked_rpms="$repacked_rpms $repacked_rpm"
to_remove_pkg_files="$to_remove_pkg_files $repacked_rpm"
else
warning "Can't find converted rpm for source binary $pkg package"
fi
cd - >/dev/null
rm -rf $tmpbuilddir/$subdir/
#rm -rf $tmpbuilddir/../*.rpm
rm -rf $spec
done
rmdir $tmpbuilddir
#rmdir $tmpbuilddir/..
true
}
epm_repack()
{
# if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
if [ -n "$pkg_urls" ] ; then
__handle_pkg_urls_to_install
fi
[ -z "$pkg_files" ] && info "Skip empty repack list" && return 22
# TODO: если у нас rpm, а пакет - deb и наоборот
case $PKGFORMAT in
rpm)
if __epm_split_by_pkg_type deb $pkg_files ; then
__epm_repack_deb_to_rpm $split_replaced_pkgs
cp -v $repacked_rpms .
pkg_files="$(estrlist exclude $split_replaced_pkgs $pkg_files)"
fi
if [ -n "$pkg_files" ] ; then
__epm_repack_rpm $pkg_files || fatal
cp -v $repacked_rpms .
fi
;;
deb)
if __epm_split_by_pkg_type rpm $pkg_files ; then
__epm_repack_rpm_to_deb $split_replaced_pkgs
cp -v $repacked_debs .
pkg_files="$(estrlist exclude $split_replaced_pkgs $pkg_files)"
fi
;;
*)
fatal "$PKGFORMAT is not supported for repack yet"
;;
esac
# TODO: move it to exit handler
if [ -z "$DEBUG" ] ; then
# TODO: reinvent
[ -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
fi
}
# File bin/epm-repofix: # File bin/epm-repofix:
...@@ -4714,7 +5024,7 @@ __try_fix_apt_source_list() ...@@ -4714,7 +5024,7 @@ __try_fix_apt_source_list()
__fix_apt_sources_list() __fix_apt_sources_list()
{ {
# for beauty spaces # for beauty spaces
local SUBST_ALT_RULE='s!^(.*)[/ ](ALTLinux|LINUX\@Etersoft)[/ ](Sisyphus|p8[/ ]branch|p7[/ ]branch|t7[/ ]branch|c7[/ ]branch|p6[/ ]branch|t6[/ ]branch)[/ ](x86_64|i586|x86_64-i586|noarch) !\1 \2/\3/\4 !gi' local SUBST_ALT_RULE='s!^(.*)[/ ](ALTLinux|LINUX\@Etersoft)[/ ]*(Sisyphus|p8[/ ]branch|p7[/ ]branch|t7[/ ]branch|c7[/ ]branch|p6[/ ]branch|t6[/ ]branch)[/ ](x86_64|i586|x86_64-i586|noarch) !\1 \2/\3/\4 !gi'
local i local i
assure_root assure_root
for i in "$@" ; do for i in "$@" ; do
...@@ -5009,7 +5319,12 @@ case $PMTYPE in ...@@ -5009,7 +5319,12 @@ case $PMTYPE in
slackpkg) slackpkg)
# FIXME # FIXME
echo "Note: case sensitive search" echo "Note: case sensitive search"
CMD="/usr/sbin/slackpkg search" if [ -n "$verbose" ] ; then
CMD="/usr/sbin/slackpkg search"
else
LANG=C docmd /usr/sbin/slackpkg search $string | grep " - " | sed -e 's|.* - ||g'
return
fi
;; ;;
homebrew) homebrew)
CMD="brew search" CMD="brew search"
...@@ -5091,6 +5406,18 @@ __epm_search_make_grep() ...@@ -5091,6 +5406,18 @@ __epm_search_make_grep()
fi fi
} }
__epm_search_internal()
{
[ -n "$pkg_filenames" ] || fatal "Search: missing search argument(s)"
# it is useful for first time running
update_repo_if_needed soft
warmup_bases
__epm_search_output $(get_firstarg $pkg_filenames) | grep "$pkg_filenames"
}
epm_search() epm_search()
{ {
...@@ -5295,9 +5622,9 @@ tasknumber() ...@@ -5295,9 +5622,9 @@ tasknumber()
is_warmup_allowed() is_warmup_allowed()
{ {
local MEM local MEM
MEM=$($DISTRVENDOR -m) MEM="$($DISTRVENDOR -m)"
# disable warm if have no enough memory # disable warm if have no enough memory
[ $MEM -le 1024 ] && return 1 [ "$MEM" -le 1024 ] && return 1
return 0 return 0
} }
...@@ -5462,8 +5789,11 @@ EOF ...@@ -5462,8 +5789,11 @@ EOF
for pkg in $filenames ; do for pkg in $filenames ; do
# FIXME: -[0-0] does not work in search! # FIXME: -[0-0] does not work in search!
# FIXME: we need strict search here (not find gst-plugins-base if search for gst-plugins # FIXME: we need strict search here (not find gst-plugins-base if search for gst-plugins
pkg_filenames="$pkg-[0-9]" epm_search | grep -E "(installed|upgrade)" && continue # TODO: use short?
pkg_filenames="$pkg" epm_search | grep -E "(installed|upgrade)" && continue # use verbose for get package status
#pkg_filenames="$pkg-[0-9]" verbose=--verbose __epm_search_internal | egrep "(installed|upgrade)" && continue
#pkg_filenames="$pkg" verbose=--verbose __epm_search_internal | egrep "(installed|upgrade)" && continue
pkg_filenames="$pkg" __epm_search_internal | grep -q "^$pkg-[0-9]" && continue
res=1 res=1
info "Package '$pkg' does not found in repository." info "Package '$pkg' does not found in repository."
done done
...@@ -6267,15 +6597,23 @@ esac ...@@ -6267,15 +6597,23 @@ esac
echo "$DIST_OS" echo "$DIST_OS"
} }
get_uname_m()
{
uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"
}
get_arch() get_arch()
{ {
local DIST_ARCH local DIST_ARCH
# Resolve the architecture # Resolve the architecture
DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"` DIST_ARCH="$(get_uname_m)"
case "$DIST_ARCH" in case "$DIST_ARCH" in
'amd64' | 'ia32' | 'i386' | 'i486' | 'i586' | 'i686' | 'x86_64') 'ia32' | 'i386' | 'i486' | 'i586' | 'i686')
DIST_ARCH="x86" DIST_ARCH="x86"
;; ;;
'amd64' | 'x86_64')
DIST_ARCH="x86_64"
;;
'ia64' | 'ia-64') 'ia64' | 'ia-64')
DIST_ARCH="ia64" DIST_ARCH="ia64"
;; ;;
...@@ -6295,7 +6633,7 @@ case "$DIST_ARCH" in ...@@ -6295,7 +6633,7 @@ case "$DIST_ARCH" in
DIST_ARCH="parisc" DIST_ARCH="parisc"
;; ;;
armv*) armv*)
if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then if [ -z "$(readelf -A /proc/self/exe | grep Tag_ABI_VFP_args)" ] ; then
DIST_ARCH="armel" DIST_ARCH="armel"
else else
DIST_ARCH="armhf" DIST_ARCH="armhf"
...@@ -6309,7 +6647,7 @@ get_bit_size() ...@@ -6309,7 +6647,7 @@ get_bit_size()
{ {
local DIST_BIT local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now... # 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"` DIST_BIT="$(get_uname_m)"
case "$DIST_BIT" in case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64') 'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64" DIST_BIT="64"
...@@ -6330,20 +6668,23 @@ esac ...@@ -6330,20 +6668,23 @@ esac
echo "$DIST_BIT" echo "$DIST_BIT"
} }
# TODO: check before calc
get_memory_size() { get_memory_size() {
local detected=0 local detected=0
local DIST_OS=$(get_base_os_name) local DIST_OS="$(get_base_os_name)"
if [ $DIST_OS = "macosx" ] case "$DIST_OS" in
then macosx)
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024)) detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
elif [ $DIST_OS = "freebsd" ] ;;
then freebsd)
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024)) detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
elif [ $DIST_OS = "linux" ] ;;
then linux)
detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024)) [ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
fi ;;
# Exit codes only support values between 0 and 255. So use stdout. esac
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected echo $detected
} }
...@@ -6403,7 +6744,7 @@ case $1 in ...@@ -6403,7 +6744,7 @@ case $1 in
exit 0 exit 0
;; ;;
-V) -V)
echo "20161212" echo "20171010"
exit 0 exit 0
;; ;;
*) *)
...@@ -6443,12 +6784,31 @@ internal_tools_eget() ...@@ -6443,12 +6784,31 @@ internal_tools_eget()
WGET="wget" WGET="wget"
# TODO: passthrou all wget options
if [ "$1" = "-q" ] ; then if [ "$1" = "-q" ] ; then
WGET="wget -q" WGET="wget -q"
shift shift
fi fi
# TODO: if [ "$1" = "--list" ] ; then
LISTONLY="$1"
shift
fi
fatal()
{
echo "$*" >&2
exit 1
}
# check man glob
filter_glob()
{
# translate glob to regexp
grep "^$(echo "$1" | sed -e "s|\*|.*|g" -e "s|\?|.|g")$"
}
# download to this file # download to this file
WGET_OPTION_TARGET= WGET_OPTION_TARGET=
if [ "$1" = "-O" ] ; then if [ "$1" = "-O" ] ; then
...@@ -6462,66 +6822,299 @@ fi ...@@ -6462,66 +6822,299 @@ fi
if [ -z "$1" ] ; then if [ -z "$1" ] ; then
echo "eget - wget wrapper" >&2 echo "eget - wget wrapper" >&2
echo "Run with URL, like http://somesite.ru/dir/*.log" >&2 fatal "Run with URL, like http://somesite.ru/dir/*.log"
exit 1
fi fi
# If ftp protocol, just download if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
if echo "$1" | grep -q "^ftp://" ; then echo "eget - wget wrapper, with support"
$WGET $WGET_OPTION_TARGET "$1" echo "Usage: eget [-O target file] [--list] http://somesite.ru/dir/na*.log"
echo "Options:"
echo " --list - print files frm url with mask"
echo
wget --help
return return
fi fi
# drop mask part (if has /$, not changed) # do not support /
URL=$(echo "$1" | grep "/$" || dirname "$1") if echo "$1" | grep -q "/$" ; then
fatal "Use http://example.com/e/* to download all files in dir"
fi
# If have no wildcard symbol like asterisk and no / at the end, just download # If ftp protocol, just download
if [ "$URL" != "$1" ] && echo "$1" | grep -qv "[*?]" ; then if echo "$1" | grep -q "^ftp://" ; then
[ -n "$LISTONLY" ] && fatal "Error: list files for ftp:// do not supported yet"
$WGET $WGET_OPTION_TARGET "$1" $WGET $WGET_OPTION_TARGET "$1"
return return
fi fi
echo "Fall to http workaround" # drop mask part
URL="$(dirname "$1")/"
if echo "$URL" | grep -q "[*?]" ; then
fatal "Error: there are globbing symbols (*?) in $URL"
fi
# 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
# add * if full dir
#[ "$URL" != "$1" ] && MASK="*"
print_files() # If have no wildcard symbol like asterisk, just download
if echo "$MASK" | grep -qv "[*?]" ; then
$WGET $WGET_OPTION_TARGET "$1"
return
fi
get_urls()
{ {
$WGET -O- $URL | \ $WGET -O- $URL | \
grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2 grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
} }
create_fake_files() if [ -n "$LISTONLY" ] ; then
WGET="$WGET -q"
for fn in $(get_urls | filter_glob "$MASK") ; do
echo "$(basename "$fn")"
done
return
fi
ERROR=0
for fn in $(get_urls | filter_glob "$MASK") ; do
$WGET "$URL/$(basename "$fn")" || ERROR=1
done
exit $ERROR
}
################# end of incorporated bin/tools_eget #################
################# incorporate bin/tools_estrlist #################
internal_tools_estrlist()
{ {
DIRALLFILES="$MYTMPDIR/files/" #!/bin/bash
mkdir -p "$DIRALLFILES" # 2009-2010, 2012, 2017 Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# TODO: rewrite with shell commands, perl or C
# Python - http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch16s03.html
# Shell - http://linux.byexamples.com/archives/127/uniq-and-basic-set-theory/
# - http://maiaco.com/articles/shellSetOperations.php
# Perl - http://docstore.mik.ua/orelly/perl/cookbook/ch04_09.htm
# - http://blogs.perl.org/users/polettix/2012/03/sets-operations.html
# http://rosettacode.org/wiki/Symmetric_difference
# TODO: add unit tests
# http://ru.wikipedia.org/wiki/Операции_над_множествами
# Base set operations:
# * union
# "1 2 3" "3 4 5" -> "1 2 3 4 5"
# * intersection
# "1 2 3" "3 4 5" -> "3"
# * relative complement (substracted, difference) ( A ? B – members in A but not in B )
# http://en.wikipedia.org/wiki/Complement_%28set_theory%29
# "1 3" "1 2 3 4" -> "2 4"
# * symmetric difference (симметричная разность) ( A ^ B – members in A or B but not both )
# http://en.wikipedia.org/wiki/Symmetric_difference
# "1 2 3" "3 4 5" -> "1 2 4 5"
print_files | while read -r line ; do filter_strip_spaces()
touch $DIRALLFILES/$(basename "$line") {
done # possible use just
#xargs echo
sed -e "s| \+| |g" -e "s|^ ||" -e "s| \$||"
} }
download_files() strip_spaces()
{ {
ERROR=0 echo "$*" | filter_strip_spaces
# TODO: test fix / at the end
for line in $DIRALLFILES/$MASK ; do
[ -r "$line" ] || { ERROR=1 ; break ; }
$WGET $URL/$(basename "$line") || ERROR=1
done
return $ERROR
} }
MYTMPDIR="$(mktemp -d)" isempty()
create_fake_files {
download_files || echo "There was some download errors" >&2 [ "$(strip_spaces "$*")" = "" ]
rm -rf "$MYTMPDIR" }
list()
{
local i
for i in $@ ; do
echo "$i"
done
} }
################# end of incorporated bin/tools_eget #################
count()
{
list $@ | wc -l
}
union()
{
strip_spaces $(list $@ | sort -u)
}
uniq()
{
union $@
}
has()
{
local wd="$1"
shift
echo "$*" | grep -q -- "$wd"
}
# Note: used egrep! write '[0-9]+(first|two)', not '[0-9]\+...'
match()
{
local wd="$1"
shift
echo "$*" | egrep -q -- "$wd"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_remove()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q "$1" || RES="$RES $i"
done
strip_spaces "$RES"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_wordremove()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q -w "$1" || RES="$RES $i"
done
strip_spaces "$RES"
}
# Args: LIST1 LIST2
# do_exclude_list print LIST2 list exclude fields contains also in LIST1
# Example: exclude "1 3" "1 2 3 4" -> "2 4"
exclude()
{
local i
local RES=
for i in $2 ; do
echo "$1" | grep -q -w "$i" || RES="$RES $i"
done
strip_spaces "$RES"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_exclude()
{
local i
local RES="$2"
for i in $1 ; do
RES=$(reg_remove "$i" "$RES")
done
strip_spaces "$RES"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_wordexclude()
{
local i
local RES="$2"
for i in $1 ; do
RES=$(reg_wordremove "$i" "$RES")
done
strip_spaces "$RES"
}
# FIXME:
# reg_include "1." "11 12 21 22" -> "11 12"
reg_include()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q -w "$1" && RES="$RES $i"
done
strip_spaces "$RES"
}
example()
{
local CMD="$1"
local ARG1="$2"
shift 2
echo "\$ $0 $CMD \"$ARG1\" \"$@\""
$0 $CMD "$ARG1" "$@"
}
example_res()
{
example "$@" && echo TRUE || echo FALSE
}
help()
{
echo "estrlist developed for string list operations. See also cut, join, paste..."
echo "Usage: $0 <command> [args]"
echo "Commands:"
echo " strip_spaces [args] - remove spaces between words"
echo " filter_strip_spaces - remove spaces from words from standart input"
echo " reg_remove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep notation)"
echo " reg_wordremove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep -w notation)"
echo " exclude <list1> <list2> - print list2 words exclude list1 items"
echo " reg_exclude <PATTERN> [word list] - print only words do not matched with PATTERN"
echo " reg_wordexclude <PATTERN> [word list] - print only words do not matched with PATTERN"
echo " has <PATTERN> string - check the string for a match to the regular expression given in PATTERN (grep notation)"
echo " match <PATTERN> string - check the string for a match to the regular expression given in PATTERN (egrep notation)"
echo " isempty [string] - true if string has no any symbols (only zero or more spaces)"
echo " union [word list] - sort and remove duplicates"
echo " uniq [word list] - alias for union"
echo " list [word list] - just list words line by line"
echo " count [word list] - print word count"
echo
echo "Examples:"
example reg_remove "1." "11 12 21 22"
example reg_wordremove "1." "11 12 21 22"
example exclude "1 3" "1 2 3 4"
example reg_exclude "22 1." "11 12 21 22"
example reg_wordexclude "wo.* er" "work were more else"
example union "1 2 2 3 3"
example count "1 2 3 4 10"
example_res isempty " "
#example_res isempty " 1 "
example_res has ex "exactly"
example_res has exo "exactly"
example_res match "M[0-9]+" "M250"
example_res match "M[0-9]+" "MI"
}
COMMAND="$1"
if [ -z "$COMMAND" ] ; then
echo "Run with --help for get command description."
exit 1
fi
if [ "$COMMAND" = "-h" ] || [ "$COMMAND" = "--help" ] ; then
COMMAND="help"
fi
shift
# FIXME: do to call function directly, use case instead?
if [ "$1" = "-" ] ; then
shift
"$COMMAND" "$(cat) $@"
elif [ "$2" = "-" ] ; then
"$COMMAND" "$1" "$(cat)"
else
"$COMMAND" "$@"
fi
}
################# end of incorporated bin/tools_estrlist #################
################# incorporate bin/tools_json ################# ################# incorporate bin/tools_json #################
...@@ -6765,7 +7358,7 @@ $(get_help HELPOPT) ...@@ -6765,7 +7358,7 @@ $(get_help HELPOPT)
print_version() print_version()
{ {
echo "EPM package manager version 2.3.0" echo "EPM package manager version 2.4.6"
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."
...@@ -6775,13 +7368,15 @@ print_version() ...@@ -6775,13 +7368,15 @@ print_version()
Usage="Usage: epm [options] <command> [package name(s), package files]..." Usage="Usage: epm [options] <command> [package name(s), package files]..."
Descr="epm - EPM package manager" Descr="epm - EPM package manager"
EPMVERSION=2.4.6
verbose= verbose=
quiet= quiet=
nodeps= nodeps=
noremove= noremove=
dryrun= dryrun=
force= force=
repack=
scripts=
short= short=
direct= direct=
sort= sort=
...@@ -6795,6 +7390,10 @@ pkg_names= ...@@ -6795,6 +7390,10 @@ pkg_names=
pkg_urls= pkg_urls=
quoted_args= quoted_args=
# load system wide config
[ -f /etc/eepm/eepm.conf ] && . /etc/eepm/eepm.conf
case $PROGNAME in case $PROGNAME in
epmi) epmi)
epm_cmd=install epm_cmd=install
...@@ -6934,7 +7533,7 @@ check_command() ...@@ -6934,7 +7533,7 @@ check_command()
addrepo|ar) # HELPCMD: add package repo addrepo|ar) # HELPCMD: add package repo
epm_cmd=addrepo epm_cmd=addrepo
;; ;;
repolist|sl|rl|listrepo) # HELPCMD: print repo list repolist|sl|rl|listrepo|repo) # HELPCMD: print repo list
epm_cmd=repolist epm_cmd=repolist
;; ;;
repofix) # HELPCMD: fix paths in sources lists (ALT Linux only) repofix) # HELPCMD: fix paths in sources lists (ALT Linux only)
...@@ -6988,12 +7587,15 @@ check_command() ...@@ -6988,12 +7587,15 @@ check_command()
site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site) site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site)
epm_cmd=site epm_cmd=site
;; ;;
ei|epminstall|epm-install|selfinstall) # HELPCMD: install or update eepm package from all in one script ei|ik|epminstall|epm-install|selfinstall) # HELPCMD: install package(s) from Korinf (eepm by default)
epm_cmd=epm_install epm_cmd=epm_install
;; ;;
print) # HELPCMD: print various info, run epm print help for details print) # HELPCMD: print various info, run epm print help for details
epm_cmd=print epm_cmd=print
;; ;;
repack) # HELPCMD: repack rpm to local compatibility
epm_cmd=repack
;;
-V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum) -V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum)
epm_cmd=checkpkg epm_cmd=checkpkg
;; ;;
...@@ -7046,11 +7648,17 @@ check_option() ...@@ -7046,11 +7648,17 @@ check_option()
--direct) # HELPOPT: direct install package file from ftp (not via hilevel repository manager) --direct) # HELPOPT: direct install package file from ftp (not via hilevel repository manager)
direct="--direct" direct="--direct"
;; ;;
--repack) # HELPOPT: repack rpm package(s) before install
repack="--repack"
;;
--scripts) # HELPOPT: include scripts in repacked rpm package(s) (see --repack or repacking when foreign package is installed)
scripts="--scripts"
;;
--sort) # HELPOPT: sort output, f.i. --sort=size (supported only for packages command) --sort) # HELPOPT: sort output, f.i. --sort=size (supported only for packages command)
# TODO: how to read arg? # TODO: how to read arg?
sort="$1" sort="$1"
;; ;;
--auto) # HELPOPT: non interactive mode --auto|--non-interactive) # HELPOPT: non interactive mode
non_interactive=1 non_interactive=1
;; ;;
*) *)
......
...@@ -370,6 +370,20 @@ disabled_eget() ...@@ -370,6 +370,20 @@ disabled_eget()
$EGET "$@" $EGET "$@"
} }
disabled_estrlist()
{
if [ -s $SHAREDIR/tools_estrlist ] ; then
$SHAREDIR/tools_estrlist "$@"
return
fi
fatal "missed tools_estrlist"
}
estrlist()
{
internal_tools_estrlist "$@"
}
eget() eget()
{ {
assure_exists wget assure_exists wget
...@@ -531,6 +545,13 @@ is_active_systemd() ...@@ -531,6 +545,13 @@ is_active_systemd()
ps ax | grep '[s]ystemd' | grep -q -v 'systemd-udev' ps ax | grep '[s]ystemd' | grep -q -v 'systemd-udev'
} }
assure_distr()
{
local TEXT="this option"
[ -n "$2" ] && TEXT="$2"
[ "$DISTRNAME" = "$1" ] || fatal "$TEXT supported only for $1 distro"
}
# File bin/serv-common: # File bin/serv-common:
serv_common() serv_common()
...@@ -649,6 +670,7 @@ serv_enable() ...@@ -649,6 +670,7 @@ serv_enable()
serv_list() serv_list()
{ {
info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
service-upstart) service-upstart)
sudocmd initctl list sudocmd initctl list
...@@ -660,7 +682,9 @@ serv_list() ...@@ -660,7 +682,9 @@ serv_list()
sudocmd systemctl list-units $@ sudocmd systemctl list-units $@
;; ;;
*) *)
for i in $(serv_list_all) ; do # hack to improve list speed
[ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; }
for i in $(quiet=1 serv_list_all) ; do
is_service_running $i >/dev/null && echo $i is_service_running $i >/dev/null && echo $i
done done
;; ;;
...@@ -674,7 +698,7 @@ serv_list_all() ...@@ -674,7 +698,7 @@ serv_list_all()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 sudocmd chkconfig --list | cut -f1 | grep -v "^$" | grep -v "xinetd:$"
if [ -n "$ANYSERVICE" ] ; then if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice --quiet list sudocmd anyservice --quiet list
...@@ -853,23 +877,27 @@ serv_start() ...@@ -853,23 +877,27 @@ serv_start()
is_service_running() is_service_running()
{ {
local SERVICE="$1" local SERVICE="$1"
local OUTPUT
# TODO: real status can be checked only with grep output
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $1 ; then if is_anyservice $1 ; then
$SUDO anyservice $1 status >/dev/null OUTPUT="$($SUDO anyservice $1 status 2>/dev/null)" || return 1
return echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0
fi fi
$SUDO service $1 status >/dev/null OUTPUT="$($SUDO service $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0
;; ;;
service-initd|service-update) service-initd|service-update)
$SUDO $INITDIR/$1 status >/dev/null $SUDO $INITDIR/$1 status >/dev/null 2>/dev/null
;; ;;
systemd) systemd)
$SUDO systemctl status $1 >/dev/null $SUDO systemctl status $1 >/dev/null 2>/dev/null
;; ;;
runit) runit)
$SUDO sv status "$SERVICE" >/dev/null $SUDO sv status "$SERVICE" >/dev/null 2>/dev/null
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
...@@ -1377,15 +1405,23 @@ esac ...@@ -1377,15 +1405,23 @@ esac
echo "$DIST_OS" echo "$DIST_OS"
} }
get_uname_m()
{
uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"
}
get_arch() get_arch()
{ {
local DIST_ARCH local DIST_ARCH
# Resolve the architecture # Resolve the architecture
DIST_ARCH=`uname -m | tr [:upper:] [:lower:] | tr -d " \t\r\n"` DIST_ARCH="$(get_uname_m)"
case "$DIST_ARCH" in case "$DIST_ARCH" in
'amd64' | 'ia32' | 'i386' | 'i486' | 'i586' | 'i686' | 'x86_64') 'ia32' | 'i386' | 'i486' | 'i586' | 'i686')
DIST_ARCH="x86" DIST_ARCH="x86"
;; ;;
'amd64' | 'x86_64')
DIST_ARCH="x86_64"
;;
'ia64' | 'ia-64') 'ia64' | 'ia-64')
DIST_ARCH="ia64" DIST_ARCH="ia64"
;; ;;
...@@ -1405,7 +1441,7 @@ case "$DIST_ARCH" in ...@@ -1405,7 +1441,7 @@ case "$DIST_ARCH" in
DIST_ARCH="parisc" DIST_ARCH="parisc"
;; ;;
armv*) armv*)
if [ -z "`readelf -A /proc/self/exe | grep Tag_ABI_VFP_args`" ] ; then if [ -z "$(readelf -A /proc/self/exe | grep Tag_ABI_VFP_args)" ] ; then
DIST_ARCH="armel" DIST_ARCH="armel"
else else
DIST_ARCH="armhf" DIST_ARCH="armhf"
...@@ -1419,7 +1455,7 @@ get_bit_size() ...@@ -1419,7 +1455,7 @@ get_bit_size()
{ {
local DIST_BIT local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now... # 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"` DIST_BIT="$(get_uname_m)"
case "$DIST_BIT" in case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64') 'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64" DIST_BIT="64"
...@@ -1440,20 +1476,23 @@ esac ...@@ -1440,20 +1476,23 @@ esac
echo "$DIST_BIT" echo "$DIST_BIT"
} }
# TODO: check before calc
get_memory_size() { get_memory_size() {
local detected=0 local detected=0
local DIST_OS=$(get_base_os_name) local DIST_OS="$(get_base_os_name)"
if [ $DIST_OS = "macosx" ] case "$DIST_OS" in
then macosx)
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024)) detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
elif [ $DIST_OS = "freebsd" ] ;;
then freebsd)
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024)) detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
elif [ $DIST_OS = "linux" ] ;;
then linux)
detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024)) [ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
fi ;;
# Exit codes only support values between 0 and 255. So use stdout. esac
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected echo $detected
} }
...@@ -1513,7 +1552,7 @@ case $1 in ...@@ -1513,7 +1552,7 @@ case $1 in
exit 0 exit 0
;; ;;
-V) -V)
echo "20161212" echo "20171010"
exit 0 exit 0
;; ;;
*) *)
...@@ -1553,12 +1592,31 @@ internal_tools_eget() ...@@ -1553,12 +1592,31 @@ internal_tools_eget()
WGET="wget" WGET="wget"
# TODO: passthrou all wget options
if [ "$1" = "-q" ] ; then if [ "$1" = "-q" ] ; then
WGET="wget -q" WGET="wget -q"
shift shift
fi fi
# TODO: if [ "$1" = "--list" ] ; then
LISTONLY="$1"
shift
fi
fatal()
{
echo "$*" >&2
exit 1
}
# check man glob
filter_glob()
{
# translate glob to regexp
grep "^$(echo "$1" | sed -e "s|\*|.*|g" -e "s|\?|.|g")$"
}
# download to this file # download to this file
WGET_OPTION_TARGET= WGET_OPTION_TARGET=
if [ "$1" = "-O" ] ; then if [ "$1" = "-O" ] ; then
...@@ -1572,66 +1630,299 @@ fi ...@@ -1572,66 +1630,299 @@ fi
if [ -z "$1" ] ; then if [ -z "$1" ] ; then
echo "eget - wget wrapper" >&2 echo "eget - wget wrapper" >&2
echo "Run with URL, like http://somesite.ru/dir/*.log" >&2 fatal "Run with URL, like http://somesite.ru/dir/*.log"
exit 1
fi fi
# If ftp protocol, just download if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
if echo "$1" | grep -q "^ftp://" ; then echo "eget - wget wrapper, with support"
$WGET $WGET_OPTION_TARGET "$1" echo "Usage: eget [-O target file] [--list] http://somesite.ru/dir/na*.log"
echo "Options:"
echo " --list - print files frm url with mask"
echo
wget --help
return return
fi fi
# drop mask part (if has /$, not changed) # do not support /
URL=$(echo "$1" | grep "/$" || dirname "$1") if echo "$1" | grep -q "/$" ; then
fatal "Use http://example.com/e/* to download all files in dir"
fi
# If have no wildcard symbol like asterisk and no / at the end, just download # If ftp protocol, just download
if [ "$URL" != "$1" ] && echo "$1" | grep -qv "[*?]" ; then if echo "$1" | grep -q "^ftp://" ; then
[ -n "$LISTONLY" ] && fatal "Error: list files for ftp:// do not supported yet"
$WGET $WGET_OPTION_TARGET "$1" $WGET $WGET_OPTION_TARGET "$1"
return return
fi fi
echo "Fall to http workaround" # drop mask part
URL="$(dirname "$1")/"
if echo "$URL" | grep -q "[*?]" ; then
fatal "Error: there are globbing symbols (*?) in $URL"
fi
# 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
# add * if full dir
#[ "$URL" != "$1" ] && MASK="*"
print_files() # If have no wildcard symbol like asterisk, just download
if echo "$MASK" | grep -qv "[*?]" ; then
$WGET $WGET_OPTION_TARGET "$1"
return
fi
get_urls()
{ {
$WGET -O- $URL | \ $WGET -O- $URL | \
grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2 grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
} }
create_fake_files() if [ -n "$LISTONLY" ] ; then
WGET="$WGET -q"
for fn in $(get_urls | filter_glob "$MASK") ; do
echo "$(basename "$fn")"
done
return
fi
ERROR=0
for fn in $(get_urls | filter_glob "$MASK") ; do
$WGET "$URL/$(basename "$fn")" || ERROR=1
done
exit $ERROR
}
################# end of incorporated bin/tools_eget #################
################# incorporate bin/tools_estrlist #################
internal_tools_estrlist()
{ {
DIRALLFILES="$MYTMPDIR/files/" #!/bin/bash
mkdir -p "$DIRALLFILES" # 2009-2010, 2012, 2017 Etersoft www.etersoft.ru
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
# TODO: rewrite with shell commands, perl or C
# Python - http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch16s03.html
# Shell - http://linux.byexamples.com/archives/127/uniq-and-basic-set-theory/
# - http://maiaco.com/articles/shellSetOperations.php
# Perl - http://docstore.mik.ua/orelly/perl/cookbook/ch04_09.htm
# - http://blogs.perl.org/users/polettix/2012/03/sets-operations.html
# http://rosettacode.org/wiki/Symmetric_difference
# TODO: add unit tests
# http://ru.wikipedia.org/wiki/Операции_над_множествами
# Base set operations:
# * union
# "1 2 3" "3 4 5" -> "1 2 3 4 5"
# * intersection
# "1 2 3" "3 4 5" -> "3"
# * relative complement (substracted, difference) ( A ? B – members in A but not in B )
# http://en.wikipedia.org/wiki/Complement_%28set_theory%29
# "1 3" "1 2 3 4" -> "2 4"
# * symmetric difference (симметричная разность) ( A ^ B – members in A or B but not both )
# http://en.wikipedia.org/wiki/Symmetric_difference
# "1 2 3" "3 4 5" -> "1 2 4 5"
print_files | while read -r line ; do filter_strip_spaces()
touch $DIRALLFILES/$(basename "$line") {
done # possible use just
#xargs echo
sed -e "s| \+| |g" -e "s|^ ||" -e "s| \$||"
} }
download_files() strip_spaces()
{ {
ERROR=0 echo "$*" | filter_strip_spaces
# TODO: test fix / at the end
for line in $DIRALLFILES/$MASK ; do
[ -r "$line" ] || { ERROR=1 ; break ; }
$WGET $URL/$(basename "$line") || ERROR=1
done
return $ERROR
} }
MYTMPDIR="$(mktemp -d)" isempty()
create_fake_files {
download_files || echo "There was some download errors" >&2 [ "$(strip_spaces "$*")" = "" ]
rm -rf "$MYTMPDIR"
} }
################# end of incorporated bin/tools_eget #################
list()
{
local i
for i in $@ ; do
echo "$i"
done
}
count()
{
list $@ | wc -l
}
union()
{
strip_spaces $(list $@ | sort -u)
}
uniq()
{
union $@
}
has()
{
local wd="$1"
shift
echo "$*" | grep -q -- "$wd"
}
# Note: used egrep! write '[0-9]+(first|two)', not '[0-9]\+...'
match()
{
local wd="$1"
shift
echo "$*" | egrep -q -- "$wd"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_remove()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q "$1" || RES="$RES $i"
done
strip_spaces "$RES"
}
# remove_from_list "1." "11 12 21 22" -> "21 22"
reg_wordremove()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q -w "$1" || RES="$RES $i"
done
strip_spaces "$RES"
}
# Args: LIST1 LIST2
# do_exclude_list print LIST2 list exclude fields contains also in LIST1
# Example: exclude "1 3" "1 2 3 4" -> "2 4"
exclude()
{
local i
local RES=
for i in $2 ; do
echo "$1" | grep -q -w "$i" || RES="$RES $i"
done
strip_spaces "$RES"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_exclude()
{
local i
local RES="$2"
for i in $1 ; do
RES=$(reg_remove "$i" "$RES")
done
strip_spaces "$RES"
}
# regexclude_list "22 1." "11 12 21 22" -> "21"
reg_wordexclude()
{
local i
local RES="$2"
for i in $1 ; do
RES=$(reg_wordremove "$i" "$RES")
done
strip_spaces "$RES"
}
# FIXME:
# reg_include "1." "11 12 21 22" -> "11 12"
reg_include()
{
local i
local RES=
for i in $2 ; do
echo "$i" | grep -q -w "$1" && RES="$RES $i"
done
strip_spaces "$RES"
}
example()
{
local CMD="$1"
local ARG1="$2"
shift 2
echo "\$ $0 $CMD \"$ARG1\" \"$@\""
$0 $CMD "$ARG1" "$@"
}
example_res()
{
example "$@" && echo TRUE || echo FALSE
}
help()
{
echo "estrlist developed for string list operations. See also cut, join, paste..."
echo "Usage: $0 <command> [args]"
echo "Commands:"
echo " strip_spaces [args] - remove spaces between words"
echo " filter_strip_spaces - remove spaces from words from standart input"
echo " reg_remove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep notation)"
echo " reg_wordremove <PATTERN> [word list] - remove words containing a match to the given PATTERN (grep -w notation)"
echo " exclude <list1> <list2> - print list2 words exclude list1 items"
echo " reg_exclude <PATTERN> [word list] - print only words do not matched with PATTERN"
echo " reg_wordexclude <PATTERN> [word list] - print only words do not matched with PATTERN"
echo " has <PATTERN> string - check the string for a match to the regular expression given in PATTERN (grep notation)"
echo " match <PATTERN> string - check the string for a match to the regular expression given in PATTERN (egrep notation)"
echo " isempty [string] - true if string has no any symbols (only zero or more spaces)"
echo " union [word list] - sort and remove duplicates"
echo " uniq [word list] - alias for union"
echo " list [word list] - just list words line by line"
echo " count [word list] - print word count"
echo
echo "Examples:"
example reg_remove "1." "11 12 21 22"
example reg_wordremove "1." "11 12 21 22"
example exclude "1 3" "1 2 3 4"
example reg_exclude "22 1." "11 12 21 22"
example reg_wordexclude "wo.* er" "work were more else"
example union "1 2 2 3 3"
example count "1 2 3 4 10"
example_res isempty " "
#example_res isempty " 1 "
example_res has ex "exactly"
example_res has exo "exactly"
example_res match "M[0-9]+" "M250"
example_res match "M[0-9]+" "MI"
}
COMMAND="$1"
if [ -z "$COMMAND" ] ; then
echo "Run with --help for get command description."
exit 1
fi
if [ "$COMMAND" = "-h" ] || [ "$COMMAND" = "--help" ] ; then
COMMAND="help"
fi
shift
# FIXME: do to call function directly, use case instead?
if [ "$1" = "-" ] ; then
shift
"$COMMAND" "$(cat) $@"
elif [ "$2" = "-" ] ; then
"$COMMAND" "$1" "$(cat)"
else
"$COMMAND" "$@"
fi
}
################# end of incorporated bin/tools_estrlist #################
################# incorporate bin/tools_json ################# ################# incorporate bin/tools_json #################
...@@ -1948,7 +2239,7 @@ $(get_help HELPOPT) ...@@ -1948,7 +2239,7 @@ $(get_help HELPOPT)
print_version() print_version()
{ {
echo "Service manager version 2.3.0" echo "Service manager version 2.4.6"
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