implemented patchfile and pre post action of package manager, renamed pkgrem -> pkgrm
This commit is contained in:
@@ -15,7 +15,13 @@ export COM_UPGRADE="full-upgrade -y"
|
||||
export COM_REMOVE="remove --purge -y"
|
||||
export COM_AUTOREM="autoremove --purge -y"
|
||||
|
||||
# Special variable for apt tools to disable any interactive behaviour
|
||||
export GET_INSTALLLIST="apt-get -s install @pkg@ -V | grep 'Inst' | awk '{print$2}'"
|
||||
export GET_UPGRADELIST="apt-get -s full-upgrade -V | grep 'Inst' | awk '{print$2}'"
|
||||
export GET_REMOVELIST="apt-get -s remove @pkg@ -V | grep 'Remv' | awk '{print$2}'"
|
||||
export GET_AUTOREMLIST="apt-get -s autoremove -V | grep 'Remv' | awk '{print$2}'"
|
||||
|
||||
# Special variable for apt like tools to disable any interactive behaviour
|
||||
# This is not used by init.sh
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Conf chemin
|
||||
|
||||
@@ -15,7 +15,13 @@ export COM_UPGRADE="full-upgrade -y"
|
||||
export COM_REMOVE="remove --purge -y"
|
||||
export COM_AUTOREM="autoremove --purge -y"
|
||||
|
||||
export GET_INSTALLLIST="apt-get -s install @pkg@ -V | grep 'Inst' | awk '{print$2}'"
|
||||
export GET_UPGRADELIST="apt-get -s full-upgrade -V | grep 'Inst' | awk '{print$2}'"
|
||||
export GET_REMOVELIST="apt-get -s remove @pkg@ -V | grep 'Remv' | awk '{print$2}'"
|
||||
export GET_AUTOREMLIST="apt-get -s autoremove -V | grep 'Remv' | awk '{print$2}'"
|
||||
|
||||
# Special variable for apt tools to disable any interactive behaviour
|
||||
# This is not used by init.sh
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Conf chemin
|
||||
|
||||
@@ -15,7 +15,13 @@ export COM_UPGRADE="full-upgrade -y"
|
||||
export COM_REMOVE="remove --purge -y"
|
||||
export COM_AUTOREM="autoremove --purge -y"
|
||||
|
||||
export GET_INSTALLLIST="apt-get -s install @pkg@ -V | grep 'Inst' | awk '{print$2}'"
|
||||
export GET_UPGRADELIST="apt-get -s full-upgrade -V | grep 'Inst' | awk '{print$2}'"
|
||||
export GET_REMOVELIST="apt-get -s remove @pkg@ -V | grep 'Remv' | awk '{print$2}'"
|
||||
export GET_AUTOREMLIST="apt-get -s autoremove -V | grep 'Remv' | awk '{print$2}'"
|
||||
|
||||
# Special variable for apt tools to disable any interactive behaviour
|
||||
# This is not used by init.sh
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Conf chemin
|
||||
|
||||
@@ -177,9 +177,39 @@ isdirempty()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# patch a file replacing all @var@ by the corresponding value in environment
|
||||
# or the variable list given in parameter
|
||||
patchfile()
|
||||
{
|
||||
: # todo
|
||||
local dstfile=$1 && shift
|
||||
local workfile=${dstfile}.work
|
||||
|
||||
# Create a sub-process, to avoid bash environment pollution
|
||||
(
|
||||
local varlist= pattern=
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
pattern="-e s/<\(.*\)>/\$\1\$\1/g"
|
||||
else
|
||||
local var=
|
||||
for var in $* ; do
|
||||
if ! declare -p $var >/dev/null 2>&1 ; then
|
||||
local $var=$(eval echo \$$var)
|
||||
fi
|
||||
export $var
|
||||
pattern="$pattern -e s/@$var@/\$$var/g"
|
||||
varlist=$varlist\$$var
|
||||
done
|
||||
fi
|
||||
|
||||
# sed replace <VAR> with \$$VAR and envsubst do the replace by value
|
||||
sed $pattern $dstfile | envsubst ${varlist:+"$varlist"} > "$workfile"
|
||||
)
|
||||
|
||||
local -a rights=( $(stat --printf="%a %u %g" "$dstfile") )
|
||||
mv "$workfile" "$dstfile"
|
||||
chmod ${rights[0]} "$dstfile"
|
||||
chown ${rights[1]}:${rights[2]} "$dstfile"
|
||||
|
||||
unset dstfile
|
||||
}
|
||||
|
||||
# EOF
|
||||
|
||||
156
lib/pkgman.sh
156
lib/pkgman.sh
@@ -29,11 +29,15 @@ pkginst()
|
||||
exit 11
|
||||
fi
|
||||
if [[ ! $INSTALL_MODE == dev ]]; then
|
||||
exec_preinst $@
|
||||
$PKG_MAN $COM_INSTALL $@
|
||||
exec_postinst $@
|
||||
else
|
||||
local pkg=
|
||||
for pkg in $@; do
|
||||
exec_preinst $pkg
|
||||
$PKG_MAN $COM_INSTALL $pkg
|
||||
exec_postinst $pkg
|
||||
done
|
||||
unset pkg
|
||||
fi
|
||||
@@ -46,14 +50,16 @@ export -f pkginst
|
||||
pkgupgd()
|
||||
{
|
||||
prnt I "Application de la mise à jours du système..."
|
||||
exec_preupgd
|
||||
$PKG_MAN $COM_UPGRADE
|
||||
exec_postupgd
|
||||
}
|
||||
export -f pkgupgd
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uninstallation
|
||||
pkgrem()
|
||||
pkgrm()
|
||||
{
|
||||
prnt I "Désinstallation de paquets..."
|
||||
if [[ $# -lt 1 ]]; then
|
||||
@@ -61,25 +67,167 @@ pkgrem()
|
||||
exit 11
|
||||
fi
|
||||
if [[ ! $INSTALL_MODE == dev ]]; then
|
||||
exec_prerm $@
|
||||
$PKG_MAN $COM_REMOVE $@
|
||||
exec_postrm
|
||||
else
|
||||
local pkg=
|
||||
for pkg in $@; do
|
||||
exec_prerm $pkg
|
||||
$PKG_MAN $COM_REMOVE $pkg
|
||||
exec_postrm
|
||||
done
|
||||
uset pkg
|
||||
fi
|
||||
}
|
||||
export -f pkgrem
|
||||
export -f pkgrm
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
pkgautorem()
|
||||
pkgautorm()
|
||||
{
|
||||
prnt I "Désinstallation de paquets superflus..."
|
||||
exec_preautorm
|
||||
$PKG_MAN $COM_AUTOREM
|
||||
exec_postautorm
|
||||
}
|
||||
export -f pkgautorem
|
||||
export -f pkgautorm
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute preinstallation code
|
||||
exec_preinst()
|
||||
{
|
||||
local cmd=$(echo $GET_INSTALLLIST | sed "s/@pkg@/$@/")
|
||||
local pkglist=$($cmd)
|
||||
unset $cmd
|
||||
for pkg in $pkglist; do
|
||||
if [[ $(function_exists preinst_$pkg) ]]; then
|
||||
prnt I "Exécution de la préinstallation de $pkg ..."
|
||||
preinst_$pkg
|
||||
fi
|
||||
done
|
||||
export POSTINSTLIST=$pkglist
|
||||
unset pkglist
|
||||
}
|
||||
export -f exec_preinst
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute postinstallation code
|
||||
exec_postinst()
|
||||
{
|
||||
if [[ -z $POSTINSTLIST ]]; then
|
||||
return 0
|
||||
fi
|
||||
for pkg in $POSTINSTLIST; do
|
||||
if [[ $(function_exists postinst_$pkg) ]]; then
|
||||
prnt I "Exécution de la postinstallation de $pkg ..."
|
||||
postinst_$pkg
|
||||
fi
|
||||
done
|
||||
unset POSTINSTLIST
|
||||
}
|
||||
export -f exec_postinst
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute preremove code
|
||||
exec_prerm()
|
||||
{
|
||||
local cmd=$(echo $GET_REMOVELIST | sed "s/@pkg@/$@/")
|
||||
local pkglist=$($cmd)
|
||||
unset $cmd
|
||||
for pkg in $pkglist; do
|
||||
if [[ $(function_exists prerm_$pkg) ]]; then
|
||||
prnt I "Exécution du préretrait de $pkg ..."
|
||||
prerm_$pkg
|
||||
fi
|
||||
done
|
||||
export POSTRMLIST=$pkglist
|
||||
unset pkglist
|
||||
}
|
||||
export -f exec_prerm
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute postremove code
|
||||
exec_postrm()
|
||||
{
|
||||
if [[ -z $POSTRMLIST ]]; then
|
||||
return 0
|
||||
fi
|
||||
for pkg in $POSTRMLIST; do
|
||||
if [[ $(function_exists postrm_$pkg) ]]; then
|
||||
prnt I "Exécution de la postretrait de $pkg ..."
|
||||
postrm_$pkg
|
||||
fi
|
||||
done
|
||||
unset POSTRMLIST
|
||||
}
|
||||
export -f exec_postrm
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute preupgrade code
|
||||
exec_preupgd()
|
||||
{
|
||||
local pkglist=$($GET_UPGRADELIST)
|
||||
for pkg in $pkglist; do
|
||||
if [[ $(function_exists preupgd_$pkg) ]]; then
|
||||
prnt I "Exécution de la pré mise à jour de $pkg ..."
|
||||
preupgd_$pkg
|
||||
fi
|
||||
done
|
||||
export POSTUPGDLIST=$pkglist
|
||||
unset pkglist
|
||||
}
|
||||
export -f exec_preupgd
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute postupgrade code
|
||||
exec_postupgd()
|
||||
{
|
||||
if [[ -z $POSTUPGDLIST ]]; then
|
||||
return 0
|
||||
fi
|
||||
for pkg in $POSTUPGDLIST; do
|
||||
if [[ $(function_exists postupgd_$pkg) ]]; then
|
||||
prnt I "Exécution de la post mise à jour de $pkg ..."
|
||||
postupgd_$pkg
|
||||
fi
|
||||
done
|
||||
unset POSTUPGDLIST
|
||||
}
|
||||
export -f exec_postupgd
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute prerm code in autoremove context
|
||||
exec_preautorm()
|
||||
{
|
||||
local pkglist=$($GET_AUTOREMLIST)
|
||||
for pkg in $pkglist; do
|
||||
if [[ $(function_exists prerm_$pkg) ]]; then
|
||||
prnt I "Exécution du préretrait de $pkg ..."
|
||||
prerm_$pkg
|
||||
fi
|
||||
done
|
||||
export POSTRMLIST=$pkglist
|
||||
unset pkglist
|
||||
}
|
||||
export -f exec_preautorm
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Execute postrm code in autoremove context
|
||||
exec_postautorm()
|
||||
{
|
||||
exec_postrm
|
||||
}
|
||||
export -f exec_postautorm
|
||||
|
||||
|
||||
# EOF
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# * PKGSEL: List of package to install
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
export VER_install_pkg="0.1.1"
|
||||
export VER_install_pkg="0.1.2"
|
||||
export DEP_install_pkg="upgrade_dist"
|
||||
|
||||
install_pkg()
|
||||
@@ -21,7 +21,7 @@ install_pkg()
|
||||
# Remove unnecessary packages
|
||||
if [[ -n $PKGS_RMLIST ]]; then
|
||||
prnt I "Suppression de paquets supperflus..."
|
||||
pkgrem $PKGS_RMLIST
|
||||
pkgrm $PKGS_RMLIST
|
||||
fi
|
||||
|
||||
# Blacklist some anoying packages (and remove them if needed)
|
||||
@@ -33,7 +33,7 @@ install_pkg()
|
||||
sed -i -e "s/@pkg@/pkg/" $dest
|
||||
|
||||
# If blacklisted we suppose uninstall as well (if neeeded)
|
||||
pkgrem $pkg
|
||||
pkgrm $pkg
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -45,7 +45,7 @@ install_pkg()
|
||||
|
||||
# Cleaning
|
||||
prnt I "Suppression des paquets résiduels le cas échéant..."
|
||||
pkgautorem
|
||||
pkgautorm
|
||||
}
|
||||
|
||||
precheck_install_pkg()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# * PROXYAPTPORT: Working port for APT proxy
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
export VER_upgrade_dist="0.1.2"
|
||||
export VER_upgrade_dist="0.1.3"
|
||||
|
||||
# As aptitude might fail if clock is too far from real time, we need to depend
|
||||
# on ntp
|
||||
@@ -53,7 +53,7 @@ upgrade_dist()
|
||||
pkgupgd
|
||||
|
||||
prnt I "Suppression des paquets résiduels..."
|
||||
pkgautorem
|
||||
pkgautorm
|
||||
}
|
||||
|
||||
precheck_upgrade_dist()
|
||||
|
||||
Reference in New Issue
Block a user