Commit 3c521de8 authored by Vitaly Lipatov's avatar Vitaly Lipatov

backported to c7.1 as 2.5.8-alt0.M70C.1.1 (with rpmbph script)

parents a1107eb8 835a9dde
pkgdatadir=$(datadir)/eepm pkgdatadir=$(datadir)/eepm
# due using %makeinstallstd in spec # due using %makeinstallstd in spec
instpkgdatadir=/usr/share/eepm instpkgdatadir=$(pkgdatadir)
install: install:
mkdir -p $(DESTDIR)$(bindir)/ mkdir -p $(DESTDIR)$(bindir)/
# breaks link # breaks link
#install -m 755 `ls -1 bin/* | grep -v "-"` $(DESTDIR)$(bindir)/ cp -a `ls -1 bin/* | grep -v "[-_]"` $(DESTDIR)$(bindir)/
cp -a `ls -1 bin/* | grep -v "-"` $(DESTDIR)$(bindir)/ cp -a bin/distr_info $(DESTDIR)$(bindir)/
chmod 0755 $(DESTDIR)$(bindir)/* chmod 0755 $(DESTDIR)$(bindir)/*
sed -e "s|SHAREDIR=.*|SHAREDIR=$(instpkgdatadir)|g" -e "s|@VERSION@|$(version)|g" <bin/epm >$(DESTDIR)$(bindir)/epm sed -e "s|SHAREDIR=.*|SHAREDIR=$(instpkgdatadir)|g" \
-e "s|CONFIGDIR=.*|CONFIGDIR=$(sysconfdir)/eepm|g" \
-e "s|@VERSION@|$(version)|g" <bin/epm >$(DESTDIR)$(bindir)/epm
sed -e "s|SHAREDIR=.*|SHAREDIR=$(instpkgdatadir)|g" -e "s|@VERSION@|$(version)|g" <bin/serv >$(DESTDIR)$(bindir)/serv sed -e "s|SHAREDIR=.*|SHAREDIR=$(instpkgdatadir)|g" -e "s|@VERSION@|$(version)|g" <bin/serv >$(DESTDIR)$(bindir)/serv
mkdir -p $(DESTDIR)$(pkgdatadir)/ mkdir -p $(DESTDIR)$(pkgdatadir)/
install -m 644 `ls -1 bin/* | grep "-"` $(DESTDIR)$(pkgdatadir)/ install -m 644 `ls -1 bin/* | grep "[-_]"` $(DESTDIR)$(pkgdatadir)/
rm -f $(DESTDIR)$(pkgdatadir)/distr_info
mkdir -p $(DESTDIR)$(mandir)/man1 mkdir -p $(DESTDIR)$(mandir)/man1
cp -a `ls -1 man/*` $(DESTDIR)$(mandir)/man1/ cp -a `ls -1 man/*` $(DESTDIR)$(mandir)/man1/
...@@ -37,7 +37,17 @@ Note: epm is placed as /usr/bin/epm ...@@ -37,7 +37,17 @@ Note: epm is placed as /usr/bin/epm
$ rpm -qf /usr/bin/epm $ rpm -qf /usr/bin/epm
eepm-1.1.0-alt2 eepm-1.1.0-alt2
== Install on any system ==
Just run under root user:
# curl -s https://raw.githubusercontent.com/Etersoft/eepm/master/packed/epm.sh | bash /dev/stdin ei --auto
== How to add new distro support ==
1. Fix detection with distr_info
2. Add distro support in set_pm_type function
3. Realize every command in epm-* files
4. Check epm packages and epm --short packages works correctly
(epm package 'awk' have to print packages with awk substring in their names)
See detailed description in russian at See detailed description in russian at
http://wiki.etersoft.ru/Epm http://wiki.etersoft.ru/Epm
......
Загрузку конфига на 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_(Русский)
systemctl edit юнит
аналог epm purge: запоминаем список файлов, удаляем пакеты и по возможности всё, от чего зависит (рекурсивно).
--interactive
встроить вычисление зависимость сюда rpmreqs
хочется видеть прямые зависимости, обратные, и рекурсивно.
выводить в цивилизованном виде (в прямом только с --direct)
Синхронизация списков файлов по пакетам:
rsync -av --inplace --progress --compress
Но лучше получать с сервиса
epm sf - скачивание через rsync -z для компактности?
epmqp uuid на x86_64/Ubuntu не различает архитектуру
get system checking
https://github.com/gwicke/mediawiki-containers
list перехватывается:
# serv openvpn
# service openvpn
Usage: openvpn {start|stop|reload|restart|reopen|condstop|condrestart|condreload|status|list|help}
[root@priv etc]# serv openvpn list
# chkconfig --list
# anyservice --quiet list
epmqf - если каталог есть, искать полный /usr/share/node
TODO: yaourt (pacman frontend), need we?
https://archlinux.fr/man/yaourt.8.html
/etc/eepm.conf конфиг
Проверить всё с кавычками implement distr_info as inside tool and do access via epm command
Неверно передаёт кавычки: [18:21:12] <danil> Вот так можно:
__separate_sudocmd() RED='\033[0;31m' ; NC='\033[0m' b="b" ; echo -e "aba" | sed -e "s|${b}|\\${RED}${b}\\${NC}|g" | xargs -0 printf
А другие? [18:23:40] <danil> > Ты знаешь способы?
readlink -f — что делать и нужен ли colorise_word(){ //aba b
Нужен realfullpath RED='\033[0;31m'
NC='\033[0m' b="b"
echo -e "$1" | sed -e "s|${2}|\\${RED}${2}\\${NC}|g" | xargs -0 printf
}
[18:24:18] <lav> Ну в общем-то да... Ещё можно попробовать готовый
yum list extras – имена тех пакетов, которые наличествуют в системе, но которыми в репозиториях и не пахло, то есть установленные “в лоб”, например, через
--dump-options for write simple bash completition
yum remove $(package-cleanup --orphans
https://github.com/biow0lf/prometheus-cli
$ ruby prometheus-cli.rb srpm openbox
Branch: Sisyphus
Name: openbox
Version: 3.5.0
Release: alt5
http://packages.altlinux.org/api_doc/
См. описание алгоритма установки с URL
строки в кавычках до rr (удаления репозитория) и добавления репозитория не доходят
dotty - через ссылки на реальные названия (epm req верхнего уровня)
менеджер пакетов из NetBSD — pkgsrc (команды для поиска нужных пакетов – pkgin update; pkgin avail; pkgin search).
Загрузку конфига
Использование | less теряет код возврата команды. Нужно сделать nobash решение, которое сохранит статус Использование | less теряет код возврата команды. Нужно сделать nobash решение, которое сохранит статус
Команда Команда
...@@ -17,24 +100,21 @@ docmdmore ...@@ -17,24 +100,21 @@ docmdmore
Установка (для отсутствующих файлов пакетов) и удаление (в любом случае) должны производиться с укороченными именами (которые воспримет верхний уровень) Установка (для отсутствующих файлов пакетов) и удаление (в любом случае) должны производиться с укороченными именами (которые воспримет верхний уровень)
Чтобы было легко выстраивать цепочки, нужно ввод не с консоли (если есть) воспринимать как параметры. Дописать таблицу на вики на основании реализованных команд.
То же для EPM
2. Дописать таблицу на вики на основании реализованных команд. Было предложение вывернуть:
3. Доделать и проверить deplist|requires
https://wiki.archlinux.org/index.php/Pacman_Rosetta
Вывернуть:
Не case по каждой системе, а в каталоге по каждой системе разместить файлы, выполняющие нужные действия. Не case по каждой системе, а в каталоге по каждой системе разместить файлы, выполняющие нужные действия.
apt-rpm/install apt-rpm/install
apt-rpm/remove apt-rpm/remove
<<<<<<< HEAD
при упаковке лучше собирать в один файл. при упаковке лучше собирать в один файл.
Внесто общих функций тоже модули. Внесто общих функций тоже модули.
<<<<<<< HEAD <<<<<<< HEAD
======= =======
=======
>>>>>>> 2.5.8-alt1
serv должен уметь показывать порядок загрузки? serv должен уметь показывать порядок загрузки?
>>>>>>> master >>>>>>> master
#!/bin/sh #!/bin/sh
# Author: Vitaly Lipatov <lav@etersoft.ru> # Author: Vitaly Lipatov <lav@etersoft.ru>
# 2007, 2009, 2010, 2012 (c) Etersoft # 2007, 2009, 2010, 2012, 2016, 2017, 2018 (c) Etersoft
# 2007 Public domain # 2007-2018 Public domain
# Detect the distro and version # Detect the distro and version
# Welcome to send updates! # Welcome to send updates!
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
# You can set ROOTDIR to root system dir # You can set ROOTDIR to root system dir
#ROOTDIR= #ROOTDIR=
# TODO: check /etc/system-release
# Check for DISTRO specific file in /etc # Check for DISTRO specific file in /etc
distro() distro()
{ {
...@@ -25,12 +27,34 @@ has() ...@@ -25,12 +27,34 @@ has()
grep "$*" "$DISTROFILE" >/dev/null 2>&1 grep "$*" "$DISTROFILE" >/dev/null 2>&1
} }
# Has a system the specified command?
hascommand()
{
which $1 2>/dev/null >/dev/null
}
firstupper()
{
echo "$*" | sed 's/.*/\u&/'
}
tolower()
{
# tr is broken in busybox (checked with OpenWrt)
#echo "$*" | tr "[:upper:]" "[:lower:]"
echo "$*" | awk '{print tolower($0)}'
}
# Translate DISTRIB_ID to vendor name (like %_vendor does) # Translate DISTRIB_ID to vendor name (like %_vendor does)
rpmvendor() rpmvendor()
{ {
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return [ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
[ "$DISTRIB_ID" = "AstraLinux" ] && echo "astra" && return
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return [ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
echo "$DISTRIB_ID" | tr "[A-Z]" "[a-z]" [ "$DISTRIB_ID" = "TinyCoreLinux" ] && echo "tcl" && return
[ "$DISTRIB_ID" = "VoidLinux" ] && echo "void" && return
[ "$DISTRIB_ID" = "OpenSUSE" ] && echo "suse" && return
tolower "$DISTRIB_ID"
} }
# Translate DISTRIB_ID name to package manner (like in the package release name) # Translate DISTRIB_ID name to package manner (like in the package release name)
...@@ -43,18 +67,24 @@ pkgvendor() ...@@ -43,18 +67,24 @@ pkgvendor()
# Print pkgtype (need DISTRIB_ID var) # Print pkgtype (need DISTRIB_ID var)
pkgtype() pkgtype()
{ {
case `pkgvendor` in # TODO: try use generic names
case $(pkgvendor) in
freebsd) echo "tbz" ;; freebsd) echo "tbz" ;;
sunos) echo "pkg.gz" ;; sunos) echo "pkg.gz" ;;
slackware|mopslinux) echo "tgz" ;; slackware|mopslinux) echo "tgz" ;;
archlinux) echo "pkg.tar.xz" ;; archlinux|manjaro) echo "pkg.tar.xz" ;;
gentoo) echo "tbz2" ;; gentoo) echo "tbz2" ;;
windows) echo "exe" ;; windows) echo "exe" ;;
android) echo "apk" ;; android) echo "apk" ;;
debian|ubuntu|mint|runtu) echo "deb" ;; alpine) echo "apk" ;;
tinycorelinux) echo "tcz" ;;
voidlinux) echo "xbps" ;;
openwrt) echo "ipk" ;;
cygwin) echo "tar.xz" ;;
debian|ubuntu|mint|runtu|mcst|astra) echo "deb" ;;
alt|asplinux|suse|mandriva|rosa|mandrake|pclinux|sled|sles) alt|asplinux|suse|mandriva|rosa|mandrake|pclinux|sled|sles)
echo "rpm" ;; echo "rpm" ;;
fedora|redhat|scientific|centos|rhel) fedora|redhat|scientific|centos|rhel|goslinux|amzn)
echo "rpm" ;; echo "rpm" ;;
*) echo "rpm" ;; *) echo "rpm" ;;
esac esac
...@@ -62,8 +92,8 @@ pkgtype() ...@@ -62,8 +92,8 @@ pkgtype()
get_var() get_var()
{ {
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" # get first variable and print it out, drop quotes if exists
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" | sed -e "s/^[\'\"]\(.*\)[\'\"]/\1/"
} }
# 2010.1 -> 2010 # 2010.1 -> 2010
...@@ -75,52 +105,71 @@ get_major_version() ...@@ -75,52 +105,71 @@ get_major_version()
# Default values # Default values
DISTRIB_ID="Generic" DISTRIB_ID="Generic"
DISTRIB_RELEASE="" DISTRIB_RELEASE=""
DISTRIB_CODENAME=""
# Default with LSB # Default with LSB
if distro lsb-release ; then if distro lsb-release ; then
DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID` DISTRIB_ID=$(cat $DISTROFILE | get_var DISTRIB_ID)
DISTRIB_RELEASE=`cat $DISTROFILE | get_var DISTRIB_RELEASE` DISTRIB_RELEASE=$(cat $DISTROFILE | get_var DISTRIB_RELEASE)
DISTRIB_CODENAME=$(cat $DISTROFILE | get_var DISTRIB_CODENAME)
fi fi
# ALT Linux based # ALT Linux based
if distro altlinux-release ; then if distro altlinux-release ; then
DISTRIB_ID="ALTLinux" DISTRIB_ID="ALTLinux"
if has Strawberry ; then DISTRIB_RELEASE="2.3" if has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
elif has Citron ; then DISTRIB_RELEASE="2.4" elif has "ALT Linux 7." ; then DISTRIB_RELEASE="p7"
elif has 20050723 ; then DISTRIB_RELEASE="3.0" elif has "ALT Linux t7." ; then DISTRIB_RELEASE="t7"
elif has Ajuga ; then DISTRIB_RELEASE="4.0" elif has "ALT Linux 8." ; then DISTRIB_RELEASE="p8"
elif has 20070810 ; then DISTRIB_RELEASE="4.0" elif has "ALT .*8.[0-9]" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0" elif has "Simply Linux 6." ; then DISTRIB_RELEASE="p6"
elif has "Simply Linux 7." ; then DISTRIB_RELEASE="p7"
elif has "Simply Linux 8." ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux 6." ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p8" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5"
elif has "ALT Linux 5.1" ; then DISTRIB_RELEASE="5.1"
elif has "ALT Linux 5.0" ; then DISTRIB_RELEASE="5.0"
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1" elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
elif has Walnut ; then DISTRIB_RELEASE="4.0" elif has Walnut ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0" elif has Hypericum ; then DISTRIB_RELEASE="p8"
elif has 5.1 ; then DISTRIB_RELEASE="5.1" elif has "starter kit" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5" elif has 20070810 ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6" elif has Ajuga ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7" elif has 20050723 ; then DISTRIB_RELEASE="3.0"
elif has 6.0 ; then DISTRIB_RELEASE="p6" elif has Citron ; then DISTRIB_RELEASE="2.4"
elif has Centaurea ; then DISTRIB_RELEASE="p6"
elif has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
fi fi
elif distro gentoo-release ; then elif distro gentoo-release ; then
DISTRIB_ID="Gentoo" DISTRIB_ID="Gentoo"
MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile) MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile)
DISTRIB_RELEASE=`basename $MAKEPROFILE` DISTRIB_RELEASE=$(basename $MAKEPROFILE)
echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=`basename $(dirname $MAKEPROFILE)` echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=$(basename "$(dirname $MAKEPROFILE)") #"
# Slackware based
elif distro mopslinux-version ; then
DISTRIB_ID="MOPSLinux"
if has 4.0 ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has 6.0 ; then DISTRIB_RELEASE="6.0"
elif has 6.1 ; then DISTRIB_RELEASE="6.1"
fi
elif distro slackware-version ; then elif distro slackware-version ; then
DISTRIB_ID="Slackware" DISTRIB_ID="Slackware"
DISTRIB_RELEASE="$(grep -Eo [0-9]+\.[0-9]+ $DISTROFILE)" DISTRIB_RELEASE="$(grep -Eo '[0-9]+\.[0-9]+' $DISTROFILE)"
elif distro os-release && hascommand apk ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && hascommand tce-ab ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="TinyCoreLinux"
DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && hascommand xbps-query ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="VoidLinux"
DISTRIB_RELEASE="Live"
elif distro arch-release ; then elif distro arch-release ; then
DISTRIB_ID="ArchLinux" DISTRIB_ID="ArchLinux"
...@@ -129,6 +178,22 @@ elif distro arch-release ; then ...@@ -129,6 +178,22 @@ elif distro arch-release ; then
DISTRIB_RELEASE="2011" DISTRIB_RELEASE="2011"
fi fi
# Elbrus
elif distro mcst_version ; then
DISTRIB_ID="MCST"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g")
# OpenWrt
elif distro openwrt_release ; then
. $DISTROFILE
DISTRIB_RELEASE=$(cat $ROOTDIR/etc/openwrt_version)
elif distro astra_version ; then
#DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID`
DISTRIB_ID="AstraLinux"
#DISTRIB_RELEASE=$(cat "$DISTROFILE" | head -n1 | sed -e "s|.* \([a-z]*\).*|\1|g")
DISTRIB_RELEASE=$DISTRIB_CODENAME
# for Ubuntu use standard LSB info # for Ubuntu use standard LSB info
elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB version # use LSB version
...@@ -137,7 +202,7 @@ elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then ...@@ -137,7 +202,7 @@ elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# Debian based # Debian based
elif distro debian_version ; then elif distro debian_version ; then
DISTRIB_ID="Debian" DISTRIB_ID="Debian"
DISTRIB_RELEASE=`cat $DISTROFILE` DISTRIB_RELEASE=$(cat $DISTROFILE | sed -e "s/\..*//g")
# Mandriva based # Mandriva based
...@@ -164,26 +229,6 @@ elif distro mandriva-release || distro mandrake-release ; then ...@@ -164,26 +229,6 @@ elif distro mandriva-release || distro mandrake-release ; then
fi fi
# Fedora based # Fedora based
elif distro linux-xp-release || distro lxp-release; then
DISTRIB_ID="LinuxXP"
if has "Attack of the Clones" ; then DISTRIB_RELEASE="2006"
elif has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
elif has "2009" ; then DISTRIB_RELEASE="2009"
fi
elif distro asplinux-release ; then
DISTRIB_ID="ASPLinux"
if has Karelia ; then DISTRIB_RELEASE="10"
elif has Seliger ; then DISTRIB_RELEASE="11"
elif has "11.1" ; then DISTRIB_RELEASE="11.1"
elif has Ladoga ; then DISTRIB_RELEASE="11.2"
elif has "11.2" ; then DISTRIB_RELEASE="11.2"
elif has "12" ; then DISTRIB_RELEASE="12"
elif has "13" ; then DISTRIB_RELEASE="13"
elif has "14" ; then DISTRIB_RELEASE="14"
elif has "15" ; then DISTRIB_RELEASE="15"
fi
elif distro MCBC-release ; then elif distro MCBC-release ; then
DISTRIB_ID="MCBC" DISTRIB_ID="MCBC"
...@@ -193,7 +238,7 @@ elif distro MCBC-release ; then ...@@ -193,7 +238,7 @@ elif distro MCBC-release ; then
elif distro fedora-release ; then elif distro fedora-release ; then
DISTRIB_ID="Fedora" DISTRIB_ID="Fedora"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") #"
elif distro redhat-release ; then elif distro redhat-release ; then
# FIXME if need # FIXME if need
...@@ -203,18 +248,17 @@ elif distro redhat-release ; then ...@@ -203,18 +248,17 @@ elif distro redhat-release ; then
DISTRIB_ID="CentOS" DISTRIB_ID="CentOS"
elif has Scientific ; then elif has Scientific ; then
DISTRIB_ID="Scientific" DISTRIB_ID="Scientific"
elif has GosLinux ; then
DISTRIB_ID="GosLinux"
fi fi
if has Beryllium ; then if has Beryllium ; then
DISTRIB_ID="Scientific" DISTRIB_ID="Scientific"
DISTRIB_RELEASE="4.1" DISTRIB_RELEASE="4.1"
elif has Shrike ; then
DISTRIB_ID="RedHat"
DISTRIB_RELEASE="9"
elif has Taroon ; then DISTRIB_RELEASE="3"
elif has "release 4" ; then DISTRIB_RELEASE="4" elif has "release 4" ; then DISTRIB_RELEASE="4"
elif has "release 5" ; then DISTRIB_RELEASE="5" elif has "release 5" ; then DISTRIB_RELEASE="5"
elif has "release 6" ; then DISTRIB_RELEASE="6" elif has "release 6" ; then DISTRIB_RELEASE="6"
elif has "release 7" ; then DISTRIB_RELEASE="7" elif has "release 7" ; then DISTRIB_RELEASE="7"
elif has "release 8" ; then DISTRIB_RELEASE="8"
fi fi
# SUSE based # SUSE based
...@@ -227,38 +271,181 @@ elif distro SuSe-release || distro SuSE-release ; then ...@@ -227,38 +271,181 @@ elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SLES" DISTRIB_ID="SLES"
fi fi
# https://www.freedesktop.org/software/systemd/man/os-release.html
elif distro os-release ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID"
[ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR"
if [ "$ID" = "opensuse-leap" ] ; then
DISTRIB_ID="SUSE"
fi
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ `uname` = "FreeBSD" ] ; then elif [ "$(uname)" = "FreeBSD" ] ; then
DISTRIB_ID="FreeBSD" DISTRIB_ID="FreeBSD"
UNAME=$(uname -r) UNAME=$(uname -r)
DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g") DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g")
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ `uname` = "SunOS" ] ; then elif [ "$(uname)" = "SunOS" ] ; then
DISTRIB_ID="SunOS" DISTRIB_ID="SunOS"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ `uname` = "Darwin" ] ; then elif [ "$(uname -s 2>/dev/null)" = "Darwin" ] ; then
DISTRIB_ID="MacOS" DISTRIB_ID="MacOS"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: move to up # fixme: move to up
elif [ `uname` = "Linux" ] && which guix 2>/dev/null >/dev/null ; then elif [ "$(uname)" = "Linux" ] && hascommand guix ; then
DISTRIB_ID="GNU/Linux/Guix" DISTRIB_ID="GNU/Linux/Guix"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: move to up # fixme: move to up
elif [ `uname` = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then elif [ "$(uname)" = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then
DISTRIB_ID="Android" DISTRIB_ID="Android"
DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]') DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]')
elif [ "$(uname -o 2>/dev/null)" = "Cygwin" ] ; then
DISTRIB_ID="Cygwin"
DISTRIB_RELEASE="all"
# try use standart LSB info by default # try use standart LSB info by default
elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB # use LSB
true
# fix distro name
case "$DISTRIB_ID" in
"openSUSE Tumbleweed")
DISTRIB_ID="SUSE"
DISTRIB_RELEASE="Tumbleweed"
;;
esac
fi fi
get_uname()
{
tolower $(uname $1) | tr -d " \t\r\n"
}
get_base_os_name()
{
local DIST_OS
# Resolve the os
DIST_OS="$(get_uname -s)"
case "$DIST_OS" in
'sunos')
DIST_OS="solaris"
;;
'hp-ux' | 'hp-ux64')
DIST_OS="hpux"
;;
'darwin' | 'oarwin')
DIST_OS="macosx"
;;
'unix_sv')
DIST_OS="unixware"
;;
'freebsd' | 'openbsd' | 'netbsd')
DIST_OS="freebsd"
;;
esac
echo "$DIST_OS"
}
get_arch()
{
local DIST_ARCH
# Resolve the architecture
DIST_ARCH="$(get_uname -m)"
case "$DIST_ARCH" in
'ia32' | 'i386' | 'i486' | 'i586' | 'i686')
DIST_ARCH="x86"
;;
'amd64' | 'x86_64')
DIST_ARCH="x86_64"
;;
'ia64' | 'ia-64')
DIST_ARCH="ia64"
;;
'ip27' | 'mips')
DIST_ARCH="mips"
;;
'powermacintosh' | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
DIST_ARCH="ppc"
;;
'pa_risc' | 'pa-risc')
DIST_ARCH="parisc"
;;
'sun4u' | 'sparcv9')
DIST_ARCH="sparc"
;;
'9000/800')
DIST_ARCH="parisc"
;;
armv*)
if [ -z "$(readelf -A /proc/self/exe | grep Tag_ABI_VFP_args)" ] ; then
DIST_ARCH="armel"
else
DIST_ARCH="armhf"
fi
;;
esac
echo "$DIST_ARCH"
}
get_bit_size()
{
local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now...
DIST_BIT="$(get_uname -m)"
case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64"
;;
'aarch64')
DIST_BIT="64"
;;
# 'pa_risc' | 'pa-risc') # Are some of these 64bit? Least not all...
# BIT="64"
# ;;
'sun4u' | 'sparcv9') # Are all sparcs 64?
DIST_BIT="64"
;;
# '9000/800')
# DIST_BIT="64"
# ;;
*) # In any other case default to 32
DIST_BIT="32"
;;
esac
echo "$DIST_BIT"
}
# TODO: check before calc
get_memory_size() {
local detected=0
local DIST_OS="$(get_base_os_name)"
case "$DIST_OS" in
macosx)
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
;;
freebsd)
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
;;
linux)
[ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
;;
esac
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected
}
case $1 in case $1 in
-p) -p)
# override DISTRIB_ID # override DISTRIB_ID
...@@ -271,6 +458,10 @@ case $1 in ...@@ -271,6 +458,10 @@ case $1 in
echo "Usage: distr_vendor [options] [args]" echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system" echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name" echo "-d - print distro name"
echo "-a - print hardware architecture"
echo "-b - print size of arch bit (32/64)"
echo "-m - print system memory size (in MB)"
echo "-o - print base os name"
echo "-v - print version of distro" echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)" echo "-e - print full name of distro with version (by default)"
echo "-s [SystemName] - print name of distro for build system (like in the package release name)" echo "-s [SystemName] - print name of distro for build system (like in the package release name)"
...@@ -282,6 +473,18 @@ case $1 in ...@@ -282,6 +473,18 @@ case $1 in
-d) -d)
echo $DISTRIB_ID echo $DISTRIB_ID
;; ;;
-a)
get_arch
;;
-b)
get_bit_size
;;
-m)
get_memory_size
;;
-o)
get_base_os_name
;;
-v) -v)
echo $DISTRIB_RELEASE echo $DISTRIB_RELEASE
;; ;;
...@@ -298,7 +501,7 @@ case $1 in ...@@ -298,7 +501,7 @@ case $1 in
exit 0 exit 0
;; ;;
-V) -V)
echo "20120519" echo "20171010"
exit 0 exit 0
;; ;;
*) *)
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2014 Etersoft # Copyright (C) 2012-2018 Etersoft
# Copyright (C) 2012-2014 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
...@@ -17,17 +17,24 @@ ...@@ -17,17 +17,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
PROGDIR=$(dirname $0) PROGDIR=$(dirname "$0")
PROGNAME=$(basename "$0")
[ "$PROGDIR" = "." ] && PROGDIR=$(pwd) [ "$PROGDIR" = "." ] && PROGDIR=$(pwd)
if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
PROGDIR=""
PROGNAME=""
fi
# will replaced to /usr/share/eepm during install # will replaced to /usr/share/eepm during install
SHAREDIR=$PROGDIR SHAREDIR=$PROGDIR
CONFIGDIR=$PROGDIR/..
load_helper() load_helper()
{ {
local CMD="$SHAREDIR/$1" local CMD="$SHAREDIR/$1"
# do not use fatal() here, it can be initial state # do not use fatal() here, it can be initial state
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; } [ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
# shellcheck disable=SC1090
. $CMD . $CMD
} }
...@@ -36,6 +43,8 @@ load_helper epm-sh-functions ...@@ -36,6 +43,8 @@ load_helper epm-sh-functions
#PATH=$PATH:/sbin:/usr/sbin #PATH=$PATH:/sbin:/usr/sbin
set_pm_type
set_sudo set_sudo
check_tty check_tty
...@@ -58,7 +67,7 @@ print_version() ...@@ -58,7 +67,7 @@ print_version()
{ {
echo "EPM package manager version @VERSION@" echo "EPM package manager version @VERSION@"
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-2014" echo "Copyright (c) Etersoft 2012-2018"
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."
} }
...@@ -66,28 +75,39 @@ print_version() ...@@ -66,28 +75,39 @@ 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"
set_pm_type EPMVERSION=@VERSION@
verbose= verbose=
quiet= quiet=
nodeps= nodeps=
noremove=
dryrun=
force= force=
repack=
scripts=
short= short=
direct=
sort= sort=
non_interactive= non_interactive=
skip_installed= skip_installed=
show_command_only= show_command_only=
epm_cmd= epm_cmd=
pkg_files= pkg_files=
pkg_dirs=
pkg_names= pkg_names=
pkg_urls=
quoted_args= quoted_args=
progname="${0##*/}" # 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
;; ;;
epmI)
epm_cmd=Install
;;
epme) epme)
epm_cmd=remove epm_cmd=remove
;; ;;
...@@ -118,17 +138,25 @@ case $progname in ...@@ -118,17 +138,25 @@ case $progname in
epmql) epmql)
epm_cmd=filelist epm_cmd=filelist
;; ;;
epmrl)
epm_cmd=repolist
;;
epmu) epmu)
epm_cmd=update epm_cmd=update
;; ;;
epm|upm|eepm) epm|upm|eepm)
;; ;;
epm.sh)
;;
*) *)
# epm by default # epm by default
# fatal "Unknown command: $progname" # fatal "Unknown command: $progname"
;; ;;
esac esac
# was called with alias name
[ -n "$epm_cmd" ] && PROGNAME="epm"
check_command() check_command()
{ {
# do not override command # do not override command
...@@ -139,10 +167,10 @@ check_command() ...@@ -139,10 +167,10 @@ check_command()
-i|install|add|i) # HELPCMD: install package(s) from remote repositories or from local file -i|install|add|i) # HELPCMD: install package(s) from remote repositories or from local file
epm_cmd=install epm_cmd=install
;; ;;
-e|-P|remove|delete|uninstall|erase|e) # HELPCMD: remove (delete) package(s) from the database and the system -e|-P|rm|del|remove|delete|uninstall|erase|e) # HELPCMD: remove (delete) package(s) from the database and the system
epm_cmd=remove epm_cmd=remove
;; ;;
-s|search) # HELPCMD: search in remote package repositories -s|search|s) # HELPCMD: search in remote package repositories
epm_cmd=search epm_cmd=search
;; ;;
-qp|qp|query_package) # HELPCMD: search in the list of installed packages -qp|qp|query_package) # HELPCMD: search in the list of installed packages
...@@ -171,7 +199,7 @@ check_command() ...@@ -171,7 +199,7 @@ check_command()
check|fix|verify) # HELPCMD: check local package base integrity and fix it check|fix|verify) # HELPCMD: check local package base integrity and fix it
epm_cmd=check epm_cmd=check
;; ;;
changelog|cl|-cl) # HELPCMD: show changelog for package -cl|cl|changelog) # HELPCMD: show changelog for package
epm_cmd=changelog epm_cmd=changelog
;; ;;
-qi|qi|info|show) # HELPCMD: print package detail info -qi|qi|info|show) # HELPCMD: print package detail info
...@@ -183,7 +211,7 @@ check_command() ...@@ -183,7 +211,7 @@ check_command()
provides|prov) # HELPCMD: print package provides provides|prov) # HELPCMD: print package provides
epm_cmd=provides epm_cmd=provides
;; ;;
whatdepends) # HELPCMD: print packages dependences on that whatdepends|wd) # HELPCMD: print packages dependences on that
epm_cmd=whatdepends epm_cmd=whatdepends
;; ;;
whatprovides) # HELPCMD: print packages provides that target whatprovides) # HELPCMD: print packages provides that target
...@@ -192,56 +220,97 @@ check_command() ...@@ -192,56 +220,97 @@ check_command()
conflicts) # HELPCMD: print package conflicts conflicts) # HELPCMD: print package conflicts
epm_cmd=conflicts epm_cmd=conflicts
;; ;;
-qa|list|packages|-l|qa) # HELPCMD: print list of installed package(s) -qa|qa|-l|list|packages) # HELPCMD: print list of installed package(s)
epm_cmd=packages epm_cmd=packages
;; ;;
programs) # HELPCMD: print list of installed GUI program(s) programs) # HELPCMD: print list of installed GUI program(s) (they have .desktop files)
epm_cmd=programs epm_cmd=programs
;; ;;
assure) # HELPCMD: <command> [package]: install package if command does not exists assure) # HELPCMD: <command> [package]: install package if command does not exist
epm_cmd=assure epm_cmd=assure
;; ;;
policy) # HELPCMD: print detailed information about the priority selection of package
epm_cmd=policy
;;
# Repository control # Repository control
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) # 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)
epm_cmd=repofix
;;
removerepo|rr) # HELPCMD: remove package repo removerepo|rr) # HELPCMD: remove package repo
epm_cmd=removerepo epm_cmd=removerepo
;; ;;
release-upgrade) # 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
epm_cmd=kernel_update epm_cmd=kernel_update
;; ;;
remove-old-kernels|remove-old-kernel) # HELPCMD: remove old system kernels (exclude current or last two kernels)
epm_cmd=remove_old_kernels
;;
# Other commands # Other commands
clean) # HELPCMD: clean local package cache clean) # HELPCMD: clean local package cache
epm_cmd=clean epm_cmd=clean
;; ;;
autoremove) # HELPCMD: auto remove unneeded package(s) autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [libs|python|perl|libs-devel]
epm_cmd=autoremove epm_cmd=autoremove
;; ;;
autoorphans|--orphans) # HELPCMD: remove all packages not from the repository
epm_cmd=autoorphans
;;
upgrade|dist-upgrade) # HELPCMD: performs upgrades of package software distributions upgrade|dist-upgrade) # HELPCMD: performs upgrades of package software distributions
epm_cmd=upgrade epm_cmd=upgrade
;; ;;
Upgrade) # HELPCMD: force update package base, then run upgrade Upgrade) # HELPCMD: force update package base, then run upgrade
epm_cmd=Upgrade epm_cmd=Upgrade
;; ;;
downgrade) # HELPCMD: downgrade [all] packages to the repo state
epm_cmd=downgrade
;;
download) # HELPCMD: download package(s) file to the current dir
epm_cmd=download
;;
# TODO: replace with install --simulate
simulate) # HELPCMD: simulate install with check requires simulate) # HELPCMD: simulate install with check requires
epm_cmd=simulate epm_cmd=simulate
;; ;;
checkpkg|integrity) # HELPCMD: check package file integrity (checksum) audit) # HELPCMD: audits installed packages against known vulnerabilities
epm_cmd=audit
;;
#checksystem) # HELPCMD: check system for known errors (package management related)
# epm_cmd=checksystem
# ;;
site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site)
epm_cmd=site
;;
ei|ik|epminstall|epm-install|selfinstall) # HELPCMD: install package(s) from Korinf (eepm by default)
epm_cmd=epm_install
;;
print) # HELPCMD: print various info, run epm print help for details
epm_cmd=print
;;
repack) # HELPCMD: repack rpm to local compatibility
epm_cmd=repack
;;
-V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum)
epm_cmd=checkpkg epm_cmd=checkpkg
;; ;;
-h|--help|help) # HELPOPT: print this help
help=1
phelp
exit 0
;;
*) *)
return 1 return 1
;; ;;
...@@ -252,10 +321,6 @@ check_command() ...@@ -252,10 +321,6 @@ check_command()
check_option() check_option()
{ {
case $1 in case $1 in
-h|--help|help) # HELPOPT: this help
phelp
exit 0
;;
-v|--version) # HELPOPT: print version -v|--version) # HELPOPT: print version
print_version print_version
exit 0 exit 0
...@@ -269,7 +334,7 @@ check_option() ...@@ -269,7 +334,7 @@ check_option()
--show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY) --show-command-only) # HELPOPT: show command only, do not any action (supports install and remove ONLY)
show_command_only=1 show_command_only=1
;; ;;
--quiet) # HELPOPT: quiet mode (do not print commands before exec) --quiet|--silent) # HELPOPT: quiet mode (do not print commands before exec)
quiet=1 quiet=1
;; ;;
--nodeps) # HELPOPT: skip dependency check (during install/simulate and so on) --nodeps) # HELPOPT: skip dependency check (during install/simulate and so on)
...@@ -278,13 +343,29 @@ check_option() ...@@ -278,13 +343,29 @@ check_option()
--force) # HELPOPT: force install/remove package (f.i., override) --force) # HELPOPT: force install/remove package (f.i., override)
force="--force" force="--force"
;; ;;
--noremove|--no-remove) # HELPOPT: exit if any packages are to be removed during upgrade
noremove="--no-remove"
;;
--dry-run|--simulate|--just-print|-recon--no-act) # HELPOPT: print only (autoremove/autoorphans/remove only)
dryrun="--dry-run"
;;
--short) # HELPOPT: short output (just 'package' instead 'package-version-release') --short) # HELPOPT: short output (just 'package' instead 'package-version-release')
short="--short" short="--short"
;; ;;
--direct) # HELPOPT: direct install package file from ftp (not via hilevel repository manager)
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?
sort="$1" sort="$1"
;; ;;
--auto) # HELPOPT: non interactive mode --auto|--non-interactive) # HELPOPT: non interactive mode
non_interactive=1 non_interactive=1
;; ;;
*) *)
...@@ -296,14 +377,20 @@ check_option() ...@@ -296,14 +377,20 @@ check_option()
check_filenames() check_filenames()
{ {
local opt="$1" local opt
for opt in "$@" ; do
# files can be with full path or have extension via . # files can be with full path or have extension via .
if [ -f "$opt" ] && echo "$opt" | grep -q "[/\.]" ; then if [ -f "$opt" ] && echo "$opt" | grep -q "[/\.]" ; then
pkg_files="$pkg_files $opt" pkg_files="$pkg_files $opt"
elif [ -d "$opt" ] ; then
pkg_dirs="$pkg_dirs $opt"
elif echo "$opt" | grep -q "://" ; then
pkg_urls="$pkg_urls $opt"
else else
pkg_names="$pkg_names $opt" pkg_names="$pkg_names $opt"
fi fi
quoted_args="$quoted_args \"$opt\"" quoted_args="$quoted_args \"$opt\""
done
} }
FLAGENDOPTS= FLAGENDOPTS=
...@@ -313,18 +400,26 @@ for opt in "$@" ; do ...@@ -313,18 +400,26 @@ for opt in "$@" ; do
check_command $opt && continue check_command $opt && continue
check_option $opt && continue check_option $opt && continue
fi fi
# Note: will parse all params separately (no package names with spaces!)
check_filenames $opt check_filenames $opt
done done
# if input is not console, get pkg from it too # if input is not console and run script from file, get pkgs from stdin too
if ! inputisatty ; then if ! inputisatty && [ -n "$PROGDIR" ] ; then
for opt in $(timeout 1 cat) ; do for opt in $(withtimeout 2 cat) ; do
# FIXME: do not work
# workaround against # yes | epme
[ "$opt" = "y" ] && break;
[ "$opt" = "yes" ] && break;
check_filenames $opt check_filenames $opt
done done
fi fi
pkg_files=$(strip_spaces "$pkg_files") pkg_files=$(strip_spaces "$pkg_files")
pkg_names=$(strip_spaces "$pkg_names") pkg_dirs=$(strip_spaces "$pkg_dirs")
# in common case dirs equals to names only suddenly
pkg_names=$(strip_spaces "$pkg_names $pkg_dirs")
pkg_urls=$(strip_spaces "$pkg_urls")
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names") pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
...@@ -337,7 +432,9 @@ pkg_filenames=$(strip_spaces "$pkg_files $pkg_names") ...@@ -337,7 +432,9 @@ pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
if [ -z "$epm_cmd" ] ; then if [ -z "$epm_cmd" ] ; then
print_version print_version
echo echo
fatal "Run $ $progname --help for get help" fatstr="Unknown command in $* arg(s)"
[ -n "$*" ] || fatstr="That program needs be running with some command"
fatal "$fatstr. Run $ $PROGNAME --help to get help."
fi fi
# Use eatmydata for write specific operations # Use eatmydata for write specific operations
......
...@@ -33,7 +33,7 @@ epm_Install() ...@@ -33,7 +33,7 @@ epm_Install()
yum-rpm) yum-rpm)
;; ;;
*) *)
epm_update || return pkg_filenames='' epm_update || return
;; ;;
esac esac
......
...@@ -26,7 +26,7 @@ epm_Upgrade() ...@@ -26,7 +26,7 @@ epm_Upgrade()
yum-rpm) yum-rpm)
;; ;;
*) *)
epm_update || return pkg_filenames='' epm_update || return
;; ;;
esac esac
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2017 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -17,27 +17,112 @@ ...@@ -17,27 +17,112 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-sh-altlinux
__epm_addrepo_altlinux()
{
local repo="$@"
case "$1" in
etersoft)
info "add Etersoft's addon repo"
load_helper epm-query
epm install --skip-installed apt-conf-etersoft-common apt-conf-etersoft-hold
# TODO: ignore only error code 22 (skipped) || fatal
local branch="$DISTRVERSION/branch"
[ "$DISTRVERSION" = "Sisyphus" ] && branch="$DISTRVERSION"
# FIXME
[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
# TODO: func?
local arch=$(uname -m)
[ "$arch" = "i686" ] && arch="i586"
# TODO: use apt-repo add ?
echo "" | sudocmd tee -a /etc/apt/sources.list
echo "# added with eepm addrepo etersoft" | sudocmd tee -a /etc/apt/sources.list
echo "rpm [etersoft] http://download.etersoft.ru/pub/Etersoft LINUX@Etersoft/$branch/$arch addon" | sudocmd tee -a /etc/apt/sources.list
if [ "$arch" = "x86_64" ] ; then
echo "rpm [etersoft] http://download.etersoft.ru/pub/Etersoft LINUX@Etersoft/$branch/$arch-i586 addon" | sudocmd tee -a /etc/apt/sources.list
fi
echo "rpm [etersoft] http://download.etersoft.ru/pub/Etersoft LINUX@Etersoft/$branch/noarch addon" | sudocmd tee -a /etc/apt/sources.list
repo="$DISTRVERSION"
return 0
;;
autoimports)
[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
;;
archive)
datestr="$2"
echo "$datestr" | grep -Eq "^20[0-2][0-9]/[01][0-9]/[0-3][0-9]$" || fatal "use follow date format: 2017/12/31"
# TODO: func?
local arch=$(uname -m)
[ "$arch" = "i686" ] && arch="i586"
echo "" | sudocmd tee -a /etc/apt/sources.list
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
echo "rpm $rpmsign http://ftp.altlinux.org/pub/distributions archive/$distrversion/date/$datestr/$arch-i586 classic" | sudocmd tee -a /etc/apt/sources.list
fi
echo "rpm $rpmsign http://ftp.altlinux.org/pub/distributions archive/$distrversion/date/$datestr/noarch classic" | sudocmd tee -a /etc/apt/sources.list
return 0
;;
esac
assure_exists apt-repo
if tasknumber "$repo" >/dev/null ; then
sudocmd apt-repo add $(tasknumber "$repo")
return
fi
if [ -z "$repo" ] ; then
info "Add branch repo. Use follow params:"
sudocmd apt-repo add branch
echo "etersoft (for LINUX@Etersoft repo)"
echo "archive 2018/02/09 (for archive from that date)"
return
fi
sudocmd apt-repo add "$repo"
}
epm_addrepo() epm_addrepo()
{ {
local repo="$(eval echo "$quoted_args")"
case $DISTRNAME in
ALTLinux)
__epm_addrepo_altlinux $repo
return
;;
esac
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-dpkg)
assure_exists apt-repo assure_exists apt-add-repository software-properties-common
sudocmd apt-repo add $pkg_filenames if echo "$repo" | grep -q "https://" ; then
assure_exists apt-transport-https
fi
sudocmd apt-add-repository "$repo"
info "Check file /etc/apt/sources.list if needed"
;; ;;
apt-dpkg|aptitude-dpkg) aptitude-dpkg)
info "You need manually add repo to /etc/apt/sources.list" info "You need manually add repo to /etc/apt/sources.list (TODO)"
;; ;;
yum-rpm) yum-rpm)
info "You need manually add repo to /etc/yum.repos.d/" assure_exists yum-utils
sudocmd yum-config-manager --add-repo "$repo"
;; ;;
urpm-rpm) urpm-rpm)
sudocmd urpmi.addmedia $pkg_filenames sudocmd urpmi.addmedia "$repo"
;; ;;
zypper-rpm) zypper-rpm)
sudocmd zypper ar $pkg_filenames sudocmd zypper ar "$repo"
;; ;;
emerge) emerge)
sudocmd layman -a $pkg_filenames sudocmd layman -a "$repo"
;; ;;
pacman) pacman)
info "You need manually add repo to /etc/pacman.conf" info "You need manually add repo to /etc/pacman.conf"
...@@ -45,7 +130,7 @@ case $PMTYPE in ...@@ -45,7 +130,7 @@ case $PMTYPE in
#sudocmd repo-add $pkg_filenames #sudocmd repo-add $pkg_filenames
;; ;;
npackd) npackd)
sudocmd npackdcl add-repo --url=$pkg_filenames sudocmd npackdcl add-repo --url="$repo"
;; ;;
slackpkg) slackpkg)
info "You need manually add repo to /etc/slackpkg/mirrors" info "You need manually add repo to /etc/slackpkg/mirrors"
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2013, 2014 Etersoft # Copyright (C) 2013-2016 Etersoft
# Copyright (C) 2013, 2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2013-2016 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,42 +17,103 @@ ...@@ -17,42 +17,103 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-install
__check_command_in_path() __check_command_in_path()
{ {
PATH=$PATH:/sbin:/usr/sbin which "$1" 2>/dev/null PATH=$PATH:/sbin:/usr/sbin which "$1" 2>/dev/null
} }
# Do fast checking for command and install package if the command does not exist # copied from strings
# CHECKME: the same like estrlist has ?
# Note: used egrep! write '[0-9]+(first|two)', not '[0-9]\+...'
rhas()
{
echo "$1" | grep -E -q -- "$2"
}
# $1 - command name # copied from strings
# $2 - package name is_dirpath()
{
[ "$1" = "." ] && return $?
rhas "$1" "/"
}
__epm_assure() __epm_need_update()
{ {
if __check_command_in_path "$1" >/dev/null ; then local PACKAGE="$1"
local PACKAGEVERSION="$2"
[ -n "$PACKAGEVERSION" ] || return 0
load_helper epm-query
is_installed "$PACKAGE" || return 0
load_helper epm-print
# epm print version for package N
local INSTALLEDVERSION=$(query_package_field "version" "$PACKAGE")
# if needed >= installed, return 0
[ "$(compare_version "$PACKAGEVERSION" "$INSTALLEDVERSION")" -gt 0 ] && return 0
return 1
}
__epm_assure_checking()
{
local CMD="$1"
local PACKAGE="$2"
local PACKAGEVERSION="$3"
[ -n "$PACKAGEVERSION" ] && return 1
if is_dirpath "$CMD" ; then
if [ -e "$CMD" ] ; then
if [ -n "$verbose" ] ; then
info "File or directory $CMD is already exists."
epm qf "$CMD"
fi
return 0
fi
[ -n "$PACKAGE" ] || fatal "You need run with package name param when use with absolute path"
return 1
fi
if __check_command_in_path "$CMD" >/dev/null ; then
if [ -n "$verbose" ] ; then if [ -n "$verbose" ] ; then
local compath="$(__check_command_in_path "$1")" local compath="$(__check_command_in_path "$1")"
info "Command $1 is exists: $compath" info "Command $CMD is exists: $compath"
epm qf "$compath" epm qf "$compath"
fi fi
return return 0
fi fi
# TODO: use package name normalization return 1
info "Installing appropriate package for $1 command..." }
# Do fast checking for command and install package if the command does not exist
# $1 - command name
# $2 - [package name]
# $3 - [needed package version]
__epm_assure()
{
local CMD="$1"
local PACKAGE="$2" local PACKAGE="$2"
local PACKAGEVERSION="$3"
[ -n "$PACKAGE" ] || PACKAGE="$1" [ -n "$PACKAGE" ] || PACKAGE="$1"
#epm install $2
# copied from epm_install __epm_assure_checking $CMD $PACKAGE $PACKAGEVERSION && return 0
local names="$(echo "$PACKAGE" | filter_out_installed_packages)"
info "Installing appropriate package for $CMD command..."
__epm_need_update $PACKAGE $PACKAGEVERSION || return 0
docmd epm --auto install $PACKAGE || return
non_interactive=1 epm_install_names $names [ -n "$PACKAGEVERSION" ] || return 0
# check if we couldn't update and still need update
__epm_need_update $PACKAGE $PACKAGEVERSION && return 1
return 0
} }
...@@ -61,5 +122,6 @@ epm_assure() ...@@ -61,5 +122,6 @@ epm_assure()
[ -n "$pkg_filenames" ] || fatal "Assure: Missing params. Check $0 --help for info." [ -n "$pkg_filenames" ] || fatal "Assure: Missing params. Check $0 --help for info."
# use helper func for extract separate params # use helper func for extract separate params
__epm_assure $pkg_filenames # shellcheck disable=SC2046
__epm_assure $(eval echo $quoted_args)
} }
#!/bin/sh
#
# Copyright (C) 2014 Etersoft
# Copyright (C) 2014 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
epm_audit()
{
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in
pkgng)
sudocmd pkg audit -F
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh
#
# Copyright (C) 2015, 2017 Etersoft
# Copyright (C) 2015, 2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__epm_orphan_altrpm()
{
docmd "apt-cache list-extras"
}
epm_autoorphans()
{
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in
apt-rpm)
# ALT Linux only
assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts
if [ -z "$dryrun" ] ; then
echo "We will try remove all installed packages which are missed in repositories"
warning "Use with caution!"
fi
local PKGLIST=$(__epm_orphan_altrpm \
| sed -e "s/\.32bit//g" \
| grep -v -- "^eepm$" \
| grep -v -- "^kernel")
if [ -n "$quiet" ] ; then
echo "$PKGLIST"
else
docmd epm remove $dryrun $PKGLIST
fi
;;
apt-dpkg|aptitude-dpkg)
assure_exists deborphan
showcmd deborphan
a='' deborphan | docmd epm remove $dryrun
;;
#aura)
# sudocmd aura -Oj
# ;;
yum-rpm)
docmd epm upgrade
assure_exists package-cleanup yum-utils
showcmd package-cleanup --orphans
local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
docmd epm remove $dryrun $PKGLIST
;;
dnf-rpm)
# TODO: dnf list extras
docmd epm upgrade
assure_exists package-cleanup dnf-utils
showcmd package-cleanup --orphans
local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
docmd epm remove $dryrun $PKGLIST
;;
urpm-rpm)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
else
showcmd urpme --report-orphans
sudocmd urpme --auto-orphans
fi
;;
#emerge)
# sudocmd emerge --depclean
# assure_exists revdep-rebuild
# sudocmd revdep-rebuild
# ;;
pacman)
if [ -n "$dryrun" ] ; then
info "Autoorphans packages list:"
sudocmd pacman -Qdtq
else
sudocmd pacman -Qdtq | sudocmd pacman -Rs -
fi
;;
slackpkg)
# clean-system removes non official packages
sudocmd slackpkg clean-system
;;
#guix)
# sudocmd guix gc
# ;;
#pkgng)
# sudocmd pkg autoremove
# ;;
zypper-rpm)
# https://www.linux.org.ru/forum/desktop/11931830
assure_exists zypper zypper 1.9.2
# For zypper < 1.9.2: zypper se -si | grep 'System Packages'
sudocmd zypper packages --orphaned
# FIXME: x86_64/i586 are duplicated
local PKGLIST=$(zypper packages --orphaned | tail -n +5 | cut -d \| -f 3 | sort -u)
docmd epm remove $dryrun --clean-deps $PKGLIST
;;
xbps)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
else
sudocmd xbps-remove -o
fi
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2017, 2018 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2017, 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,61 +17,219 @@ ...@@ -17,61 +17,219 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
__epm_autoremove_altrpm() load_helper epm-check_updated_repo
__epm_print_excluded()
{
local pkgs="$1"
local fullpkgs="$2"
local excluded
excluded="$(estrlist exclude "$pkgs" "$fullpkgs")"
if [ -n "$excluded" ] ; then
echo "Skipped manually installed:"
estrlist union $excluded
fi
}
__epm_autoremove_altrpm_pp()
{ {
local pkg local pkgs fullpkgs
info "Removing unused python/perl modules..."
#[ -n "$force" ] || info "You can run with --force for more deep removing"
local force=force
local libexclude="$1"
local flag= local flag=
load_helper epm-packages
[ -n "$force" ] || libexclude=$libexclude'[^-]*$'
showcmd "apt-cache list-nodeps | grep -E -- \"$libexclude\""
fullpkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" )
pkgs=$(skip_manually_installed $fullpkgs)
if [ -n "$dryrun" ] ; then
info "Packages for autoremoving:"
echo "$pkgs"
__epm_print_excluded "$pkgs" "$fullpkgs"
return 0
fi
__epm_print_excluded "$pkgs" "$fullpkgs"
[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1
if [ -n "$flag" ] ; then
info ""
info "call again for next cycle until all modules will be removed"
__epm_autoremove_altrpm_pp "$libexclude"
fi
return 0
}
__epm_autoremove_altrpm_lib()
{
local pkgs fullpkgs
local nodevel="$1"
info info
info "Just removing all non -devel libs packages not need by anything" if [ "$nodevel" = "nodevel" ] ; then
for pkg in $(short=1 pkg_filenames= epm_packages | grep -- "^lib" | grep -v -- "-devel$" | grep -v -- ^libreoffice ) ; do info "Removing all non -devel/-debuginfo libs packages not need by anything..."
sudocmd rpm -v -e $pkg && flag=1 local develrule='-(devel|devel-static)$'
done else
info "Removing all non -debuginfo libs packages (-devel too) not need by anything..."
local develrule='-(NONONO)$'
fi
#[ -n "$force" ] || info "You can run with --force for more deep removing"
local force=force
local flag=
local libgrep='^(lib|i586-lib|bzlib|zlib)'
[ -n "$force" ] || libexclude=$libgrep'[^-]*$'
# call again for next cycle until all libs will removed # https://www.altlinux.org/APT_в_ALT_Linux/Советы_по_использованию#apt-cache_list-nodeps
[ -n "$flag" ] && __epm_autoremove_altrpm showcmd "apt-cache list-nodeps | grep -E -- \"$libgrep\""
fullpkgs=$(apt-cache list-nodeps | grep -E -- "$libgrep" \
| sed -e "s/[-\.]32bit$//g" \
| grep -E -v -- "$develrule" \
| grep -E -v -- "-(debuginfo)$" \
| grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \
| grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm)" )
pkgs=$(skip_manually_installed $fullpkgs)
if [ -n "$dryrun" ] ; then
info "Packages for autoremoving:"
echo "$pkgs"
__epm_print_excluded "$pkgs" "$fullpkgs"
return 0
fi
__epm_print_excluded "$pkgs" "$fullpkgs"
# commented, with hi probability user install i586- manually
# workaround against missed i586- handling in apt-cache list-nodeps
if epmqp i586-lib >/dev/null ; then
info "You can try removing all i586- with follow command"
showcmd rpm -v -e $(epmqp i586-lib)
fi
[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1
if [ -n "$flag" ] ; then
info ""
info "call again for next cycle until all libs will be removed"
__epm_autoremove_altrpm_lib $nodevel
fi
return 0 return 0
} }
__epm_autoremove_altrpm()
{
local i
load_helper epm-packages
assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts
if [ -z "$pkg_names" ] ; then
__epm_autoremove_altrpm_pp '^(python-module-|python3-module-|python-modules-|python3-modules|perl-)'
__epm_autoremove_altrpm_lib nodevel
return 0
fi
for i in $pkg_names ; do
case $i in
libs)
__epm_autoremove_altrpm_lib nodevel
;;
python)
__epm_autoremove_altrpm_pp '^(python-module-|python3-module-|python-modules-|python3-modules)'
;;
perl)
__epm_autoremove_altrpm_pp '^(perl-)'
;;
libs-devel)
__epm_autoremove_altrpm_lib
;;
*)
fatal "autoremove: unsupported '$i'. Use libs, python, perl, libs-devel."
;;
esac
done
return 0
}
# TODO: keep our eepm package
epm_autoremove() epm_autoremove()
{ {
case $PMTYPE in
apt-rpm) case $DISTRNAME in
assure_exists remove-old-kernels ALTLinux)
# ALT Linux only
__epm_autoremove_altrpm __epm_autoremove_altrpm
# ALT Linux only
sudocmd remove-old-kernels [ -n "$dryrun" ] && return
docmd epm remove-old-kernels
if which nvidia-clean-driver 2>/dev/null ; then
sudocmd nvidia-clean-driver
fi
return
;;
*)
;; ;;
esac
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
sudocmd apt-get autoremove sudocmd apt-get autoremove $dryrun
;; ;;
aura) aura)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd aura -Oj sudocmd aura -Oj
;; ;;
yum-rpm) yum-rpm)
# cleanup orphanes? # cleanup orphanes?
while true ; do while true ; do
# shellcheck disable=SC2046
docmd package-cleanup --leaves $(subst_option non_interactive --assumeyes) docmd package-cleanup --leaves $(subst_option non_interactive --assumeyes)
# FIXME: package-cleanup have to use stderr for errors # FIXME: package-cleanup have to use stderr for errors
local PKGLIST=$(package-cleanup --leaves | grep -v "Loaded plugins" | grep -v "Unable to") local PKGLIST=$(package-cleanup -q --leaves | grep -v "^eepm-")
[ -n "$PKGLIST" ] || break [ -n "$PKGLIST" ] || break
sudocmd yum remove $PKGLIST showcmd epm remove $PKGLIST
done done
;; ;;
urpm-rpm) dnf-rpm)
sudocmd urpme --auto-orphans if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd dnf autoremove
;; ;;
# see autoorhans
#urpm-rpm)
# sudocmd urpme --auto-orphans
# ;;
emerge) emerge)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd emerge --depclean sudocmd emerge --depclean
assure_exists revdep-rebuild assure_exists revdep-rebuild
sudocmd revdep-rebuild sudocmd revdep-rebuild
;; ;;
pacman) # see autoorhans
sudocmd pacman -Qdtq | sudocmd pacman -Rs - #pacman)
;; # sudocmd pacman -Qdtq | sudocmd pacman -Rs -
# ;;
slackpkg) slackpkg)
# clean-system removes non official packages # clean-system removes non official packages
#sudocmd slackpkg clean-system #sudocmd slackpkg clean-system
...@@ -79,9 +237,30 @@ case $PMTYPE in ...@@ -79,9 +237,30 @@ case $PMTYPE in
guix) guix)
sudocmd guix gc sudocmd guix gc
;; ;;
#zypper-rpm) pkgng)
# sudocmd zypper clean sudocmd pkg autoremove
# ;; ;;
zypper-rpm)
# https://www.linux.org.ru/forum/desktop/11931830
assure_exists zypper zypper 1.9.3
sudocmd zypper packages --unneeded
# FIXME: x86_64/i586 are duplicated
local PKGLIST=$(zypper packages --unneeded | tail -n +5 | cut -d \| -f 3 | sort -u)
showcmd epm remove --clean-deps $PKGLIST
;;
xbps)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd xbps-remove -O
;;
opkg)
if [ -n "$dryrun" ] ; then
sudocmd opkg --noaction --autoremove
else
sudocmd opkg --autoremove
fi
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -34,7 +34,8 @@ __epm_changelog_files() ...@@ -34,7 +34,8 @@ __epm_changelog_files()
# TODO: detect every file # TODO: detect every file
case $(get_package_type $1) in case $(get_package_type $1) in
rpm) rpm)
docmd_foreach "rpm -p --changelog" $@ | less assure_exists rpm
docmd_foreach "rpm -q -p --changelog" $@ | less
;; ;;
# deb) # deb)
# #
...@@ -50,8 +51,8 @@ __epm_changelog_local_names() ...@@ -50,8 +51,8 @@ __epm_changelog_local_names()
[ -z "$*" ] && return [ -z "$*" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm) apt-rpm|yum-rpm|dnf-rpm|urpm-rpm|zypper-rpm)
docmd_foreach "rpm --changelog" $@ | less docmd_foreach "rpm -q --changelog" $@ | less
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
docmd zcat /usr/share/doc/$1/changelog.Debian.gz | less docmd zcat /usr/share/doc/$1/changelog.Debian.gz | less
...@@ -84,9 +85,9 @@ __epm_changelog_unlocal_names() ...@@ -84,9 +85,9 @@ __epm_changelog_unlocal_names()
#yum-rpm) #yum-rpm)
# sudocmd yum clean all # sudocmd yum clean all
# ;; # ;;
#urpm-rpm) urpm-rpm)
# sudocmd urpmi --clean docmd urpmq --changelog $@ | less
# ;; ;;
#zypper-rpm) #zypper-rpm)
# sudocmd zypper clean # sudocmd zypper clean
# ;; # ;;
...@@ -95,7 +96,7 @@ __epm_changelog_unlocal_names() ...@@ -95,7 +96,7 @@ __epm_changelog_unlocal_names()
docmd equery changes -f $1 | less docmd equery changes -f $1 | less
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE. Try install the package firstly."
;; ;;
esac esac
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2013 Etersoft # Copyright (C) 2012-2019 Etersoft
# Copyright (C) 2012-2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2019 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,22 +17,56 @@ ...@@ -17,22 +17,56 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# remove duplicates
try_fix_apt_rpm_dupls()
{
info "Check for duplicates ..."
local TESTPKG="ignoreflock"
local has_testpkg=""
if epm --quiet installed $TESTPKG ; then
has_testpkg=1
sudocmd epm remove --auto $TESTPKG || return
fi
local PKGLIST
PKGLIST=$(LANG=C $SUDO apt-get install $TESTPKG 2>&1 | grep "W: There are multiple versions of" | \
sed -e 's|W: There are multiple versions of "\(.*\)" in your system.|\1|')
local TODEL
for i in $PKGLIST ; do
local pkg=${i/.32bit/}
local todel="$(rpm -q $pkg | head -n1)"
local todel2="$(rpm -q $pkg | head -n2 | tail -n1)"
if [ "$todel" = "$todel2" ] ; then
echo "Fix the same name duplicates for $pkg..."
sudocmd rpm -e "$todel" --allmatches --nodeps && epm install $pkg && continue
fi
sudocmd rpm -e "$todel" || TODEL="$TODEL $todel"
done
[ -n "$TODEL" ] && sudocmd rpm -e "$TODEL"
[ -n "$has_testpkg" ] && epm install $TESTPKG
}
epm_check() epm_check()
{ {
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm)
#sudocmd apt-get check || exit
#sudocmd apt-get update || exit
sudocmd apt-get -f install || return
try_fix_apt_rpm_dupls
;;
apt-dpkg)
#sudocmd apt-get check || exit #sudocmd apt-get check || exit
#sudocmd apt-get update || exit #sudocmd apt-get update || exit
sudocmd apt-get -f install || exit sudocmd apt-get -f install || return
;; ;;
apt-dpkg) apt-dpkg)
#sudocmd apt-get update || exit #sudocmd apt-get update || exit
#sudocmd apt-get check || exit #sudocmd apt-get check || exit
sudocmd apt-get -f install || exit sudocmd apt-get -f install || return
sudocmd apt-get autoremove #sudocmd apt-get autoremove
;; ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude -f install || exit sudocmd aptitude -f install || return
#sudocmd apt-get autoremove #sudocmd apt-get autoremove
;; ;;
yum-rpm) yum-rpm)
...@@ -44,6 +78,9 @@ case $PMTYPE in ...@@ -44,6 +78,9 @@ case $PMTYPE in
docmd rpm -Va --nofiles --nodigest docmd rpm -Va --nofiles --nodigest
;; ;;
dnf-rpm)
sudocmd dnf check
;;
emerge) emerge)
sudocmd revdep-rebuild sudocmd revdep-rebuild
;; ;;
...@@ -56,8 +93,11 @@ case $PMTYPE in ...@@ -56,8 +93,11 @@ case $PMTYPE in
conary) conary)
sudocmd conary verify sudocmd conary verify
;; ;;
pkgng)
sudocmd pkg check -d -a
;;
homebrew) homebrew)
sudocmd brew doctor docmd brew doctor
;; ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2014 Etersoft # Copyright (C) 2014, 2015 Etersoft
# Copyright (C) 2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2014, 2015 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,13 +17,12 @@ ...@@ -17,13 +17,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
__is_repo_info_download() __is_repo_info_downloaded()
{ {
case $PMTYPE in case $PMTYPE in
apt-*) apt-*)
if [ -r /var/cache/apt ] ; then if [ -r /var/cache/apt ] ; then
# FIXME: only if root permissions $SUDO test -r /var/cache/apt/pkgcache.bin || return
test -r /var/cache/apt/pkgcache.bin || return
fi fi
;; ;;
*) *)
...@@ -32,14 +31,60 @@ __is_repo_info_download() ...@@ -32,14 +31,60 @@ __is_repo_info_download()
return 0 return 0
} }
__is_repo_info_uptodate()
{
case $PMTYPE in
apt-*)
# apt-deb do not update lock file date
#if $SUDO test -r /var/lib/apt/lists ; then
local LOCKFILE=/var/lib/apt/lists
$SUDO test -r $LOCKFILE || return
# if repo older than 1 day, return false
# find print string if file is obsoleted
test -z "$(find $LOCKFILE -maxdepth 0 -mtime +1)" || return
#fi
;;
*)
;;
esac
return 0
}
update_repo_if_needed() update_repo_if_needed()
{ {
if ! __is_repo_info_download ; then # check if we need skip update checking
if [ "$1" = "soft" ] && [ -n "$SUDO" ] ; then
# if sudo requires a password, skip autoupdate
sudo -n true 2>/dev/null || { info "sudo requires a password, skip repo status checking" ; return 0 ; }
fi
cd / || fatal
if ! __is_repo_info_downloaded || ! __is_repo_info_uptodate ; then
load_helper epm-update load_helper epm-update
epm_update pkg_filenames='' epm_update
return
fi fi
cd - >/dev/null || fatal
}
# save manually installed packages
save_installed_packages()
{
[ -d /var/lib/rpm ] || return 0
estrlist list "$@" | $SUDO tee /var/lib/rpm/EPM-installed >/dev/null
}
# TODO: if repo info is very obsoleted (a few days?), we need run update check_manually_installed()
{
[ -r /var/lib/rpm/EPM-installed ] || return 1
grep -q -- "^$1\$" /var/lib/rpm/EPM-installed
}
skip_manually_installed()
{
local i
for i in "$@" ; do
check_manually_installed "$i" && continue
echo "$i"
done
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2009, 2012, 2013 Etersoft # Copyright (C) 2009, 2012, 2013, 2014, 2016, 2018 Etersoft
# Copyright (C) 2009, 2012, 2013 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,21 +17,37 @@ ...@@ -17,21 +17,37 @@
# 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)
docmd rpm --checksig $PKG assure_exists rpm
__rpm_allows_nosignature && NOSIGNATURE="--nosignature" || NOSIGNATURE="--nogpg"
docmd rpm --checksig $NOSIGNATURE $PKG
;; ;;
deb) deb)
assure_exists dpkg
# FIXME: debsums -ca package ? # FIXME: debsums -ca package ?
docmd dpkg --contents $PKG >/dev/null && echo "Package $PKG is correct." docmd dpkg --contents $PKG >/dev/null && echo "Package $PKG is correct."
;; ;;
exe) exe)
true file $PKG | grep -q "executable for MS Windows"
;;
msi)
# TODO: add to patool via cabextract
assure_exists cabextract
#file $PKG | grep -q "Microsoft Office Document"
docmd cabextract -t $PKG
;; ;;
ebuild) ebuild)
true true
...@@ -50,6 +66,7 @@ case $PMTYPE in ...@@ -50,6 +66,7 @@ case $PMTYPE in
docmd rpm -V $@ docmd rpm -V $@
;; ;;
*-dpkg) *-dpkg)
assure_exists debsums
docmd debsums $@ docmd debsums $@
;; ;;
emerge) emerge)
...@@ -67,14 +84,31 @@ esac ...@@ -67,14 +84,31 @@ esac
epm_checkpkg() epm_checkpkg()
{ {
if [ -n "$pkg_names" ] ; then if [ -n "$pkg_names" ] ; then
# TODO: если есть / или расширение, это отсутствующий файл
info "Suggest $pkg_names are name(s) of installed packages" info "Suggest $pkg_names are name(s) of installed packages"
__epm_check_installed_pkg $pkg_names __epm_check_installed_pkg $pkg_names
return return
fi fi
# if possible, it will put pkg_urls into pkg_files or pkg_names
if [ -n "$pkg_urls" ] ; then
load_helper epm-download
__handle_pkg_urls_to_checking
fi
[ -n "$pkg_files" ] || fatal "Checkpkg: missing file or package name(s)" [ -n "$pkg_files" ] || fatal "Checkpkg: missing file or package name(s)"
local RETVAL=0
local pkg local pkg
for pkg in $pkg_files ; do for pkg in $pkg_files ; do
check_pkg_integrity $pkg || fatal "Broken package $pkg" check_pkg_integrity $pkg || RETVAL=1
done done
# 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
#fatal "Broken package $pkg"
return $RETVAL
} }
#!/bin/sh
#
# Copyright (C) 2015 Etersoft
# Copyright (C) 2015 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# TODO: rpm list from bash_completion in /var/log/rpmpkgs
epm_checksystem_ALTLinux()
{
local TDIR=$(mktemp -d)
assure_exists time
touch $TDIR/added
for ft in $(ls /usr/lib/rpm/*.filetrigger | sort) ; do
echo "Try run $ft ..."
echo $TDIR/added $TDIR/removed | a='' time $ft
done
rm -f $TDIR/added fatal
rmdir $TDIR || fatal
echo "Count lines:"
wc -l /var/lib/rpm/files-awaiting-filetriggers
}
epm_checksystem()
{
[ $EFFUID = "0" ] && fatal "Do not use checksystem under root"
case $DISTRNAME in
ALTLinux)
epm_checksystem_$DISTRNAME
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
# direct debug run
if [ "$1" = "--debug" ] ; then
shift
SUDO=sudo
DISTRNAME=ALTLinux
epm_checksystem
fi
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2014 Etersoft # Copyright (C) 2012,2014,2016 Etersoft
# Copyright (C) 2012,2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012,2014,2016 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,14 +17,41 @@ ...@@ -17,14 +17,41 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
__remove_alt_apt_cache_file()
{
sudocmd rm -vf /var/cache/apt/*.bin
sudocmd rm -vf /var/cache/apt/partial/*
sudocmd rm -vf /var/lib/apt/lists/*pkglist*
sudocmd rm -vf /var/lib/apt/lists/*release*
}
__remove_deb_apt_cache_file()
{
sudocmd rm -vf /var/cache/apt/*.bin
sudocmd rm -vf /var/cache/apt/archives/partial/*
sudocmd rm -vf /var/lib/apt/lists/*Packages*
sudocmd rm -vf /var/lib/apt/lists/*Release*
sudocmd rm -vf /var/lib/apt/lists/*Translation*
}
epm_clean() epm_clean()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm)
sudocmd apt-get clean
[ -n "$force" ] && __remove_alt_apt_cache_file
;;
apt-dpkg)
sudocmd apt-get clean sudocmd apt-get clean
[ -n "$force" ] && __remove_deb_apt_cache_file
;; ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude clean sudocmd aptitude clean
[ -n "$force" ] && __remove_deb_apt_cache_file
;; ;;
yum-rpm) yum-rpm)
sudocmd yum clean all sudocmd yum clean all
...@@ -37,7 +64,7 @@ case $PMTYPE in ...@@ -37,7 +64,7 @@ case $PMTYPE in
sudocmd urpmi --clean sudocmd urpmi --clean
;; ;;
pacman) pacman)
sudocmd pacman -Sc sudocmd pacman -Sc --noconfirm
;; ;;
zypper-rpm) zypper-rpm)
sudocmd zypper clean sudocmd zypper clean
...@@ -47,6 +74,12 @@ case $PMTYPE in ...@@ -47,6 +74,12 @@ case $PMTYPE in
;; ;;
slackpkg) slackpkg)
;; ;;
pkgng)
sudocmd pkg clean -a
;;
xbps)
sudocmd xbps-remove -O
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
......
...@@ -25,6 +25,7 @@ epm_conflicts_files() ...@@ -25,6 +25,7 @@ epm_conflicts_files()
case $(get_package_type $pkg_files) in case $(get_package_type $pkg_files) in
rpm) rpm)
assure_exists rpm
docmd "rpm -q --conflicts -p" $pkg_files docmd "rpm -q --conflicts -p" $pkg_files
;; ;;
#deb) #deb)
...@@ -69,7 +70,7 @@ case $PMTYPE in ...@@ -69,7 +70,7 @@ case $PMTYPE in
# FIXME: need fix for a few names case # FIXME: need fix for a few names case
if is_installed $pkg_names ; then if is_installed $pkg_names ; then
showcmd dpkg -s $pkg_names showcmd dpkg -s $pkg_names
a= dpkg -s $pkg_names | grep "^Conflicts:" | sed "s|^Conflicts:||g" a='' dpkg -s $pkg_names | grep "^Conflicts:" | sed "s|^Conflicts:||g"
return return
else else
EXTRA_SHOWDOCMD=' | grep "Conflicts:"' EXTRA_SHOWDOCMD=' | grep "Conflicts:"'
......
#!/bin/sh
#
# Copyright (C) 2012,2014,2016 Etersoft
# Copyright (C) 2012,2014,2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-check_updated_repo
__epm_add_alt_apt_downgrade_preferences()
{
[ -r /etc/apt/preferences ] && fatal "/etc/apt/preferences already exists"
cat <<EOF | $SUDO tee /etc/apt/preferences
# main repo
Package: *
Pin: release c=classic
Pin-Priority: 1001
# overload with addon repo
Package: *
Pin: release c=addon
Pin-Priority: 1101
EOF
}
# See https://wiki.debian.org/ru/AptPreferences
__epm_add_deb_apt_downgrade_preferences()
{
[ -r /etc/apt/preferences ] && fatal "/etc/apt/preferences already exists"
info "Running with /etc/apt/preferences:"
cat <<EOF | $SUDO tee /etc/apt/preferences
Package: *
Pin: release a=stable
Pin-Priority: 1001
Package: *
Pin: release a=testing
Pin-Priority: 900
Package: *
Pin: release a=unstable
Pin-Priority: 800
EOF
}
__epm_remove_apt_downgrade_preferences()
{
sudocmd rm -f /etc/apt/preferences
}
epm_downgrade()
{
local CMD
# it is useful for first time running
update_repo_if_needed
info "Running command for downgrade packages"
case $PMTYPE in
apt-rpm)
local APTOPTIONS="$(subst_option non_interactive -y)"
__epm_add_alt_apt_downgrade_preferences || return
if [ -n "$pkg_filenames" ] ; then
sudocmd apt-get $APTOPTIONS install $pkg_filenames
else
sudocmd apt-get $APTOPTIONS dist-upgrade
fi
__epm_remove_apt_downgrade_preferences
;;
apt-dpkg)
local APTOPTIONS="$(subst_option non_interactive -y)"
__epm_add_deb_apt_downgrade_preferences || return
if [ -n "$pkg_filenames" ] ; then
sudocmd apt-get $APTOPTIONS install $pkg_filenames
else
sudocmd apt-get $APTOPTIONS dist-upgrade
fi
__epm_remove_apt_downgrade_preferences
;;
yum-rpm)
# can do update repobase automagically
if [ -n "$pkg_filenames" ] ; then
sudocmd yum downgrade $pkg_filenames
else
sudocmd yum distro-sync
fi
;;
dnf-rpm)
if [ -n "$pkg_filenames" ] ; then
sudocmd dnf downgrade $pkg_filenames
else
sudocmd dnf distro-sync
fi
;;
urpm-rpm)
assure_exists urpm-reposync urpm-tools
sudocmd urpm-reposync -v
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh
#
# Copyright (C) 2016-2018 Etersoft
# Copyright (C) 2016-2018 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
alt_base_dist_url="http://ftp.basealt.ru/pub/distributions"
__use_url_install()
{
case $DISTRNAME in
"ALTLinux")
# do not support https yet
echo "$pkg_urls" | grep -q "https://" && return 1
# force download if wildcard is used
echo "$pkg_urls" | grep -q "[?*]" && return 1
pkg_names="$pkg_names $pkg_urls"
return 0
;;
esac
case $PMTYPE in
#apt-rpm)
# pkg_names="$pkg_names $pkg_urls"
# ;;
#deepsolver-rpm)
# pkg_names="$pkg_names $pkg_urls"
# ;;
#urpm-rpm)
# pkg_names="$pkg_names $pkg_urls"
# ;;
pacman)
pkg_names="$pkg_names $pkg_urls"
;;
yum-rpm|dnf-rpm)
pkg_names="$pkg_names $pkg_urls"
;;
#zypper-rpm)
# pkg_names="$pkg_names $pkg_urls"
# ;;
*)
return 1
;;
esac
return 0
}
# for download before install / checking
__download_pkg_urls()
{
local url
[ -z "$pkg_urls" ] && return
for url in $pkg_urls ; do
local tmppkg=$(mktemp -d) || fatal "failed mktemp -d"
cd $tmppkg || fatal
if docmd eget "$url" ; then
local i
for i in $(basename $url) ; do
[ -s "$tmppkg/$i" ] || continue
pkg_files="$pkg_files $tmppkg/$i"
to_remove_pkg_files="$to_remove_pkg_files $tmppkg/$i"
done
else
warning "Failed to download $url, ignoring"
fi
cd - >/dev/null
done
# reconstruct
pkg_filenames=$(strip_spaces "$pkg_files $pkg_names")
}
# NOTE: call __clean_downloaded_pkg_files after
__handle_pkg_urls_to_install()
{
#[ -n "$pkg_urls" ] || return
# TODO: do it correctly
to_remove_pkg_files=
# FIXME: check type of pkg_urls separately?
if [ "$(get_package_type "$pkg_urls")" != $PKGFORMAT ] || ! __use_url_install ; then
# use workaround with eget: download and put in pkg_files
__download_pkg_urls
fi
pkg_urls=
}
__handle_pkg_urls_to_checking()
{
#[ -n "$pkg_urls" ] || return
# TODO: do it correctly
to_remove_pkg_files=
# use workaround with eget: download and put in pkg_files
__download_pkg_urls
pkg_urls=
}
#__clean_downloaded_pkg_files()
#{
# [ -z "$to_remove_pkg_files" ] && return
# rm -fv $to_remove_pkg_files
#}
__epm_get_altpkg_url()
{
info "TODO: https://packages.altlinux.org/api/branches"
load_helper epm-site
local arch=$(paoapi packages/$1 | get_pao_var arch)
# FIXME: arch can be list
[ "$arch" = "noarch" ] || arch=$(arch)
# HACK: filename can be list
local filename=$(paoapi packages/$1 | get_pao_var filename | grep $arch)
[ -n "$filename" ] || fatal "Can't get filename"
# fixme: get from /branches
local dv=$DISTRNAME/$DISTRVERSION/branch
[ "$DISTRVERSION" = "Sisyphus" ] && dv=$DISTRNAME/$DISTRVERSION
echo "$alt_base_dist_url/$dv/$arch/RPMS.classic/$filename"
}
__epm_print_url_alt()
{
local url="$1"
echo "$url"
echo "$url" | sed -e "s|$alt_base_dist_url/$DISTRNAME|http://mirror.yandex.ru/altlinux|g"
echo "$url" | sed -e "s|$alt_base_dist_url/$DISTRNAME|http://download.etersoft.ru/pub/ALTLinux|g"
}
__epm_print_url_alt_check()
{
local pkg=$1
shift
local tm=$(mktemp)
epm assure curl
load_helper epm-site
quiet=1
local buildtime=$(paoapi packages/$pkg | get_pao_var buildtime)
echo
echo "Latest release: $(paoapi packages/$pkg | get_pao_var sourcepackage) $buildtime"
__epm_print_url_alt "$1" | while read url ; do
a='' curl -s --head $url >$tm || { echo "$url: missed" ; continue ; }
local http=$(cat $tm | grep "^HTTP" | sed -e "s|\r||g")
local lastdate=$(cat $tm | grep "^Last-Modified:" | sed -e "s|\r||g")
local size=$(cat $tm | grep "^Content-Length:" | sed -e "s|^Content-Length: ||g" | sed -e "s|\r||g")
echo "$url ($http $lastdate) Size: $size"
done
rm -f $tm
}
__epm_download_alt()
{
local pkg
if [ "$1" = "--check" ] ; then
local checkflag="$1"
shift
fi
for pkg in "$@" ; do
local url=$(__epm_get_altpkg_url $pkg)
[ -n "$url" ] || warning "Can't get URL for $pkg"
if [ -n "$checkflag" ] ; then
__epm_print_url_alt_check "$pkg" "$url"
else
docmd eget $url || return
fi
done
}
epm_download()
{
local CMD
case $DISTRNAME in
ALTLinux)
__epm_download_alt $pkg_filenames
return
;;
esac
case $PMTYPE in
dnf-rpm)
sudocmd dnf download $pkg_filenames
;;
aptcyg)
sudocmd apt-cyg download $pkg_filenames
;;
yum-rpm)
# TODO: check yum install --downloadonly --downloaddir=/tmp <package-name>
assure_exists yumdownloader yum-utils
sudocmd yumdownloader $pkg_filenames
;;
dnf-rpm)
sudocmd dnf download $pkg_filenames
;;
urpm-rpm)
sudocmd urpmi --no-install $URPMOPTIONS $@
;;
tce)
sudocmd tce-load -w $pkg_filenames
;;
opkg)
docmd opkg $pkg_filenames
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh
# Copyright (C) 2016 Etersoft
# Copyright (C) 2016 Danil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-install
__epm_korinf_site() {
local archprefix=""
[ "$($DISTRVENDOR -a)" = "x86_64" ] && archprefix="x86_64/"
local aftername="-"
[ "$($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
}
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
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2014 Etersoft # Copyright (C) 2012-2018 Etersoft
# Copyright (C) 2012-2014 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
...@@ -18,31 +18,36 @@ ...@@ -18,31 +18,36 @@
# #
load_helper epm-query load_helper epm-query
load_helper epm-print
load_helper epm-sh-warmup
# TODO: port or rewrite apt-file # TODO: port or rewrite apt-file
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449 # https://bugzilla.altlinux.org/show_bug.cgi?id=14449
# see also epm-search-file # see also epm-search-file
local_content_filelist() __alt_local_content_filelist()
{ {
local SYSARCH load_helper epm-sh-altlinux
SYSARCH=$(uname -m)
[ "$SYSARCH" = "x86_64" ] || SYSARCH=i586
local REPODIR=/var/ftp/pub/ALTLinux/Sisyphus local CI="$(get_local_alt_contents_index)"
local CI=$REPODIR/$SYSARCH/base/contents_index [ -n "$CI" ] || fatal "Have no local contents index"
local CINOA=$REPODIR/noarch/base/contents_index
# TODO: safe way to use less
#local OUTCMD="less" #local OUTCMD="less"
#[ -n "$USETTY" ] || OUTCMD="cat" #[ -n "$USETTY" ] || OUTCMD="cat"
OUTCMD="cat" OUTCMD="cat"
test -r $CI && test -r $CINOA || fatal "Can't locate $CI or $CINOA"
{ {
[ -n "$USETTY" ] && echo "Search in $CI and $CINOA for $1..." [ -n "$USETTY" ] && info "Search in $CI for $1..."
grep -h -- ".*$1$" $CI $CINOA | sed -e "s|\(.*\)\t\(.*\)|\1|g" __local_ercat $CI | grep -h -- ".*$1$" | sed -e "s|\(.*\)\t\(.*\)|\1|g"
} | $OUTCMD } | $OUTCMD
} }
__deb_local_content_filelist()
{
showcmd "apt-file list $1 | grep '^$1: ' | sed -e 's|$1: ||g'"
a='' apt-file list "$1" | grep "^$1: " | sed -e "s|$1: ||g"
}
__epm_filelist_remote() __epm_filelist_remote()
{ {
...@@ -51,10 +56,27 @@ __epm_filelist_remote() ...@@ -51,10 +56,27 @@ __epm_filelist_remote()
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
# TODO: use RESTful interface to prometeus? See ALT bug #29496 # TODO: use RESTful interface to prometeus? See ALT bug #29496
docmd_foreach local_content_filelist $@ docmd_foreach __alt_local_content_filelist "$@"
;;
apt-dpkg)
assure_exists apt-file || return
if sudo -n true 2>/dev/null ; then
sudocmd apt-file update
else
info "sudo requires a password, skip apt-file update"
fi
docmd_foreach __deb_local_content_filelist "$@"
;;
yum-rpm)
assure_exists yum-utils || return
docmd repoquery -q -l "$@"
;;
dnf-rpm)
assure_exists dnf-plugins-core || return
docmd dnf repoquery -l "$@"
;; ;;
*) *)
fatal "Query filelist for non installed packages does not realized" fatal "Query filelist for non installed packages is not implemented yet."
;; ;;
esac esac
} }
...@@ -68,9 +90,11 @@ __epm_filelist_file() ...@@ -68,9 +90,11 @@ __epm_filelist_file()
# TODO: allow a new packages # TODO: allow a new packages
case $(get_package_type $1) in case $(get_package_type $1) in
rpm) rpm)
assure_exists rpm
CMD="rpm -qlp" CMD="rpm -qlp"
;; ;;
deb) deb)
assure_exists dpkg
CMD="dpkg --contents" CMD="dpkg --contents"
;; ;;
*) *)
...@@ -87,22 +111,15 @@ __epm_filelist_name() ...@@ -87,22 +111,15 @@ __epm_filelist_name()
[ -z "$*" ] && return [ -z "$*" ] && return
warmup_lowbase
case $PMTYPE in case $PMTYPE in
apt-rpm) *-rpm)
CMD="rpm -ql" CMD="rpm -ql"
;; ;;
*-dpkg) *-dpkg)
CMD="dpkg -L" CMD="dpkg -L"
;; ;;
yum-rpm)
CMD="rpm -ql"
;;
urpm-rpm)
CMD="rpm -ql"
;;
zypper-rpm)
CMD="rpm -ql"
;;
android) android)
CMD="pm list packages -f" CMD="pm list packages -f"
;; ;;
...@@ -110,15 +127,31 @@ __epm_filelist_name() ...@@ -110,15 +127,31 @@ __epm_filelist_name()
CMD="conary query --ls" CMD="conary query --ls"
;; ;;
pacman) pacman)
docmd pacman -Ql $pkg_names | sed -e "s|.* ||g" | less docmd pacman -Ql $@ | sed -e "s|.* ||g" | less
return return
;; ;;
emerge) emerge)
assure_exists equery assure_exists equery
CMD="equery files" CMD="equery files"
;; ;;
homebrew)
CMD="brew list"
;;
pkgng)
CMD="pkg info -l"
;;
opkg)
CMD="opkg files"
;;
xbps)
CMD="xbps-query -f"
;;
aptcyg)
docmd apt-cyg listfiles $@ | sed -e "s|^|/|g"
return
;;
slackpkg) slackpkg)
is_installed $pkg_names || fatal "Query filelist for non installed packages does not realized" is_installed $@ || fatal "Query filelist for non installed packages is not implemented yet"
docmd awk 'BEGIN{desk=1}{if(/^FILE LIST:$/){desk=0} else if (desk==0) {print}}' /var/log/packages/${pkg_filenames}* | less docmd awk 'BEGIN{desk=1}{if(/^FILE LIST:$/){desk=0} else if (desk==0) {print}}' /var/log/packages/${pkg_filenames}* | less
return return
;; ;;
...@@ -128,8 +161,9 @@ __epm_filelist_name() ...@@ -128,8 +161,9 @@ __epm_filelist_name()
esac esac
# TODO: add less # TODO: add less
docmd $CMD $pkg_names && return docmd $CMD $@ && return
is_installed $pkg_names || __epm_filelist_remote $pkg_names # TODO: may be we need check is installed before prev. line?
is_installed $@ || __epm_filelist_remote $@
} }
...@@ -139,6 +173,7 @@ epm_filelist() ...@@ -139,6 +173,7 @@ epm_filelist()
__epm_filelist_file $pkg_files || return __epm_filelist_file $pkg_files || return
__epm_filelist_name $pkg_names || return # shellcheck disable=SC2046
__epm_filelist_name $(print_name $pkg_names) || return
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2014 Etersoft # Copyright (C) 2012, 2014, 2016 Etersoft
# Copyright (C) 2012,2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2014, 2016 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
...@@ -28,13 +28,25 @@ __epm_info_rpm_low() ...@@ -28,13 +28,25 @@ __epm_info_rpm_low()
is_installed $pkg_names && docmd rpm -qi $pkg_names && return is_installed $pkg_names && docmd rpm -qi $pkg_names && return
} }
# TODO: separate to _files and _names parts __epm_info_by_pkgtype()
# realize _files part per package, not by PMTYPE (see filelist)
epm_info()
{ {
[ -n "$pkg_files" ] || return 1
[ -n "$pkg_filenames" ] || fatal "Info: missing package(s) name" case $(get_package_type $pkg_files) in
rpm)
__epm_info_rpm_low && return
;;
deb)
docmd dpkg -I $pkg_files
;;
*)
return 1
;;
esac
}
__epm_info_by_pmtype()
{
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
__epm_info_rpm_low && return __epm_info_rpm_low && return
...@@ -59,6 +71,10 @@ case $PMTYPE in ...@@ -59,6 +71,10 @@ case $PMTYPE in
__epm_info_rpm_low && return __epm_info_rpm_low && return
docmd yum info $pkg_names docmd yum info $pkg_names
;; ;;
urpmi-rpm)
__epm_info_rpm_low && return
docmd urpmq -i $pkg_names
;;
dnf-rpm) dnf-rpm)
__epm_info_rpm_low && return __epm_info_rpm_low && return
docmd dnf info $pkg_names docmd dnf info $pkg_names
...@@ -93,15 +109,48 @@ case $PMTYPE in ...@@ -93,15 +109,48 @@ case $PMTYPE in
slackpkg) slackpkg)
docmd /usr/sbin/slackpkg info $pkg_names docmd /usr/sbin/slackpkg info $pkg_names
;; ;;
ipkg) opkg)
docmd ipkg info $pkg_names docmd opkg info $pkg_names
;;
pkgng)
docmd pkg info $pkg_names
;;
xbps)
docmd xbps-query --show $pkg_names
;; ;;
homebrew) homebrew)
docmd brew info $pkg_names docmd brew info $pkg_names
;; ;;
aptcyg)
docmd apt-cyg show $pkg_names
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
esac esac
}
# TODO: separate to _files and _names parts
# implement _files part per package, not by PMTYPE (see filelist)
epm_info()
{
# if possible, it will put pkg_urls into pkg_files or pkg_names
if [ -n "$pkg_urls" ] ; then
load_helper epm-download
__handle_pkg_urls_to_checking
fi
[ -n "$pkg_filenames" ] || fatal "Info: missing package(s) name"
__epm_info_by_pkgtype || __epm_info_by_pmtype
local RETVAL=$?
# 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
return $RETVAL
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2013 Etersoft # Copyright (C) 2012-2018 Etersoft
# Copyright (C) 2012-2013 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
...@@ -17,18 +17,39 @@ ...@@ -17,18 +17,39 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-sh-altlinux
load_helper epm-query load_helper epm-query
load_helper epm-assure
load_helper epm-repack
load_helper epm-check_updated_repo load_helper epm-check_updated_repo
load_helper epm-sh-warmup
__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'
}
# TODO: use when run install with epm --skip-installed install # TODO: use when run install with epm --skip-installed install
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")
...@@ -36,6 +57,7 @@ filter_out_installed_packages() ...@@ -36,6 +57,7 @@ filter_out_installed_packages()
# sed -e 's|\.\+$||g' -e 's|^.*[Nn]o packages found matching \(.*\)|\1|g' # sed -e 's|\.\+$||g' -e 's|^.*[Nn]o packages found matching \(.*\)|\1|g'
# ;; # ;;
*) *)
# shellcheck disable=SC2013
for i in $(cat) ; do for i in $(cat) ; do
is_installed $i || echo $i is_installed $i || echo $i
done done
...@@ -46,7 +68,7 @@ filter_out_installed_packages() ...@@ -46,7 +68,7 @@ filter_out_installed_packages()
# for zypper before SUSE/11.0 # for zypper before SUSE/11.0
__use_zypper_no_gpg_checks() __use_zypper_no_gpg_checks()
{ {
a= zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks" a='' zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks"
} }
# args: cmd_reinstall, cmd_install, packages # args: cmd_reinstall, cmd_install, packages
...@@ -84,15 +106,19 @@ __separate_sudocmd() ...@@ -84,15 +106,19 @@ __separate_sudocmd()
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg # copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
epm_install_names() epm_install_names()
{ {
[ -z "$1" ] && return
warmup_hibase
if [ -n "$non_interactive" ] ; then if [ -n "$non_interactive" ] ; then
epm_ni_install_names "$@" epm_ni_install_names "$@"
return return
fi fi
[ -z "$1" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
sudocmd apt-get $APTOPTIONS install $@ APTOPTIONS="$APTOPTIONS $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
sudocmd apt-get $APTOPTIONS $noremove install $@ && save_installed_packages $@
return ;; return ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude install $@ sudocmd aptitude install $@
...@@ -106,6 +132,9 @@ epm_install_names() ...@@ -106,6 +132,9 @@ epm_install_names()
pkgsrc) pkgsrc)
sudocmd pkg_add -r $@ sudocmd pkg_add -r $@
return ;; return ;;
pkgng)
sudocmd pkg install $@
return ;;
emerge) emerge)
sudocmd emerge -uD $@ sudocmd emerge -uD $@
return ;; return ;;
...@@ -116,10 +145,13 @@ epm_install_names() ...@@ -116,10 +145,13 @@ 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 ;;
snappy)
sudocmd snappy install $@
return ;; return ;;
zypper-rpm) zypper-rpm)
sudocmd zypper install $ZYPPEROPTIONS $@ sudocmd zypper install $ZYPPEROPTIONS $@
...@@ -139,14 +171,20 @@ epm_install_names() ...@@ -139,14 +171,20 @@ epm_install_names()
return ;; return ;;
homebrew) homebrew)
# FIXME: sudo and quote # FIXME: sudo and quote
__separate_sudocmd "brew install" "brew upgrade" $@ SUDO='' __separate_sudocmd "brew install" "brew upgrade" "$@"
return ;; return ;;
ipkg) opkg)
[ -n "$force" ] && force=-force-depends [ -n "$force" ] && force=-force-depends
sudocmd ipkg $force install $@ sudocmd opkg $force install $@
return ;; return ;;
nix) nix)
__separate_sudocmd "nix-env --install" "nix-env --upgrade" $@ __separate_sudocmd "nix-env --install" "nix-env --upgrade" "$@"
return ;;
apk)
sudocmd apk add $@
return ;;
tce)
sudocmd tce-load -wi $@
return ;; return ;;
guix) guix)
__separate_sudocmd "guix package -i" "guix package -i" $@ __separate_sudocmd "guix package -i" "guix package -i" $@
...@@ -154,6 +192,12 @@ epm_install_names() ...@@ -154,6 +192,12 @@ epm_install_names()
android) android)
fatal "We still have no idea how to use package repository, ever if it is F-Droid." fatal "We still have no idea how to use package repository, ever if it is F-Droid."
return ;; return ;;
aptcyg)
sudocmd apt-cyg install $@
return ;;
xbps)
sudocmd xbps-install $@
return ;;
*) *)
fatal "Have no suitable install command for $PMTYPE" fatal "Have no suitable install command for $PMTYPE"
;; ;;
...@@ -164,16 +208,20 @@ epm_install_names() ...@@ -164,16 +208,20 @@ epm_install_names()
epm_ni_install_names() epm_ni_install_names()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
sudocmd apt-get -y --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $APTOPTIONS install $@ sudocmd apt-get -y $noremove --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $APTOPTIONS install $@
return ;; return ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitde -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 ;;
dnf-rpm)
sudocmd dnf -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
return ;; return ;;
urpm-rpm) urpm-rpm)
sudocmd urpmi --auto $URPMOPTIONS $@ sudocmd urpmi --auto $URPMOPTIONS $@
...@@ -185,6 +233,9 @@ epm_ni_install_names() ...@@ -185,6 +233,9 @@ epm_ni_install_names()
pkgsrc) pkgsrc)
sudocmd pkg_add -r $@ sudocmd pkg_add -r $@
return ;; return ;;
pkgng)
sudocmd pkg install -y $@
return ;;
emerge) emerge)
sudocmd emerge -uD $@ sudocmd emerge -uD $@
return ;; return ;;
...@@ -196,17 +247,30 @@ epm_ni_install_names() ...@@ -196,17 +247,30 @@ epm_ni_install_names()
return ;; return ;;
npackd) npackd)
# npackdcl update --package=<package> (remove old and install new) # npackdcl update --package=<package> (remove old and install new)
sudocmd npackdcl add --package=$@ sudocmd npackdcl add --package="$*"
return ;; return ;;
chocolatey) chocolatey)
docmd chocolatey install $@ docmd chocolatey install $@
return ;; return ;;
ipkg) opkg)
sudocmd ipkg -force-defaults install $@ sudocmd opkg -force-defaults install $@
return ;; return ;;
nix) nix)
sudocmd nix-env --install $@ sudocmd nix-env --install $@
return ;; return ;;
apk)
sudocmd apk add $@
return ;;
tce)
sudocmd tce-load -wi $@
return ;;
xbps)
sudocmd xbps-install -y $@
return ;;
homebrew)
# FIXME: sudo and quote
SUDO='' __separate_sudocmd "brew install" "brew upgrade" $@
return ;;
#android) #android)
# sudocmd pm install $@ # sudocmd pm install $@
# return ;; # return ;;
...@@ -226,28 +290,59 @@ __epm_check_if_rpm_already_installed() ...@@ -226,28 +290,59 @@ __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"
} }
__handle_direct_install()
{
case "$DISTRNAME" in
"ALTLinux")
load_helper epm-download
local pkg url
for pkg in $pkg_names ; do
url=$(__epm_get_altpkg_url $pkg)
[ -n "$url" ] || continue
# TODO: use estrlist
pkg_urls="$pkg_urls $url"
done
# FIXME: need remove
pkg_names=""
;;
esac
}
epm_install_files() epm_install_files()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
# TODO: check read permissions
# sudo test -r FILE
# do not fallback to install_names if we have no permissions
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
sudocmd rpm -Uvh $force $nodeps $@ && return # TODO: replace with name changed function
local RES=$? __epm_check_if_try_install_deb $@ && return
# do not using low-level for install by file path (FIXME: reasons?)
if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then
sudocmd rpm -Uvh $force $nodeps $@ && save_installed_packages $@ && return
local RES=$?
# TODO: check rpm result code and convert it to compatible format if possible
__epm_check_if_rpm_already_installed $@ && return __epm_check_if_rpm_already_installed $@ && return
# if run with --nodeps, do not fallback on hi level # if run with --nodeps, do not fallback on hi level
[ -n "$nodeps" ] && return $RES [ -n "$nodeps" ] && return $RES
fi
# use install_names # use install_names
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
# the new version of the conf. file is installed with a .dpkg-dist suffix # the new version of the conf. file is installed with a .dpkg-dist suffix
if [ -n "$non_interactive" ] ; then if [ -n "$non_interactive" ] ; then
DPKGOPTIONS="--force-confdef --force-confold" DPKGOPTIONS="--force-confdef --force-confold"
fi fi
__epm_check_if_try_install_rpm $@ && return
# FIXME: return false in case no install and in case install with broken deps # FIXME: return false in case no install and in case install with broken deps
sudocmd dpkg $DPKGOPTIONS -i $@ sudocmd dpkg $DPKGOPTIONS -i $@
local RES=$? local RES=$?
...@@ -262,7 +357,10 @@ epm_install_files() ...@@ -262,7 +357,10 @@ epm_install_files()
sudocmd dpkg $DPKGOPTIONS -i $@ sudocmd dpkg $DPKGOPTIONS -i $@
return return
;; ;;
yum-rpm|dnf-rpm) yum-rpm|dnf-rpm)
__epm_check_if_try_install_deb $@ && return
sudocmd rpm -Uvh $force $nodeps $@ && return sudocmd rpm -Uvh $force $nodeps $@ && return
# if run with --nodeps, do not fallback on hi level # if run with --nodeps, do not fallback on hi level
...@@ -272,7 +370,9 @@ epm_install_files() ...@@ -272,7 +370,9 @@ epm_install_files()
YUMOPTIONS=--nogpgcheck YUMOPTIONS=--nogpgcheck
# use install_names # use install_names
;; ;;
zypper-rpm) zypper-rpm)
__epm_check_if_try_install_deb $@ && return
sudocmd rpm -Uvh $force $nodeps $@ && return sudocmd rpm -Uvh $force $nodeps $@ && return
local RES=$? local RES=$?
...@@ -284,7 +384,9 @@ epm_install_files() ...@@ -284,7 +384,9 @@ epm_install_files()
ZYPPEROPTIONS=$(__use_zypper_no_gpg_checks) ZYPPEROPTIONS=$(__use_zypper_no_gpg_checks)
# use install_names # use install_names
;; ;;
urpm-rpm) urpm-rpm)
__epm_check_if_try_install_deb $@ && return
sudocmd rpm -Uvh $force $nodeps $@ && return sudocmd rpm -Uvh $force $nodeps $@ && return
local RES=$? local RES=$?
...@@ -299,6 +401,17 @@ epm_install_files() ...@@ -299,6 +401,17 @@ epm_install_files()
pkgsrc) pkgsrc)
sudocmd pkg_add $@ sudocmd pkg_add $@
return ;; return ;;
pkgng)
local PKGTYPE="$(get_package_type $@)"
case "$PKGTYPE" in
tbz)
sudocmd pkg_add $@
;;
*)
sudocmd pkg add $@
;;
esac
return ;;
android) android)
sudocmd pm install $@ sudocmd pm install $@
return ;; return ;;
...@@ -326,35 +439,94 @@ epm_install_files() ...@@ -326,35 +439,94 @@ epm_install_files()
epm_print_install_command() epm_print_install_command()
{ {
# print out low level command by default (wait --low-level for control it)
#[ -z "$1" ] && return
[ -z "$1" ] && [ -n "$pkg_names" ] && return
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm) apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
echo "rpm -Uvh --force $nodeps $@" echo "rpm -Uvh --force $nodeps $*"
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
echo "dpkg -i $@" echo "dpkg -i $*"
;; ;;
pkgsrc) pkgsrc)
echo "pkg_add $@" echo "pkg_add $*"
;;
pkgng)
echo "pkg add $*"
;; ;;
emerge) emerge)
# need be placed in /usr/portage/packages/somewhere # need be placed in /usr/portage/packages/somewhere
echo "emerge --usepkg $@" echo "emerge --usepkg $*"
;; ;;
pacman) pacman)
echo "pacman -U --noconfirm --force $nodeps $@" echo "pacman -U --noconfirm --force $nodeps $*"
;; ;;
slackpkg) slackpkg)
echo "/sbin/installpkg $@" echo "/sbin/installpkg $*"
;; ;;
npackd) npackd)
echo "npackdcl add --package=$@" echo "npackdcl add --package=$*"
;; ;;
ipkg) opkg)
echo "ipkg install $@" echo "opkg install $*"
;; ;;
android) android)
echo "pm install $@" echo "pm install $*"
;;
aptcyg)
echo "apt-cyg install $*"
;;
tce)
echo "tce-load -wi $*"
;;
xbps)
echo "xbps-install -y $*"
;;
homebrew)
# FIXME: sudo and quote
echo "brew install $*"
;; ;;
*)
fatal "Have no suitable appropriate install command for $PMTYPE"
;;
esac
}
epm_print_install_names_command()
{
# check for pkg_files to support print out command without pkg names in args
#[ -z "$1" ] && [ -n "$pkg_files" ] && return
[ -z "$1" ] && return
case $PMTYPE in
apt-rpm|apt-dpkg)
echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
return ;;
aptitude-dpkg)
echo "aptitude -y install $*"
return ;;
yum-rpm)
echo "yum -y $YUMOPTIONS install $*"
return ;;
dnf-rpm)
echo "dnf -y $YUMOPTIONS install $*"
return ;;
urpm-rpm)
echo "urpmi --auto $URPMOPTIONS $*"
return ;;
zypper-rpm)
echo "zypper --non-interactive $ZYPPEROPTIONS install $*"
return ;;
pacman)
echo "pacman -S --noconfirm $force $*"
return ;;
chocolatey)
echo "chocolatey install $*"
return ;;
nix)
echo "nix-env --install $*"
return ;;
*) *)
fatal "Have no suitable appropriate install command for $PMTYPE" fatal "Have no suitable appropriate install command for $PMTYPE"
;; ;;
...@@ -364,21 +536,70 @@ epm_print_install_command() ...@@ -364,21 +536,70 @@ epm_print_install_command()
epm_install() epm_install()
{ {
if tasknumber "$pkg_names" >/dev/null ; then
assure_distr ALTLinux "install with task number"
assure_exists apt-repo
sudocmd apt-repo test $(tasknumber "$pkg_names")
return
fi
if [ -n "$show_command_only" ] ; then if [ -n "$show_command_only" ] ; then
epm_print_install_command $pkg_filenames epm_print_install_command $pkg_files
epm_print_install_names_command $pkg_names
return return
fi fi
if [ -n "$direct" ] && [ -z "$repack" ] ; then
__handle_direct_install
fi
# if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
if [ -n "$pkg_urls" ] ; then
load_helper epm-download
__handle_pkg_urls_to_install
fi
[ -z "$pkg_files$pkg_names" ] && info "Skip empty install list" && return 22 [ -z "$pkg_files$pkg_names" ] && info "Skip empty install list" && return 22
# to be filter happy
warmup_lowbase
local names="$(echo $pkg_names | filter_out_installed_packages)" local names="$(echo $pkg_names | filter_out_installed_packages)"
#local 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)"
[ -z "$files$names" ] && info "Skip empty install list" && return 22 # can be empty only after skip installed
if [ -z "$files$names" ] ; then
# TODO: assert $skip_installed
[ -n "$verbose" ] && info "Skip empty install list"
# FIXME: see to_remove below
return 22
fi
if [ -z "$files" ] && [ -z "$direct" ] ; then
# it is useful for first time running # it is useful for first time running
update_repo_if_needed update_repo_if_needed
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=$?
# 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
return $RETVAL
} }
...@@ -55,6 +55,7 @@ __emerge_install_ebuild() ...@@ -55,6 +55,7 @@ __emerge_install_ebuild()
# copy tarballs # copy tarballs
local DDIR=/usr/portage/distfiles local DDIR=/usr/portage/distfiles
# FIXME: use independent dir
[ -d /var/calculate/remote/distfiles ] && DDIR=/var/calculate/remote/distfiles [ -d /var/calculate/remote/distfiles ] && DDIR=/var/calculate/remote/distfiles
docmd cp -f $TARBALLS $DDIR/ || return docmd cp -f $TARBALLS $DDIR/ || return
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2013 Etersoft # Copyright (C) 2013, 2016, 2017 Etersoft
# Copyright (C) 2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2013, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -17,14 +17,26 @@ ...@@ -17,14 +17,26 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-check_updated_repo
load_helper epm-sh-warmup
epm_kernel_update() epm_kernel_update()
{ {
info "Starting update system kernel to the latest version" warmup_bases
info "Updating system kernel to the latest version..."
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
assure_exists update-kernel load_helper epm-query_package
sudocmd update-kernel if ! __epm_query_package kernel-image >/dev/null ; then
info "No installed kernel packages, skipping update"
return
fi
assure_exists update-kernel update-kernel 0.9.9
update_repo_if_needed
sudocmd update-kernel $pkg_filenames || return
docmd epm remove-old-kernels $pkg_filenames || fatal
return ;; return ;;
esac esac
......
#!/bin/sh
#
# Copyright (C) 2015 Etersoft
# Copyright (C) 2015 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# TODO: is it different from rpm --rebuilddb?
__repack_rpm_base()
{
assure_exists db_dump || fatal
assure_exists db_load || fatal
cd /var/lib/rpm || fatal
mv Packages Packages.BACKUP || fatal
# mask dependencies with a=
a='' db_dump Packages.BACKUP | a='' db_load Packages || fatal
rm Packages.BACKUP
}
epm_optimize()
{
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in
*-rpm)
#__repack_rpm_base
#rm -f /var/lib/rpm/__db*
rpm --rebuilddb
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016, 2017 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -17,22 +17,40 @@ ...@@ -17,22 +17,40 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-sh-warmup
__epm_packages_sort() __epm_packages_sort()
{ {
# FIXME: sort depends on --sort value # FIXME: sort depends on --sort value
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm) apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
docmd rpm -qa --queryformat "%{size} %{name}-%{version}-%{release}\n" $pkg_filenames | sort -n # FIXME: space with quotes problems, use point instead
warmup_rpmbase
docmd rpm -qa --queryformat "%{size}@%{name}-%{version}-%{release}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
;; ;;
apt-dpkg) apt-dpkg)
docmd dpkg-query -W --showformat="\${Size} \${Package}-\${Version}\n" $pkg_filenames | sort -n warmup_dpkgbase
docmd dpkg-query -W --showformat="\${Installed-Size}@\${Package}-\${Version}:\${Architecture}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
;; ;;
*) *)
fatal "Sorted package list are not realized for $PMTYPE" fatal "Sorted package list function is not implemented for $PMTYPE"
;; ;;
esac esac
} }
__aptcyg_print_full()
{
#showcmd apt-cyg show
local VERSION=$(apt-cyg show "$1" | grep -m1 "^version: " | sed -e "s|^version: ||g")
echo "$1-$VERSION"
}
__fo_pfn()
{
grep -v "^$" | grep -- "$pkg_filenames"
}
# TODO: we have a problem with error status here
epm_packages() epm_packages()
{ {
local CMD local CMD
...@@ -40,18 +58,32 @@ epm_packages() ...@@ -40,18 +58,32 @@ epm_packages()
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
warmup_rpmbase
# FIXME: strong equal
CMD="rpm -qa $pkg_filenames" CMD="rpm -qa $pkg_filenames"
[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames" [ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
;; docmd $CMD
return ;;
*-dpkg) *-dpkg)
warmup_dpkgbase
# FIXME: strong equal
#CMD="dpkg -l $pkg_filenames" #CMD="dpkg -l $pkg_filenames"
CMD="dpkg-query -W --showformat=\${Package}-\${Version}\n $pkg_filenames" CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}-\${Version}:\${Architecture}\n $pkg_filenames"
[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${Package}\n $pkg_filenames" # TODO: ${Architecture}
[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}\n $pkg_filenames"
showcmd $CMD
$CMD | grep "^i" | sed -e "s|.* ||g" | __fo_pfn
return ;;
snappy)
CMD="snappy info"
;; ;;
yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm) yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
warmup_rpmbase
# FIXME: strong equal
CMD="rpm -qa $pkg_filenames" CMD="rpm -qa $pkg_filenames"
[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames" [ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
;; docmd $CMD
return ;;
emerge) emerge)
CMD="qlist -I -C" CMD="qlist -I -C"
# print with colors for console output # print with colors for console output
...@@ -59,11 +91,27 @@ case $PMTYPE in ...@@ -59,11 +91,27 @@ case $PMTYPE in
;; ;;
pkgsrc) pkgsrc)
CMD="pkg_info" CMD="pkg_info"
;; showcmd $CMD
$CMD | sed -e "s| .*||g" | __fo_pfn
return ;;
pkgng)
if [ -n "$pkg_filenames" ] ; then
CMD="pkg info -E $pkg_filenames"
else
CMD="pkg info"
fi
showcmd $CMD
if [ -n "$short" ] ; then
$CMD | sed -e "s| .*||g" | sed -e "s|-[0-9].*||g" | __fo_pfn
else
$CMD | sed -e "s| .*||g" | __fo_pfn
fi
return ;;
pacman) pacman)
CMD="pacman -Qs $pkg_filenames" CMD="pacman -Qs $pkg_filenames"
showcmd $CMD
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
docmd $CMD | sed -e "s| .*||g" -e "s|.*/||g" | grep -v "^$" $CMD | sed -e "s| .*||g" -e "s|.*/||g" | __fo_pfn
return return
fi fi
;; ;;
...@@ -74,38 +122,67 @@ case $PMTYPE in ...@@ -74,38 +122,67 @@ case $PMTYPE in
conary) conary)
CMD="conary query" CMD="conary query"
;; ;;
# chocolatey) chocolatey)
# CMD="chocolatey list" CMD="chocolatey list"
# ;; ;;
slackpkg) slackpkg)
CMD="ls -1 /var/log/packages/" CMD="ls -1 /var/log/packages/"
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
# FIXME: does not work for libjpeg-v8a # FIXME: does not work for libjpeg-v8a
# TODO: remove last 3 elements (if arch is second from the last?) # TODO: remove last 3 elements (if arch is second from the last?)
# FIXME this hack # FIXME this hack
docmd ls -1 /var/log/packages/ | sed -e "s|-[0-9].*||g" | sed -e "s|libjpeg-v8a.*|libjpeg|g" docmd ls -1 /var/log/packages/ | sed -e "s|-[0-9].*||g" | sed -e "s|libjpeg-v8a.*|libjpeg|g" | __fo_pfn
return return
fi fi
;; ;;
homebrew) homebrew)
CMD="brew list $pkg_filenames" docmd brew list | xargs -n1 echo
;; ;;
ipkg) opkg)
CMD="ipkg list" CMD="opkg list-installed"
;;
apk)
CMD="apk info"
;;
tce)
CMD="ls -1 /usr/local/tce.installed"
;; ;;
guix) guix)
CMD="guix package -I" CMD="guix package -I"
;; ;;
xbps)
CMD="xbps-query -l"
showcmd $CMD
if [ -n "$short" ] ; then
$CMD | sed -e "s|^ii ||g" -e "s| .*||g" -e "s|\(.*\)-.*|\1|g" | __fo_pfn
else
$CMD | sed -e "s|^ii ||g" -e "s| .*||g" | __fo_pfn
fi
return 0
;;
android) android)
CMD="pm list packages" CMD="pm list packages"
docmd $CMD | sed -e "s|^package:||g" showcmd $CMD
$CMD | sed -e "s|^package:||g" | __fo_pfn
return return
;; ;;
aptcyg)
CMD="apt-cyg list $pkg_filenames"
if [ -z "$short" ] ; then
showcmd $CMD
# TODO: fix this slow way
for i in $($CMD) ; do
__aptcyg_print_full $i
done
return
fi
;;
*) *)
fatal "Have no suitable query command for $PMTYPE" fatal "Have no suitable query command for $PMTYPE"
;; ;;
esac esac
docmd $CMD docmd $CMD | __fo_pfn
# FIXME: we print empty lines, but will lost error status
} }
#!/bin/sh
#
# Copyright (C) 2015, 2017 Etersoft
# Copyright (C) 2015, 2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-query
load_helper epm-sh-warmup
epm_policy()
{
[ -n "$pkg_names" ] || fatal "Info: missing package(s) name"
warmup_bases
# get package name for hi level package management command (with version if supported and if possible)
pkg_names=$(__epm_get_hilevel_name $pkg_names)
case $PMTYPE in
apt-rpm)
docmd apt-cache policy $pkg_names
;;
apt-dpkg)
docmd apt-cache policy $pkg_names
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh
#
# Copyright (C) 2015, 2016, 2018 Etersoft
# Copyright (C) 2008, 2015, 2016, 2018 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Query variables from rpm package
# TODO: rpm only
query_package_field()
{
local FORMAT="%{$1}\n"
shift
local INSTALLED="-p"
# if not file, drop -p for get from rpm base
[ -e "$1" ] || INSTALLED=""
rpmquery $INSTALLED --queryformat "$FORMAT" "$@"
}
# build binary package list (1st - repo dir, 2st - pkgname)
# algorithm: list all files in PKGDIR, print packages with our source pkg name
print_binpkgfilelist()
{
local PKGDIR=$1
local PKGNAME=$(basename $2)
find "$PKGDIR" ! -name '*\.src\.rpm' -name '*\.rpm' -execdir \
rpmquery -p --qf='%{sourcerpm}\t%{name}-%{version}-%{release}.%{arch}.rpm\n' "{}" \; \
| grep "^$PKGNAME[[:space:]].*" \
| cut -f2 \
| xargs -n1 -I "{}" echo -n "$PKGDIR/{} "
}
# TODO: need try detect more strict
# TODO: package name mask for every system
#PKGNAMEMASK1="\(.*\)-\([^0-9].*[^0-9]\)-\(.*[0-9].*\)"
# mask to parse package name
PKGNAMEMASK="\(.*\)-\([0-9].*\)-\(.*[0-9].*\)\.\(.*\)\.\(.*\)"
print_name()
{
echo "$@" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK|\1|g"
}
print_version()
{
echo "$1" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK|\2|g"
}
print_release()
{
echo "$1" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK|\3|g"
}
print_version_release()
{
echo "$1" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK|\2-\3|g"
}
print_pkgname()
{
local i
for i in $@ ; do
# TODO: deb and other, arch string
echo "$(basename "$i") " | sed -e "s|\.[a-z_0-9]*\.rpm||g" -e "s|\(.*\)_\(.*\)_[a-z_0-9]*\.deb|\1-\2|g"
done
}
print_srcname()
{
print_name "$(print_srcpkgname "$@")"
}
print_specname()
{
# CHECKME: it is possible to have two or more specs in one package?
rpm -qlp "$@" | grep "\.spec\$"
}
print_srcpkgname()
{
query_package_field sourcerpm "$@"
}
compare_version()
{
which rpmevrcmp 2>/dev/null >/dev/null || fatal "rpmevrcmp exists in ALT Linux only"
rpmevrcmp "$@"
}
__epm_print()
{
local WHAT="$1"
shift
local FNFLAG=
local PKFLAG=
[ "$1" = "from" ] && shift
[ "$1" = "for" ] && shift
[ "$1" = "in" ] && shift
if [ "$1" = "filename" ] ; then
FNFLAG="$1"
shift
fi
if [ "$1" = "package" ] ; then
PKFLAG="$1"
shift
fi
case "$WHAT" in
"")
fatal "Use epm print help for get help."
;;
"-h"|"--help"|"help")
cat <<EOF
Examples:
epm print name [from filename|for package] NN print only name of package name or package file
epm print version [from filename|for package] NN print only version of package name or package file
epm print release [from filename|for package] NN print only release of package name or package file
epm print version-release [from filename|for package] NN print only release-release of package name or package file
epm print field FF for package NN print field of the package
epm print pkgname from filename NN print package name for the package file
epm print srcname from filename NN print source name for the package file
epm print srcpkgname from [filename|package] NN print source package name for the binary package file
epm print specname from filename NN print spec filename for the source package file
epm print binpkgfilelist in DIR for NN list binary package(s) filename(s) from DIR for the source package file
epm print compare [package] version N1 N2 compare (package) versions and print -1, 0, 1
EOF
;;
"name")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_name "$(print_pkgname "$@")"
elif [ -n "$PKFLAG" ] ; then
query_package_field "name" "$@"
else
print_name "$@"
fi
;;
"version")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_version "$(print_pkgname "$@")"
elif [ -n "$PKFLAG" ] ; then
query_package_field "version" "$@"
else
print_version "$@"
fi
;;
"release")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_release "$(print_pkgname "$@")"
elif [ -n "$PKFLAG" ] ; then
query_package_field "release" "$@"
else
print_release "$@"
fi
;;
"version-release")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_version_release "$(print_pkgname "$@")"
elif [ -n "$PKFLAG" ] ; then
echo "$(query_package_field "version" "$@")-$(query_package_field "release" "$@")"
else
print_version_release "$@"
fi
;;
"field")
[ -n "$1" ] || fatal "Arg is missed"
local FIELD="$1"
shift
[ "$1" = "for" ] && shift
query_package_field "$FIELD" "$@"
;;
"pkgname")
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
# TODO: drop_pkg_extensions
print_pkgname "$@"
;;
"srcname")
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
print_srcname "$@"
;;
"srcpkgname")
[ -n "$FNFLAG" ] || [ -n "$PKFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
print_srcpkgname "$@"
;;
"specname")
[ -n "$FNFLAG" ] || [ -n "$PKFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
print_specname "$@"
;;
"binpkgfilelist")
# TODO: rpm only
# TODO: replace get_binpkg_list
local DIR="$1"
shift
[ "$1" = "for" ] && shift
[ -n "$DIR" ] || fatal "DIR arg is missed"
[ -n "$1" ] || fatal "source package filename is missed"
print_binpkgfilelist "$DIR" "$1"
;;
"compare")
[ "$1" = "version" ] && shift
[ -n "$1" ] || fatal "Arg is missed"
#if [ -n "$PKFLAG" ] ; then
# query_package_field "name" "$@"
#else
compare_version "$1" "$2"
#fi
;;
*)
fatal "Unknown command $ epm print $WHAT. Use epm print help for get help."
;;
esac
}
epm_print()
{
[ -n "$pkg_filenames" ] || fatal "Missed args. Use epm print help for get help."
# Note! do not quote args below (see eterbug #11863)
# shellcheck disable=SC2046
__epm_print $(eval echo $quoted_args)
}
...@@ -22,10 +22,18 @@ load_helper epm-query_file ...@@ -22,10 +22,18 @@ load_helper epm-query_file
# Inspired by http://www.altlinux.org/Tips # Inspired by http://www.altlinux.org/Tips
epm_programs() epm_programs()
{ {
case $DISTRNAME in
FreeBSD|NetBSD|OpenBSD|Solaris)
local DESKTOPDIR=/usr/local/share/applications
;;
*)
local DESKTOPDIR=/usr/share/applications local DESKTOPDIR=/usr/share/applications
;;
esac
[ -d "$DESKTOPDIR" ] || fatal "There is no $DESKTOPDIR dir on the system." [ -d "$DESKTOPDIR" ] || fatal "There is no $DESKTOPDIR dir on the system."
#find /usr/share/applications -type f -name "*.desktop" | while read f; do pkg_files="$f" quiet=1 short=1 epm_query_file ; done | sort -u #find /usr/share/applications -type f -name "*.desktop" | while read f; do pkg_files="$f" quiet=1 short=1 epm_query_file ; done | sort -u
showcmd "find $DESKTOPDIR -type f -name "*.desktop" | xargs $0 -qf --quiet --short | sort -u" showcmd "find $DESKTOPDIR -type f -print0 -name "*.desktop" | xargs -0 $0 -qf --quiet --short | sort -u"
find /usr/share/applications -type f -name "*.desktop" | \ find $DESKTOPDIR -type f -print0 -name "*.desktop" | \
xargs $0 -qf --quiet --short | sort -u xargs -0 $0 -qf --quiet --short | sort -u
} }
...@@ -18,16 +18,22 @@ ...@@ -18,16 +18,22 @@
# #
load_helper epm-query load_helper epm-query
load_helper epm-print
epm_provides_files() epm_provides_files()
{ {
local pkg_files="$*"
[ -n "$pkg_files" ] || return [ -n "$pkg_files" ] || return
case $(get_package_type $pkg_files) in local PKGTYPE="$(get_package_type $pkg_files)"
case $PKGTYPE in
rpm) rpm)
assure_exists rpm
docmd rpm -q --provides -p $pkg_files docmd rpm -q --provides -p $pkg_files
;; ;;
deb) deb)
assure_exists dpkg
# FIXME: will we provide ourself? # FIXME: will we provide ourself?
docmd dpkg -I $pkg_files | grep "^ *Provides:" | sed "s|^ *Provides:||g" docmd dpkg -I $pkg_files | grep "^ *Provides:" | sed "s|^ *Provides:||g"
;; ;;
...@@ -40,6 +46,7 @@ epm_provides_files() ...@@ -40,6 +46,7 @@ epm_provides_files()
epm_provides_names() epm_provides_names()
{ {
local pkg_names="$*"
local CMD local CMD
[ -n "$pkg_names" ] || return [ -n "$pkg_names" ] || return
...@@ -56,7 +63,7 @@ case $PMTYPE in ...@@ -56,7 +63,7 @@ case $PMTYPE in
return return
fi fi
;; ;;
urpm-rpm|zypper-rpm|yum-rpm) urpm-rpm|zypper-rpm|yum-rpm|dnf-rpm)
if is_installed $pkg_names ; then if is_installed $pkg_names ; then
CMD="rpm -q --provides" CMD="rpm -q --provides"
else else
...@@ -70,6 +77,9 @@ case $PMTYPE in ...@@ -70,6 +77,9 @@ case $PMTYPE in
# yum-rpm) # yum-rpm)
# CMD="yum deplist" # CMD="yum deplist"
# ;; # ;;
pkgng)
CMD="pkg info -b"
;;
apt-dpkg) apt-dpkg)
# FIXME: need fix for a few names case # FIXME: need fix for a few names case
if is_installed $pkg_names ; then if is_installed $pkg_names ; then
...@@ -95,6 +105,7 @@ epm_provides() ...@@ -95,6 +105,7 @@ epm_provides()
{ {
[ -n "$pkg_filenames" ] || fatal "Provides: missing package(s) name" [ -n "$pkg_filenames" ] || fatal "Provides: missing package(s) name"
epm_provides_files epm_provides_files $pkg_files
epm_provides_names # shellcheck disable=SC2046
epm_provides_names $(print_name $pkg_names)
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012, 2013 Etersoft # Copyright (C) 2012, 2013, 2015-2017 Etersoft
# Copyright (C) 2012, 2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2013, 2015-2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -18,6 +18,51 @@ ...@@ -18,6 +18,51 @@
# #
load_helper epm-packages load_helper epm-packages
load_helper epm-print
# pkg suffix
__print_with_arch_suffix()
{
local pkg="$1"
local suffix="$2"
[ -n "$pkg" ] || return 1
# 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"
}
# add suffix .x86_64 if we have 64 arch
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
local p
# check only packages without arch
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()
...@@ -30,23 +75,55 @@ _get_grep_exp() ...@@ -30,23 +75,55 @@ _get_grep_exp()
} }
# TODO: combine with -qa (the difference only in return status now) # TODO: combine with -qa (the difference only in return status now)
_query_via_packages_list() _shortquery_via_packages_list()
{ {
local res=0 local res=1
local grepexp local grepexp
local firstpkg=$1 local firstpkg=$1
shift shift
grepexp=$(_get_grep_exp $firstpkg) grepexp=$(_get_grep_exp $firstpkg)
# TODO: we miss status due grep
# Note: double call due stderr redirect
# Note: we use short=1 here due grep by ^name$
# separate first line for print out command # separate first line for print out command
short=1 pkg_filenames=$firstpkg epm_packages | grep -- "$grepexp" || res=1 short=1 pkg_filenames=$firstpkg epm_packages | grep -- "$grepexp" && res=0 || res=1
local pkg
for pkg in "$@" ; do for pkg in "$@" ; do
grepexp=$(_get_grep_exp $pkg) grepexp=$(_get_grep_exp $pkg)
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
}
# Note: modified from _shortquery_via_packages_list
# TODO: non optimal double epm packages call
_query_via_packages_list()
{
local res=1
local grepexp
local firstpkg=$1
shift
grepexp=$(_get_grep_exp $firstpkg)
# TODO: we miss status due grep
# TODO: grep correctly
# Note: double call due stderr redirect
# Note: we use short=1 here due grep by ^name$
# separate first line for print out command
short=1 pkg_filenames=$firstpkg epm_packages | grep -q -- "$grepexp" && quiet=1 pkg_filenames=$firstpkg epm_packages && res=0 || res=1
local pkg
for pkg in "$@" ; do
grepexp=$(_get_grep_exp $pkg)
short=1 pkg_filenames=$pkg epm_packages 2>/dev/null | grep -q -- "$grepexp" && quiet=1 pkg_filenames=$pkg epm_packages || res=1
done
return $res return $res
} }
...@@ -66,11 +143,11 @@ __epm_get_hilevel_nameform() ...@@ -66,11 +143,11 @@ __epm_get_hilevel_nameform()
echo $pkg echo $pkg
return return
;; ;;
yum-rpm) yum-rpm|dnf-rpm)
# just use strict version with Epoch and Serial # just use strict version with Epoch and Serial
local pkg local pkg
pkg=$(rpm -q --queryformat "%{EPOCH}:%{NAME}%{VERSION}-%{RELEASE}.${ARCH}\n" $1) pkg=$(rpm -q --queryformat "%{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" $1)
echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.${ARCH}\n" $1) echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" $1)
echo $pkg echo $pkg
return return
;; ;;
...@@ -88,11 +165,12 @@ __epm_get_hilevel_name() ...@@ -88,11 +165,12 @@ __epm_get_hilevel_name()
for i in $@ ; do for i in $@ ; do
local pkg local pkg
# get short form in pkg # get short form in pkg
quiet=1 short=1 pkg=$(__epm_query_name $i) || continue # drop not installed packages # FIXME: where we use it? continue or pkg=$i?
quiet=1 pkg=$(__epm_query_shortname "$i") || pkg="$i" #continue # drop not installed packages
# if already short form, skipped # if already short form, skipped
[ "$pkg" = "$i" ] && echo "$i" && continue [ "$pkg" = "$i" ] && echo "$i" && continue
# try get long form or use short form # try get long form or use short form
__epm_get_hilevel_nameform $i || echo $pkg __epm_get_hilevel_nameform "$i" || echo $pkg
done done
} }
...@@ -119,6 +197,16 @@ __epm_query_file() ...@@ -119,6 +197,16 @@ __epm_query_file()
docmd $CMD $@ docmd $CMD $@
} }
# hack: dpkg -W will print names for removed packages too (until newest Ubuntu)
__epm_query_dpkg_check()
{
local i
for i in $@ ; do
a='' dpkg -s $i >/dev/null 2>/dev/null || return
done
return 0
}
__epm_query_name() __epm_query_name()
{ {
local CMD local CMD
...@@ -128,26 +216,36 @@ __epm_query_name() ...@@ -128,26 +216,36 @@ __epm_query_name()
case $PMTYPE in case $PMTYPE in
*-rpm) *-rpm)
CMD="rpm -q" CMD="rpm -q"
[ -n "$short" ] && CMD="rpm -q --queryformat %{name}\n"
;; ;;
*-dpkg) *-dpkg)
#docmd dpkg -l $@ | grep "^ii" #docmd dpkg -l $@ | grep "^ii"
CMD="dpkg-query -W --showformat=\${Package}-\${Version}\n" #CMD="dpkg-query -W --showformat=\${Package}-\${Version}\n"
[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${Package}\n" docmd dpkg-query -W "--showformat=\${Package}-\${Version}\n" $@ || return
__epm_query_dpkg_check $@ || return
return
;; ;;
npackd) npackd)
docmd "npackdcl path --package=$@" docmd "npackdcl path --package=$1"
return return
;; ;;
conary) conary)
CMD="conary query" CMD="conary query"
;; ;;
homebrew) homebrew)
warning "fix query" docmd brew info "$1" >/dev/null 2>/dev/null && echo "$1" && return
return 1 return 1
;; ;;
pacman)
docmd pacman -Q $@
return
;;
# TODO: need to print name if exists
#pkgng)
# CMD="pkg info -e"
# ;;
# Note: slackpkg info pkgname # Note: slackpkg info pkgname
*) *)
# default slow workaround
_query_via_packages_list $@ _query_via_packages_list $@
return return
;; ;;
...@@ -156,10 +254,58 @@ __epm_query_name() ...@@ -156,10 +254,58 @@ __epm_query_name()
docmd $CMD $@ docmd $CMD $@
} }
__epm_query_shortname()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
*-rpm)
CMD="rpm -q --queryformat %{name}\n"
;;
*-dpkg)
#CMD="dpkg-query -W --showformat=\${Package}\n"
docmd dpkg-query -W "--showformat=\${Package}\n" $@ || return
__epm_query_dpkg_check $@ || return
return
;;
npackd)
docmd "npackdcl path --package=$1"
return
;;
conary)
CMD="conary query"
;;
homebrew)
docmd brew info "$1" >/dev/null 2>/dev/null && echo "$1" && return
return 1
;;
# TODO: check status
#pacman)
# docmd pacman -Q $@ | sed -e "s| .*||g"
# return
# ;;
# TODO: need to print name if exists
#pkgng)
# CMD="pkg info -e"
# ;;
# Note: slackpkg info pkgname
*)
# default slow workaround
_shortquery_via_packages_list $@
return
;;
esac
docmd $CMD $@
}
# check if pkg is installed # check if pkg is installed
is_installed() is_installed()
{ {
pkg_filenames="$@" pkg_names="$@" epm_query >/dev/null 2>/dev/null __epm_query_shortname "$@" >/dev/null 2>/dev/null
# broken way to recursive call here (overhead!) # broken way to recursive call here (overhead!)
#epm installed $@ >/dev/null 2>/dev/null #epm installed $@ >/dev/null 2>/dev/null
} }
...@@ -169,7 +315,7 @@ separate_installed() ...@@ -169,7 +315,7 @@ separate_installed()
{ {
pkg_installed= pkg_installed=
pkg_noninstalled= pkg_noninstalled=
for i in $* ; do for i in "$@" ; do
is_installed $i && pkg_installed="$pkg_installed $i" || pkg_noninstalled="$pkg_noninstalled $i" is_installed $i && pkg_installed="$pkg_installed $i" || pkg_noninstalled="$pkg_noninstalled $i"
done done
} }
...@@ -180,5 +326,11 @@ epm_query() ...@@ -180,5 +326,11 @@ epm_query()
__epm_query_file $pkg_files || return __epm_query_file $pkg_files || return
__epm_query_name $pkg_names || return if [ -n "$short" ] ; then
# shellcheck disable=SC2046
__epm_query_shortname $(print_name $pkg_names) || return
else
# shellcheck disable=SC2046
__epm_query_name $(print_name $pkg_names) || return
fi
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2009, 2012 Etersoft # Copyright (C) 2009, 2012, 2016 Etersoft
# Copyright (C) 2009, 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2009, 2012, 2016 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,21 +17,31 @@ ...@@ -17,21 +17,31 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-search_file
# copied from etersoft-build-utils/bin/rpmqf # copied from etersoft-build-utils/bin/rpmqf
# use and modify TOFILE recursively # TODO: check for lib64/name situations
__abs_filename()
{
if echo "$1" | grep -q "/" ; then
echo "$1"
return
fi
if [ -e "$1" ] ; then
echo "$(pwd)/$1"
return
fi
echo "$1"
}
__do_query_real_file() __do_query_real_file()
{ {
local LINKTO1 LINKTO
local TOFILE local TOFILE
# get canonical path # get canonical path
if [ -e "$1" ] ; then if [ -e "$1" ] ; then
TOFILE=$1 TOFILE="$(__abs_filename "$1")"
else else
TOFILE=`which $1 2>/dev/null || echo $1` TOFILE=$(which "$1" 2>/dev/null || echo "$1")
if [ "$TOFILE" != "$1" ] ; then if [ "$TOFILE" != "$1" ] ; then
info "Note: $1 is placed as $TOFILE" info "Note: $1 is placed as $TOFILE"
fi fi
...@@ -39,10 +49,12 @@ __do_query_real_file() ...@@ -39,10 +49,12 @@ __do_query_real_file()
# get value of symbolic link # get value of symbolic link
if [ -L "$TOFILE" ] ; then if [ -L "$TOFILE" ] ; then
__do_query $TOFILE local LINKTO
LINKTO=`readlink "$TOFILE"` __do_query "$TOFILE"
LINKTO=$(readlink -f "$TOFILE")
info "Note: $TOFILE is link to $LINKTO" info "Note: $TOFILE is link to $LINKTO"
__do_query_real_file "$LINKTO" __do_query_real_file "$LINKTO"
return
fi fi
FULLFILEPATH="$TOFILE" FULLFILEPATH="$TOFILE"
...@@ -51,7 +63,7 @@ __do_query_real_file() ...@@ -51,7 +63,7 @@ __do_query_real_file()
dpkg_print_name_version() dpkg_print_name_version()
{ {
local ver i local ver i
for i in $* ; do for i in "$@" ; do
ver=$(dpkg -s $i 2>/dev/null | grep "Version:" | sed -e "s|Version: ||g") ver=$(dpkg -s $i 2>/dev/null | grep "Version:" | sed -e "s|Version: ||g")
if [ -z "$ver" ] ; then if [ -z "$ver" ] ; then
echo "$i" echo "$i"
...@@ -70,10 +82,10 @@ __do_query() ...@@ -70,10 +82,10 @@ __do_query()
CMD="rpm -qf" CMD="rpm -qf"
;; ;;
*-dpkg) *-dpkg)
showcmd dpkg -S $1 showcmd dpkg -S "$1"
dpkg_print_name_version $(dpkg -S $1 | grep -v "^diversion by" | sed -e "s|:.*||") dpkg_print_name_version "$(dpkg -S $1 | grep -v "^diversion by" | sed -e "s|:.*||")"
return ;; return ;;
yum-rpm|urpm-rpm) yum-rpm|dnf-rpm|urpm-rpm)
CMD="rpm -qf" CMD="rpm -qf"
;; ;;
zypper-rpm) zypper-rpm)
...@@ -86,6 +98,9 @@ __do_query() ...@@ -86,6 +98,9 @@ __do_query()
pacman) pacman)
CMD="pacman -Qo" CMD="pacman -Qo"
;; ;;
pkgng)
CMD="pkg which"
;;
conary) conary)
CMD="conary query --path" CMD="conary query --path"
;; ;;
...@@ -94,8 +109,17 @@ __do_query() ...@@ -94,8 +109,17 @@ __do_query()
docmd grep -R -- "$(echo $@ | sed -e 's|^/\+||g')" /var/log/packages | sed -e "s|/var/log/packages/||g" docmd grep -R -- "$(echo $@ | sed -e 's|^/\+||g')" /var/log/packages | sed -e "s|/var/log/packages/||g"
return return
;; ;;
ipkg) opkg)
CMD="ipkg files" CMD="opkg search"
;;
xbps)
# FIXME: maybe it is search file?
CMD="xbps-query -o"
;;
aptcyg)
#CMD="apt-cyg packageof"
# is not implemented locally
return 1
;; ;;
*) *)
fatal "Have no suitable query command for $PMTYPE" fatal "Have no suitable query command for $PMTYPE"
...@@ -114,8 +138,8 @@ __do_short_query() ...@@ -114,8 +138,8 @@ __do_short_query()
CMD="rpm -qf --queryformat %{NAME}\n" CMD="rpm -qf --queryformat %{NAME}\n"
;; ;;
NOapt-dpkg) NOapt-dpkg)
showcmd dpkg -S $1 showcmd dpkg -S "$1"
dpkg_print_name_version $(dpkg -S $1 | sed -e "s|:.*||" | grep -v "^diversion by") dpkg_print_name_version "$(dpkg -S $1 | sed -e "s|:.*||" | grep -v "^diversion by")"
return ;; return ;;
NOemerge) NOemerge)
assure_exists equery assure_exists equery
...@@ -140,21 +164,25 @@ __do_short_query() ...@@ -140,21 +164,25 @@ __do_short_query()
epm_query_file() epm_query_file()
{ {
# И где это используется?
# in short mode print handle only real names and do short output # in short mode print handle only real names and do short output
# TODO: move to separate command? # TODO: move to separate command?
# FIXME: it is possible use query # FIXME: it is possible use query
if [ -n "$short" ] ; then if [ -n "$short" ] ; then
[ -n "$pkg_files" ] || fatal "Run query without file names (needed path to files)" [ -n "$pkg_files$pkg_dirs" ] || fatal "Run query without file names (needed path to files)"
__do_short_query $pkg_files __do_short_query $pkg_files $pkg_dirs
return return
fi fi
# file can exists or not # file can exists or not
[ -n "$pkg_filenames" ] || fatal "Run query without file names" [ -n "$pkg_filenames" ] || fatal "Run query without file names"
#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
} }
...@@ -20,6 +20,11 @@ ...@@ -20,6 +20,11 @@
load_helper epm-packages load_helper epm-packages
load_helper epm-search load_helper epm-search
__epm_query_package()
{
(pkg_filenames="$*" quoted_args="$*" quiet=1 epm_query_package)
}
epm_query_package() epm_query_package()
{ {
[ -n "$pkg_filenames" ] || fatal "Please, use search with some argument or run epmqa for get all packages." [ -n "$pkg_filenames" ] || fatal "Please, use search with some argument or run epmqa for get all packages."
...@@ -27,5 +32,6 @@ epm_query_package() ...@@ -27,5 +32,6 @@ epm_query_package()
local MGS local MGS
MGS=$(eval __epm_search_make_grep $quoted_args) MGS=$(eval __epm_search_make_grep $quoted_args)
EXTRA_SHOWDOCMD=$MGS EXTRA_SHOWDOCMD=$MGS
eval "pkg_filenames= epm_packages \"$(eval get_firstarg $quoted_args)\" $MGS" # Note: get all packages list and do grep
(eval "pkg_filenames='' epm_packages \"$(eval get_firstarg $quoted_args)\" $MGS")
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2014 Etersoft # Copyright (C) 2012,2014,2016,2017 Etersoft
# Copyright (C) 2012,2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012,2014,2016,2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -18,21 +18,33 @@ ...@@ -18,21 +18,33 @@
# #
load_helper epm-install load_helper epm-install
load_helper epm-sh-warmup
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg # copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
epm_reinstall_names() epm_reinstall_names()
{ {
[ -n "$1" ] || return [ -n "$1" ] || return
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
sudocmd apt-get --reinstall install $@ local APTOPTIONS="$(subst_option non_interactive -y)"
sudocmd apt-get --reinstall $APTOPTIONS install $@
return ;; return ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude reinstall $@ sudocmd aptitude reinstall $@
return ;; return ;;
yum-rpm)
sudocmd yum reinstall $@
return ;;
dnf-rpm) dnf-rpm)
sudocmd dnf reinstall $@ sudocmd dnf reinstall $@
return ;; return ;;
pkgng)
sudocmd pkg install -f $@
return ;;
opkg)
sudocmd opkg --force-reinstall install $@
return ;;
slackpkg) slackpkg)
sudocmd_foreach "/usr/sbin/slackpkg reinstall" $@ sudocmd_foreach "/usr/sbin/slackpkg reinstall" $@
return ;; return ;;
...@@ -68,6 +80,13 @@ epm_reinstall() ...@@ -68,6 +80,13 @@ epm_reinstall()
{ {
[ -n "$pkg_filenames" ] || fatal "Reinstall: missing package(s) name." [ -n "$pkg_filenames" ] || fatal "Reinstall: missing package(s) name."
warmup_lowbase
# get package name for hi level package management command (with version if supported and if possible)
pkg_names=$(__epm_get_hilevel_name $pkg_names)
warmup_hibase
epm_reinstall_names $pkg_names epm_reinstall_names $pkg_names
epm_reinstall_files $pkg_files epm_reinstall_files $pkg_files
} }
......
#!/bin/sh
#
# Copyright (C) 2013 Etersoft
# Copyright (C) 2013 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
epm_release_upgrade()
{
info "Starting upgrade whole system to the next release"
info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
case $PMTYPE in
apt-rpm)
docmd epm update
docmd epm install apt rpm
showcmd "TODO: change repo"
docmd epm Upgrade
docmd epm update-kernel
;;
*-dpkg)
sudocmd do-release-upgrade -d
;;
yum-rpm)
docmd epm install rpm yum
sudocmd yum clean all
# TODO
showcmd rpm -Uvh http://mirror.yandex.ru/fedora/linux/releases/16/Fedora/x86_64/os/Packages/fedora-release-16-1.noarch.rpm
docmd epm Upgrade
;;
urpm-rpm)
sudocmd urpmi.removemedia -av
# TODO
showcmd urpmi.addmedia --distrib http://mirror.yandex.ru/mandriva/devel/2010.2/i586/
sudocmd urpmi --auto-update --replacefiles
;;
zypper-rpm)
docmd epm repolist
# TODO
# sudocmd zypper rr <номер_репозитория>
showcmd rr N
showcmd epm ar http://mirror.yandex.ru/opensuse/distribution/11.1/repo/oss 11.1oss
showcmd zypper ref
docmd epm update
docmd epm install rpm zypper
docmd epm upgrade
;;
pacman)
epm Upgrade
;;
conary)
epm Upgrade
;;
emerge)
epm Upgrade
;;
guix)
sudocmd guix pull --verbose
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
sudocmd $CMD $pkg_filenames
}
#!/bin/sh
#
# Copyright (C) 2013, 2016, 2017 Etersoft
# Copyright (C) 2013, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-query
confirm_info()
{
info "$*"
if [ -z "$non_interactive" ] ; then
confirm "Are you sure? [y/N]" || fatal "Exiting"
fi
}
__replace_text_in_alt_repo()
{
local i
for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
[ -s "$i" ] || continue
regexp_subst "$1" "$i"
done
}
__wcount()
{
echo "$*" | wc -w
}
__detect_alt_release_by_repo()
{
local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
| grep -v "^#" \
| grep "[tp][5-9]/branch/" \
| sed -e "s|.*\([tp][5-9]\)/branch.*|\1|g" \
| sort -u )
if [ "$(__wcount $BRD)" = "1" ] ; then
echo "$BRD"
return
fi
local BRD=$(cat /etc/apt/sources.list /etc/apt/sources.list.d/*.list \
| grep -v "^#" \
| grep "Sisyphus/" \
| sed -e "s|.*\(Sisyphus\).*|\1|g" \
| sort -u )
if [ "$(__wcount $BRD)" = "1" ] ; then
echo "$BRD"
return
fi
return 1
}
__replace_alt_version_in_repo()
{
local i
assure_exists apt-repo
#echo "Upgrading $DISTRNAME from $1 to $2 ..."
docmd apt-repo list | sed -e "s|\($1\)|{\1}->{$2}|g" | grep -E --color -- "$1"
# ask and replace only we will have changes
if a='' apt-repo list | grep -E -q -- "$1" ; then
__replace_text_in_alt_repo "/^ *#/! s!$1!$2!g"
fi
docmd apt-repo list
}
__alt_repofix()
{
load_helper epm-repofix
showcmd epm repofix
quiet=1 pkg_filenames='' epm_repofix >/dev/null
__replace_text_in_alt_repo "/^ *#/! s!\[[tpc][6-9]\]![updates]!g"
}
__get_conflict_release_pkg()
{
epmqf --quiet --short /etc/fedora-release | head -n1
}
get_fix_release_pkg()
{
local TOINSTALL=''
local FORCE=''
if [ "$1" == "--force" ] ; then
FORCE="$1"
shift
fi
local TO="$1"
if [ "$TO" = "Sisyphus" ] ; then
TO="sisyphus"
echo "apt-conf-$TO"
else
echo "apt-conf-branch"
fi
if [ "$FORCE" == "--force" ] ; then
# assure we have set needed release
TOINSTALL="altlinux-release-$TO"
else
# just assure we have /etc/altlinux-release and switched from sisyphus
if [ ! -s /etc/altlinux-release ] || epmqf /etc/altlinux-release | grep -q sisyphus ; then
TOINSTALL="altlinux-release-$TO"
fi
fi
# workaround against obsoleted altlinux-release-sisyphus package from 2008 year
[ "$TOINSTALL" = "altlinux-release-sisyphus" ] && TOINSTALL="branding-alt-sisyphus-release"
if [ -n "$TOINSTALL" ] ; then
echo "$TOINSTALL"
# workaround against
# file /etc/fedora-release from install of altlinux-release-p8-20160414-alt1 conflicts with file from package branding-simply-linux-release-8.2.0-alt1
# problem
if __get_conflict_release_pkg | grep -q -v "^altlinux-release" && [ "$TOINSTALL" != "$(__get_conflict_release_pkg)" ] ; then
echo $(__get_conflict_release_pkg)-
fi
fi
}
__update_to_the_distro()
{
local TO="$1"
__alt_repofix
case "$TO" in
p7)
docmd epm update || fatal
docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
__alt_repofix
__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
docmd epm update || fatal
docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
;;
p8)
docmd epm update || fatal
docmd epm install rpm apt "$(get_fix_release_pkg --force "$TO")" || fatal "Check an error and run epm release-upgrade again"
__alt_repofix
__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![$TO]!g"
docmd epm update || fatal
# sure we have systemd if systemd is running
if is_installed systemd && is_active_systemd systemd ; then
docmd epm install systemd || fatal
fi
docmd epm upgrade || fatal "Check an error and run epm release-upgrade again"
;;
Sisyphus)
docmd epm update || fatal
local ADDPKG
ADDPKG=$(epm -q --short make-initrd sssd-ad 2>/dev/null)
docmd epm install librpm7 librpm rpm apt $ADDPKG "$(get_fix_release_pkg --force "$TO")" ConsoleKit2- || fatal "Check an error and run again"
#docmd 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
}
__update_alt_to_next_distro()
{
local TO="$2"
local FROM="$1"
[ -n "$TO" ] || TO="$FROM"
info
case "$*" in
"p6"|"p6 p7"|"t6 p7"|"c6 c7")
TO="p7"
confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo "$FROM/branch/" "$TO/branch/"
__update_to_the_distro "$TO"
docmd epm update-kernel
info "Done."
info "Run epm release-upgrade again for update to p8"
;;
"p7"|"p7 p8"|"t7 p8"|"c7 c8"|"p8 p8")
TO="p8"
confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo $FROM/branch/ $TO/branch/
__update_to_the_distro $TO
docmd epm update-kernel || fatal
info "Done."
;;
"Sisyphus p8")
TO="p8"
confirm_info "Downgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install "$(get_fix_release_pkg "$FROM")" || fatal
__replace_alt_version_in_repo "$FROM/" "$TO/branch/"
__replace_text_in_alt_repo "/^ *#/! s!\[alt\]![$TO]!g"
__update_to_the_distro $TO
docmd epm downgrade || fatal
info "Done."
;;
"p8 Sisyphus"|"Sisyphus Sisyphus")
TO="Sisyphus"
confirm_info "Upgrade $DISTRNAME from $FROM to $TO ..."
docmd epm install rpm apt "$(get_fix_release_pkg "$FROM")" || fatal
docmd epm upgrade || fatal
__replace_alt_version_in_repo "$FROM/branch/" "$TO/"
__alt_repofix
__replace_text_in_alt_repo "/^ *#/! s!\[updates\]![alt]!g"
__update_to_the_distro $TO
docmd epm update-kernel || fatal
info "Done."
;;
*)
if [ "$FROM" = "$TO" ] ; then
info "It seems your system is already updated to newest $DISTRNAME $TO"
else
warning "Have no idea how to update from $DISTRNAME $FROM to $DISTRNAME $TO."
fi
info "Try run f.i. # epm release-upgrade p8 or # epm release-upgrade Sisyphus"
info "Also possible you need install altlinux-release-p? package for correct distro version detecting"
return 1
esac
}
epm_release_upgrade()
{
assure_root
info "Starting upgrade whole system to the next release"
info "Check also http://wiki.etersoft.ru/Admin/UpdateLinux"
# TODO: it is possible eatmydata does not do his work
export EPMNOEATMYDATA=1
case $DISTRNAME in
ALTLinux)
docmd epm update || fatal
# try to detect current release by repo
if [ "$DISTRVERSION" = "Sisyphus" ] || [ -z "$DISTRVERSION" ] ; then
local dv
dv="$(__detect_alt_release_by_repo)"
if [ -n "$dv" ] && [ "$dv" != "$DISTRVERSION" ] ; then
DISTRVERSION="$dv"
info "Detected running $DISTRNAME $DISTRVERSION (according to using repos)"
fi
fi
__alt_repofix
# check forced target
if [ -n "$pkg_filenames" ] ; then
[ "$(__wcount $pkg_filenames)" = "1" ] || fatal "Too many args: $pkg_filenames"
fi
# TODO: ask before upgrade
__update_alt_to_next_distro $DISTRVERSION $pkg_filenames
return
;;
*)
;;
esac
case $PMTYPE in
apt-rpm)
#docmd epm update
info "Have no idea how to upgrade $DISTRNAME"
;;
*-dpkg)
assure_exists do-release-upgrade update-manager-core
sudocmd do-release-upgrade
;;
yum-rpm)
docmd epm install rpm yum
sudocmd yum clean all
# TODO
showcmd rpm -Uvh http://mirror.yandex.ru/fedora/linux/releases/16/Fedora/x86_64/os/Packages/fedora-release-16-1.noarch.rpm
docmd epm Upgrade
;;
dnf-rpm)
info "Check https://fedoraproject.org/wiki/DNF_system_upgrade for an additional info"
docmd epm install dnf
sudocmd dnf --refresh upgrade
sudocmd dnf clean all
assure_exists dnf-plugin-system-upgrade
sudocmd dnf upgrade --refresh
local RELEASEVER="$pkg_filenames"
[ -n "$RELEASEVER" ] || RELEASEVER=$(($DISTRVERSION + 1))
#[ -n "$RELEASEVER" ] || fatal "Run me with new version"
confirm_info "Upgrade to $DISTRNAME/$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
info "Run epm autoorphans to remove orphaned packages"
;;
urpm-rpm)
sudocmd urpmi.removemedia -av
# TODO
showcmd urpmi.addmedia --distrib http://mirror.yandex.ru/mandriva/devel/2010.2/i586/
sudocmd urpmi --auto-update --replacefiles
;;
zypper-rpm)
docmd epm repolist
# TODO
# sudocmd zypper rr <номер_репозитория>
showcmd rr N
showcmd epm ar http://mirror.yandex.ru/opensuse/distribution/11.1/repo/oss 11.1oss
showcmd zypper ref
docmd epm update
docmd epm install rpm zypper
docmd epm upgrade
;;
pacman)
epm Upgrade
;;
conary)
epm Upgrade
;;
emerge)
epm Upgrade
;;
guix)
sudocmd guix pull --verbose
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2014 Etersoft # Copyright (C) 2012-2014, 2016, 2017 Etersoft
# Copyright (C) 2012-2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2014, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -17,22 +17,32 @@ ...@@ -17,22 +17,32 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-sh-altlinux
load_helper epm-query load_helper epm-query
load_helper epm-print
load_helper epm-sh-warmup
# Try remove with low level removing # Try remove with low level removing
epm_remove_low() epm_remove_low()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
warmup_lowbase
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm) apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm)
sudocmd rpm -ev $nodeps $@ sudocmd rpm -ev $nodeps $@
return ;; return ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
sudocmd dpkg -P $(subst_option nodeps --force-all) $@ # shellcheck disable=SC2046
sudocmd dpkg -P $(subst_option nodeps --force-all) $(print_name "$@")
return ;; return ;;
pkgsrc) pkgsrc)
sudocmd pkg_delete -r $@ sudocmd pkg_delete -r $@
return ;; return ;;
pkgng)
sudocmd pkg delete -R $@
return ;;
emerge) emerge)
sudocmd emerge --unmerge $@ sudocmd emerge --unmerge $@
return ;; return ;;
...@@ -50,15 +60,17 @@ epm_remove_names() ...@@ -50,15 +60,17 @@ epm_remove_names()
{ {
[ -z "$1" ] && return [ -z "$1" ] && return
warmup_bases
case $PMTYPE in case $PMTYPE in
apt-dpkg) apt-dpkg)
sudocmd apt-get remove --purge $@ sudocmd apt-get remove --purge $APTOPTIONS $@
return ;; return ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude purge $@ sudocmd aptitude purge $@
return ;; return ;;
apt-rpm) apt-rpm)
sudocmd apt-get remove $@ sudocmd apt-get remove $APTOPTIONS $@
return ;; return ;;
deepsolver-rpm) deepsolver-rpm)
sudocmd ds-remove $@ sudocmd ds-remove $@
...@@ -69,6 +81,9 @@ epm_remove_names() ...@@ -69,6 +81,9 @@ epm_remove_names()
pkgsrc) # without dependencies pkgsrc) # without dependencies
sudocmd pkg_delete $@ sudocmd pkg_delete $@
return ;; return ;;
pkgng)
sudocmd pkg delete -R $@
return ;;
emerge) emerge)
#sudocmd emerge --unmerge $@ #sudocmd emerge --unmerge $@
sudocmd emerge -aC $@ sudocmd emerge -aC $@
...@@ -82,8 +97,11 @@ epm_remove_names() ...@@ -82,8 +97,11 @@ epm_remove_names()
dnf-rpm) dnf-rpm)
sudocmd dnf remove $@ sudocmd dnf remove $@
return ;; return ;;
snappy)
sudocmd snappy uninstall $@
return ;;
zypper-rpm) zypper-rpm)
sudocmd zypper remove $@ sudocmd zypper remove --clean-deps $@
return ;; return ;;
mpkg) mpkg)
sudocmd mpkg remove $@ sudocmd mpkg remove $@
...@@ -92,11 +110,14 @@ epm_remove_names() ...@@ -92,11 +110,14 @@ epm_remove_names()
sudocmd conary erase $@ sudocmd conary erase $@
return ;; return ;;
npackd) npackd)
sudocmd npackdcl remove --package=$@ sudocmd npackdcl remove --package=$1
return ;; return ;;
nix) nix)
sudocmd nix-env --uninstall $@ sudocmd nix-env --uninstall $@
return ;; return ;;
apk)
sudocmd apk del $@
return ;;
guix) guix)
sudocmd guix package -r $@ sudocmd guix package -r $@
return ;; return ;;
...@@ -110,10 +131,17 @@ epm_remove_names() ...@@ -110,10 +131,17 @@ epm_remove_names()
sudocmd /usr/sbin/slackpkg remove $@ sudocmd /usr/sbin/slackpkg remove $@
return ;; return ;;
homebrew) homebrew)
sudocmd brew remove $@ docmd brew remove $@
return ;;
aptcyg)
sudocmd apt-cyg remove $@
return ;; return ;;
ipkg) xbps)
sudocmd ipkg $(subst_option force -force-depends) remove $@ sudocmd xbps remove -R $@
return ;;
opkg)
# shellcheck disable=SC2046
sudocmd opkg $(subst_option force -force-depends) remove $@
return ;; return ;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
...@@ -124,6 +152,8 @@ epm_remove_names() ...@@ -124,6 +152,8 @@ epm_remove_names()
# TODO # TODO
epm_remove_nonint() epm_remove_nonint()
{ {
warmup_bases
case $PMTYPE in case $PMTYPE in
apt-dpkg) apt-dpkg)
sudocmd apt-get -y --force-yes remove --purge $@ sudocmd apt-get -y --force-yes remove --purge $@
...@@ -143,14 +173,23 @@ epm_remove_nonint() ...@@ -143,14 +173,23 @@ 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 $@ sudocmd zypper --non-interactive remove --clean-deps $@
return ;; return ;;
slackpkg) slackpkg)
sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes remove $@ sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes remove $@
return ;; return ;;
ipkg) pkgng)
sudocmd ipkg -force-defaults remove $@ sudocmd pkg delete -y -R $@
return ;;
opkg)
sudocmd opkg -force-defaults remove $@
return ;;
xbps)
sudocmd xbps remove -y $@
return ;; return ;;
esac esac
return 5 return 5
...@@ -160,25 +199,34 @@ epm_print_remove_command() ...@@ -160,25 +199,34 @@ epm_print_remove_command()
{ {
case $PMTYPE in case $PMTYPE in
apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm) apt-rpm|yum-rpm|zypper-rpm|urpm-rpm|dnf-rpm)
echo "rpm -ev $nodeps $@" echo "rpm -ev $nodeps $*"
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
echo "dpkg -P $@" echo "dpkg -P $*"
;; ;;
pkgsrc) pkgsrc)
echo "pkg_delete -r $@" echo "pkg_delete -r $*"
;;
pkgng)
echo "pkg delete -R $*"
;; ;;
pacman) pacman)
echo "pacman -R $@" echo "pacman -R $*"
;; ;;
emerge) emerge)
echo "emerge --unmerge $@" echo "emerge --unmerge $*"
;; ;;
slackpkg) slackpkg)
echo "/sbin/removepkg $@" echo "/sbin/removepkg $*"
;;
opkg)
echo "opkg remove $*"
;; ;;
ipkg) aptcyg)
echo "ipkg remove $@" echo "apt-cyg remove $*"
;;
xbps)
echo "xbps remove -y $*"
;; ;;
*) *)
fatal "Have no suitable appropriate remove command for $PMTYPE" fatal "Have no suitable appropriate remove command for $PMTYPE"
...@@ -194,11 +242,45 @@ epm_remove() ...@@ -194,11 +242,45 @@ epm_remove()
return return
fi fi
local tn=$(tasknumber "$pkg_names")
if [ -n "$tn" ] ; then
assure_distr ALTLinux "remove with task number"
assure_exists apt-repo
pkg_names=$(showcmd apt-repo list $tn)
#docmd epm remove $dryrun
return
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
info "Packages for removing:"
echo "$pkg_names"
case $PMTYPE in
apt-rpm)
nodeps="--test"
APTOPTIONS="--simulate"
;;
*)
return
;;
esac
fi
epm_remove_low $pkg_names && return epm_remove_low $pkg_names && return
local STATUS=$?
# TODO: check if we need continue with hi level
if [ -n "$direct" ] ; then
return $STATUS
fi
# get package name for hi level package management command (with version if supported and if possible) # get package name for hi level package management command (with version if supported and if possible)
pkg_names=$(__epm_get_hilevel_name $pkg_names) pkg_names=$(__epm_get_hilevel_name $pkg_names)
......
#!/bin/sh
#
# Copyright (C) 2016-2017 Etersoft
# Copyright (C) 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-sh-warmup
epm_remove_old_kernels()
{
warmup_bases
case $DISTRNAME in
ALTLinux)
load_helper epm-query_package
if ! __epm_query_package kernel-image >/dev/null ; then
info "No installed kernel packages, skipping cleaning"
return
fi
assure_exists update-kernel update-kernel 0.9.9
sudocmd remove-old-kernels $pkg_filenames
return ;;
Ubuntu)
load_helper epm-query_package
if ! __epm_query_package linux-image >/dev/null ; then
info "No installed kernel packages, skipping cleaning"
return
fi
info "Note: it is enough to use eepm autoremove for old kernel removing..."
info "Check also http://ubuntuhandbook.org/index.php/2016/05/remove-old-kernels-ubuntu-16-04/"
# http://www.opennet.ru/tips/2980_ubuntu_apt_clean_kernel_packet.shtml
case $DISTRVERSION in
10.04|12.04|14.04|15.04|15.10)
assure_exists purge-old-kernels bikeshed
;;
*)
# since Ubuntu 16.04
assure_exists purge-old-kernels byobu
;;
esac
sudocmd purge-old-kernels $pkg_filenames
return ;;
Gentoo)
sudocmd emerge -P gentoo-sources
return ;;
VoidLinux)
sudocmd vkpurge rm all
return ;;
esac
case $PMTYPE in
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2017 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -17,33 +17,78 @@ ...@@ -17,33 +17,78 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-sh-altlinux
epm_removerepo() epm_removerepo()
{ {
case $PMTYPE in local repo="$(eval echo $quoted_args)"
apt-rpm)
case $DISTRNAME in
ALTLinux)
case "$repo" in
autoimports)
info "remove autoimports repo"
[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
repo="$repo.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
;;
archive)
info "remove archive repos"
assure_exists apt-repo
epm repolist | grep "archive/" | while read repo ; do
sudocmd apt-repo rm "$repo"
done
return 0
;;
tasks)
info "remove task repos"
assure_exists apt-repo
epm repolist | grep "/repo/" | while read repo ; do
sudocmd apt-repo rm "$repo"
done
return 0
;;
*)
if tasknumber "$repo" >/dev/null ; then
repo="$(epm repolist | grep "repo/$(tasknumber "$repo")" | line)"
# "
fi
;;
esac
[ -n "$repo" ] || fatal "No such repo or task. Use epm remove repo [autoimports|archive|TASK]"
assure_exists apt-repo assure_exists apt-repo
sudocmd apt-repo rm $pkg_filenames sudocmd apt-repo rm "$repo"
return
;;
esac;
case $PMTYPE in
apt-dpkg)
assure_exists apt-add-repository software-properties-common
sudocmd apt-add-repository --remove "$repo"
info "Check file /etc/apt/sources.list if needed"
;; ;;
apt-dpkg|aptitude-dpkg) 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)
info "You need remove repo from /etc/yum.repos.d/" assure_exists yum-utils
sudocmd yum-config-manager --disable "$repo"
;; ;;
urpm-rpm) urpm-rpm)
sudocmd urpmi.removemedia $pkg_filenames sudocmd urpmi.removemedia "$repo"
;; ;;
zypper-rpm) zypper-rpm)
sudocmd zypper removerepo $pkg_filenames sudocmd zypper removerepo "$repo"
;; ;;
emerge) emerge)
sudocmd layman -d$pkg_filenames sudocmd layman "-d$repo"
;; ;;
pacman) pacman)
info "You need remove repo from /etc/pacman.conf" info "You need remove repo from /etc/pacman.conf"
;; ;;
npackd) npackd)
sudocmd npackdcl remove-repo --url=$pkg_filenames sudocmd npackdcl remove-repo --url="$repo"
;; ;;
slackpkg) slackpkg)
info "You need remove repo from /etc/slackpkg/mirrors" info "You need remove repo from /etc/slackpkg/mirrors"
......
#!/bin/sh
#
# Copyright (C) 2017-2018 Etersoft
# Copyright (C) 2017-2018 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-sh-altlinux
load_helper epm-assure
# arg: rpm or deb
# fills split_replaced_pkgs with packages of that type
__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" ]
}
# fills repacked_rpms
__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
}
# fills repacked_debs
__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
}
# 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
}
# args: buildroot spec
__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="$CONFIGDIR/repack.d/$1.sh"
[ -x "$repackcode" ] || return
shift
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
__epm_repack_rpm()
{
assure_distr ALTLinux "install --repack"
assure_exists fakeroot || fatal
assure_exists alien || fatal
assure_exists rpmbuild rpm-build || fatal
local pkg
export HOME=$(mktemp -d)
local tmpbuilddir=$HOME/repack
mkdir $tmpbuilddir
__create_rpmmacros
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
load_helper epm-download
__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
}
#!/bin/sh
#
# Copyright (C) 2015-2016 Etersoft
# Copyright (C) 2015-2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-query
__repofix_check_vendor()
{
local i
for i in /etc/apt/vendors.list.d/*.list; do
[ -e "$i" ] || continue
grep -q "^simple-key \"$1\"" $i && return
done
return 1
}
# source-list vendor path
# example: /etc/apt/source.list p7 ALTLinux\/Sisyphus
__try_fix_apt_source_list()
{
local list="$1"
local br="$2"
local path="$3"
if grep -q -e "^[^#].*$path" $list ; then
if __repofix_check_vendor $br ; then
regexp_subst "/$path/s/^rpm[[:space:]]*([fhr])/rpm [$br] \1/" $list
else
warning "Skip set $br vendor key (it misssed) for $list"
regexp_subst "/$path/s/^rpm[[:space:]]*\[$br\][[:space:]]*([fhr])/rpm \1/" $list
fi
fi
}
__fix_apt_sources_list()
{
# 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 i
assure_root
for i in "$@" ; do
[ -s "$i" ] || continue
#perl -i.bak -pe "$SUBST_ALT_RULE" $i
# TODO: only for uncommented strings
#sed -i -r -e "$SUBST_ALT_RULE" $i
regexp_subst "/^ *#/! $SUBST_ALT_RULE" $i
# Sisyphus uses 'alt' vendor key
__try_fix_apt_source_list $i alt "ALTLinux\/Sisyphus"
__try_fix_apt_source_list $i etersoft "Etersoft\/Sisyphus"
# skip branch replacement for ALT Linux Sisyphus
[ "$DISTRVERSION" = "Sisyphus" ] && continue
# add signs for branches
__try_fix_apt_source_list $i $DISTRVERSION "ALTLinux\/$DISTRVERSION\/branch"
__try_fix_apt_source_list $i etersoft "Etersoft\/$DISTRVERSION\/branch"
done
}
epm_repofix()
{
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
case $PMTYPE in
apt-rpm)
assure_exists apt-repo
[ -n "$quiet" ] || docmd apt-repo list
__fix_apt_sources_list /etc/apt/sources.list
__fix_apt_sources_list /etc/apt/sources.list.d/*.list
docmd apt-repo list
# FIXME: what the best place?
# rebuild rpm database
#sudocmd rm -fv /var/lib/rpm/__db*
#sudocmd rpm --rebuilddb
;;
yum-rpm|dnf-rpm)
# FIXME: what the best place?
#sudocmd rm -fv /var/lib/rpm/__db*
#sudocmd rpm --rebuilddb
;;
xbps)
sudocmd xbps-pkgdb -a
;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -39,11 +39,11 @@ case $PMTYPE in ...@@ -39,11 +39,11 @@ 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)
docmd yum repolist docmd yum repolist -v
;; ;;
dnf-rpm) dnf-rpm)
docmd dnf repolist -v docmd dnf repolist -v
...@@ -58,6 +58,9 @@ case $PMTYPE in ...@@ -58,6 +58,9 @@ case $PMTYPE in
docmd eselect profile list docmd eselect profile list
docmd layman -L docmd layman -L
;; ;;
xbps)
docmd xbps-query -L
;;
pacman) pacman)
docmd grep -v -- "^#\|^$" /etc/pacman.conf docmd grep -v -- "^#\|^$" /etc/pacman.conf
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2013 Etersoft # Copyright (C) 2012-2013, 2016, 2018 Etersoft
# Copyright (C) 2012-2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2013, 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
...@@ -18,19 +18,23 @@ ...@@ -18,19 +18,23 @@
# #
load_helper epm-query load_helper epm-query
load_helper epm-print
epm_requires_files() epm_requires_files()
{ {
local pkg_files="$*"
[ -n "$pkg_files" ] || return [ -n "$pkg_files" ] || return
local PKGTYPE="$(case $(get_package_type $pkg_files))" local PKGTYPE="$(get_package_type $pkg_files)"
case "$PKGTYPE" in case "$PKGTYPE" in
rpm) rpm)
assure_exists rpm
docmd rpm -q --requires -p $pkg_files docmd rpm -q --requires -p $pkg_files
;; ;;
deb) deb)
a= docmd dpkg -I $pkg_files | grep "^ *Depends:" | sed "s|^ *Depends:||g" assure_exists dpkg
a='' docmd dpkg -I $pkg_files | grep "^ *Depends:" | sed "s|^ *Depends:||g"
;; ;;
*) *)
fatal "Have no suitable command for $PKGTYPE" fatal "Have no suitable command for $PKGTYPE"
...@@ -40,6 +44,7 @@ epm_requires_files() ...@@ -40,6 +44,7 @@ epm_requires_files()
epm_requires_names() epm_requires_names()
{ {
local pkg_names="$*"
local CMD local CMD
[ -n "$pkg_names" ] || return [ -n "$pkg_names" ] || return
...@@ -58,12 +63,26 @@ case $PMTYPE in ...@@ -58,12 +63,26 @@ case $PMTYPE in
fi fi
;; ;;
urpm-rpm|zypper-rpm) #zypper-rpm)
# FIXME: use hi level commands # # FIXME: use hi level commands
CMD="rpm -q --requires" # CMD="rpm -q --requires"
# ;;
urpm-rpm)
CMD="urpmq --requires"
;; ;;
yum-rpm) yum-rpm)
if is_installed $pkg_names ; then
CMD="rpm -q --requires"
else
CMD="yum deplist" CMD="yum deplist"
fi
;;
dnf-rpm)
if is_installed $pkg_names ; then
CMD="rpm -q --requires"
else
CMD="dnf repoquery --requires"
fi
;; ;;
pacman) pacman)
CMD="pactree" CMD="pactree"
...@@ -72,7 +91,7 @@ case $PMTYPE in ...@@ -72,7 +91,7 @@ case $PMTYPE in
# FIXME: need fix for a few names case # FIXME: need fix for a few names case
if is_installed $pkg_names ; then if is_installed $pkg_names ; then
showcmd dpkg -s $pkg_names showcmd dpkg -s $pkg_names
a= dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g" a='' dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
return return
else else
CMD="apt-cache depends" CMD="apt-cache depends"
...@@ -82,6 +101,22 @@ case $PMTYPE in ...@@ -82,6 +101,22 @@ case $PMTYPE in
assure_exists equery assure_exists equery
CMD="equery depgraph" CMD="equery depgraph"
;; ;;
pkgng)
#CMD="pkg rquery '%dn-%dv'"
CMD="pkg info -d"
;;
opkg)
CMD="opkg depends"
;;
xbps)
CMD="xbps-query -x"
;;
aptcyg)
#CMD="apt-cyg depends"
# print show version
docmd apt-cyg show $pkg_names | grep "^requires: " | sed "s|^requires: ||g"
return
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
...@@ -95,6 +130,7 @@ docmd $CMD $pkg_names ...@@ -95,6 +130,7 @@ docmd $CMD $pkg_names
epm_requires() epm_requires()
{ {
[ -n "$pkg_filenames" ] || fatal "Requires: missing package(s) name" [ -n "$pkg_filenames" ] || fatal "Requires: missing package(s) name"
epm_requires_files epm_requires_files $pkg_files
epm_requires_names # shellcheck disable=SC2046
epm_requires_names $(print_name $pkg_names)
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2013 Etersoft # Copyright (C) 2012, 2013, 2016-2018 Etersoft
# Copyright (C) 2012,2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2013, 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
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
# #
load_helper epm-check_updated_repo load_helper epm-check_updated_repo
load_helper epm-sh-warmup
__epm_search_output() __epm_search_output()
{ {
...@@ -40,6 +41,9 @@ case $PMTYPE in ...@@ -40,6 +41,9 @@ case $PMTYPE in
pkgsrc) pkgsrc)
CMD="pkg_info -x --" CMD="pkg_info -x --"
;; ;;
pkgng)
CMD="pkg search -i --"
;;
emerge) emerge)
CMD="emerge --search --" CMD="emerge --search --"
;; ;;
...@@ -61,6 +65,12 @@ case $PMTYPE in ...@@ -61,6 +65,12 @@ case $PMTYPE in
mpkg) mpkg)
CMD="mpkg search" CMD="mpkg search"
;; ;;
apk)
CMD="apk search"
;;
tce)
CMD="tce-ab"
;;
conary) conary)
CMD="conary repquery" CMD="conary repquery"
;; ;;
...@@ -74,7 +84,15 @@ case $PMTYPE in ...@@ -74,7 +84,15 @@ case $PMTYPE in
slackpkg) slackpkg)
# FIXME # FIXME
echo "Note: case sensitive search" echo "Note: case sensitive search"
if [ -n "$verbose" ] ; then
CMD="/usr/sbin/slackpkg search" CMD="/usr/sbin/slackpkg search"
else
LANG=C docmd /usr/sbin/slackpkg search $string | grep " - " | sed -e 's|.* - ||g'
return
fi
;;
opkg)
CMD="opkg find"
;; ;;
homebrew) homebrew)
CMD="brew search" CMD="brew search"
...@@ -85,12 +103,18 @@ case $PMTYPE in ...@@ -85,12 +103,18 @@ case $PMTYPE in
android) android)
CMD="pm list packages" CMD="pm list packages"
;; ;;
aptcyg)
CMD="apt-cyg searchall"
;;
xbps)
CMD="xbps-query -s"
;;
*) *)
fatal "Have no suitable search command for $PMTYPE" fatal "Have no suitable search command for $PMTYPE"
;; ;;
esac esac
docmd $CMD $string LANG=C docmd $CMD $string
} }
# produce grep sequence # produce grep sequence
...@@ -103,8 +127,8 @@ __epm_search_make_grep() ...@@ -103,8 +127,8 @@ __epm_search_make_grep()
local listN= local listN=
for i in $@ ; do for i in $@ ; do
case "$i" in case "$i" in
^*) ~*)
# will clean from ^ later (and have the bug here with empty arg if run with one ^ only) # will clean from ~ later (and have the bug here with empty arg if run with one ~ only)
listN="$listN $i" listN="$listN $i"
;; ;;
*) *)
...@@ -114,24 +138,30 @@ __epm_search_make_grep() ...@@ -114,24 +138,30 @@ __epm_search_make_grep()
done done
#list=$(strip_spaces $list | sed -e "s/ /|/g") #list=$(strip_spaces $list | sed -e "s/ /|/g")
listN=$(strip_spaces $listN | sed -e "s/ /|/g" | sed -e "s/\^//g") listN=$(strip_spaces $listN | sed -e "s/ /|/g" | sed -e "s/~//g")
if [ -n "$short" ] ; then
echon " | sed -e \"s| .*||g\""
fi
[ -n "$listN" ] && echon " | egrep -i -v -- \"$listN\"" [ -n "$listN" ] && echon " | egrep -i -v -- \"$listN\""
# FIXME: The World has not idea how to do grep both string # FIXME: The World has not idea how to do grep both string
# http://stackoverflow.com/questions/10110051/grep-with-two-strings-logical-and-in-regex?rq=1 # http://stackoverflow.com/questions/10110051/grep-with-two-strings-logical-and-in-regex?rq=1
# Need only if we have more than one word (with one word we will grep for colorify)
if [ "$(echo "$list" | wc -w)" -gt 1 ] ; then
for i in $list ; do for i in $list ; do
# FIXME -n on MacOS? # FIXME -n on MacOS?
echon " | egrep -i -- \"$i\"" echon " | egrep -i -- \"$i\""
done done
if [ "$short" ] ; then
echon " | sed -e \"s| .*||g\""
fi fi
# FIXME: move from it # FIXME: move from it
#isatty || return #isatty || return
# TODO: sorts word by length from large to short
local COLO="" local COLO=""
# rule for colorife # rule for colorife
for i in $list $listN; do for i in $list $listN; do
...@@ -139,11 +169,24 @@ __epm_search_make_grep() ...@@ -139,11 +169,24 @@ __epm_search_make_grep()
COLO="$COLO$i" COLO="$COLO$i"
done done
# TODO: use some colorifer instead grep (check grep adove too)
if [ -n "$list" ] ; then if [ -n "$list" ] ; then
echon " | egrep -i $EGREPCOLOR -- \"($COLO)\"" echon " | egrep -i $EGREPCOLOR -- \"($COLO)\""
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"
}
# copied from korinf/tools/run-script/scripts/search # copied from korinf/tools/run-script/scripts/search
epm_search() epm_search()
...@@ -151,7 +194,9 @@ epm_search() ...@@ -151,7 +194,9 @@ epm_search()
[ -n "$pkg_filenames" ] || fatal "Search: missing search argument(s)" [ -n "$pkg_filenames" ] || fatal "Search: missing search argument(s)"
# it is useful for first time running # it is useful for first time running
update_repo_if_needed update_repo_if_needed soft
warmup_bases
# FIXME: do it better # FIXME: do it better
local MGS local MGS
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016, 2017 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -17,29 +17,34 @@ ...@@ -17,29 +17,34 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# TODO: port or rewrite apt-file # TODO: see epm-search (colorify for all distro)
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
local_content_search() # args: index_lists word grep_string
__alt_search_file_output()
{
# grep only on left part (filename), then revert order and grep with color
__local_ercat $1 | grep -h -- ".*$2.*[[:space:]]" | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g" $3
}
__alt_local_content_search()
{ {
# TODO: use global get_sysarch function load_helper epm-sh-altlinux
local SYSARCH load_helper epm-search
SYSARCH=$(uname -m)
[ "$SYSARCH" = "x86_64" ] || SYSARCH=i586
# FIXME: use config or/and web url info "Locate contents index file(s) ..."
local REPODIR=/var/ftp/pub/ALTLinux/Sisyphus local CI="$(get_local_alt_contents_index)"
local CI=$REPODIR/$SYSARCH/base/contents_index # TODO use something like
local CINOA=$REPODIR/noarch/base/contents_index [ -n "$CI" ] || fatal "Have no local contents index"
#local OUTCMD="less"
#[ -n "$USETTY" ] || OUTCMD="cat"
OUTCMD="cat"
test -r $CI && test -r $CINOA || fatal "Can't locate $CI or $CINOA" info "Searching in"
echo "$CI"
echo "for $1... "
{ # FIXME: do it better
[ -n "$USETTY" ] && echo "Search in $CI and $CINOA for $1..." local MGS
grep -h -- ".*$1.*\t" $CI $CINOA | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g" MGS=$(eval __epm_search_make_grep $quoted_args)
} | $OUTCMD showcmd "$ cat contents_index $MGS"
eval "__alt_search_file_output \"$CI\" \"$(eval get_firstarg $quoted_args)\" $MGS"
} }
epm_search_file() epm_search_file()
...@@ -49,7 +54,7 @@ epm_search_file() ...@@ -49,7 +54,7 @@ epm_search_file()
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
local_content_search $pkg_filenames __alt_local_content_search $pkg_filenames
return ;; return ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
assure_exists apt-file assure_exists apt-file
...@@ -57,9 +62,13 @@ case $PMTYPE in ...@@ -57,9 +62,13 @@ case $PMTYPE in
docmd apt-file search $pkg_filenames docmd apt-file search $pkg_filenames
return ;; return ;;
yum-rpm) yum-rpm)
# TODO
info "Search by full packages list is not implemented yet"
CMD="yum provides" CMD="yum provides"
;; ;;
dnf-rpm) dnf-rpm)
# TODO
info "Search by full packages list is not implemented yet"
CMD="dnf provides" CMD="dnf provides"
;; ;;
urpm-rpm) urpm-rpm)
...@@ -74,8 +83,15 @@ case $PMTYPE in ...@@ -74,8 +83,15 @@ case $PMTYPE in
slackpkg) slackpkg)
CMD="/usr/sbin/slackpkg file-search" CMD="/usr/sbin/slackpkg file-search"
;; ;;
ipkg) opkg)
CMD="ipkg search" CMD="opkg -A search"
;;
xbps)
CMD="xbps-query -Ro"
;;
aptcyg)
docmd apt-cyg searchall "$(echo " $pkg_filenames" | sed -e "s| /| |g")"
return
;; ;;
*) *)
fatal "Have no suitable search file command for $PMTYPE" fatal "Have no suitable search file command for $PMTYPE"
......
#!/bin/sh
#
# Copyright (C) 2014, 2017 Etersoft
# Copyright (C) 2014, 2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# apt-file like. See also
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
# convert "http://download.etersoft.ru/pub/ALTLinux/p8/branch x86_64" to /tmp/epm/ALTLinux/p8/branch/x86_64
get_local_alt_mirror_path()
{
local DN1=$(dirname "$1")
local DN2=$(dirname $DN1)
local DN3=$(dirname $DN2)
local BN0=$(basename "$1") # arch
local BN1=$(basename $DN1) # branch/Sisyphus
local BN2=$(basename $DN2) # p8/ALTLinux
local BN3=$(basename $DN3) # ALTLinux/
[ "$BN1" = "branch" ] && echo "/tmp/eepm/$BN3/$BN2/$BN1/$BN0" || echo "/tmp/eepm/$BN2/$BN1/$BN0"
}
__local_ercat()
{
local i
for i in "$@" ; do
case "$i" in
*.xz)
a='' xzcat $i
;;
*.lz4)
a='' lz4cat $i
;;
*.failed)
# just ignore
;;
*)
cat $i
;;
esac
done
}
# something like gzip
compress_file_inplace()
{
local OFILE="$1"
if epm assure lz4 </dev/null ; then
#docmd lz4 --rm "$OFILE" "$OFILE.lz4" || return
# due old lz4
docmd lz4 -f "$OFILE" "$OFILE.lz4" || return
rm -fv "$OFILE"
else
epm assure xz </dev/null || return
docmd xz -f "$OFILE" || return
fi
return 0
}
# args: url/path target_file
# result: will set FILE
download_alt_contents_index()
{
local URL="$1"
local TD="$2"
local OFILE="$TD/$(basename "$URL")"
local DONE=$(echo $OFILE*)
# TODO: check if too old
if [ -r "$DONE" ] ; then
return
fi
mkdir -p "$TD"
if echo "$URL" | grep -q "^file:/" ; then
URL=$(echo "$URL" | sed -e "s|^file:||")
[ -s "$URL" ] || { touch $OFILE.failed ; return 1; }
ln -sf "$URL" "$OFILE" || { touch $OFILE.failed ; return 1; }
# TODO rsync
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449#c22
else
docmd eget -O "$OFILE" "$URL" || { rm -fv $OFILE ; touch $OFILE.failed ; return 1; }
fi
rm -f $OFILE.failed
compress_file_inplace "$OFILE"
}
get_local_alt_contents_index()
{
load_helper epm-repolist
local LOCALPATH
epm_repolist | grep -E "rpm.*(ftp://|http://|https://|file:/)" | sed -e "s@^rpm.*\(ftp://\|http://\|https://\|file:\)@\1@g" | while read -r URL ARCH other ; do
LOCALPATH=$(get_local_alt_mirror_path "$URL/$ARCH")
download_alt_contents_index $URL/$ARCH/base/contents_index $LOCALPATH >&2 || continue
echo "$LOCALPATH/contents_index*"
done
}
tasknumber()
{
local num="$(echo "$*" | sed -e "s| *#*||g")"
isnumber "$num" && echo "$num"
}
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
inputisatty() inputisatty()
{ {
# check stdin # check stdin
tty -s 2>/dev/null #tty -s 2>/dev/null
test -t 0
} }
isatty() isatty()
...@@ -48,8 +49,8 @@ check_tty() ...@@ -48,8 +49,8 @@ check_tty()
# egrep from busybox may not --color # egrep from busybox may not --color
# egrep from MacOS print help to stderr # egrep from MacOS print help to stderr
if egrep --help 2>&1 | grep -q -- "--color" ; then if grep -E --help 2>&1 | grep -q -- "--color" ; then
EGREPCOLOR="--color" export EGREPCOLOR="--color"
fi fi
which tput >/dev/null 2>/dev/null || return which tput >/dev/null 2>/dev/null || return
...@@ -89,7 +90,7 @@ echover() ...@@ -89,7 +90,7 @@ echover()
echon() echon()
{ {
# default /bin/sh on MacOS does not recognize -n # default /bin/sh on MacOS does not recognize -n
/bin/echo -n "$@" /bin/echo -n "$*"
} }
...@@ -109,7 +110,7 @@ showcmd() ...@@ -109,7 +110,7 @@ showcmd()
set_boldcolor $GREEN set_boldcolor $GREEN
local PROMTSIG="\$" local PROMTSIG="\$"
[ "$EFFUID" = 0 ] && PROMTSIG="#" [ "$EFFUID" = 0 ] && PROMTSIG="#"
echo " $PROMTSIG $@" echo " $PROMTSIG $*"
restore_color restore_color
fi >&2 fi >&2
} }
...@@ -117,7 +118,7 @@ showcmd() ...@@ -117,7 +118,7 @@ showcmd()
# Print command line and run command line # Print command line and run command line
docmd() docmd()
{ {
showcmd "$@$EXTRA_SHOWDOCMD" showcmd "$*$EXTRA_SHOWDOCMD"
#FIXME #FIXME
$@ $@
} }
...@@ -137,11 +138,12 @@ docmd_foreach() ...@@ -137,11 +138,12 @@ docmd_foreach()
# Print command line and run command line with SUDO # Print command line and run command line with SUDO
sudocmd() sudocmd()
{ {
showcmd "$SUDO $@" [ -n "$SUDO" ] && showcmd "$SUDO $*" || showcmd "$*"
$SUDO $@ $SUDO $@
} }
# Run every arg with sudocmd # Run every arg with sudocmd
# Returns on any error
sudocmd_foreach() sudocmd_foreach()
{ {
local cmd pkg local cmd pkg
...@@ -149,10 +151,18 @@ sudocmd_foreach() ...@@ -149,10 +151,18 @@ sudocmd_foreach()
#showcmd "$@" #showcmd "$@"
shift shift
for pkg in "$@" ; do for pkg in "$@" ; do
sudocmd "$cmd" $pkg sudocmd "$cmd" $pkg || return
done done
} }
# add realpath if missed
if ! which realpath 2>/dev/null >/dev/null ; then
realpath()
{
readlink -f "$@"
}
fi
get_firstarg() get_firstarg()
{ {
echon "$1" echon "$1"
...@@ -161,10 +171,15 @@ get_firstarg() ...@@ -161,10 +171,15 @@ get_firstarg()
get_lastarg() get_lastarg()
{ {
local lastarg local lastarg
eval lastarg=\${$#} eval "lastarg=\${$#}"
echon "$lastarg" echon "$lastarg"
} }
# TODO: see etersoft-build-utils/tests/test_isnumber.sh
isnumber()
{
echo "$*" | filter_strip_spaces | grep -q "^[0-9]\+$"
}
filter_strip_spaces() filter_strip_spaces()
{ {
...@@ -193,12 +208,18 @@ store_output() ...@@ -193,12 +208,18 @@ store_output()
echo 1 >$CMDSTATUS echo 1 >$CMDSTATUS
#RC_STDERR=$(mktemp) #RC_STDERR=$(mktemp)
( $@ 2>&1 ; echo $? >$CMDSTATUS ) | tee $RC_STDOUT ( $@ 2>&1 ; echo $? >$CMDSTATUS ) | tee $RC_STDOUT
return $(cat $CMDSTATUS) return "$(cat $CMDSTATUS)"
# bashism # bashism
# http://tldp.org/LDP/abs/html/bashver3.html#PIPEFAILREF # http://tldp.org/LDP/abs/html/bashver3.html#PIPEFAILREF
#return $PIPESTATUS #return $PIPESTATUS
} }
showcmd_store_output()
{
showcmd "$@"
store_output "$@"
}
clean_store_output() clean_store_output()
{ {
rm -f $RC_STDOUT $RC_STDOUT.pipestatus rm -f $RC_STDOUT $RC_STDOUT.pipestatus
...@@ -207,14 +228,15 @@ clean_store_output() ...@@ -207,14 +228,15 @@ clean_store_output()
# run epm, possible from side repo # run epm, possible from side repo
epm() epm()
{ {
$PROGDIR/epm $@ [ -n "$PROGNAME" ] || fatal "Can't use epm call from the piped script"
$PROGDIR/$PROGNAME $@
} }
# Print error message and stop the program # Print error message and stop the program
fatal() fatal()
{ {
if [ -z "$TEXTDOMAIN" ] ; then if [ -z "$TEXTDOMAIN" ] ; then
echo "Error: $@" >&2 echo "Error: $*" >&2
# else # else
# echog "Error in $0: $@" >&2 # echog "Error in $0: $@" >&2
fi fi
...@@ -225,7 +247,7 @@ fatal() ...@@ -225,7 +247,7 @@ fatal()
warning() warning()
{ {
if [ -z "$TEXTDOMAIN" ] ; then if [ -z "$TEXTDOMAIN" ] ; then
echo "Warning: $@" >&2 echo "Warning: $*" >&2
# else # else
# echog "Error in $0: $@" >&2 # echog "Error in $0: $@" >&2
fi fi
...@@ -238,9 +260,9 @@ info() ...@@ -238,9 +260,9 @@ info()
# print message to stderr if stderr forwarded to (a file) # print message to stderr if stderr forwarded to (a file)
if isatty2 ; then if isatty2 ; then
isatty || return 0 isatty || return 0
echo "$@" echo "$*"
else else
echo "$@" >&2 echo "$*" >&2
fi fi
} }
...@@ -249,26 +271,49 @@ set_sudo() ...@@ -249,26 +271,49 @@ set_sudo()
SUDO="" SUDO=""
# skip SUDO if disabled # skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return [ -n "$EPMNOSUDO" ] && return
if [ "$DISTRNAME" = "Cygwin" ] || [ "$DISTRNAME" = "Windows" ] ; then
# skip sudo using on Windows
return
fi
EFFUID=`id -u` EFFUID=$(id -u)
# do not need sudo # do not need sudo
[ $EFFUID = "0" ] && return [ $EFFUID = "0" ] && return
# use sudo if possible # use sudo if possible
which sudo >/dev/null 2>/dev/null && SUDO="sudo" && return if which sudo >/dev/null 2>/dev/null ; then
SUDO="sudo --"
# check for < 1.7 version which do not support -- (and --help possible too)
sudo -h 2>/dev/null | grep -q " --" || SUDO="sudo"
return
fi
SUDO="fatal 'Can't find sudo. Please install sudo or run epm under root.'" SUDO="fatal 'Can't find sudo. Please install sudo or run epm under root.'"
} }
# wait for n seconds (if possible) during executing command
# args: seconds command
withtimeout()
{
local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null)
if [ -x "$TO" ] ; then
$TO "$@"
return
fi
# fallback: drop time arg and run without timeout
shift
"$@"
}
set_eatmydata() set_eatmydata()
{ {
# skip if disabled # skip if disabled
[ -n "$EPMNOEATMYDATA" ] && return [ -n "$EPMNOEATMYDATA" ] && return
# use if possible # use if possible
which eatmydata >/dev/null 2>/dev/null || return which eatmydata >/dev/null 2>/dev/null || return
SUDO="$SUDO eatmydata" [ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata"
info "Uwaga! eatmydata is installed, we will use it for disable all sync operations." [ -n "$verbose" ] && info "Uwaga! eatmydata is installed, we will use it for disable all sync operations."
return 0 return 0
} }
...@@ -285,13 +330,81 @@ __get_package_for_command() ...@@ -285,13 +330,81 @@ __get_package_for_command()
esac esac
} }
# TODO:
confirm() {
local response
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
assure_root()
{
[ "$EFFUID" = 0 ] || fatal "run me only under root"
}
regexp_subst()
{
local expression="$1"
shift
sed -i -r -e "$expression" "$@"
}
# TODO: we we can't use epm directly?
assure_exists() assure_exists()
{ {
load_helper epm-assure load_helper epm-assure
__epm_assure "$1" $(__get_package_for_command "$1") local package="$2"
local textpackage=
[ -n "$package" ] || package="$(__get_package_for_command "$1")"
[ -n "$3" ] && textpackage=" >= $3"
__epm_assure "$1" $package $3 || fatal "Can't assure in '$1' command from $package$textpackage package"
} }
# improve # will replaced within disabled_eget in packaged version
eget()
{
# use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@"
return
fi
assure_exists eget
# run external command, not the function
EGET=$(which eget) || fatal "Missed command eget from installed package eget"
$EGET "$@"
}
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
onefile_eget()
{
assure_exists wget
internal_tools_eget "$@"
}
# TODO: improve and drop!
get_package_type() get_package_type()
{ {
local i local i
...@@ -304,6 +417,22 @@ get_package_type() ...@@ -304,6 +417,22 @@ get_package_type()
echo "rpm" echo "rpm"
return return
;; ;;
*.txz)
echo "txz"
return
;;
*.tbz)
echo "tbz"
return
;;
*.exe)
echo "exe"
return
;;
*.msi)
echo "msi"
return
;;
*) *)
#fatal "Don't know type of $1" #fatal "Don't know type of $1"
# return package name for info # return package name for info
...@@ -317,7 +446,11 @@ get_package_type() ...@@ -317,7 +446,11 @@ get_package_type()
# print options description from HELPCMD/HELPOPT lines in the code # print options description from HELPCMD/HELPOPT lines in the code
get_help() get_help()
{ {
grep -v -- "^#" $0 | grep -- "# $1" | while read n ; do if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
return
fi
grep -v -- "^#" $0 | grep -- "# $1" | while read -r n ; do
opt=$(echo $n | sed -e "s|) # $1:.*||g") opt=$(echo $n | sed -e "s|) # $1:.*||g")
desc=$(echo $n | sed -e "s|.*) # $1:||g") desc=$(echo $n | sed -e "s|.*) # $1:||g")
printf " %-20s %s\n" $opt "$desc" printf " %-20s %s\n" $opt "$desc"
...@@ -342,6 +475,8 @@ if [ -n "$FORCEPM" ] ; then ...@@ -342,6 +475,8 @@ if [ -n "$FORCEPM" ] ; then
return return
fi fi
# TODO: move it in distr_vendor?
# FIXME: some problems with multibased distros (Server Edition on CentOS and Desktop Edition on Ubuntu)
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
CMD="apt-rpm" CMD="apt-rpm"
...@@ -350,15 +485,17 @@ case $DISTRNAME in ...@@ -350,15 +485,17 @@ case $DISTRNAME in
PCLinux) PCLinux)
CMD="apt-rpm" CMD="apt-rpm"
;; ;;
Ubuntu|Debian|Mint) Ubuntu|Debian|Mint|AstraLinux|Elbrus)
CMD="apt-dpkg" CMD="apt-dpkg"
#which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg #which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg
which snappy 2>/dev/null >/dev/null && CMD=snappy
;; ;;
Mandriva|ROSA) Mandriva|ROSA)
CMD="urpm-rpm" CMD="urpm-rpm"
;; ;;
FreeBSD|NetBSD|OpenBSD|Solaris) FreeBSD|NetBSD|OpenBSD|Solaris)
CMD="pkgsrc" CMD="pkgsrc"
which pkg 2>/dev/null >/dev/null && CMD=pkgng
;; ;;
Gentoo) Gentoo)
CMD="emerge" CMD="emerge"
...@@ -366,9 +503,9 @@ case $DISTRNAME in ...@@ -366,9 +503,9 @@ case $DISTRNAME in
ArchLinux) ArchLinux)
CMD="pacman" CMD="pacman"
;; ;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific) Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific|GosLinux|Amzn)
CMD="yum-rpm" CMD="yum-rpm"
#which dnf 2>/dev/null >/dev/null && CMD=dnf-rpm which dnf 2>/dev/null >/dev/null && test -d /var/lib/dnf/yumdb && CMD=dnf-rpm
;; ;;
Slackware) Slackware)
CMD="slackpkg" CMD="slackpkg"
...@@ -385,8 +522,8 @@ case $DISTRNAME in ...@@ -385,8 +522,8 @@ case $DISTRNAME in
MacOS) MacOS)
CMD="homebrew" CMD="homebrew"
;; ;;
OpenWRT) OpenWrt)
CMD="ipkg" CMD="opkg"
;; ;;
GNU/Linux/Guix) GNU/Linux/Guix)
CMD="guix" CMD="guix"
...@@ -394,6 +531,18 @@ case $DISTRNAME in ...@@ -394,6 +531,18 @@ case $DISTRNAME in
Android) Android)
CMD="android" CMD="android"
;; ;;
Cygwin)
CMD="aptcyg"
;;
alpine)
CMD="apk"
;;
TinyCoreLinux)
CMD="tce"
;;
VoidLinux)
CMD="xbps"
;;
*) *)
fatal "Have no suitable DISTRNAME $DISTRNAME" fatal "Have no suitable DISTRNAME $DISTRNAME"
;; ;;
...@@ -401,3 +550,24 @@ esac ...@@ -401,3 +550,24 @@ esac
PMTYPE=$CMD PMTYPE=$CMD
} }
is_active_systemd()
{
local a
SYSTEMCTL=/bin/systemctl
SYSTEMD_CGROUP_DIR=/sys/fs/cgroup/systemd
[ -x "$SYSTEMCTL" ] || return
[ -d "$SYSTEMD_CGROUP_DIR" ] || return
a='' mountpoint -q "$SYSTEMD_CGROUP_DIR" || return
readlink /sbin/init | grep -q 'systemd' || return
# some hack
# shellcheck disable=SC2009
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"
}
#!/bin/sh
#
# Copyright (C) 2017 Etersoft
# Copyright (C) 2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
is_warmup_allowed()
{
local MEM
MEM="$($DISTRVENDOR -m)"
# disable warm if have no enough memory
[ "$MEM" -le 1024 ] && return 1
return 0
}
__warmup_files()
{
local D="$1"
shift
#showcmd "$*"
[ -n "$D" ] && info "Warming up $D ..."
# TODO: use progress, calc files size before
docmd cat $* >/dev/null 2>/dev/null
}
warmup_rpmbase()
{
is_warmup_allowed || return
__warmup_files "rpm" "/var/lib/rpm/*"
}
warmup_dpkgbase()
{
is_warmup_allowed || { warning "Skipping warmup bases due low memory size" ; return ; }
__warmup_files "dpkg" "/var/lib/dpkg/*"
}
warmup_lowbase()
{
case $PKGFORMAT in
"rpm")
warmup_rpmbase "$@"
;;
"dpkg")
warmup_dpkgbase "$@"
;;
*)
;;
esac
}
warmup_aptbase()
{
is_warmup_allowed || return
__warmup_files "apt" "/var/lib/apt/lists/* /var/cache/apt/*.bin"
}
warmup_hibase()
{
case $PMTYPE in
"apt-rpm"|"apt-dpkg")
warmup_aptbase "$@"
;;
*)
;;
esac
}
warmup_bases()
{
DISquiet=1 warmup_lowbase
DISquiet=1 warmup_hibase
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2014 Etersoft # Copyright (C) 2012-2015, 2018 Etersoft
# Copyright (C) 2012-2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2015, 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
...@@ -23,12 +23,12 @@ load_helper epm-search ...@@ -23,12 +23,12 @@ load_helper epm-search
# for zypper before SUSE/11.0 # for zypper before SUSE/11.0
__use_zypper_dry_run() __use_zypper_dry_run()
{ {
a= zypper install --help 2>&1 | grep -q -- "--dry-run" && echo "--dry-run" a='' zypper install --help 2>&1 | grep -q -- "--dry-run" && echo "--dry-run"
} }
__use_yum_assumeno() __use_yum_assumeno()
{ {
a= yum --help 2>&1 | grep -q -- "--assumeno" a='' yum --help 2>&1 | grep -q -- "--assumeno"
} }
...@@ -36,8 +36,9 @@ __check_yum_result() ...@@ -36,8 +36,9 @@ __check_yum_result()
{ {
grep "^No package" $1 && return 1 grep "^No package" $1 && return 1
grep "^Complete!" $1 && return 0 grep "^Complete!" $1 && return 0
grep "^Exiting on user Command" $1 && return 0 grep "Exiting on user [Cc]ommand" $1 && return 0
grep "^Exiting on user command" $1 && return 0 # dnf issue
grep "^Operation aborted." $1 && return 0
# return default result by default # return default result by default
return $2 return $2
} }
...@@ -78,6 +79,12 @@ EOF ...@@ -78,6 +79,12 @@ EOF
RES=$? RES=$?
clean_store_output clean_store_output
return $RES ;; return $RES ;;
dnf-rpm)
LC_ALL=C store_output sudocmd dnf --assumeno install $filenames
__check_yum_result $RC_STDOUT $?
RES=$?
clean_store_output
return $RES ;;
urpm-rpm) urpm-rpm)
CMD="urpmi --test --auto" CMD="urpmi --test --auto"
;; ;;
...@@ -96,6 +103,9 @@ EOF ...@@ -96,6 +103,9 @@ EOF
break break
done done
return $res ;; return $res ;;
opkg)
docmd --noaction install $filenames
return $res ;;
pacman) pacman)
LC_ALL=C store_output sudocmd pacman -v -S $filenames <<EOF LC_ALL=C store_output sudocmd pacman -v -S $filenames <<EOF
no no
...@@ -113,8 +123,11 @@ EOF ...@@ -113,8 +123,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
...@@ -138,7 +151,11 @@ epm_simulate() ...@@ -138,7 +151,11 @@ epm_simulate()
_epm_do_simulate $filenames _epm_do_simulate $filenames
local RES=$? local RES=$?
if [ -z "$quiet" ] ; then if [ -z "$quiet" ] ; then
[ "$RES" = 0 ] && info "Simulate result: $filenames package(s) CAN BE installed" || info "Simulate result: There are PROBLEMS with install some package(s)" if [ "$RES" = 0 ] ; then
info "Simulate result: $filenames package(s) CAN BE installed"
else
info "Simulate result: There are PROBLEMS with install some package(s)"
fi
fi fi
return $RES return $RES
} }
......
#!/bin/sh
#
# Copyright (C) 2015,2016 Etersoft
# Copyright (C) 2015,2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper epm-query
load_helper epm-print
PAOURL="https://packages.altlinux.org"
paoapi()
{
# http://petstore.swagger.io/?url=http://packages.altlinux.org/api/docs
epm assure curl || return 1
showcmd curl "$PAOURL/api/$1"
a='' curl -s --header "Accept: application/json" "$PAOURL/api/$1"
}
# TODO: use /home/lav/Projects/git/JSON.sh
get_pao_var()
{
local FIELD="$1"
#grep '"$FIELD"' | sed -e 's|.*"$FIELD":"||g' | sed -e 's|".*||g'
$SHAREDIR/tools_json -b | grep -E "\[.*\"$FIELD\"\]" | sed -e 's|.*[[:space:]]"\(.*\)"|\1|g'
return 0
}
run_command_if_exists()
{
local CMD="$1"
shift
if which "$CMD" 2>/dev/null >/dev/null ; then
docmd "$CMD" "$@"
return 0
fi
return 1
}
open_browser()
{
local i
for i in xdg-open firefox chromium links ; do
run_command_if_exists $i "$@" && return
done
}
__query_package_hl_url()
{
case $DISTRNAME in
ALTLinux)
paoapi srpms/$1 | get_pao_var url
;;
esac
return 1
}
query_package_url()
{
local URL
case $PMTYPE in
*-rpm)
# TODO: for binary packages?
query_package_field URL "$1" || __query_package_hl_url "$1"
#LANG=C epm info "$1"
return
;;
esac
fatal "rpm based distro supported only. TODO: Realize via web service?"
}
get_locale()
{
local loc
loc=$(a='' natspec --locale 2>/dev/null)
[ -n "$loc" ] || loc=$LANG
echo $loc
}
get_pao_url()
{
local loc
loc=$(get_locale | cut -c1-2)
case $loc in
en|ru|uk|br)
loc=$loc
;;
*)
loc=en
esac
echo "$PAOURL/$loc/Sisyphus/srpms"
}
query_altlinux_url()
{
local URL
case $PMTYPE in
*-rpm)
local srpm=$(print_srcname "$1")
[ -n "$srpm" ] || fatal "Can't get source name for $1"
echo "$(get_pao_url)/$srpm"
return
;;
esac
fatal "rpm based distro supported only. TODO: Realize via web service?"
}
epm_site()
{
[ -n "$pkg_filenames" ] || fatal "Info: missing package(s) name"
local PAO=""
for f in $pkg_names $pkg_files ; do
[ "$f" = "-p" ] && PAO="$f" && continue
if [ -n "$PAO" ] ; then
pkg_url=$(query_altlinux_url $f)
else
pkg_url=$(query_package_url $f)
fi
[ -n "$pkg_url" ] && open_browser "$pkg_url" && continue
warning "Can't get URL for $f package"
done
#for f in $pkg_names ; do
# LANG=C epm info $f
#done
# TODO: -p for p.a.o (see rpmurl)
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2014 Etersoft # Copyright (C) 2012, 2014, 2016-2017 Etersoft
# Copyright (C) 2012,2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2014, 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -19,25 +19,40 @@ ...@@ -19,25 +19,40 @@
# copied from korinf/tools/run-script/scripts/update # copied from korinf/tools/run-script/scripts/update
load_helper epm-sh-warmup
epm_update() epm_update()
{ {
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
info "Running command for update remote package repository database" info "Running command for update remote package repository database"
warmup_hibase
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
sudocmd apt-get update || exit sudocmd apt-get update || return
#sudocmd apt-get -f install || exit #sudocmd apt-get -f install || exit
;; ;;
apt-dpkg) apt-dpkg)
sudocmd apt-get update || exit sudocmd apt-get update || return
#sudocmd apt-get -f install || exit #sudocmd apt-get -f install || exit
#sudocmd apt-get autoremove #sudocmd apt-get autoremove
;; ;;
#snappy)
# sudocmd snappy
# ;;
aptitude-dpkg) aptitude-dpkg)
sudocmd aptitude update || exit sudocmd aptitude update || return
;; ;;
yum-rpm) yum-rpm)
sudocmd yum check-update info "update command is stubbed for yum"
# yum makecache
#sudocmd yum check-update
;;
dnf-rpm)
info "update command is stubbed for dnf"
# dnf makecache
#sudocmd dnf check-update
;; ;;
urpm-rpm) urpm-rpm)
sudocmd urpmi.update -a sudocmd urpmi.update -a
...@@ -64,10 +79,23 @@ case $PMTYPE in ...@@ -64,10 +79,23 @@ case $PMTYPE in
sudocmd packdcl detect # get packages from MSI database sudocmd packdcl detect # get packages from MSI database
;; ;;
homebrew) homebrew)
sudocmd brew update docmd brew update
;;
opkg)
sudocmd opkg update
;;
apk)
sudocmd apk update
;;
pkgsrc)
# portsnap extract for the first time?
sudocmd portsnap fetch update
;;
aptcyg)
sudocmd apt-cyg update
;; ;;
ipkg) xbps)
sudocmd ipkg update sudocmd xbps-install -S
;; ;;
*) *)
fatal "Have no suitable update command for $PMTYPE" fatal "Have no suitable update command for $PMTYPE"
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012,2014 Etersoft # Copyright (C) 2012, 2014, 2016 Etersoft
# Copyright (C) 2012,2014 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2014, 2016 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
...@@ -18,35 +18,44 @@ ...@@ -18,35 +18,44 @@
# #
load_helper epm-check_updated_repo load_helper epm-check_updated_repo
load_helper epm-sh-warmup
epm_upgrade() epm_upgrade()
{ {
local CMD local CMD
#[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
# it is useful for first time running # it is useful for first time running
update_repo_if_needed update_repo_if_needed
warmup_bases
info "Running command for upgrade packages" info "Running command for upgrade packages"
case $PMTYPE in case $PMTYPE in
apt-rpm|apt-dpkg) apt-rpm|apt-dpkg)
# non_interactive local APTOPTIONS="$(subst_option non_interactive -y) $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
# Функцию добавления параметра при условии # Функцию добавления параметра при условии
CMD="apt-get dist-upgrade" CMD="apt-get $APTOPTIONS dist-upgrade $noremove"
;; ;;
aptitude-dpkg) aptitude-dpkg)
CMD="aptitude dist-upgrade" CMD="aptitude dist-upgrade"
;; ;;
yum-rpm) yum-rpm)
local OPTIONS="$(subst_option non_interactive -y)"
# can do update repobase automagically # can do update repobase automagically
CMD="yum update" CMD="yum $OPTIONS update $pkg_filenames"
;; ;;
dnf-rpm) dnf-rpm)
CMD="dnf update" local OPTIONS="$(subst_option non_interactive -y)"
CMD="dnf $OPTIONS distro-sync $pkg_filenames"
;;
snappy)
CMD="snappy update"
;; ;;
urpm-rpm) urpm-rpm)
# or --auto-select --replace-files # or --auto-select --replace-files
CMD="urpmi --auto-update" CMD="urpmi --update --auto-select $pkg_filenames"
;; ;;
zypper-rpm) zypper-rpm)
CMD="zypper dist-upgrade" CMD="zypper dist-upgrade"
...@@ -66,16 +75,19 @@ epm_upgrade() ...@@ -66,16 +75,19 @@ epm_upgrade()
pkgsrc) pkgsrc)
CMD="freebsd-update fetch install" CMD="freebsd-update fetch install"
;; ;;
pkgng)
CMD="pkg upgrade"
;;
chocolatey) chocolatey)
CMD="chocolatey update all" CMD="chocolatey update all"
;; ;;
homebrew) homebrew)
#CMD="brew upgrade" #CMD="brew upgrade"
sudocmd "brew upgrade `brew outdated`" docmd "brew upgrade $(brew outdated)"
return return
;; ;;
ipkg) opkg)
CMD="ipkg upgrade" CMD="opkg upgrade"
;; ;;
slackpkg) slackpkg)
CMD="/usr/sbin/slackpkg upgrade-all" CMD="/usr/sbin/slackpkg upgrade-all"
...@@ -83,6 +95,14 @@ epm_upgrade() ...@@ -83,6 +95,14 @@ epm_upgrade()
guix) guix)
CMD="guix package -u" CMD="guix package -u"
;; ;;
aptcyg)
# shellcheck disable=SC2046
docmd_foreach "epm install" $(short=1 epm packages)
return
;;
xbps)
CMD="xbps-install -Su"
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2013 Etersoft # Copyright (C) 2013, 2016, 2018 Etersoft
# Copyright (C) 2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2013, 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,14 +17,25 @@ ...@@ -17,14 +17,25 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
# TODO: will it has local only mode?
load_helper epm-print
epm_whatdepends() epm_whatdepends()
{ {
local CMD local CMD
[ -n "$pkg_filenames" ] || fatal "Whatdepends: missing package(s) name" [ -n "$pkg_files" ] && fatal "whatdepends do not handle files"
[ -n "$pkg_names" ] || fatal "whatdepends: missing package(s) name"
local pkg=$(print_name $pkg_names)
# by package name # by package name
case $PMTYPE in case $PMTYPE in
apt-rpm) apt-rpm)
if [ -n "$short" ] ; then
showcmd apt-cache whatdepends $pkg
a= apt-cache whatdepends $pkg | grep "^ [^ ]" | sed -e "s|[0-9]*:||" | grep -E -v "(i586-|-debuginfo)"
return
fi
CMD="apt-cache whatdepends" CMD="apt-cache whatdepends"
;; ;;
apt-dpkg|aptitude-dpkg) apt-dpkg|aptitude-dpkg)
...@@ -36,15 +47,34 @@ case $PMTYPE in ...@@ -36,15 +47,34 @@ case $PMTYPE in
yum-rpm) yum-rpm)
CMD="repoquery --whatrequires" CMD="repoquery --whatrequires"
;; ;;
urpm-rpm)
CMD="urpmq --whatrequires"
;;
dnf-rpm)
# check command: dnf repoquery --whatrequires
CMD="repoquery --whatrequires"
;;
emerge) emerge)
assure_exists equery assure_exists equery
CMD="equery depends -a" CMD="equery depends -a"
;; ;;
pkgng)
CMD="pkg info -r"
;;
aptcyg)
CMD="apt-cyg rdepends"
;;
opkg)
CMD="opkg whatdepends"
;;
xbps)
CMD="xbps-query -X"
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
esac esac
docmd $CMD $pkg_filenames docmd $CMD $pkg
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2013 Etersoft # Copyright (C) 2013, 2016, 2018 Etersoft
# Copyright (C) 2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2013, 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,10 +17,14 @@ ...@@ -17,10 +17,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-print
epm_whatprovides() epm_whatprovides()
{ {
local CMD local CMD
[ -n "$pkg_filenames" ] || fatal "Whatprovides: missing package(s) name" [ -n "$pkg_files" ] && fatal "whatprovides does not handle files"
[ -n "$pkg_names" ] || fatal "whatprovides: missing package(s) name"
local pkg=$(print_name $pkg_names)
# by package name # by package name
case $PMTYPE in case $PMTYPE in
...@@ -28,20 +32,29 @@ case $PMTYPE in ...@@ -28,20 +32,29 @@ case $PMTYPE in
CMD="conary repquery --what-provides" CMD="conary repquery --what-provides"
;; ;;
apt-rpm|apt-dpkg|aptitude-dpkg) apt-rpm|apt-dpkg|aptitude-dpkg)
LANG=C docmd apt-get install --print-uris $pkg_filenames | grep "^Selecting" | cut -f2 -d" " LANG=C docmd apt-get install --print-uris $pkg | grep "^Selecting" | cut -f2 -d" "
return return
;; ;;
yum-rpm) yum-rpm)
CMD="yum whatprovides" CMD="yum whatprovides"
;; ;;
urpm-rpm)
CMD="urpmq --whatprovides"
;;
dnf-rpm)
CMD="yum provides"
;;
zypper-rpm) zypper-rpm)
CMD="zypper what-provides" CMD="zypper what-provides"
;; ;;
opkg)
CMD="opkg whatprovides"
;;
*) *)
fatal "Have no suitable command for $PMTYPE" fatal "Have no suitable command for $PMTYPE"
;; ;;
esac esac
docmd $CMD $pkg_filenames docmd $CMD $pkg
} }
epm
\ No newline at end of file
epm
\ No newline at end of file
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2013 Etersoft # Copyright (C) 2012-2013, 2016 Etersoft
# Copyright (C) 2012-2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2013, 2016 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
...@@ -32,6 +32,8 @@ load_helper() ...@@ -32,6 +32,8 @@ load_helper()
load_helper epm-sh-functions load_helper epm-sh-functions
INITDIR=/etc/init.d
PATH=$PATH:/sbin:/usr/sbin PATH=$PATH:/sbin:/usr/sbin
set_sudo set_sudo
...@@ -52,18 +54,11 @@ set_service_type() ...@@ -52,18 +54,11 @@ set_service_type()
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v) [ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
set_target_pkg_env set_target_pkg_env
is_active_systemd()
{
SYSTEMCTL=/bin/systemctl
SYSTEMD_CGROUP_DIR=/sys/fs/cgroup/systemd
[ -x "$SYSTEMCTL" ] && [ -d "$SYSTEMD_CGROUP_DIR" ] && mountpoint -q "$SYSTEMD_CGROUP_DIR"
}
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
CMD="service-chkconfig" CMD="service-chkconfig"
;; ;;
Ubuntu|Debian|Mint) Ubuntu|Debian|Mint|AstraLinux)
CMD="service-update" CMD="service-update"
;; ;;
Mandriva|ROSA) Mandriva|ROSA)
...@@ -78,9 +73,12 @@ case $DISTRNAME in ...@@ -78,9 +73,12 @@ case $DISTRNAME in
# ArchLinux) # ArchLinux)
# CMD="pacman" # CMD="pacman"
# ;; # ;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific) Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific|GosLinux|Amzn)
CMD="service-chkconfig" CMD="service-chkconfig"
;; ;;
VoidLinux)
CMD="runit"
;;
Slackware) Slackware)
CMD="service-initd" CMD="service-initd"
;; ;;
...@@ -103,8 +101,18 @@ is_active_systemd && CMD="systemd" ...@@ -103,8 +101,18 @@ is_active_systemd && CMD="systemd"
SERVICETYPE=$CMD SERVICETYPE=$CMD
ANYSERVICE=$(which anyservice 2>/dev/null)
} }
# TODO: done it on anyservice part
is_anyservice()
{
[ -n "$ANYSERVICE" ] || return
[ -n "$1" ] || return
# check if anyservice is exists and checkd returns true
$ANYSERVICE "$1" checkd 2>/dev/null
}
phelp() phelp()
...@@ -122,8 +130,8 @@ $(get_help HELPOPT) ...@@ -122,8 +130,8 @@ $(get_help HELPOPT)
print_version() print_version()
{ {
echo "Service manager version @VERSION@" echo "Service manager version @VERSION@"
echo "Running on $($DISTRVENDOR)" echo "Running on $($DISTRVENDOR) with $SERVICETYPE"
echo "Copyright (c) Etersoft 2012, 2013" echo "Copyright (c) Etersoft 2012-2018"
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."
} }
...@@ -156,8 +164,12 @@ check_command() ...@@ -156,8 +164,12 @@ check_command()
serv_cmd=usage serv_cmd=usage
withoutservicename=1 withoutservicename=1
;; ;;
#restart) # HELPCMD: restart service restart) # HELPCMD: restart service
#reload) # HELPCMD: reload service serv_cmd=restart
;;
reload) # HELPCMD: reload service
serv_cmd=reload
;;
start) # HELPCMD: start service start) # HELPCMD: start service
serv_cmd=start serv_cmd=start
;; ;;
...@@ -185,6 +197,13 @@ check_command() ...@@ -185,6 +197,13 @@ check_command()
off|disable) # HELPCMD: remove service to run on startup and stop it now off|disable) # HELPCMD: remove service to run on startup and stop it now
serv_cmd=disable serv_cmd=disable
;; ;;
print) # HELPCMD: print some info
serv_cmd=print
withoutservicename=1
;;
log|journal) # HELPCMD: print log for the service
serv_cmd=log
;;
*) *)
return 1 return 1
;; ;;
...@@ -239,6 +258,7 @@ if [ -z "$withoutservicename" ] && [ -z "$service_name" ] ; then ...@@ -239,6 +258,7 @@ if [ -z "$withoutservicename" ] && [ -z "$service_name" ] ; then
fatal "Run $ $progname --help for get help" fatal "Run $ $progname --help for get help"
fi fi
# use common way if the command is unknown
if [ -z "$serv_cmd" ] ; then if [ -z "$serv_cmd" ] ; then
serv_cmd=common serv_cmd=common
fi fi
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -24,17 +24,27 @@ serv_common() ...@@ -24,17 +24,27 @@ serv_common()
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
fatal "Have no idea how to call anyservice service with args"
fi
sudocmd service $SERVICE "$@" sudocmd service $SERVICE "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd /etc/init.d/$SERVICE "$@" sudocmd $INITDIR/$SERVICE "$@"
;; ;;
systemd) systemd)
# run init script directly (for nonstandart commands)
if [ -x $INITDIR/$SERVICE ] ; then
sudocmd $INITDIR/$SERVICE "$@"
else
sudocmd systemctl "$@" $SERVICE sudocmd systemctl "$@" $SERVICE
fi
;;
runit)
sudocmd sv $SERVICE "$@"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -23,11 +23,17 @@ load_helper serv-status ...@@ -23,11 +23,17 @@ load_helper serv-status
# Enable service by default # Enable service by default
serv_disable() serv_disable()
{ {
local SERVICE="$1"
is_service_running $1 && { serv_stop $1 || return ; } is_service_running $1 && { serv_stop $1 || return ; }
is_service_autostart $1 || { echo "Service $1 already disabled for startup" && return ; } is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; }
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE off
return
fi
sudocmd chkconfig $1 off sudocmd chkconfig $1 off
;; ;;
service-initd|service-update) service-initd|service-update)
...@@ -36,6 +42,9 @@ serv_disable() ...@@ -36,6 +42,9 @@ serv_disable()
systemd) systemd)
sudocmd systemctl disable $1 sudocmd systemctl disable $1
;; ;;
runit)
sudocmd rm -fv /var/service/$SERVICE
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -21,13 +21,23 @@ load_helper serv-start ...@@ -21,13 +21,23 @@ load_helper serv-start
load_helper serv-status load_helper serv-status
# Enable service by default # Enable service by default
serv_enable() __serv_enable()
{ {
is_service_running $1 || serv_start $1 || return local SERVICE="$1"
is_service_autostart $1 && echo "Service $1 already enabled for startup" && return
is_service_autostart $1 && info "Service $1 is already enabled for startup" && return
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE on
return
fi
sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on
;;
service-upstart)
sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
service-initd|service-update) service-initd|service-update)
...@@ -36,9 +46,22 @@ serv_enable() ...@@ -36,9 +46,22 @@ serv_enable()
systemd) systemd)
sudocmd systemctl enable $1 sudocmd systemctl enable $1
;; ;;
runit)
epm assure $SERVICE
[ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE"
sudocmd ln -s /etc/sv/$SERVICE /var/service/
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
serv_enable()
{
__serv_enable "$1" || return
# start if need
is_service_running $1 && info "Service $1 is already running" && return
serv_start $1
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# List running services # List running services
serv_list() serv_list()
{ {
info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
# service-chkconfig) # service-chkconfig)
# ;; # ;;
...@@ -33,9 +34,11 @@ serv_list() ...@@ -33,9 +34,11 @@ serv_list()
sudocmd systemctl list-units $@ sudocmd systemctl list-units $@
;; ;;
*) *)
# hack to improve list speed
[ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; }
load_helper serv-list_all load_helper serv-list_all
load_helper serv-status load_helper serv-status
for i in $(serv_list_all) ; do for i in $(quiet=1 serv_list_all) ; do
is_service_running $i >/dev/null && echo $i is_service_running $i >/dev/null && echo $i
done done
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012,2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012,2016 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
...@@ -23,10 +23,15 @@ serv_list_all() ...@@ -23,10 +23,15 @@ 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
sudocmd anyservice --quiet list
return
fi
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README sudocmd ls $INITDIR/ | grep -v README
;; ;;
systemd) systemd)
sudocmd systemctl list-unit-files $@ sudocmd systemctl list-unit-files $@
......
#!/bin/sh
#
# Copyright (C) 2016 Etersoft
# Copyright (C) 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__serv_log_altlinux()
{
local SERVICE="$1"
case "$SERVICE" in
postfix)
sudocmd tail -f /var/log/mail/all /var/log/mail/errors
;;
cups)
sudocmd tail -f /var/log/cups/access_log /var/log/cups/error_log
;;
fail2ban)
sudocmd tail -f /var/log/$SERVICE.log
;;
*)
fatal "Have no suitable for $SERVICE service"
;;
esac
}
serv_log()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
systemd)
sudocmd journalctl -f -b -u "$SERVICE" "$@"
;;
*)
case $DISTRNAME in
ALTLinux)
__serv_log_altlinux "$SERVICE"
return ;;
*)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;;
esac
esac
}
#!/bin/sh
#
# Copyright (C) 2016 Etersoft
# Copyright (C) 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
serv_print()
{
echo "Detected init system: $SERVICETYPE"
[ -n "$ANYSERVICE" ] && echo "anyservice is detected too"
}
#!/bin/sh
#
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper serv-status
# Reload service (try send SIGHUP or so on to reread config)
serv_reload()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE reload
return
fi
sudocmd service $SERVICE reload "$@"
;;
service-initd|service-update)
sudocmd $INITDIR/$SERVICE reload "$@"
;;
systemd)
sudocmd systemctl reload $SERVICE "$@"
;;
*)
info "Fallback to restart..."
load_helper serv-restart
serv_restart "$SERVICE" "$@"
;;
esac
}
#!/bin/sh
#
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
load_helper serv-status
# Restart service (start if it was not running)
serv_restart()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE restart
return
fi
sudocmd service $SERVICE restart "$@"
;;
service-initd|service-update)
sudocmd $INITDIR/$SERVICE restart "$@"
;;
systemd)
sudocmd systemctl restart $SERVICE "$@"
;;
runit)
sudocmd sv restart "$SERVICE"
;;
*)
fatal "Have no suitable command for $SERVICETYPE"
;;
esac
}
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -25,14 +25,21 @@ serv_start() ...@@ -25,14 +25,21 @@ serv_start()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE start
return
fi
sudocmd service $SERVICE start "$@" sudocmd service $SERVICE start "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd /etc/init.d/$SERVICE start "$@" sudocmd $INITDIR/$SERVICE start "$@"
;; ;;
systemd) systemd)
sudocmd systemctl start "$SERVICE" "$@" sudocmd systemctl start "$SERVICE" "$@"
;; ;;
runit)
sudocmd sv up "$SERVICE"
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012, 2013 Etersoft # Copyright (C) 2012, 2013, 2016, 2017 Etersoft
# Copyright (C) 2012, 2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2013, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -20,15 +20,28 @@ ...@@ -20,15 +20,28 @@
# FIXME: sudo ask password, but we do not print command before # FIXME: sudo ask password, but we do not print command before
is_service_running() is_service_running()
{ {
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)
$SUDO service $1 status >/dev/null if is_anyservice $1 ; then
OUTPUT="$($SUDO anyservice $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0
fi
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 /etc/init.d/$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)
$SUDO sv status "$SERVICE" >/dev/null 2>/dev/null
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
...@@ -39,16 +52,27 @@ is_service_running() ...@@ -39,16 +52,27 @@ is_service_running()
# FIXME: sudo ask password, but we do not print command before # FIXME: sudo ask password, but we do not print command before
is_service_autostart() is_service_autostart()
{ {
local SERVICE="$1"
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
LANG=C $SUDO chkconfig $1 --list | grep -q "5:on" if is_anyservice $SERVICE; then
$ANYSERVICE $SERVICE isautostarted
return
fi
# FIXME: check for current runlevel
LANG=C $SUDO chkconfig $1 --list | grep -q "[35]:on"
;; ;;
service-initd|service-update) service-initd|service-update)
fatal "FIXME: don't know how detect current startup state" test -L "$(echo /etc/rc5.d/S??$1)"
;; ;;
systemd) systemd)
$SUDO systemctl is-enabled $1 $SUDO systemctl is-enabled $1
;; ;;
runit)
test -L "/var/service/$SERVICE"
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
...@@ -64,13 +88,20 @@ serv_status() ...@@ -64,13 +88,20 @@ serv_status()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE status
return
fi
sudocmd service $SERVICE status "$@" sudocmd service $SERVICE status "$@"
;; ;;
service-update) service-update)
sudocmd /etc/init.d/$SERVICE status "$@" sudocmd $INITDIR/$SERVICE status "$@"
;; ;;
systemd) systemd)
sudocmd systemctl status $SERVICE "$@" sudocmd systemctl -l status $SERVICE "$@"
;;
runit)
sudocmd sv status "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -25,14 +25,21 @@ serv_stop() ...@@ -25,14 +25,21 @@ serv_stop()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE stop
return
fi
sudocmd service $SERVICE stop "$@" sudocmd service $SERVICE stop "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd /etc/init.d/$SERVICE stop "$@" sudocmd $INITDIR/$SERVICE stop "$@"
;; ;;
systemd) systemd)
sudocmd systemctl stop $SERVICE "$@" sudocmd systemctl stop $SERVICE "$@"
;; ;;
runit)
sudocmd sv down "$SERVICE"
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 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
...@@ -26,19 +26,14 @@ serv_try_restart() ...@@ -26,19 +26,14 @@ serv_try_restart()
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart)
is_service_running $SERVICE || return 0
sudocmd service $SERVICE restart "$@"
;;
service-initd|service-update)
is_service_running $SERVICE || return 0
sudocmd /etc/init.d/$SERVICE restart "$@"
;;
systemd) systemd)
sudocmd systemctl try-restart $SERVICE "$@" sudocmd systemctl try-restart $SERVICE "$@"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" info "Fallback to restart..."
is_service_running $SERVICE || { info "Service $SERVICE is not running, restart skipping…" ; return 0 ; }
load_helper serv-restart
serv_restart "$SERVICE" "$@"
;; ;;
esac esac
} }
#!/bin/sh
# eget - simply shell on wget for loading directories over http (wget does not support wildcard for http)
# Example use:
# eget http://ftp.altlinux.ru/pub/security/ssl/*
#
# Copyright (C) 2014-2014, 2016 Etersoft
# Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
WGET="wget"
# TODO: passthrou all wget options
if [ "$1" = "-q" ] ; then
WGET="wget -q"
shift
fi
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
WGET_OPTION_TARGET=
if [ "$1" = "-O" ] ; then
TARGETFILE="$2"
WGET_OPTION_TARGET="-O $2"
shift 2
fi
# TODO:
# -P support
if [ -z "$1" ] ; then
echo "eget - wget wrapper" >&2
fatal "Run with URL, like http://somesite.ru/dir/*.log"
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 /
if echo "$1" | grep -q "/$" ; then
fatal "Use http://example.com/e/* to download all files in dir"
fi
# If ftp protocol, just download
if echo "$1" | grep -q "^ftp://" ; then
[ -n "$LISTONLY" ] && fatal "Error: list files for ftp:// do not supported yet"
$WGET $WGET_OPTION_TARGET "$1"
exit
fi
# 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=$(basename "$1")
# If have no wildcard symbol like asterisk, just download
if echo "$MASK" | grep -qv "[*?]" ; then
$WGET $WGET_OPTION_TARGET "$1"
exit
fi
get_urls()
{
$WGET -O- $URL | \
grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
}
if [ -n "$LISTONLY" ] ; then
WGET="$WGET -q"
for fn in $(get_urls | filter_glob "$MASK") ; do
echo "$(basename "$fn")"
done
exit
fi
ERROR=0
for fn in $(get_urls | filter_glob "$MASK") ; do
$WGET "$URL/$(basename "$fn")" || ERROR=1
done
exit $ERROR
#!/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
#!/bin/sh
# License: MIT or Apache
# Homepage: http://github.com/dominictarr/JSON.sh
throw() {
echo "$*" >&2
exit 1
}
BRIEF=0
LEAFONLY=0
PRUNE=0
NO_HEAD=0
NORMALIZE_SOLIDUS=0
usage() {
echo
echo "Usage: JSON.sh [-b] [-l] [-p] [-s] [-h]"
echo
echo "-p - Prune empty. Exclude fields with empty values."
echo "-l - Leaf only. Only show leaf nodes, which stops data duplication."
echo "-b - Brief. Combines 'Leaf only' and 'Prune empty' options."
echo "-n - No-head. Do not show nodes that have no path (lines that start with [])."
echo "-s - Remove escaping of the solidus symbol (straight slash)."
echo "-h - This help text."
echo
}
parse_options() {
set -- "$@"
local ARGN=$#
while [ "$ARGN" -ne 0 ]
do
case $1 in
-h) usage
exit 0
;;
-b) BRIEF=1
LEAFONLY=1
PRUNE=1
;;
-l) LEAFONLY=1
;;
-p) PRUNE=1
;;
-n) NO_HEAD=1
;;
-s) NORMALIZE_SOLIDUS=1
;;
?*) echo "ERROR: Unknown option."
usage
exit 0
;;
esac
shift 1
ARGN=$((ARGN-1))
done
}
awk_egrep () {
local pattern_string=$1
gawk '{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
print token;
$0=substr($0, start+RLENGTH);
}
}' pattern="$pattern_string"
}
tokenize () {
local GREP
local ESCAPE
local CHAR
if echo "test string" | egrep -ao --color=never "test" >/dev/null 2>&1
then
GREP='egrep -ao --color=never'
else
GREP='egrep -ao'
fi
if echo "test string" | egrep -o "test" >/dev/null 2>&1
then
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\]'
else
GREP=awk_egrep
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\\\]'
fi
local STRING="\"$CHAR*($ESCAPE$CHAR*)*\""
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD='null|false|true'
local SPACE='[[:space:]]+'
# Force zsh to expand $A into multiple words
local is_wordsplit_disabled=$(unsetopt 2>/dev/null | grep -c '^shwordsplit$')
if [ $is_wordsplit_disabled != 0 ]; then setopt shwordsplit; fi
$GREP "$STRING|$NUMBER|$KEYWORD|$SPACE|." | egrep -v "^$SPACE$"
if [ $is_wordsplit_disabled != 0 ]; then unsetopt shwordsplit; fi
}
parse_array () {
local index=0
local ary=''
read -r token
case "$token" in
']') ;;
*)
while :
do
parse_value "$1" "$index"
index=$((index+1))
ary="$ary""$value"
read -r token
case "$token" in
']') break ;;
',') ary="$ary," ;;
*) throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
[ "$BRIEF" -eq 0 ] && value=$(printf '[%s]' "$ary") || value=
:
}
parse_object () {
local key
local obj=''
read -r token
case "$token" in
'}') ;;
*)
while :
do
case "$token" in
'"'*'"') key=$token ;;
*) throw "EXPECTED string GOT ${token:-EOF}" ;;
esac
read -r token
case "$token" in
':') ;;
*) throw "EXPECTED : GOT ${token:-EOF}" ;;
esac
read -r token
parse_value "$1" "$key"
obj="$obj$key:$value"
read -r token
case "$token" in
'}') break ;;
',') obj="$obj," ;;
*) throw "EXPECTED , or } GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
[ "$BRIEF" -eq 0 ] && value=$(printf '{%s}' "$obj") || value=
:
}
parse_value () {
local jpath="${1:+$1,}$2" isleaf=0 isempty=0 print=0
case "$token" in
'{') parse_object "$jpath" ;;
'[') parse_array "$jpath" ;;
# At this point, the only valid single-character tokens are digits.
''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token
# if asked, replace solidus ("\/") in json strings with normalized value: "/"
[ "$NORMALIZE_SOLIDUS" -eq 1 ] && value=$(echo "$value" | sed 's#\\/#/#g')
isleaf=1
[ "$value" = '""' ] && isempty=1
;;
esac
[ "$value" = '' ] && return
[ "$NO_HEAD" -eq 1 ] && [ -z "$jpath" ] && return
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && [ $PRUNE -eq 0 ] && print=1
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 1 ] && [ "$isempty" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && \
[ $PRUNE -eq 1 ] && [ $isempty -eq 0 ] && print=1
[ "$print" -eq 1 ] && printf "[%s]\t%s\n" "$jpath" "$value"
:
}
parse () {
read -r token
parse_value
read -r token
case "$token" in
'') ;;
*) throw "EXPECTED EOF GOT $token" ;;
esac
}
if ([ "$0" = "$BASH_SOURCE" ] || ! [ -n "$BASH_SOURCE" ]);
then
parse_options "$@"
tokenize | parse
fi
# vi: expandtab sw=2 ts=2
...@@ -3,5 +3,21 @@ ...@@ -3,5 +3,21 @@
# http://mywiki.wooledge.org/Bashism # http://mywiki.wooledge.org/Bashism
# https://wiki.ubuntu.com/DashAsBinSh # https://wiki.ubuntu.com/DashAsBinSh
EXCL=-eSC2086,SC2039,SC2034,SC2068,SC2155
# TODO:
# SC2154: pkg_filenames is referenced but not assigned.
# SC2002: Useless cat.
EXCL="$EXCL,SC2154,SC2002"
if [ -n "$1" ] ; then
shellcheck $EXCL "$1"
checkbashisms -f "$1"
exit
fi
checkbashisms -f bin/* checkbashisms -f bin/*
checkbashisms -f Makefile eepm.spec checkbashisms -f Makefile
shellcheck $EXCL \
bin/epm bin/distr_info bin/epm-* bin/serv-* bin/tools_*
/bin/echo
coreutils
eepm
file
findutils
grep
less
procps
rpm
sed
sudo
termutils
which
#!/bin/sh
/usr/lib/rpm/shell.req bin/epm-* | sort -u | tee ./check_eepm.log
git diff ./check_eepm.log
# This spec is backported to ALTLinux p7 automatically by rpmbph script. Do not edit it. # This spec is backported to ALTLinux c7.1 automatically by rpmbph script from etersoft-build-utils.
# #
Name: eepm Name: eepm
Version: 1.5.1 Version: 2.5.8
Release: alt0.M70P.1 Release: alt0.M70C.1.1
Summary: Etersoft EPM package manager Summary: Etersoft EPM package manager
...@@ -41,9 +41,23 @@ See detailed description here: http://wiki.etersoft.ru/EPM ...@@ -41,9 +41,23 @@ See detailed description here: http://wiki.etersoft.ru/EPM
%install %install
# install to datadir and so on # install to datadir and so on
%makeinstall version=%version-%release # do not use uncommon makeinstall_std here
install -m 0755 packed/epm.sh %buildroot/%_datadir/%name/epm-packed.sh %make_install install DESTDIR=%buildroot datadir=%_datadir bindir=%_bindir mandir=%_mandir sysconfdir=%_sysconfdir version=%version-%release
install -m 0755 packed/serv.sh %buildroot/%_datadir/%name/serv-packed.sh #install -m 0755 packed/epm.sh %buildroot/%_datadir/%name/epm-packed.sh
#install -m 0755 packed/serv.sh %buildroot/%_datadir/%name/serv-packed.sh
mkdir -p %buildroot%_sysconfdir/eepm/
cat <<EOF >%buildroot%_sysconfdir/eepm/eepm.conf
# EEPM config (will insource in epm shell script)
# Not known variable yet
#verbose=--verbose
#quiet==--quiet
EOF
mkdir -p %buildroot%_sysconfdir/eepm/repack.d/
cp repack.d/*.sh %buildroot%_sysconfdir/eepm/repack.d/
chmod 0755 %buildroot%_sysconfdir/eepm/repack.d/*.sh
mkdir -p %buildroot%_sysconfdir/bash_completion.d/ mkdir -p %buildroot%_sysconfdir/bash_completion.d/
install -m 0644 bash_completion/serv %buildroot%_sysconfdir/bash_completion.d/serv install -m 0644 bash_completion/serv %buildroot%_sysconfdir/bash_completion.d/serv
...@@ -51,9 +65,19 @@ ln -s serv %buildroot%_sysconfdir/bash_completion.d/cerv ...@@ -51,9 +65,19 @@ ln -s serv %buildroot%_sysconfdir/bash_completion.d/cerv
# shebang.req.files # shebang.req.files
chmod a+x %buildroot%_datadir/%name/{serv-,epm-}* chmod a+x %buildroot%_datadir/%name/{serv-,epm-}*
chmod a+x %buildroot%_datadir/%name/tools_*
%if %_vendor == "alt"
# use external eget
rm -f %buildroot%_datadir/%name/tools_eget
%endif
%files %files
%doc README TODO LICENSE %doc README.md TODO LICENSE
%dir %_sysconfdir/eepm/
%dir %_sysconfdir/eepm/repack.d/
%config(noreplace) %_sysconfdir/eepm/eepm.conf
%config(noreplace) %_sysconfdir/eepm/repack.d/*.sh
%_bindir/epm* %_bindir/epm*
%_bindir/eepm %_bindir/eepm
%_bindir/upm %_bindir/upm
...@@ -66,8 +90,587 @@ chmod a+x %buildroot%_datadir/%name/{serv-,epm-}* ...@@ -66,8 +90,587 @@ chmod a+x %buildroot%_datadir/%name/{serv-,epm-}*
%_sysconfdir/bash_completion.d/cerv %_sysconfdir/bash_completion.d/cerv
%changelog %changelog
* Wed Mar 05 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.1-alt0.M70P.1 * Tue Mar 26 2019 Vitaly Lipatov <lav@altlinux.ru> 2.5.8-alt0.M70C.1.1
- backport to ALTLinux p7 (by rpmbph script) - backport to ALTLinux c7.1 (by rpmbph script)
* Tue Mar 26 2019 Vitaly Lipatov <lav@altlinux.ru> 2.5.8-alt1
- add trueconf-client repack config
- epm: set timeout for 2 secs
- fix broken pkg_filenames
* Mon Feb 25 2019 Vitaly Lipatov <lav@altlinux.ru> 2.5.7-alt1
- epm downgrade: add --auto support
- add CONFIGDIR support
- add repack scripts for chromium-gost and google-chrome
- fix comments
* Tue Feb 05 2019 Vitaly Lipatov <lav@altlinux.ru> 2.5.6-alt1
- check: improve remove dupls: remove identical packages, add common removing
* Fri Jan 25 2019 Vitaly Lipatov <lav@altlinux.ru> 2.5.5-alt1
- check: add fix duplicates
- epm: keep sssd-ad during upgrade
* Thu Nov 29 2018 Vitaly Lipatov <lav@altlinux.ru> 2.5.4-alt1
- add Amzn (Amazon Linux AMI) support
- rename README to README.md
- fix openSUSE Leap support
- epm-release_upgrade: force install make-initrd if exists when upgrade to Sisyphus
* Sat Oct 06 2018 Vitaly Lipatov <lav@altlinux.ru> 2.5.3-alt1
- distr_info -b: add 64 bit for aarch64
- epm-print: fix release output, add version-release support
- add yandex-browser-beta.sh
- add --short support for what-depends
* Tue Jul 24 2018 Vitaly Lipatov <lav@altlinux.ru> 2.5.2-alt1
- distr_info: add OpenWrt detection
- distr_info: drop obsoleted systems
- fix inputistty (implement via test -t)
- distr_info: use awk instead tr (broken in busybox on OpenWrt), cleanup code
* Tue Jul 17 2018 Vitaly Lipatov <lav@altlinux.ru> 2.5.1-alt1
- distr_info: small fixes
- epm-query: fix __print_suffix (skip for empty arg)
* Wed Jul 04 2018 Vitaly Lipatov <lav@altlinux.ru> 2.5.0-alt1
- epm autoremove: skip manually installed packages on ALT
* 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
- implement assure_distr and use it
- add repack command and move all repack code to a separate module
* Fri Dec 22 2017 Vitaly Lipatov <lav@altlinux.ru> 2.4.4-alt1
- distr_info: check if proc exists before use
- repack: add duplicati support
* Thu Dec 14 2017 Vitaly Lipatov <lav@altlinux.ru> 2.4.3-alt1
- implement __epm_search_internal
- full search output for Slackware only with --verbose
- fix simulate for Slackware
* Tue Dec 12 2017 Vitaly Lipatov <lav@altlinux.ru> 2.4.2-alt1
- epm-install: fix --skip-install with dnf/yum
- dnf/yum: fix install/remove current arch packages (https://bugzilla.redhat.com/show_bug.cgi?id=1525164)
* Tue Dec 12 2017 Vitaly Lipatov <lav@altlinux.ru> 2.4.1-alt1
- add teamviewer.sh for repack (ALT bug 34318)
* Sun Dec 10 2017 Vitaly Lipatov <lav@altlinux.ru> 2.4.0-alt1
- epm: add /etc/eepm/eepm.conf support
- epm install: add --repack support (binary rpm repacking before install)
- add --scripts support to repack foreign packages with alien
- epm-install: add /etc/eepm/repack.d/PKGNAME.sh support during repacking
- add mssql-server, skypeforlinux rules
- revert "epm whatdepends: use rdepends": miss many dependencies
* Sat Dec 09 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.6-alt1
- drop arch suffix adding (we can't distinct between arch/noarch)
- improve --skip-installed on x86_64 Fedora based: check for noarch too
* Thu Dec 07 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.5-alt1
- serv-status: mask stderr in is_service_running
- epm-query: fix list package by package
- serv list-all: cleanup output
- serv list: improve speed with run sudo once
- serv status: improve running state detection
- query: replace (x86-32) with .i686 for rpm/dnf
* Wed Dec 06 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.4-alt1
- apply prefix only if there are no other prefix
* Tue Dec 05 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.3-alt1
- add repo alias for repolist
- epm-install: add options support during cross install
- distr_info: distinct between x86 and x86_64 for -a
- epm install: expand package names with arch before isinstalled checking (eterbug #12332)
* Fri Dec 01 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.2-alt1
- fix --auto remove for dnf
- release_upgrade: do not update rpm apt when downgraded from Sisyphus
- release_upgrade: fix downgrade to p8
- release_upgrade: ask confirm before upgrade
- epm: add --non-interactive alias for --auto
* Sun Nov 19 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.1-alt1
- epm whatdepends: use rdepends
- repofix: fix signing when we have /
- query_file: only inform about epm sf using
- allow ei/ik install any package(s) from Korinf
- ei/ik: add support for --list [mask], install via eget
* Sun Nov 12 2017 Vitaly Lipatov <lav@altlinux.ru> 2.3.0-alt2
- epm: rewrite release_upgrade for ALT
- autoremove: small improvement
- remove: add support dry mode for rpm/apt
* Sat Nov 11 2017 Vitaly Lipatov <lav@altlinux.ru> 2.2.0-alt1
- use external eget on ALT
- disable one file version packing
- update internal eget to 2.0
* Fri Nov 10 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.10-alt1
- install: print low level install command if args is empty
- epm: add wd alias for whatdepends
- epm-clean: add --noconfirm for pacman
- fix and text install via url with wildcard
* Wed Nov 08 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.9-alt1
- tasknumber: fix bashism
* Thu Nov 02 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.8-alt1
- epm addrepo: use http for ALT archive, add date format checking
- ep-seach: use ~ for negate and ^ for a begin of line in __epm_search_make_grep
* Mon Oct 23 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.7-alt1
- improve addrepo (add archive DATE support) and removerepo (archive, tasks)
* Sun Oct 22 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.6-alt1
- add support for ALT girar task number to install/remove, improve addrepo/removerepo
- distr_info: add support for get info about arch, bus size, memory size, base os name
- add warmup bases support and use it
* Wed Oct 18 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.5-alt1
- distr_info: add firstupper function, implement full /etc/os-release checking
- add --dry-run support to remove, autoorphans, autoremove
- autoremove: add support for autoremove [libs|python|perl|libs-devel]
* Mon Oct 16 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.4-alt1
- add skip # in task number
- add support for just task number in removerepo
- repofix: add sign for Etersoft Sisyphus
* Thu Sep 14 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.3-alt1
- use force package selection only in non interactive install
- kernel_update: add update repo if needed
- install/upgrade: add debug output for apt when --verbose
* Fri Aug 04 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.2-alt1
- apt install: add force package selection (see ALT bug #22572)
* Mon Jul 31 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.1-alt1
- distr_info: fix tr using
- install --show-command-only supports hi level names now
* Sat Jul 22 2017 Vitaly Lipatov <lav@altlinux.ru> 2.1.0-alt1
- fix quotes (eterbug #11863)
- make shellcheck happy
- check_code.sh: skip global vars
* Fri Jul 21 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.9-alt1
- epm-filelist: add support with yum and dnf
- imlrement check for dnf via dnf check
- add support for ALT Linux t7
* Thu Jun 15 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.8-alt1
- make shellcheck more happy
- improve epm query
- epm-search-file: force overwrite list file
- epm-info: add support for local rpm and deb files
* Wed Apr 05 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.7-alt1
- serv-status: use -l for systemd status
- emp-query: improve for pacman
- epm-query: fix is_installed
* Mon Mar 13 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.6-alt1
- epm-packages: improve sort output
- hack to support old lz4
* Fri Mar 10 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.5-alt1
- epm sf: make compressed cache for local file too
- rewrite epm sf, colorify it
- more correct message when empty run
* Thu Mar 09 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.4-alt1
- epm-policy: move to hilevel package name
- implement local cache for contents index for ALT repos
* Tue Mar 07 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.3-alt1
- fix query hilevel name for yum/dnf
- epm install: fix install rpm on deb
- add missed in some cases AstraLinux and GosLinux
* Thu Mar 02 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.2-alt1
- distr_info: fix version detection for all ALT p8 distros
- add workaround for ALT rpm missed https support
- install librpm7 during upgrade to Sisyphus
- improve systemd checking
* Tue Feb 07 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.1-alt1
- autoremove: skip -32bit suffix
* Mon Jan 16 2017 Vitaly Lipatov <lav@altlinux.ru> 2.0.0-alt1
- distr_info: fix get lsb-release file with quoted fields
- epm-download: add filename empty checking
- epm info: add URL support
- epm upgrade: allow extra args
- release_upgrade: improve for Fedora
- epm-download: add support for urpm
- check_update_repo: check for /var/lib/apt/lists date
- query_file: improve check for relative path
- epm-automove: fix i586-lib issue
- fix systemd detection
- epm: add/remove autoimports
* Wed Dec 07 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.9-alt1
- add own realpath implementation if missed
- add openSUSE Tumbleweed support
- autoremove: do separate removing cycles for python/perl and libs
- epm-site: fix json parsing
- epm-download: realize download via info from packages.altlinux.org
- epm-install: add direct install (not via apt) support for ALT Linux
- addrepo: implement support for epm addrepo etersoft
* Thu Dec 01 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.8-alt1
- epm-install: move download code to epm-download
- epm-checkpkg: add support for checking package by url
- downgrade: use distro-sync for downgrade with yum/dnf
- autoorphans/autoremove: fix uses package-cleanup with yum/dnf
- epmqf: use realpath for exists files by default
- improve systemd detection
* Tue Nov 15 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.7-alt1
- fix build install
- small fixes
* Sun Oct 02 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.6-alt1
- epm: improve message about incorrect command
- workaround for sudo -h prints first line in stderr
- example support for service SERVICE log command
* Fri Sep 23 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.5-alt1
- fix systemd detection
- initial log command support
- fix anyservice list (need anyservice 0.5 or above)
* Fri Sep 23 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.4-alt1
- distr_info: fix checking on MacOS
- brew fixes
- autoremove: enable deep remove by default
- small fixes
* Wed Aug 24 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.3-alt1
- implement cross install for rpm and deb packages
- serv: add runit support (Void Linux)
- serv-reload: add fallback via restart
- serv-try_restart: add fallback via restart
- small fixes
* Tue Aug 23 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.2-alt1
- add Void Linux initial support
- addrepo/removerepo: fix used repo id string
- release-upgrade: fix direct apt-repo
- epm install: disable optimize when install foreign packages
- serv: more verbose
- rewrite query and packages
* Thu Aug 18 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.1-alt1
- upgrade: add --auto support for apt and yum/dnf
- serv: add reload command support
- improve eget to support -O file
- epm-install: add real support install by url
- epm_install: rewrite, use direct install via epm_install
- epm_install: rewrite with pkg_urls support using
* Wed Aug 17 2016 Vitaly Lipatov <lav@altlinux.ru> 1.9.0-alt1
- improve urpmi support
- serv: check anyservice support against anyservice version 0.3
- autoremove: ignore libvirt
* Mon Aug 15 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.8-alt1
- epm-install: skip low-level when install by path
- anyservice support fixes
- serv: some anyssh fixes
* Sun Aug 14 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.7-alt1
- realize autoorphans/autoremove for zypper >= 1.9.2 in SUSE
- introduce epm remove-old-kernels command
- epm clean: clean local repo cache only with --force
- serv: add anyservice support
- small fixes
* Tue Jul 19 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.6-alt1
- epm-sh-functions: fix sudo -- detection
- distr_info: add AstraLinux support
- epm-sh: add AstraLinux and Elbrus support
- add epmrl alias for epm rl
- epm-autoremove: add nvidia-clean-driver
- epm-autoremove: use ALTLinux case instead apt-rpm
* Sat Jun 25 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.5-alt1
- add Tiny Core Linux support (tcl, tce)
- improve dnf support: add release-upgrade
- improve ALT Linux release upgrade
* Mon May 30 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.4-alt1
- epm install: add initial support for cross install packages (deb/rpm packages on rpm/deb-based hosts)
- install: add --noremove support for apt
- repofix: add check for vendor key if set it
- add check if sudo supports --
- repofix: skip useless Sisyphus replacements
- release_upgrade: skip confirm if there are no changes
- epm-query: add semihack for check removed packages
- epm: add support for run script from stdin
* Mon May 23 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.3-alt1
- autoorphans: do real removing
- autoremove: add update-kernel version 0.9.9 checking
- autoorphans/autoremove: improve excludes
* Fri May 20 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.2-alt1
- epm_install: added command for install or update eepm package from all in one script
- add --no-remove support during upgrade
- epm-download: add yumdownloader support
- epm-autoorphans: realize print list
- epm-autoremove: realize with apt-cache list-nodeps from apt-scripts
- epm-assure: fix for existing path checking
- distr_info: drop subversion from Debian distro version
* Thu Apr 28 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.1-alt1
- release-upgrade: install altlinux-release-p? only if /etc/altlinux-release belongs to sisyphus
* Wed Apr 27 2016 Vitaly Lipatov <lav@altlinux.ru> 1.8.0-alt1
- commit packed files
- repofix: replace Etersoft branches only if have Etersoft key
- release_upgrade: install update-manager-core package for deb-based
* Sun Apr 24 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.6-alt1
- fix assure_exists
- epm-assure: improve version checking
* Sun Apr 24 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.5-alt1
- epm-print: add compare version command
- repofix: fix Sisyphus replace
- release_upgrade: do packages downgrade after changes to p8 from Sisyphus
- epm-assure: rewrite to realize correct version comparing
- kernel_update: run remove-old-kernels too
* Sat Apr 23 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.4-alt1
- release-upgrade: small logic improvements
* Sat Apr 23 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.3-alt1
- epm release-upgrade: check for glibc-core-2.17
- release-upgrade: add detect current system by apt repo
- release-upgrade: rewrite to support p8 -> Sisyphus and vice versa
* Wed Apr 20 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.2-alt1
- distr_info: fix os-release detection
* Wed Apr 20 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.1-alt1
- epm: added alpine apk package manager install, update, remove, qa, search commands
- fix Simply Linux 6.0 detection
- kernel_update: do not install kernel if it is not installed (for ovz containers)
* Tue Apr 19 2016 Vitaly Lipatov <lav@altlinux.ru> 1.7.0-alt1
- epm release-upgrade with ALT Linux p8 support
- epm-reinstall: add names filtering (to support epmqp some | epm reinstall)
- release-upgrade: print some info
* Tue Apr 19 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.9-alt1
- check if systemd is active
- release_upgrade: fix version
* Mon Apr 18 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.8-alt1
- small output fix
- rewrite release-upgrade
* Fri Apr 15 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.7-alt1
- release_upgrade: fix sign replacement
- fix epm_update
- set p8 sign and install apt-conf-branch
- repofix: add signs for ALT Linux or Etersoft branches
* Fri Apr 15 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.6-alt1
- release_upgrade: improve upgrade way
- epm: update copyright date
* Fri Apr 15 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.5-alt1
- restrict sudo args
- small fixes
* Fri Apr 15 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.4-alt1
- epm-repofix: use sed -r instead perl -pi
- pack_in_onefile: fix run positional load_helper
- initial support for upgrade ALT Linux release to p7 / p8
- fix repofix code
* Tue Apr 05 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.3-alt1
- epm-checksystem: add assure_exists time
- check_updated_repo fix epm update
* Thu Mar 17 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.2-alt2
- add check_reqs script and cleanup all reqs
* Thu Mar 17 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.2-alt1
- epm: print error for extra unallowed args
- drop time requires
* Fri Feb 26 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.1-alt1
- distr_info: add Simply Linux detection
- epm: use yum-config-manager for managing repo in yum based distros
- fix downgrade for LINUX@Etersoft, Debian, Ubuntu, add support for downgrade one or a few packages
- epm search: optimize grep when search for one word, apply short option before all, disable localized description
- epm-site: use https for packages.altlinux.org
- add serv print command
- serv: fix systemd detection
* Wed Jan 27 2016 Vitaly Lipatov <lav@altlinux.ru> 1.6.0-alt1
- release long term support version 1.6
- epm-print: add print specname
- rewrite eget
* Wed Dec 16 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.25-alt1
- epm-checksystem: fix working in packed
- fix packed version
- improve dnf support
- small fixes
* Tue Dec 01 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.24-alt1
- add support apt-cyg on Cygwin
- drop pks-db requires
- epm-check_updated_rep: do not check on deb systems
- epm-query: fix print package version for other systems
* Sun Nov 22 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.23-alt1
- epm install: disable update if try install local package files
- epm clean: remove partial files
- real check if package(s) is installed
- small improve print name
* Sun Oct 25 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.22-alt1
- distr_info: fix ALT Linux version detection
- epm: fix print help command
- fix epm repofix
- improve epm-filelist
- use short names when possible
* Tue Oct 13 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.21-alt1
- introduce epm print for print out package names and fields
- epm-site: use functions from epm-print
- epm-remove: do short package name from deb
* Mon Oct 12 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.20-alt1
- distr_info: add mcst support
- skip update checking for non root users have no nopassword sudo
- epm_checksystem: add initial file for check system health
* Wed Aug 26 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.19-alt1
- epm-clean: add deb-based support
- check_updated_repo: use $SUDO for check if updated
- epm-site: get url for noninstalled packages from packages.altlinux.org on ALT Linux
* Tue Aug 25 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.18-alt1
- epm: add policy (like apt-cache policy) command
- initial repofix code, need fix regexp and test
- epm-filelist: realize low level file list for rpm in the same code
- fix checking update files
- epm clean: clean all cached files on ALT
* Wed Aug 19 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.17-alt1
- fix update repo checking
- print Uwaga about eatmydata only if verbose mode
- changelog: use query rpm mode for --changelog
* Sun Aug 16 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.16-alt1
- run update if repo info older than 1 day
- epm-query_file: fix read link
- add epm url|site command (with -p arg for open at packages.altlinux.org)
* Wed Aug 12 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.15-alt1
- epm-assure: fix for dir checking support
- epm query file: fix recursion result and more quoting
* Fri Jul 24 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.14-alt1
- simulate: allow Exiting on user Command in any place of the line
* Tue Jul 21 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.13-alt1
- epm-assure: add support for checking any path on a file system
- small fixes
* Fri Jul 10 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.12-alt1
- epm: initial download package support
- fix update and simulate for dnf
- allow changelog and query file for dnf
- install: allow return command for dnf
- use dnf only if /var/lib/dnf/yumdb is exists
* Thu Jul 09 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.11-alt1
- epm-filelist: add support file list for noninstalled packages on deb
- introduce autoorphans command
- epm-install: add workaround to fix urls works
- fix behaviour when has dir with the same name like package
- serv: implement native restart
- use dnf on Fedora if exists
* Wed Feb 25 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.10-alt1
- serv-status: realize detection scheduled status for Ubuntu
- epm-sh: fix withtimeout
* Sat Feb 21 2015 Vitaly Lipatov <lav@altlinux.ru> 1.5.9-alt1
- fix withtimeout (was incorrect workaround)
- remove epm-eget -> tools-eget for exclude from one pack file
- add epmI == epm Install
- serv-enable: use chkconfig --add and chkconfig SERVICE on
- query_file: fix for dirs
* Wed Dec 24 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.8-alt1
- add initial snappy support
- remove extra deps
* Fri Dec 05 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.7-alt1
- checkpkg: add msi checking
- epm-packages: fix --sort
- serv-enable: assure chkconfig add
- autoremove: do not remove libnss-*, *debuginfo
- fatal exit if assure_exists is failed
- epm: fix search file in ALT Linux repo
- epm: add 'epm s' like epms
- initial eget commit
* Thu Jul 17 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.6-alt1
- assure we have a command rpm/dpkg when work with a package file
- fix for use package name list in quotes
- fix build without rpm-build-altlinux-compat
* Sat Jun 07 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.5-alt1
- fix epmqp, epm clean for FreeBSD
- epm programs: use /usr/local/share/applications on BSD systems
- epm reinstall: add pkgng support
- fix timeout using on FreeBSD
* Wed Jun 04 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.4-alt1
- add initial support for FreeBSD's pkgng
- add audit command for check installed packages against known vulnerabilities
* Wed May 28 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.3-alt1
- prefer to use init script directly
- introduce downgrade command
- use correct datadir
* Tue Mar 25 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.2-alt1
- use repolist for get local repo path
- support --auto for reinstall
- epm-requires: fix typo
* Wed Mar 05 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.1-alt1 * Wed Mar 05 2014 Vitaly Lipatov <lav@altlinux.ru> 1.5.1-alt1
- epm: check real file detection - epm: check real file detection
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
# #
# Run for create one-file-scripts # Run for create one-file-scripts
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016, 2017 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016, 2017 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
...@@ -20,17 +20,21 @@ ...@@ -20,17 +20,21 @@
# #
incorporate_distr_info() incorporate_subfile()
{ {
cat <<EOF >>$OUTPUT cat <<EOF >>$OUTPUT
internal_distr_info()
################# incorporate $1 #################
internal_$(basename $1)()
{ {
EOF EOF
cat bin/distr_info >>$OUTPUT cat $1 | grep -v "^#!/bin/sh" | sed -e "s| exit$| return|g" >>$OUTPUT
cat <<EOF >>$OUTPUT cat <<EOF >>$OUTPUT
} }
################# end of incorporated $1 #################
EOF EOF
} }
...@@ -41,7 +45,13 @@ get_version() ...@@ -41,7 +45,13 @@ get_version()
filter_out() filter_out()
{ {
grep -v "^load_helper " | sed -e 's|DISTRVENDOR=$PROGDIR/distr_info|DISTRVENDOR=internal_distr_info|g' | \ grep -v "^[ ]*load_helper " | \
sed -e 's|^eget()|disabled_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|DISTRVENDOR=$PROGDIR/distr_info|DISTRVENDOR=internal_distr_info|g' | \
sed -e "s|@VERSION@|$(get_version)|g" sed -e "s|@VERSION@|$(get_version)|g"
} }
...@@ -59,7 +69,11 @@ for i in bin/epm-sh-functions $(ls -1 bin/$PACKCOMMAND-* | grep -v epm-sh-functi ...@@ -59,7 +69,11 @@ for i in bin/epm-sh-functions $(ls -1 bin/$PACKCOMMAND-* | grep -v epm-sh-functi
cat $i | grep -v "^#" cat $i | grep -v "^#"
done | filter_out >>$OUTPUT done | filter_out >>$OUTPUT
incorporate_distr_info incorporate_subfile bin/distr_info
#incorporate_subfile /usr/bin/eget
incorporate_subfile bin/tools_eget
incorporate_subfile bin/tools_estrlist
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
chmod 0755 $OUTPUT chmod 0755 $OUTPUT
......
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012-2013 Etersoft # Copyright (C) 2012-2013, 2016 Etersoft
# Copyright (C) 2012-2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012-2013, 2016 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
...@@ -37,7 +37,8 @@ load_helper() ...@@ -37,7 +37,8 @@ load_helper()
inputisatty() inputisatty()
{ {
# check stdin # check stdin
tty -s 2>/dev/null #tty -s 2>/dev/null
test -t 0
} }
isatty() isatty()
...@@ -62,8 +63,8 @@ check_tty() ...@@ -62,8 +63,8 @@ check_tty()
# egrep from busybox may not --color # egrep from busybox may not --color
# egrep from MacOS print help to stderr # egrep from MacOS print help to stderr
if egrep --help 2>&1 | grep -q -- "--color" ; then if grep -E --help 2>&1 | grep -q -- "--color" ; then
EGREPCOLOR="--color" export EGREPCOLOR="--color"
fi fi
which tput >/dev/null 2>/dev/null || return which tput >/dev/null 2>/dev/null || return
...@@ -102,37 +103,32 @@ echover() ...@@ -102,37 +103,32 @@ echover()
echon() echon()
{ {
# default /bin/sh on MacOS does not recognize -n # default /bin/sh on MacOS does not recognize -n
/bin/echo -n "$@" /bin/echo -n "$*"
} }
set_target_pkg_env() set_target_pkg_env()
{ {
[ -n "$DISTRNAME" ] || fatal "Run set_target_pkg_env without DISTRNAME" [ -n "$DISTRNAME" ] || fatal "Missing DISTRNAME in set_target_pkg_env."
PKGFORMAT=$($DISTRVENDOR -p "$DISTRNAME") PKGFORMAT=$($DISTRVENDOR -p "$DISTRNAME")
PKGVENDOR=$($DISTRVENDOR -s "$DISTRNAME") PKGVENDOR=$($DISTRVENDOR -s "$DISTRNAME")
RPMVENDOR=$($DISTRVENDOR -n "$DISTRNAME") RPMVENDOR=$($DISTRVENDOR -n "$DISTRNAME")
} }
realpath()
{
readlink -f "$@"
}
showcmd() showcmd()
{ {
if [ -z "$quiet" ] ; then if [ -z "$quiet" ] ; then
set_boldcolor $GREEN set_boldcolor $GREEN
local PROMTSIG="\$" local PROMTSIG="\$"
[ "$EFFUID" = 0 ] && PROMTSIG="#" [ "$EFFUID" = 0 ] && PROMTSIG="#"
echo " $PROMTSIG $@" echo " $PROMTSIG $*"
restore_color restore_color
fi >&2 fi >&2
} }
docmd() docmd()
{ {
showcmd "$@$EXTRA_SHOWDOCMD" showcmd "$*$EXTRA_SHOWDOCMD"
$@ $@
} }
...@@ -149,7 +145,7 @@ docmd_foreach() ...@@ -149,7 +145,7 @@ docmd_foreach()
sudocmd() sudocmd()
{ {
showcmd "$SUDO $@" [ -n "$SUDO" ] && showcmd "$SUDO $*" || showcmd "$*"
$SUDO $@ $SUDO $@
} }
...@@ -160,10 +156,17 @@ sudocmd_foreach() ...@@ -160,10 +156,17 @@ sudocmd_foreach()
#showcmd "$@" #showcmd "$@"
shift shift
for pkg in "$@" ; do for pkg in "$@" ; do
sudocmd "$cmd" $pkg sudocmd "$cmd" $pkg || return
done done
} }
if ! which realpath 2>/dev/null >/dev/null ; then
realpath()
{
readlink -f "$@"
}
fi
get_firstarg() get_firstarg()
{ {
echon "$1" echon "$1"
...@@ -172,10 +175,14 @@ get_firstarg() ...@@ -172,10 +175,14 @@ get_firstarg()
get_lastarg() get_lastarg()
{ {
local lastarg local lastarg
eval lastarg=\${$#} eval "lastarg=\${$#}"
echon "$lastarg" echon "$lastarg"
} }
isnumber()
{
echo "$*" | filter_strip_spaces | grep -q "^[0-9]\+$"
}
filter_strip_spaces() filter_strip_spaces()
{ {
...@@ -203,12 +210,18 @@ store_output() ...@@ -203,12 +210,18 @@ store_output()
echo 1 >$CMDSTATUS echo 1 >$CMDSTATUS
#RC_STDERR=$(mktemp) #RC_STDERR=$(mktemp)
( $@ 2>&1 ; echo $? >$CMDSTATUS ) | tee $RC_STDOUT ( $@ 2>&1 ; echo $? >$CMDSTATUS ) | tee $RC_STDOUT
return $(cat $CMDSTATUS) return "$(cat $CMDSTATUS)"
# bashism # bashism
# http://tldp.org/LDP/abs/html/bashver3.html#PIPEFAILREF # http://tldp.org/LDP/abs/html/bashver3.html#PIPEFAILREF
#return $PIPESTATUS #return $PIPESTATUS
} }
showcmd_store_output()
{
showcmd "$@"
store_output "$@"
}
clean_store_output() clean_store_output()
{ {
rm -f $RC_STDOUT $RC_STDOUT.pipestatus rm -f $RC_STDOUT $RC_STDOUT.pipestatus
...@@ -216,13 +229,14 @@ clean_store_output() ...@@ -216,13 +229,14 @@ clean_store_output()
epm() epm()
{ {
$PROGDIR/epm $@ [ -n "$PROGNAME" ] || fatal "Can't use epm call from the piped script"
$PROGDIR/$PROGNAME $@
} }
fatal() fatal()
{ {
if [ -z "$TEXTDOMAIN" ] ; then if [ -z "$TEXTDOMAIN" ] ; then
echo "Error: $@" >&2 echo "Error: $*" >&2
fi fi
exit 1 exit 1
} }
...@@ -230,7 +244,20 @@ fatal() ...@@ -230,7 +244,20 @@ fatal()
warning() warning()
{ {
if [ -z "$TEXTDOMAIN" ] ; then if [ -z "$TEXTDOMAIN" ] ; then
echo "Warning: $@" >&2 echo "Warning: $*" >&2
fi
}
info()
{
[ -n "$quiet" ] && return
# print message to stderr if stderr forwarded to (a file)
if isatty2 ; then
isatty || return 0
echo "$*"
else
echo "$*" >&2
fi fi
} }
...@@ -239,52 +266,131 @@ set_sudo() ...@@ -239,52 +266,131 @@ set_sudo()
SUDO="" SUDO=""
# skip SUDO if disabled # skip SUDO if disabled
[ -n "$EPMNOSUDO" ] && return [ -n "$EPMNOSUDO" ] && return
if [ "$DISTRNAME" = "Cygwin" ] || [ "$DISTRNAME" = "Windows" ] ; then
# skip sudo using on Windows
return
fi
EFFUID=`id -u` EFFUID=$(id -u)
# do not need sudo # do not need sudo
[ $EFFUID = "0" ] && return [ $EFFUID = "0" ] && return
# use sudo if possible # use sudo if possible
which sudo >/dev/null 2>/dev/null && SUDO="sudo" && return if which sudo >/dev/null 2>/dev/null ; then
SUDO="sudo --"
# check for < 1.7 version which do not support -- (and --help possible too)
sudo -h 2>/dev/null | grep -q " --" || SUDO="sudo"
return
fi
SUDO="fatal 'Can't find sudo. Please install sudo or run epm under root.'" SUDO="fatal 'Can't find sudo. Please install sudo or run epm under root.'"
} }
withtimeout()
{
local TO=$(which timeout 2>/dev/null || which gtimeout 2>/dev/null)
if [ -x "$TO" ] ; then
$TO "$@"
return
fi
# fallback: drop time arg and run without timeout
shift
"$@"
}
set_eatmydata() set_eatmydata()
{ {
# skip if disabled # skip if disabled
[ -n "$EPMNOEATMYDATA" ] && return [ -n "$EPMNOEATMYDATA" ] && return
# use if possible # use if possible
which eatmydata >/dev/null 2>/dev/null || return which eatmydata >/dev/null 2>/dev/null || return
SUDO="$SUDO eatmydata" [ -n "$SUDO" ] && SUDO="$SUDO eatmydata" || SUDO="eatmydata"
isatty && echo "Uwaga! eatmydata is installed, we will use it for disable all sync operations." >&2 [ -n "$verbose" ] && info "Uwaga! eatmydata is installed, we will use it for disable all sync operations."
return 0 return 0
} }
assure_exists() __get_package_for_command()
{ {
PATH=$PATH:/sbin:/usr/sbin which $1 2>/dev/null >/dev/null && return case "$1" in
echo "Install appropriate package for $1 command..."
case $1 in
equery|revdep-rebuild) equery|revdep-rebuild)
epm install gentoolkit echo 'gentoolkit'
;;
apt-repo)
epm install apt-repo
;;
apt-file)
epm install apt-file
;; ;;
update-kernel|remove-old-kernels) update-kernel|remove-old-kernels)
epm install update-kernel echo 'update-kernel'
;;
esac
}
confirm() {
local response
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;; ;;
*) *)
fatal "Internal error: Unknown binary $1 to check if exists" false
;; ;;
esac esac
} }
assure_root()
{
[ "$EFFUID" = 0 ] || fatal "run me only under root"
}
regexp_subst()
{
local expression="$1"
shift
sed -i -r -e "$expression" "$@"
}
assure_exists()
{
local package="$2"
local textpackage=
[ -n "$package" ] || package="$(__get_package_for_command "$1")"
[ -n "$3" ] && textpackage=" >= $3"
__epm_assure "$1" $package $3 || fatal "Can't assure in '$1' command from $package$textpackage package"
}
disabled_eget()
{
# use internal eget only if exists
if [ -s $SHAREDIR/tools_eget ] ; then
$SHAREDIR/tools_eget "$@"
return
fi
assure_exists eget
# run external command, not the function
EGET=$(which eget) || fatal "Missed command eget from installed package eget"
$EGET "$@"
}
disabled_estrlist()
{
if [ -s $SHAREDIR/tools_estrlist ] ; then
$SHAREDIR/tools_estrlist "$@"
return
fi
fatal "missed tools_estrlist"
}
estrlist()
{
internal_tools_estrlist "$@"
}
eget()
{
assure_exists wget
internal_tools_eget "$@"
}
get_package_type() get_package_type()
{ {
local i local i
...@@ -297,6 +403,22 @@ get_package_type() ...@@ -297,6 +403,22 @@ get_package_type()
echo "rpm" echo "rpm"
return return
;; ;;
*.txz)
echo "txz"
return
;;
*.tbz)
echo "tbz"
return
;;
*.exe)
echo "exe"
return
;;
*.msi)
echo "msi"
return
;;
*) *)
#fatal "Don't know type of $1" #fatal "Don't know type of $1"
# return package name for info # return package name for info
...@@ -309,7 +431,11 @@ get_package_type() ...@@ -309,7 +431,11 @@ get_package_type()
get_help() get_help()
{ {
grep -v -- "^#" $0 | grep -- "# $1" | while read n ; do if [ "$0" = "/dev/stdin" ] || [ "$0" = "sh" ] ; then
return
fi
grep -v -- "^#" $0 | grep -- "# $1" | while read -r n ; do
opt=$(echo $n | sed -e "s|) # $1:.*||g") opt=$(echo $n | sed -e "s|) # $1:.*||g")
desc=$(echo $n | sed -e "s|.*) # $1:||g") desc=$(echo $n | sed -e "s|.*) # $1:||g")
printf " %-20s %s\n" $opt "$desc" printf " %-20s %s\n" $opt "$desc"
...@@ -340,15 +466,17 @@ case $DISTRNAME in ...@@ -340,15 +466,17 @@ case $DISTRNAME in
PCLinux) PCLinux)
CMD="apt-rpm" CMD="apt-rpm"
;; ;;
Ubuntu|Debian|Mint) Ubuntu|Debian|Mint|AstraLinux|Elbrus)
CMD="apt-dpkg" CMD="apt-dpkg"
#which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg #which aptitude 2>/dev/null >/dev/null && CMD=aptitude-dpkg
which snappy 2>/dev/null >/dev/null && CMD=snappy
;; ;;
Mandriva|ROSA) Mandriva|ROSA)
CMD="urpm-rpm" CMD="urpm-rpm"
;; ;;
FreeBSD|NetBSD|OpenBSD|Solaris) FreeBSD|NetBSD|OpenBSD|Solaris)
CMD="pkgsrc" CMD="pkgsrc"
which pkg 2>/dev/null >/dev/null && CMD=pkgng
;; ;;
Gentoo) Gentoo)
CMD="emerge" CMD="emerge"
...@@ -356,9 +484,9 @@ case $DISTRNAME in ...@@ -356,9 +484,9 @@ case $DISTRNAME in
ArchLinux) ArchLinux)
CMD="pacman" CMD="pacman"
;; ;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific) Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific|GosLinux|Amzn)
CMD="yum-rpm" CMD="yum-rpm"
#which dnf 2>/dev/null >/dev/null && CMD=dnf-rpm which dnf 2>/dev/null >/dev/null && test -d /var/lib/dnf/yumdb && CMD=dnf-rpm
;; ;;
Slackware) Slackware)
CMD="slackpkg" CMD="slackpkg"
...@@ -375,8 +503,8 @@ case $DISTRNAME in ...@@ -375,8 +503,8 @@ case $DISTRNAME in
MacOS) MacOS)
CMD="homebrew" CMD="homebrew"
;; ;;
OpenWRT) OpenWrt)
CMD="ipkg" CMD="opkg"
;; ;;
GNU/Linux/Guix) GNU/Linux/Guix)
CMD="guix" CMD="guix"
...@@ -384,6 +512,18 @@ case $DISTRNAME in ...@@ -384,6 +512,18 @@ case $DISTRNAME in
Android) Android)
CMD="android" CMD="android"
;; ;;
Cygwin)
CMD="aptcyg"
;;
alpine)
CMD="apk"
;;
TinyCoreLinux)
CMD="tce"
;;
VoidLinux)
CMD="xbps"
;;
*) *)
fatal "Have no suitable DISTRNAME $DISTRNAME" fatal "Have no suitable DISTRNAME $DISTRNAME"
;; ;;
...@@ -392,6 +532,27 @@ PMTYPE=$CMD ...@@ -392,6 +532,27 @@ PMTYPE=$CMD
} }
is_active_systemd()
{
local a
SYSTEMCTL=/bin/systemctl
SYSTEMD_CGROUP_DIR=/sys/fs/cgroup/systemd
[ -x "$SYSTEMCTL" ] || return
[ -d "$SYSTEMD_CGROUP_DIR" ] || return
a='' mountpoint -q "$SYSTEMD_CGROUP_DIR" || return
readlink /sbin/init | grep -q 'systemd' || return
# some hack
# shellcheck disable=SC2009
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()
...@@ -400,19 +561,29 @@ serv_common() ...@@ -400,19 +561,29 @@ serv_common()
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
fatal "Have no idea how to call anyservice service with args"
fi
sudocmd service $SERVICE "$@" sudocmd service $SERVICE "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd /etc/init.d/$SERVICE "$@" sudocmd $INITDIR/$SERVICE "$@"
;; ;;
systemd) systemd)
# run init script directly (for nonstandart commands)
if [ -x $INITDIR/$SERVICE ] ; then
sudocmd $INITDIR/$SERVICE "$@"
else
sudocmd systemctl "$@" $SERVICE sudocmd systemctl "$@" $SERVICE
fi
;;
runit)
sudocmd sv $SERVICE "$@"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
esac esac
} }
# File bin/serv-disable: # File bin/serv-disable:
...@@ -420,11 +591,17 @@ serv_common() ...@@ -420,11 +591,17 @@ serv_common()
serv_disable() serv_disable()
{ {
local SERVICE="$1"
is_service_running $1 && { serv_stop $1 || return ; } is_service_running $1 && { serv_stop $1 || return ; }
is_service_autostart $1 || { echo "Service $1 already disabled for startup" && return ; } is_service_autostart $1 || { info "Service $1 already disabled for startup" && return ; }
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE off
return
fi
sudocmd chkconfig $1 off sudocmd chkconfig $1 off
;; ;;
service-initd|service-update) service-initd|service-update)
...@@ -433,6 +610,9 @@ serv_disable() ...@@ -433,6 +610,9 @@ serv_disable()
systemd) systemd)
sudocmd systemctl disable $1 sudocmd systemctl disable $1
;; ;;
runit)
sudocmd rm -fv /var/service/$SERVICE
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
...@@ -442,13 +622,23 @@ serv_disable() ...@@ -442,13 +622,23 @@ serv_disable()
# File bin/serv-enable: # File bin/serv-enable:
serv_enable() __serv_enable()
{ {
is_service_running $1 || serv_start $1 || return local SERVICE="$1"
is_service_autostart $1 && echo "Service $1 already enabled for startup" && return
is_service_autostart $1 && info "Service $1 is already enabled for startup" && return
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE on
return
fi
sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on
;;
service-upstart)
sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
service-initd|service-update) service-initd|service-update)
...@@ -457,6 +647,11 @@ serv_enable() ...@@ -457,6 +647,11 @@ serv_enable()
systemd) systemd)
sudocmd systemctl enable $1 sudocmd systemctl enable $1
;; ;;
runit)
epm assure $SERVICE
[ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE"
sudocmd ln -s /etc/sv/$SERVICE /var/service/
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
...@@ -464,10 +659,19 @@ serv_enable() ...@@ -464,10 +659,19 @@ serv_enable()
} }
serv_enable()
{
__serv_enable "$1" || return
# start if need
is_service_running $1 && info "Service $1 is already running" && return
serv_start $1
}
# File bin/serv-list: # File bin/serv-list:
serv_list() serv_list()
{ {
info "Running services:"
case $SERVICETYPE in case $SERVICETYPE in
service-upstart) service-upstart)
sudocmd initctl list sudocmd initctl list
...@@ -479,9 +683,9 @@ serv_list() ...@@ -479,9 +683,9 @@ serv_list()
sudocmd systemctl list-units $@ sudocmd systemctl list-units $@
;; ;;
*) *)
load_helper serv-list_all # hack to improve list speed
load_helper serv-status [ "$UID" = 0 ] || { sudocmd $PROGDIR/serv --quiet list ; return ; }
for i in $(serv_list_all) ; do for i in $(quiet=1 serv_list_all) ; do
is_service_running $i >/dev/null && echo $i is_service_running $i >/dev/null && echo $i
done done
;; ;;
...@@ -495,10 +699,15 @@ serv_list_all() ...@@ -495,10 +699,15 @@ 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
sudocmd anyservice --quiet list
return
fi
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README sudocmd ls $INITDIR/ | grep -v README
;; ;;
systemd) systemd)
sudocmd systemctl list-unit-files $@ sudocmd systemctl list-unit-files $@
...@@ -515,8 +724,6 @@ serv_list_startup() ...@@ -515,8 +724,6 @@ serv_list_startup()
{ {
case $SERVICETYPE in case $SERVICETYPE in
*) *)
load_helper serv-list_all
load_helper serv-status
for i in $(serv_list_all | cut -f 1 -d" " | grep "\.service$") ; do for i in $(serv_list_all | cut -f 1 -d" " | grep "\.service$") ; do
is_service_autostart >/dev/null $i && echo $i is_service_autostart >/dev/null $i && echo $i
done done
...@@ -525,6 +732,117 @@ serv_list_startup() ...@@ -525,6 +732,117 @@ serv_list_startup()
esac esac
} }
# File bin/serv-log:
__serv_log_altlinux()
{
local SERVICE="$1"
case "$SERVICE" in
postfix)
sudocmd tail -f /var/log/mail/all /var/log/mail/errors
;;
cups)
sudocmd tail -f /var/log/cups/access_log /var/log/cups/error_log
;;
fail2ban)
sudocmd tail -f /var/log/$SERVICE.log
;;
*)
fatal "Have no suitable for $SERVICE service"
;;
esac
}
serv_log()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
systemd)
sudocmd journalctl -f -b -u "$SERVICE" "$@"
;;
*)
case $DISTRNAME in
ALTLinux)
__serv_log_altlinux "$SERVICE"
return ;;
*)
fatal "Have no suitable for $DISTRNAME command for $SERVICETYPE"
;;
esac
esac
}
# File bin/serv-print:
serv_print()
{
echo "Detected init system: $SERVICETYPE"
[ -n "$ANYSERVICE" ] && echo "anyservice is detected too"
}
# File bin/serv-reload:
serv_reload()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE reload
return
fi
sudocmd service $SERVICE reload "$@"
;;
service-initd|service-update)
sudocmd $INITDIR/$SERVICE reload "$@"
;;
systemd)
sudocmd systemctl reload $SERVICE "$@"
;;
*)
info "Fallback to restart..."
serv_restart "$SERVICE" "$@"
;;
esac
}
# File bin/serv-restart:
serv_restart()
{
local SERVICE="$1"
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE restart
return
fi
sudocmd service $SERVICE restart "$@"
;;
service-initd|service-update)
sudocmd $INITDIR/$SERVICE restart "$@"
;;
systemd)
sudocmd systemctl restart $SERVICE "$@"
;;
runit)
sudocmd sv restart "$SERVICE"
;;
*)
fatal "Have no suitable command for $SERVICETYPE"
;;
esac
}
# File bin/serv-start: # File bin/serv-start:
serv_start() serv_start()
...@@ -534,14 +852,21 @@ serv_start() ...@@ -534,14 +852,21 @@ serv_start()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE start
return
fi
sudocmd service $SERVICE start "$@" sudocmd service $SERVICE start "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd /etc/init.d/$SERVICE start "$@" sudocmd $INITDIR/$SERVICE start "$@"
;; ;;
systemd) systemd)
sudocmd systemctl start "$SERVICE" "$@" sudocmd systemctl start "$SERVICE" "$@"
;; ;;
runit)
sudocmd sv up "$SERVICE"
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
...@@ -552,15 +877,28 @@ serv_start() ...@@ -552,15 +877,28 @@ serv_start()
is_service_running() is_service_running()
{ {
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)
$SUDO service $1 status >/dev/null if is_anyservice $1 ; then
OUTPUT="$($SUDO anyservice $1 status 2>/dev/null)" || return 1
echo "$OUTPUT" | grep -q "is stopped" && return 1
return 0
fi
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 /etc/init.d/$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)
$SUDO sv status "$SERVICE" >/dev/null 2>/dev/null
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
...@@ -570,16 +908,27 @@ is_service_running() ...@@ -570,16 +908,27 @@ is_service_running()
is_service_autostart() is_service_autostart()
{ {
local SERVICE="$1"
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
LANG=C $SUDO chkconfig $1 --list | grep -q "5:on" if is_anyservice $SERVICE; then
$ANYSERVICE $SERVICE isautostarted
return
fi
# FIXME: check for current runlevel
LANG=C $SUDO chkconfig $1 --list | grep -q "[35]:on"
;; ;;
service-initd|service-update) service-initd|service-update)
fatal "FIXME: don't know how detect current startup state" test -L "$(echo /etc/rc5.d/S??$1)"
;; ;;
systemd) systemd)
$SUDO systemctl is-enabled $1 $SUDO systemctl is-enabled $1
;; ;;
runit)
test -L "/var/service/$SERVICE"
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
...@@ -595,13 +944,20 @@ serv_status() ...@@ -595,13 +944,20 @@ serv_status()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE status
return
fi
sudocmd service $SERVICE status "$@" sudocmd service $SERVICE status "$@"
;; ;;
service-update) service-update)
sudocmd /etc/init.d/$SERVICE status "$@" sudocmd $INITDIR/$SERVICE status "$@"
;; ;;
systemd) systemd)
sudocmd systemctl status $SERVICE "$@" sudocmd systemctl -l status $SERVICE "$@"
;;
runit)
sudocmd sv status "$SERVICE"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
...@@ -618,14 +974,21 @@ serv_stop() ...@@ -618,14 +974,21 @@ serv_stop()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE stop
return
fi
sudocmd service $SERVICE stop "$@" sudocmd service $SERVICE stop "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd /etc/init.d/$SERVICE stop "$@" sudocmd $INITDIR/$SERVICE stop "$@"
;; ;;
systemd) systemd)
sudocmd systemctl stop $SERVICE "$@" sudocmd systemctl stop $SERVICE "$@"
;; ;;
runit)
sudocmd sv down "$SERVICE"
;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" fatal "Have no suitable command for $SERVICETYPE"
;; ;;
...@@ -641,19 +1004,13 @@ serv_try_restart() ...@@ -641,19 +1004,13 @@ serv_try_restart()
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart)
is_service_running $SERVICE || return 0
sudocmd service $SERVICE restart "$@"
;;
service-initd|service-update)
is_service_running $SERVICE || return 0
sudocmd /etc/init.d/$SERVICE restart "$@"
;;
systemd) systemd)
sudocmd systemctl try-restart $SERVICE "$@" sudocmd systemctl try-restart $SERVICE "$@"
;; ;;
*) *)
fatal "Have no suitable command for $SERVICETYPE" info "Fallback to restart..."
is_service_running $SERVICE || { info "Service $SERVICE is not running, restart skipping…" ; return 0 ; }
serv_restart "$SERVICE" "$@"
;; ;;
esac esac
} }
...@@ -690,12 +1047,13 @@ serv_usage() ...@@ -690,12 +1047,13 @@ serv_usage()
_print_additional_usage _print_additional_usage
} }
################# incorporate bin/distr_info #################
internal_distr_info() internal_distr_info()
{ {
#!/bin/sh
# Author: Vitaly Lipatov <lav@etersoft.ru> # Author: Vitaly Lipatov <lav@etersoft.ru>
# 2007, 2009, 2010, 2012 (c) Etersoft # 2007, 2009, 2010, 2012, 2016, 2017, 2018 (c) Etersoft
# 2007 Public domain # 2007-2018 Public domain
# Detect the distro and version # Detect the distro and version
# Welcome to send updates! # Welcome to send updates!
...@@ -703,6 +1061,8 @@ internal_distr_info() ...@@ -703,6 +1061,8 @@ internal_distr_info()
# You can set ROOTDIR to root system dir # You can set ROOTDIR to root system dir
#ROOTDIR= #ROOTDIR=
# TODO: check /etc/system-release
# Check for DISTRO specific file in /etc # Check for DISTRO specific file in /etc
distro() distro()
{ {
...@@ -719,12 +1079,34 @@ has() ...@@ -719,12 +1079,34 @@ has()
grep "$*" "$DISTROFILE" >/dev/null 2>&1 grep "$*" "$DISTROFILE" >/dev/null 2>&1
} }
# Has a system the specified command?
hascommand()
{
which $1 2>/dev/null >/dev/null
}
firstupper()
{
echo "$*" | sed 's/.*/\u&/'
}
tolower()
{
# tr is broken in busybox (checked with OpenWrt)
#echo "$*" | tr "[:upper:]" "[:lower:]"
echo "$*" | awk '{print tolower($0)}'
}
# Translate DISTRIB_ID to vendor name (like %_vendor does) # Translate DISTRIB_ID to vendor name (like %_vendor does)
rpmvendor() rpmvendor()
{ {
[ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return [ "$DISTRIB_ID" = "ALTLinux" ] && echo "alt" && return
[ "$DISTRIB_ID" = "AstraLinux" ] && echo "astra" && return
[ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return [ "$DISTRIB_ID" = "LinuxXP" ] && echo "lxp" && return
echo "$DISTRIB_ID" | tr "[A-Z]" "[a-z]" [ "$DISTRIB_ID" = "TinyCoreLinux" ] && echo "tcl" && return
[ "$DISTRIB_ID" = "VoidLinux" ] && echo "void" && return
[ "$DISTRIB_ID" = "OpenSUSE" ] && echo "suse" && return
tolower "$DISTRIB_ID"
} }
# Translate DISTRIB_ID name to package manner (like in the package release name) # Translate DISTRIB_ID name to package manner (like in the package release name)
...@@ -737,18 +1119,24 @@ pkgvendor() ...@@ -737,18 +1119,24 @@ pkgvendor()
# Print pkgtype (need DISTRIB_ID var) # Print pkgtype (need DISTRIB_ID var)
pkgtype() pkgtype()
{ {
case `pkgvendor` in # TODO: try use generic names
case $(pkgvendor) in
freebsd) echo "tbz" ;; freebsd) echo "tbz" ;;
sunos) echo "pkg.gz" ;; sunos) echo "pkg.gz" ;;
slackware|mopslinux) echo "tgz" ;; slackware|mopslinux) echo "tgz" ;;
archlinux) echo "pkg.tar.xz" ;; archlinux|manjaro) echo "pkg.tar.xz" ;;
gentoo) echo "tbz2" ;; gentoo) echo "tbz2" ;;
windows) echo "exe" ;; windows) echo "exe" ;;
android) echo "apk" ;; android) echo "apk" ;;
debian|ubuntu|mint|runtu) echo "deb" ;; alpine) echo "apk" ;;
tinycorelinux) echo "tcz" ;;
voidlinux) echo "xbps" ;;
openwrt) echo "ipk" ;;
cygwin) echo "tar.xz" ;;
debian|ubuntu|mint|runtu|mcst|astra) echo "deb" ;;
alt|asplinux|suse|mandriva|rosa|mandrake|pclinux|sled|sles) alt|asplinux|suse|mandriva|rosa|mandrake|pclinux|sled|sles)
echo "rpm" ;; echo "rpm" ;;
fedora|redhat|scientific|centos|rhel) fedora|redhat|scientific|centos|rhel|goslinux|amzn)
echo "rpm" ;; echo "rpm" ;;
*) echo "rpm" ;; *) echo "rpm" ;;
esac esac
...@@ -756,8 +1144,8 @@ pkgtype() ...@@ -756,8 +1144,8 @@ pkgtype()
get_var() get_var()
{ {
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" # get first variable and print it out, drop quotes if exists
grep -i "^$1 *=" | head -n 1 | sed -e "s/^[^=]*[ \t]*=[ \t]*//" | sed -e "s/^[\'\"]\(.*\)[\'\"]/\1/"
} }
# 2010.1 -> 2010 # 2010.1 -> 2010
...@@ -769,52 +1157,71 @@ get_major_version() ...@@ -769,52 +1157,71 @@ get_major_version()
# Default values # Default values
DISTRIB_ID="Generic" DISTRIB_ID="Generic"
DISTRIB_RELEASE="" DISTRIB_RELEASE=""
DISTRIB_CODENAME=""
# Default with LSB # Default with LSB
if distro lsb-release ; then if distro lsb-release ; then
DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID` DISTRIB_ID=$(cat $DISTROFILE | get_var DISTRIB_ID)
DISTRIB_RELEASE=`cat $DISTROFILE | get_var DISTRIB_RELEASE` DISTRIB_RELEASE=$(cat $DISTROFILE | get_var DISTRIB_RELEASE)
DISTRIB_CODENAME=$(cat $DISTROFILE | get_var DISTRIB_CODENAME)
fi fi
# ALT Linux based # ALT Linux based
if distro altlinux-release ; then if distro altlinux-release ; then
DISTRIB_ID="ALTLinux" DISTRIB_ID="ALTLinux"
if has Strawberry ; then DISTRIB_RELEASE="2.3" if has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
elif has Citron ; then DISTRIB_RELEASE="2.4" elif has "ALT Linux 7." ; then DISTRIB_RELEASE="p7"
elif has 20050723 ; then DISTRIB_RELEASE="3.0" elif has "ALT Linux t7." ; then DISTRIB_RELEASE="t7"
elif has Ajuga ; then DISTRIB_RELEASE="4.0" elif has "ALT Linux 8." ; then DISTRIB_RELEASE="p8"
elif has 20070810 ; then DISTRIB_RELEASE="4.0" elif has "ALT .*8.[0-9]" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0" elif has "Simply Linux 6." ; then DISTRIB_RELEASE="p6"
elif has "Simply Linux 7." ; then DISTRIB_RELEASE="p7"
elif has "Simply Linux 8." ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux 6." ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p8" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5"
elif has "ALT Linux 5.1" ; then DISTRIB_RELEASE="5.1"
elif has "ALT Linux 5.0" ; then DISTRIB_RELEASE="5.0"
elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1" elif has "ALT Linux 4.1" ; then DISTRIB_RELEASE="4.1"
elif has "ALT Linux 4.0" ; then DISTRIB_RELEASE="4.0"
elif has Walnut ; then DISTRIB_RELEASE="4.0" elif has Walnut ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0" elif has Hypericum ; then DISTRIB_RELEASE="p8"
elif has 5.1 ; then DISTRIB_RELEASE="5.1" elif has "starter kit" ; then DISTRIB_RELEASE="p8"
elif has "ALT Linux p5" ; then DISTRIB_RELEASE="p5" elif has 20070810 ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux p6" ; then DISTRIB_RELEASE="p6" elif has Ajuga ; then DISTRIB_RELEASE="4.0"
elif has "ALT Linux p7" ; then DISTRIB_RELEASE="p7" elif has 20050723 ; then DISTRIB_RELEASE="3.0"
elif has 6.0 ; then DISTRIB_RELEASE="p6" elif has Citron ; then DISTRIB_RELEASE="2.4"
elif has Centaurea ; then DISTRIB_RELEASE="p6"
elif has Sisyphus ; then DISTRIB_RELEASE="Sisyphus"
fi fi
elif distro gentoo-release ; then elif distro gentoo-release ; then
DISTRIB_ID="Gentoo" DISTRIB_ID="Gentoo"
MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile) MAKEPROFILE=$(readlink $ROOTDIR/etc/portage/make.profile 2>/dev/null) || MAKEPROFILE=$(readlink $ROOTDIR/etc/make.profile)
DISTRIB_RELEASE=`basename $MAKEPROFILE` DISTRIB_RELEASE=$(basename $MAKEPROFILE)
echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=`basename $(dirname $MAKEPROFILE)` echo $DISTRIB_RELEASE | grep -q "[0-9]" || DISTRIB_RELEASE=$(basename "$(dirname $MAKEPROFILE)") #"
# Slackware based
elif distro mopslinux-version ; then
DISTRIB_ID="MOPSLinux"
if has 4.0 ; then DISTRIB_RELEASE="4.0"
elif has 5.0 ; then DISTRIB_RELEASE="5.0"
elif has 5.1 ; then DISTRIB_RELEASE="5.1"
elif has 6.0 ; then DISTRIB_RELEASE="6.0"
elif has 6.1 ; then DISTRIB_RELEASE="6.1"
fi
elif distro slackware-version ; then elif distro slackware-version ; then
DISTRIB_ID="Slackware" DISTRIB_ID="Slackware"
DISTRIB_RELEASE="$(grep -Eo [0-9]+\.[0-9]+ $DISTROFILE)" DISTRIB_RELEASE="$(grep -Eo '[0-9]+\.[0-9]+' $DISTROFILE)"
elif distro os-release && hascommand apk ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && hascommand tce-ab ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="TinyCoreLinux"
DISTRIB_RELEASE="$VERSION_ID"
elif distro os-release && hascommand xbps-query ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="VoidLinux"
DISTRIB_RELEASE="Live"
elif distro arch-release ; then elif distro arch-release ; then
DISTRIB_ID="ArchLinux" DISTRIB_ID="ArchLinux"
...@@ -823,6 +1230,22 @@ elif distro arch-release ; then ...@@ -823,6 +1230,22 @@ elif distro arch-release ; then
DISTRIB_RELEASE="2011" DISTRIB_RELEASE="2011"
fi fi
# Elbrus
elif distro mcst_version ; then
DISTRIB_ID="MCST"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g")
# OpenWrt
elif distro openwrt_release ; then
. $DISTROFILE
DISTRIB_RELEASE=$(cat $ROOTDIR/etc/openwrt_version)
elif distro astra_version ; then
#DISTRIB_ID=`cat $DISTROFILE | get_var DISTRIB_ID`
DISTRIB_ID="AstraLinux"
#DISTRIB_RELEASE=$(cat "$DISTROFILE" | head -n1 | sed -e "s|.* \([a-z]*\).*|\1|g")
DISTRIB_RELEASE=$DISTRIB_CODENAME
# for Ubuntu use standard LSB info # for Ubuntu use standard LSB info
elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB version # use LSB version
...@@ -831,7 +1254,7 @@ elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then ...@@ -831,7 +1254,7 @@ elif [ "$DISTRIB_ID" = "Ubuntu" ] && [ -n "$DISTRIB_RELEASE" ]; then
# Debian based # Debian based
elif distro debian_version ; then elif distro debian_version ; then
DISTRIB_ID="Debian" DISTRIB_ID="Debian"
DISTRIB_RELEASE=`cat $DISTROFILE` DISTRIB_RELEASE=$(cat $DISTROFILE | sed -e "s/\..*//g")
# Mandriva based # Mandriva based
...@@ -858,26 +1281,6 @@ elif distro mandriva-release || distro mandrake-release ; then ...@@ -858,26 +1281,6 @@ elif distro mandriva-release || distro mandrake-release ; then
fi fi
# Fedora based # Fedora based
elif distro linux-xp-release || distro lxp-release; then
DISTRIB_ID="LinuxXP"
if has "Attack of the Clones" ; then DISTRIB_RELEASE="2006"
elif has "2007" ; then DISTRIB_RELEASE="2007"
elif has "2008" ; then DISTRIB_RELEASE="2008"
elif has "2009" ; then DISTRIB_RELEASE="2009"
fi
elif distro asplinux-release ; then
DISTRIB_ID="ASPLinux"
if has Karelia ; then DISTRIB_RELEASE="10"
elif has Seliger ; then DISTRIB_RELEASE="11"
elif has "11.1" ; then DISTRIB_RELEASE="11.1"
elif has Ladoga ; then DISTRIB_RELEASE="11.2"
elif has "11.2" ; then DISTRIB_RELEASE="11.2"
elif has "12" ; then DISTRIB_RELEASE="12"
elif has "13" ; then DISTRIB_RELEASE="13"
elif has "14" ; then DISTRIB_RELEASE="14"
elif has "15" ; then DISTRIB_RELEASE="15"
fi
elif distro MCBC-release ; then elif distro MCBC-release ; then
DISTRIB_ID="MCBC" DISTRIB_ID="MCBC"
...@@ -887,7 +1290,7 @@ elif distro MCBC-release ; then ...@@ -887,7 +1290,7 @@ elif distro MCBC-release ; then
elif distro fedora-release ; then elif distro fedora-release ; then
DISTRIB_ID="Fedora" DISTRIB_ID="Fedora"
DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") DISTRIB_RELEASE=$(cat "$DISTROFILE" | grep "release" | sed -e "s|.*release \([0-9]*\).*|\1|g") #"
elif distro redhat-release ; then elif distro redhat-release ; then
# FIXME if need # FIXME if need
...@@ -897,18 +1300,17 @@ elif distro redhat-release ; then ...@@ -897,18 +1300,17 @@ elif distro redhat-release ; then
DISTRIB_ID="CentOS" DISTRIB_ID="CentOS"
elif has Scientific ; then elif has Scientific ; then
DISTRIB_ID="Scientific" DISTRIB_ID="Scientific"
elif has GosLinux ; then
DISTRIB_ID="GosLinux"
fi fi
if has Beryllium ; then if has Beryllium ; then
DISTRIB_ID="Scientific" DISTRIB_ID="Scientific"
DISTRIB_RELEASE="4.1" DISTRIB_RELEASE="4.1"
elif has Shrike ; then
DISTRIB_ID="RedHat"
DISTRIB_RELEASE="9"
elif has Taroon ; then DISTRIB_RELEASE="3"
elif has "release 4" ; then DISTRIB_RELEASE="4" elif has "release 4" ; then DISTRIB_RELEASE="4"
elif has "release 5" ; then DISTRIB_RELEASE="5" elif has "release 5" ; then DISTRIB_RELEASE="5"
elif has "release 6" ; then DISTRIB_RELEASE="6" elif has "release 6" ; then DISTRIB_RELEASE="6"
elif has "release 7" ; then DISTRIB_RELEASE="7" elif has "release 7" ; then DISTRIB_RELEASE="7"
elif has "release 8" ; then DISTRIB_RELEASE="8"
fi fi
# SUSE based # SUSE based
...@@ -921,38 +1323,181 @@ elif distro SuSe-release || distro SuSE-release ; then ...@@ -921,38 +1323,181 @@ elif distro SuSe-release || distro SuSE-release ; then
DISTRIB_ID="SLES" DISTRIB_ID="SLES"
fi fi
# https://www.freedesktop.org/software/systemd/man/os-release.html
elif distro os-release ; then
# shellcheck disable=SC1090
. $ROOTDIR/etc/os-release
DISTRIB_ID="$(firstupper "$ID")"
DISTRIB_RELEASE="$VERSION_ID"
[ -n "$DISTRIB_RELEASE" ] || DISTRIB_RELEASE="CUR"
if [ "$ID" = "opensuse-leap" ] ; then
DISTRIB_ID="SUSE"
fi
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ `uname` = "FreeBSD" ] ; then elif [ "$(uname)" = "FreeBSD" ] ; then
DISTRIB_ID="FreeBSD" DISTRIB_ID="FreeBSD"
UNAME=$(uname -r) UNAME=$(uname -r)
DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g") DISTRIB_RELEASE=$(echo "$UNAME" | grep RELEASE | sed -e "s|\([0-9]\.[0-9]\)-RELEASE|\1|g")
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ `uname` = "SunOS" ] ; then elif [ "$(uname)" = "SunOS" ] ; then
DISTRIB_ID="SunOS" DISTRIB_ID="SunOS"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: can we detect by some file? # fixme: can we detect by some file?
elif [ `uname` = "Darwin" ] ; then elif [ "$(uname -s 2>/dev/null)" = "Darwin" ] ; then
DISTRIB_ID="MacOS" DISTRIB_ID="MacOS"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: move to up # fixme: move to up
elif [ `uname` = "Linux" ] && which guix 2>/dev/null >/dev/null ; then elif [ "$(uname)" = "Linux" ] && hascommand guix ; then
DISTRIB_ID="GNU/Linux/Guix" DISTRIB_ID="GNU/Linux/Guix"
DISTRIB_RELEASE=$(uname -r) DISTRIB_RELEASE=$(uname -r)
# fixme: move to up # fixme: move to up
elif [ `uname` = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then elif [ "$(uname)" = "Linux" ] && [ -x $ROOTDIR/system/bin/getprop ] ; then
DISTRIB_ID="Android" DISTRIB_ID="Android"
DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]') DISTRIB_RELEASE=$(getprop | awk -F": " '/build.version.release/ { print $2 }' | tr -d '[]')
elif [ "$(uname -o 2>/dev/null)" = "Cygwin" ] ; then
DISTRIB_ID="Cygwin"
DISTRIB_RELEASE="all"
# try use standart LSB info by default # try use standart LSB info by default
elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then elif distro lsb-release && [ -n "$DISTRIB_RELEASE" ]; then
# use LSB # use LSB
true
# fix distro name
case "$DISTRIB_ID" in
"openSUSE Tumbleweed")
DISTRIB_ID="SUSE"
DISTRIB_RELEASE="Tumbleweed"
;;
esac
fi fi
get_uname()
{
tolower $(uname $1) | tr -d " \t\r\n"
}
get_base_os_name()
{
local DIST_OS
# Resolve the os
DIST_OS="$(get_uname -s)"
case "$DIST_OS" in
'sunos')
DIST_OS="solaris"
;;
'hp-ux' | 'hp-ux64')
DIST_OS="hpux"
;;
'darwin' | 'oarwin')
DIST_OS="macosx"
;;
'unix_sv')
DIST_OS="unixware"
;;
'freebsd' | 'openbsd' | 'netbsd')
DIST_OS="freebsd"
;;
esac
echo "$DIST_OS"
}
get_arch()
{
local DIST_ARCH
# Resolve the architecture
DIST_ARCH="$(get_uname -m)"
case "$DIST_ARCH" in
'ia32' | 'i386' | 'i486' | 'i586' | 'i686')
DIST_ARCH="x86"
;;
'amd64' | 'x86_64')
DIST_ARCH="x86_64"
;;
'ia64' | 'ia-64')
DIST_ARCH="ia64"
;;
'ip27' | 'mips')
DIST_ARCH="mips"
;;
'powermacintosh' | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
DIST_ARCH="ppc"
;;
'pa_risc' | 'pa-risc')
DIST_ARCH="parisc"
;;
'sun4u' | 'sparcv9')
DIST_ARCH="sparc"
;;
'9000/800')
DIST_ARCH="parisc"
;;
armv*)
if [ -z "$(readelf -A /proc/self/exe | grep Tag_ABI_VFP_args)" ] ; then
DIST_ARCH="armel"
else
DIST_ARCH="armhf"
fi
;;
esac
echo "$DIST_ARCH"
}
get_bit_size()
{
local DIST_BIT
# Check if we are running on 64bit platform, seems like a workaround for now...
DIST_BIT="$(get_uname -m)"
case "$DIST_BIT" in
'amd64' | 'ia64' | 'x86_64' | 'ppc64')
DIST_BIT="64"
;;
'aarch64')
DIST_BIT="64"
;;
# 'pa_risc' | 'pa-risc') # Are some of these 64bit? Least not all...
# BIT="64"
# ;;
'sun4u' | 'sparcv9') # Are all sparcs 64?
DIST_BIT="64"
;;
# '9000/800')
# DIST_BIT="64"
# ;;
*) # In any other case default to 32
DIST_BIT="32"
;;
esac
echo "$DIST_BIT"
}
# TODO: check before calc
get_memory_size() {
local detected=0
local DIST_OS="$(get_base_os_name)"
case "$DIST_OS" in
macosx)
detected=$((`sysctl hw.memsize | sed s/"hw.memsize: "//`/1024/1024))
;;
freebsd)
detected=$((`sysctl hw.physmem | sed s/"hw.physmem: "//`/1024/1024))
;;
linux)
[ -r /proc/meminfo ] && detected=$((`cat /proc/meminfo | grep MemTotal | awk '{print $2}'`/1024))
;;
esac
# Exit codes only support values between 0 and 255. So use stdout.
echo $detected
}
case $1 in case $1 in
-p) -p)
# override DISTRIB_ID # override DISTRIB_ID
...@@ -965,6 +1510,10 @@ case $1 in ...@@ -965,6 +1510,10 @@ case $1 in
echo "Usage: distr_vendor [options] [args]" echo "Usage: distr_vendor [options] [args]"
echo "-p [SystemName] - print type of packaging system" echo "-p [SystemName] - print type of packaging system"
echo "-d - print distro name" echo "-d - print distro name"
echo "-a - print hardware architecture"
echo "-b - print size of arch bit (32/64)"
echo "-m - print system memory size (in MB)"
echo "-o - print base os name"
echo "-v - print version of distro" echo "-v - print version of distro"
echo "-e - print full name of distro with version (by default)" echo "-e - print full name of distro with version (by default)"
echo "-s [SystemName] - print name of distro for build system (like in the package release name)" echo "-s [SystemName] - print name of distro for build system (like in the package release name)"
...@@ -976,6 +1525,18 @@ case $1 in ...@@ -976,6 +1525,18 @@ case $1 in
-d) -d)
echo $DISTRIB_ID echo $DISTRIB_ID
;; ;;
-a)
get_arch
;;
-b)
get_bit_size
;;
-m)
get_memory_size
;;
-o)
get_base_os_name
;;
-v) -v)
echo $DISTRIB_RELEASE echo $DISTRIB_RELEASE
;; ;;
...@@ -992,7 +1553,7 @@ case $1 in ...@@ -992,7 +1553,7 @@ case $1 in
exit 0 exit 0
;; ;;
-V) -V)
echo "20120519" echo "20171010"
exit 0 exit 0
;; ;;
*) *)
...@@ -1002,6 +1563,587 @@ case $1 in ...@@ -1002,6 +1563,587 @@ case $1 in
esac esac
} }
################# end of incorporated bin/distr_info #################
################# incorporate bin/tools_eget #################
internal_tools_eget()
{
# eget - simply shell on wget for loading directories over http (wget does not support wildcard for http)
# Example use:
# eget http://ftp.altlinux.ru/pub/security/ssl/*
#
# Copyright (C) 2014-2014, 2016 Etersoft
# Copyright (C) 2014 Daniil Mikhailov <danil@etersoft.ru>
# Copyright (C) 2016-2017 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
WGET="wget"
# TODO: passthrou all wget options
if [ "$1" = "-q" ] ; then
WGET="wget -q"
shift
fi
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
WGET_OPTION_TARGET=
if [ "$1" = "-O" ] ; then
TARGETFILE="$2"
WGET_OPTION_TARGET="-O $2"
shift 2
fi
# TODO:
# -P support
if [ -z "$1" ] ; then
echo "eget - wget wrapper" >&2
fatal "Run with URL, like http://somesite.ru/dir/*.log"
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
return
fi
# do not support /
if echo "$1" | grep -q "/$" ; then
fatal "Use http://example.com/e/* to download all files in dir"
fi
# If ftp protocol, just download
if echo "$1" | grep -q "^ftp://" ; then
[ -n "$LISTONLY" ] && fatal "Error: list files for ftp:// do not supported yet"
$WGET $WGET_OPTION_TARGET "$1"
return
fi
# 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=$(basename "$1")
# 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 | \
grep -o -E 'href="([^\*/"#]+)"' | cut -d'"' -f2
}
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()
{
#!/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
}
################# end of incorporated bin/tools_estrlist #################
################# incorporate bin/tools_json #################
internal_tools_json()
{
# License: MIT or Apache
# Homepage: http://github.com/dominictarr/JSON.sh
throw() {
echo "$*" >&2
exit 1
}
BRIEF=0
LEAFONLY=0
PRUNE=0
NO_HEAD=0
NORMALIZE_SOLIDUS=0
usage() {
echo
echo "Usage: JSON.sh [-b] [-l] [-p] [-s] [-h]"
echo
echo "-p - Prune empty. Exclude fields with empty values."
echo "-l - Leaf only. Only show leaf nodes, which stops data duplication."
echo "-b - Brief. Combines 'Leaf only' and 'Prune empty' options."
echo "-n - No-head. Do not show nodes that have no path (lines that start with [])."
echo "-s - Remove escaping of the solidus symbol (straight slash)."
echo "-h - This help text."
echo
}
parse_options() {
set -- "$@"
local ARGN=$#
while [ "$ARGN" -ne 0 ]
do
case $1 in
-h) usage
exit 0
;;
-b) BRIEF=1
LEAFONLY=1
PRUNE=1
;;
-l) LEAFONLY=1
;;
-p) PRUNE=1
;;
-n) NO_HEAD=1
;;
-s) NORMALIZE_SOLIDUS=1
;;
?*) echo "ERROR: Unknown option."
usage
exit 0
;;
esac
shift 1
ARGN=$((ARGN-1))
done
}
awk_egrep () {
local pattern_string=$1
gawk '{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
print token;
$0=substr($0, start+RLENGTH);
}
}' pattern="$pattern_string"
}
tokenize () {
local GREP
local ESCAPE
local CHAR
if echo "test string" | egrep -ao --color=never "test" >/dev/null 2>&1
then
GREP='egrep -ao --color=never'
else
GREP='egrep -ao'
fi
if echo "test string" | egrep -o "test" >/dev/null 2>&1
then
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\]'
else
GREP=awk_egrep
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\\\]'
fi
local STRING="\"$CHAR*($ESCAPE$CHAR*)*\""
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD='null|false|true'
local SPACE='[[:space:]]+'
# Force zsh to expand $A into multiple words
local is_wordsplit_disabled=$(unsetopt 2>/dev/null | grep -c '^shwordsplit$')
if [ $is_wordsplit_disabled != 0 ]; then setopt shwordsplit; fi
$GREP "$STRING|$NUMBER|$KEYWORD|$SPACE|." | egrep -v "^$SPACE$"
if [ $is_wordsplit_disabled != 0 ]; then unsetopt shwordsplit; fi
}
parse_array () {
local index=0
local ary=''
read -r token
case "$token" in
']') ;;
*)
while :
do
parse_value "$1" "$index"
index=$((index+1))
ary="$ary""$value"
read -r token
case "$token" in
']') break ;;
',') ary="$ary," ;;
*) throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
[ "$BRIEF" -eq 0 ] && value=$(printf '[%s]' "$ary") || value=
:
}
parse_object () {
local key
local obj=''
read -r token
case "$token" in
'}') ;;
*)
while :
do
case "$token" in
'"'*'"') key=$token ;;
*) throw "EXPECTED string GOT ${token:-EOF}" ;;
esac
read -r token
case "$token" in
':') ;;
*) throw "EXPECTED : GOT ${token:-EOF}" ;;
esac
read -r token
parse_value "$1" "$key"
obj="$obj$key:$value"
read -r token
case "$token" in
'}') break ;;
',') obj="$obj," ;;
*) throw "EXPECTED , or } GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
[ "$BRIEF" -eq 0 ] && value=$(printf '{%s}' "$obj") || value=
:
}
parse_value () {
local jpath="${1:+$1,}$2" isleaf=0 isempty=0 print=0
case "$token" in
'{') parse_object "$jpath" ;;
'[') parse_array "$jpath" ;;
# At this point, the only valid single-character tokens are digits.
''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token
# if asked, replace solidus ("\/") in json strings with normalized value: "/"
[ "$NORMALIZE_SOLIDUS" -eq 1 ] && value=$(echo "$value" | sed 's#\\/#/#g')
isleaf=1
[ "$value" = '""' ] && isempty=1
;;
esac
[ "$value" = '' ] && return
[ "$NO_HEAD" -eq 1 ] && [ -z "$jpath" ] && return
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && [ $PRUNE -eq 0 ] && print=1
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 1 ] && [ "$isempty" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && \
[ $PRUNE -eq 1 ] && [ $isempty -eq 0 ] && print=1
[ "$print" -eq 1 ] && printf "[%s]\t%s\n" "$jpath" "$value"
:
}
parse () {
read -r token
parse_value
read -r token
case "$token" in
'') ;;
*) throw "EXPECTED EOF GOT $token" ;;
esac
}
if ([ "$0" = "$BASH_SOURCE" ] || ! [ -n "$BASH_SOURCE" ]);
then
parse_options "$@"
tokenize | parse
fi
# vi: expandtab sw=2 ts=2
}
################# end of incorporated bin/tools_json #################
INITDIR=/etc/init.d
PATH=$PATH:/sbin:/usr/sbin PATH=$PATH:/sbin:/usr/sbin
...@@ -1023,18 +2165,11 @@ set_service_type() ...@@ -1023,18 +2165,11 @@ set_service_type()
[ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v) [ -n "$DISTRVERSION" ] || DISTRVERSION=$($DISTRVENDOR -v)
set_target_pkg_env set_target_pkg_env
is_active_systemd()
{
SYSTEMCTL=/bin/systemctl
SYSTEMD_CGROUP_DIR=/sys/fs/cgroup/systemd
[ -x "$SYSTEMCTL" ] && [ -d "$SYSTEMD_CGROUP_DIR" ] && mountpoint -q "$SYSTEMD_CGROUP_DIR"
}
case $DISTRNAME in case $DISTRNAME in
ALTLinux) ALTLinux)
CMD="service-chkconfig" CMD="service-chkconfig"
;; ;;
Ubuntu|Debian|Mint) Ubuntu|Debian|Mint|AstraLinux)
CMD="service-update" CMD="service-update"
;; ;;
Mandriva|ROSA) Mandriva|ROSA)
...@@ -1049,9 +2184,12 @@ case $DISTRNAME in ...@@ -1049,9 +2184,12 @@ case $DISTRNAME in
# ArchLinux) # ArchLinux)
# CMD="pacman" # CMD="pacman"
# ;; # ;;
Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific) Fedora|LinuxXP|ASPLinux|CentOS|RHEL|Scientific|GosLinux|Amzn)
CMD="service-chkconfig" CMD="service-chkconfig"
;; ;;
VoidLinux)
CMD="runit"
;;
Slackware) Slackware)
CMD="service-initd" CMD="service-initd"
;; ;;
...@@ -1074,8 +2212,18 @@ is_active_systemd && CMD="systemd" ...@@ -1074,8 +2212,18 @@ is_active_systemd && CMD="systemd"
SERVICETYPE=$CMD SERVICETYPE=$CMD
ANYSERVICE=$(which anyservice 2>/dev/null)
} }
# TODO: done it on anyservice part
is_anyservice()
{
[ -n "$ANYSERVICE" ] || return
[ -n "$1" ] || return
# check if anyservice is exists and checkd returns true
$ANYSERVICE "$1" checkd 2>/dev/null
}
phelp() phelp()
...@@ -1092,9 +2240,9 @@ $(get_help HELPOPT) ...@@ -1092,9 +2240,9 @@ $(get_help HELPOPT)
print_version() print_version()
{ {
echo "Service manager version 1.5.0" echo "Service manager version 2.5.8"
echo "Running on $($DISTRVENDOR)" echo "Running on $($DISTRVENDOR) with $SERVICETYPE"
echo "Copyright (c) Etersoft 2012, 2013" echo "Copyright (c) Etersoft 2012-2018"
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."
} }
...@@ -1127,8 +2275,12 @@ check_command() ...@@ -1127,8 +2275,12 @@ check_command()
serv_cmd=usage serv_cmd=usage
withoutservicename=1 withoutservicename=1
;; ;;
#restart) # HELPCMD: restart service restart) # HELPCMD: restart service
#reload) # HELPCMD: reload service serv_cmd=restart
;;
reload) # HELPCMD: reload service
serv_cmd=reload
;;
start) # HELPCMD: start service start) # HELPCMD: start service
serv_cmd=start serv_cmd=start
;; ;;
...@@ -1156,6 +2308,13 @@ check_command() ...@@ -1156,6 +2308,13 @@ check_command()
off|disable) # HELPCMD: remove service to run on startup and stop it now off|disable) # HELPCMD: remove service to run on startup and stop it now
serv_cmd=disable serv_cmd=disable
;; ;;
print) # HELPCMD: print some info
serv_cmd=print
withoutservicename=1
;;
log|journal) # HELPCMD: print log for the service
serv_cmd=log
;;
*) *)
return 1 return 1
;; ;;
...@@ -1210,6 +2369,7 @@ if [ -z "$withoutservicename" ] && [ -z "$service_name" ] ; then ...@@ -1210,6 +2369,7 @@ if [ -z "$withoutservicename" ] && [ -z "$service_name" ] ; then
fatal "Run $ $progname --help for get help" fatal "Run $ $progname --help for get help"
fi fi
# use common way if the command is unknown
if [ -z "$serv_cmd" ] ; then if [ -z "$serv_cmd" ] ; then
serv_cmd=common serv_cmd=common
fi fi
......
#!/bin/sh -x
# It will run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
subst 's|%dir "/opt/chromium-gost"|%dir "/opt/chromium-gost"\n/usr/share/icons/hicolor/*x*/apps/*.png|' $SPEC
# Make relative symlink
rm -f $BUILDROOT/usr/bin/chromium-gost-stable
ln -s ../../opt/chromium-gost/chromium-gost $BUILDROOT/usr/bin/chromium-gost-stable
ln -s chromium-gost-stable $BUILDROOT/usr/bin/chromium-gost
for i in 16 22 24 32 48 64 128 256 ; do
mkdir -p $BUILDROOT/usr/share/icons/hicolor/${i}x${i}/apps/
cp $BUILDROOT/opt/chromium-gost/product_logo_$i.png $BUILDROOT/usr/share/icons/hicolor/${i}x${i}/apps/chromium-gost.png
done
rm -f $BUILDROOT/etc/cron.daily/chromium-gost
subst 's|.*/etc/cron.daily/chromium-gost.*||' $SPEC
subst 's|exec -a "$0" "$HERE/chrome" "$@"||' $BUILDROOT/opt/chromium-gost/chromium-gost
cat <<EOF >>$BUILDROOT/opt/chromium-gost/chromium-gost
if ! [[ "\$*" =~ \-user\-data\-dir= ]]; then
exec -a "\$0" "\$HERE/chrome" "-user-data-dir=\$HOME/.config/chromium-gost" "\$@"
else
exec -a "\$0" "\$HERE/chrome" "\$@"
fi
EOF
#!/bin/sh -x
# It will be run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
REQUIRES="mono-full,libgtk-sharp2"
subst "s|^\(Name: .*\)$|# Converted from original package requires\nRequires:$REQUIRES\n\1|g" $SPEC
#!/bin/sh
# Place your shell code here
# It will be run with two args: buildroot spec
# Name this script as package name
BUILDROOT="$1"
SPEC="$2"
#!/bin/sh -x
# It will run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
subst 's|%dir "/opt/google/chrome"|%dir "/opt/google/chrome"\n/usr/share/icons/hicolor/*x*/apps/*.png|' $SPEC
# Make relative symlink
rm -f $BUILDROOT/usr/bin/google-chrome-stable
ln -s ../../opt/google/chrome/google-chrome $BUILDROOT/usr/bin/google-chrome-stable
ln -s google-chrome-stable $BUILDROOT/usr/bin/google-chrome
for i in 16 22 24 32 48 64 128 256 ; do
mkdir -p $BUILDROOT/usr/share/icons/hicolor/${i}x${i}/apps/
cp $BUILDROOT/opt/google/chrome/product_logo_$i.png $BUILDROOT/usr/share/icons/hicolor/${i}x${i}/apps/google-chrome.png
done
rm -f $BUILDROOT/etc/cron.daily/google-chrome
subst 's|.*/etc/cron.daily/google-chrome.*||' $SPEC
# google-chrome by default?
#subst 's|exec -a "$0" "$HERE/chrome" "$@"||' $BUILDROOT/opt/google/chrome/google-chrome
#cat <<EOF >>$BUILDROOT/opt/google/chrome/google-chrome
#if ! [[ "\$*" =~ \-user\-data\-dir= ]]; then
# exec -a "\$0" "\$HERE/chrome" "-user-data-dir=\$HOME/.config/google-chrome" "\$@"
#else
# exec -a "\$0" "\$HERE/chrome" "\$@"
#fi
#EOF
#!/bin/sh -x
# It will be run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
subst "s|^\(Name: .*\)$|# FIXME: due libcrypto.so.10(libcrypto.so.10)(64bit) autoreqs\nAutoReq:yes,nolib\n# Converted from original package requires\nRequires:libssl pbzip2 bzip2 gdb python-base libnuma libkrb5 libsss_nss_idmap\n\1|g" $SPEC
#!/bin/sh -x
# It will be run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
# move binaries from /usr/share/PKGNAME to _libdir/PKGNAME
LIBDIR=$(rpmbuild --eval %_libdir 2>/dev/null)
mkdir -p $BUILDROOT$LIBDIR/
mv $BUILDROOT/usr/share/skypeforlinux/ $BUILDROOT$LIBDIR/
subst "s|/usr/share/skypeforlinux|$LIBDIR/skypeforlinux|g" $SPEC
subst "s|^SKYPE_PATH=.*|SKYPE_PATH=$LIBDIR/skypeforlinux/skypeforlinux|" $BUILDROOT/usr/bin/skypeforlinux
#!/bin/sh -x
# It will be run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
if [ "$(distr_info -a)" = "x86_64" ] ; then
# 32 bit
rm -fv $BUILDROOT/opt/teamviewer/tv_bin/script/libdepend
subst "s|.*script/libdepend.*||" $SPEC
fi
REQUIRES="libdbus,libexo,libqt5-core,libqt5-dbus,libqt5-gui,libqt5-network,libqt5-qml,libqt5-quick,libqt5-webkit,libqt5-webkitwidgets,libqt5-widgets,libqt5-x11extras"
subst "s|^\(Name: .*\)$|# Converted from original package requires\nRequires:$REQUIRES\n\1|g" $SPEC
#!/bin/sh -x
# It will run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
subst 's|%dir "/usr/share/icons/hicolor/.*||' $SPEC
# Make relative symlink
# TODO: alien does not support ghost files?
mkdir -p $BUILDROOT/usr/bin/
rm -f $BUILDROOT/usr/bin/trueconf
ln -s ../../opt/trueconf/trueconf-client $BUILDROOT/usr/bin/trueconf
chmod a+x $BUILDROOT/opt/trueconf/trueconf-client
rm -rvf $BUILDROOT/usr/local/
[ "$(distr_info -b)" = 64 ] && LIBUDEV=/lib64/libudev.so.0 || LIBUDEV=/lib/libudev.so.0
ln -s $LIBUDEV $BUILDROOT/opt/trueconf/lib/libudev.so.0
REQUIRES="libudev1 pulseaudio alsa-utils libv4l sqlite gtk2 libpng openssl udev libxslt xdg-utils"
subst "s|^\(Name: .*\)$|# FIXME: due libcrypto.so.10(libcrypto.so.10)(64bit) autoreqs\nAutoReq:yes,nolib\n# Converted from original package requires\nRequires:$REQUIRES\n\1|g" $SPEC
subst 's|.*/usr/local.*||' $SPEC
#!/bin/sh -x
# It will be run with two args: buildroot spec
BUILDROOT="$1"
SPEC="$2"
[ -x $BUILDROOT/usr/bin/yandex-browser ] || ln -sv yandex-browser-beta $BUILDROOT/usr/bin/yandex-browser
LSB_VERSION="core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64"
DISTRIB_ID="openSUSE Tumbleweed"
DISTRIB_RELEASE="20161014"
DISTRIB_CODENAME=""
DISTRIB_DESCRIPTION="openSUSE Tumbleweed"
NAME="Manjaro Linux"
ID=manjaro
PRETTY_NAME="Manjaro Linux"
ANSI_COLOR="1;32"
HOME_URL="https://www.manjaro.org/"
SUPPORT_URL="https://www.manjaro.org/"
BUG_REPORT_URL="https://bugs.manjaro.org/"
#!/bin/sh
get_numdelim()
{
echo -n "$@" | sed -e "s|[^-]||g" | wc -c
}
check()
{
[ "$2" != "$3" ] && echo "FATAL with '$1': result '$3' do not match with '$2'" || echo "OK for '$1' with '$2'"
}
check_file()
{
check "$1" "$2" $(../bin/epm print name from filename "$1")
}
check_pkgfile()
{
check "$1" "$2" $(../bin/epm print pkgname from filename "$1")
}
check_pkg()
{
get_numdelim "$1"
check "$1" "$2" $(../bin/epm print name "$1")
}
echo "check_file"
check_file pkg-source-1.0.src.rpm pkg-source
check_file pkg-source_1.0.src.rpm pkg-source
check_file pkg-source[-_]1.0.src.rpm pkg-source
check_file pkg-source*.src.rpm pkg-source
check_file pkg-source-1.0-2.0*.src.rpm pkg-source-1.0
check_file pkg-source-1.0_2.0*.src.rpm pkg-source-1.0
check_file libpq5.2-9.0eter-9.0.4-alt14.i586.rpm libpq5.2-9.0eter
check_file bison_2.7.1.dfsg-1_i386.deb bison
check_file postgre-etersoft9.0_9.0.4-eter14ubuntu_i386.deb postgre-etersoft9.0
check_file libpq5.2-9.0eter-9.0.4-alt14.i586.rpm libpq5.2-9.0eter
echo
echo "check_pkgfile"
check_pkgfile libpq5.2-9.0eter-9.0.4-alt14.i586.rpm libpq5.2-9.0eter-9.0.4-alt14
check_pkgfile bison_2.7.1.dfsg-1_i386.deb bison-2.7.1.dfsg-1
check_pkgfile postgre-etersoft9.0_9.0.4-eter14ubuntu_i386.deb postgre-etersoft9.0-9.0.4-eter14ubuntu
check_pkgfile libpq5.2-9.0eter-9.0.4-alt14.i586.rpm libpq5.2-9.0eter-9.0.4-alt14
echo
echo "check_pkg"
check_pkg pkg-source-1.0 pkg-source
check_pkg pkg-source_1.0 pkg-source
check_pkg pkg-source[-_]1.0 pkg-source
check_pkg pkg-source* pkg-source
check_pkg pkg-source-1.0-2.0 pkg-source-1.0
check_pkg pkg-source-1.0_2.0 pkg-source-1.0
check_pkg libpq5.2-9.0eter-9.0.4-alt14 libpq5.2-9.0eter
check_pkg libpjlib-util2-2.1.0.0.ast20130823-1 libpjlib-util2
check_pkg rpm-build-python-tools-0.36.2-alt1 rpm-build-python-tools
check_pkg saxon9-B.9.0.0.8-alt2 saxon9
check_pkg rootfiles-alt-alt11 rootfiles
check_pkg git-bzr-1.1_48_g61d6007-alt1.1 git-bzr
check_pkg liblz4-r127-alt1.svn20141224 liblz4
check_pkg libijs-0.35_9.15-alt1 libijs
echo
echo "check_pkg"
check_pkg pkg-1.0.spec pkg
check_pkg pkg-source-1.0.spec pkg-source
check_pkg pkg-source-less-1.0.spec pkg-source-less
check_pkg pkg123-1.0.spec pkg123
check_pkg pkg123[_-]1.0.spec pkg123
check_pkg pkg*.spec pkg
check_pkg qt5-webkit-doc qt5-webkit-doc
check_pkg geronimo-j2ee-management-1.1-api geronimo-j2ee-management-1.1-api
check_pkg i586-libgphoto2_port-12 i586-libgphoto2_port-12
check_pkg python-module-qscintilla2-qt4 python-module-qscintilla2-qt4
check_pkg python-module-qscintilla2-qt4-2.9-alt4 python-module-qscintilla2-qt4
check_pkg libqscintilla2-6-qt4 libqscintilla2-6-qt4
check_pkg libqscintilla2-6-qt4-2.5.1-alt4 libqscintilla2-6-qt4
#!/bin/sh
../bin/epmqa --short >$0.0
# get two - packages list
cat $0.0 | grep ".*-.*-.*" | sort >$0.1
# try get their names, it does not have difference
cat $0.1 | ../bin/epm print name | sort >$0.1.1
cat $0.0 | ../bin/epm print name | sort >$0.2
# Local package resource list for APT goes here.
# To inspect package defined part, see /etc/apt/sources.list.d/*.list
#rpm ftp://server/pub/ALTLinux/Sisyphus x86_64 classic games media
#rpm ftp://server/pub/ALTLinux/Sisyphus x86_32 classic
#rpm ftp://server/pub/ALTLinux/Sisyphus noarch classic games media
#rpm file:/var/ftp/pub/ALTLinux i586 bonus
rpm file:/var/ftp/pub/ALTLinux/Sisyphus x86_64 classic debuginfo
rpm file:/var/ftp/pub/ALTLinux/Sisyphus x86_64-i586 classic
rpm file:/var/ftp/pub/ALTLinux/Sisyphus noarch classic
rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft/Sisyphus x86_64 addon nonfree
rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft/Sisyphus x86_64-i586 addon
rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft/Sisyphus noarch addon nonfree
rpm file:/var/ftp/pub/Etersoft/WINE@Etersoft/2.1-testing/WINE/ALTLinux Sisyphus main
rpm file:/var/ftp/pub/Etersoft/WINE@Etersoft/2.1-testing/WINE/ALTLinux Sisyphus/extra main
#rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft/Sisyphus i586 addon nonfree
#rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft/Sisyphus x86_64 nonfree
#rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft/Sisyphus noarch nonfree
#rpm http://git.altlinux.org/repo/81290/ x86_64 task
rpm http://download.etersoft.ru/pub/Etersoft/RX@Etersoft/testing x86_64/ALTLinux/Sisyphus main
rpm http://download.etersoft.ru/pub/Etersoft/RX@Etersoft/unstable x86_64/ALTLinux/Sisyphus main
#rpm http://git.altlinux.org/repo/125605/ x86_64-i586 task
# ftp.altlinux.org (ALT Linux, Moscow)
# ALT Linux Sisyphus
rpm [alt] ftp://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus x86_64 classic
rpm [alt] ftp://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus noarch classic
rpm [alt] http://ftp.altlinux.org/pub/distributions/ALTLinux p7/branch/x86_64 classic
rpm [alt] http://ftp.altlinux.org/pub/distributions/ALTLinux p7/branch/noarch classic
rpm [alt] rsync://ftp.altlinux.org/ALTLinux/Sisyphus x86_64 classic
rpm [alt] rsync://ftp.altlinux.org/ALTLinux/Sisyphus noarch classic
# possible it will be in apt-conf-etersoft?
rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft Sisyphus/i586 addon nonfree
rpm file:/var/ftp/pub/Etersoft/LINUX@Etersoft Sisyphus/noarch addon nonfree
# mirror.yandex.ru (Yandex, Moscow)
# ALT Linux Sisyphus
rpm [alt] ftp://mirror.yandex.ru/altlinux/Sisyphus x86_64 classic
rpm [alt] ftp://mirror.yandex.ru/altlinux/Sisyphus noarch classic
rpm [alt] http://mirror.yandex.ru/altlinux/Sisyphus x86_64 classic
rpm [alt] http://mirror.yandex.ru/altlinux/Sisyphus noarch classic
rpm [alt] rsync://mirror.yandex.ru/altlinux/Sisyphus x86_64 classic
rpm [alt] rsync://mirror.yandex.ru/altlinux/Sisyphus noarch classic
# Local package resource list for APT goes here.
# To inspect package defined part, see /etc/apt/sources.list.d/*.list
#rpm ftp://server/pub/ALTLinux/Sisyphus x86_64 classic games media
#rpm ftp://server/pub/ALTLinux/Sisyphus x86_32 classic
#rpm ftp://server/pub/ALTLinux/Sisyphus noarch classic games media
#rpm file:/var/ftp/pub/ALTLinux i586 bonus
rpm file:/var/ftp/pub ALTLinux/Sisyphus/x86_64 classic debuginfo
rpm file:/var/ftp/pub ALTLinux/Sisyphus/x86_64-i586 classic
rpm file:/var/ftp/pub ALTLinux/Sisyphus/noarch classic
rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/x86_64 addon nonfree
rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/x86_64-i586 addon
rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/noarch addon nonfree
rpm file:/var/ftp/pub/Etersoft WINE@Etersoft/2.1-testing/WINE/ALTLinux/Sisyphus main
rpm file:/var/ftp/pub/Etersoft WINE@Etersoft/2.1-testing/WINE/ALTLinux/Sisyphus/extra main
#rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/i586 addon nonfree
#rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/x86_64 nonfree
#rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/noarch nonfree
#rpm http://git.altlinux.org/repo/81290/ x86_64 task
rpm http://download.etersoft.ru/pub/Etersoft RX@Etersoft/testing/x86_64/ALTLinux/Sisyphus main
rpm http://download.etersoft.ru/pub/Etersoft RX@Etersoft/unstable/x86_64/ALTLinux/Sisyphus main
#rpm http://git.altlinux.org/repo/125605/ x86_64-i586 task
# ftp.altlinux.org (ALT Linux, Moscow)
# ALT Linux Sisyphus
rpm [alt] ftp://ftp.altlinux.org/pub/distributions ALTLinux/Sisyphus/x86_64 classic
rpm [alt] ftp://ftp.altlinux.org/pub/distributions ALTLinux/Sisyphus/noarch classic
rpm [alt] http://ftp.altlinux.org/pub/distributions ALTLinux/p7/branch/x86_64 classic
rpm [alt] http://ftp.altlinux.org/pub/distributions ALTLinux/p7/branch/noarch classic
rpm [alt] rsync://ftp.altlinux.org ALTLinux/Sisyphus/x86_64 classic
rpm [alt] rsync://ftp.altlinux.org ALTLinux/Sisyphus/noarch classic
# possible it will be in apt-conf-etersoft?
rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/i586 addon nonfree
rpm file:/var/ftp/pub/Etersoft LINUX@Etersoft/Sisyphus/noarch addon nonfree
# mirror.yandex.ru (Yandex, Moscow)
# ALT Linux Sisyphus
rpm [alt] ftp://mirror.yandex.ru altlinux/Sisyphus/x86_64 classic
rpm [alt] ftp://mirror.yandex.ru altlinux/Sisyphus/noarch classic
rpm [alt] http://mirror.yandex.ru altlinux/Sisyphus/x86_64 classic
rpm [alt] http://mirror.yandex.ru altlinux/Sisyphus/noarch classic
rpm [alt] rsync://mirror.yandex.ru altlinux/Sisyphus/x86_64 classic
rpm [alt] rsync://mirror.yandex.ru altlinux/Sisyphus/noarch classic
#!/bin/sh
. ../bin/epm-repofix
#__fix_apt_sources_list
perl -pe "$SUBST_ALT_RULE" <test_sources.list >test_sources.list.out
echo "Fixes:"
diff -u test_sources.list test_sources.list.out
echo "==========="
echo "Diffs:"
diff -u test_sources.list.reference test_sources.list.out && echo DONE
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