refactor remove function
- use one awk command instead of two, to determine if package is not removable - save comparison files to /etc/setup instead of /tmp - save as "essential.lst" and "$pkg.lst" respectively - use warnings where appropriate - new file list logic - extract file list - if package is essential, remove file list and exit - if package is not essential, remove package, remove file list and continue - new delete logic - remove all files - remove empty directories - utilize awk inplace where appropriate
This commit is contained in:
parent
dcd9b3d56d
commit
db7bada3d2
67
apt-cyg
67
apt-cyg
|
@ -449,51 +449,60 @@ function apt-install {
|
||||||
|
|
||||||
function apt-remove {
|
function apt-remove {
|
||||||
check-packages
|
check-packages
|
||||||
|
cd /etc
|
||||||
|
cygcheck awk bash bunzip2 grep gzip mv sed tar xz > setup/essential.lst
|
||||||
for pkg in "${pks[@]}"
|
for pkg in "${pks[@]}"
|
||||||
do
|
do
|
||||||
|
|
||||||
if ! grep -q "^$pkg " /etc/setup/installed.db
|
if ! grep -q "^$pkg " setup/installed.db
|
||||||
then
|
then
|
||||||
echo Package $pkg is not installed, skipping
|
echo Package $pkg is not installed, skipping
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cygcheck awk bash bunzip2 grep gzip mv sed tar xargs xz | awk '
|
if [ ! -e setup/"$pkg".lst.gz ]
|
||||||
/bin/ &&
|
|
||||||
!fd[$NF]++ &&
|
|
||||||
$0 = $NF
|
|
||||||
' FS='\\' > /tmp/cygcheck.txt
|
|
||||||
|
|
||||||
apt-cyg listfiles $pkg | awk '
|
|
||||||
$0 = $NF
|
|
||||||
' FS=/ > /tmp/listfiles.txt
|
|
||||||
|
|
||||||
if grep -xf /tmp/cygcheck.txt /tmp/listfiles.txt
|
|
||||||
then
|
then
|
||||||
echo apt-cyg cannot remove package $pkg, exiting
|
warn Package manifest missing, cannot remove $pkg. Exiting
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ! -e /etc/setup/"$pkg".lst.gz ]
|
gzip -dfk setup/"$pkg".lst.gz
|
||||||
then
|
awk '
|
||||||
echo Package manifest missing, cannot remove $pkg. Exiting
|
NR == FNR {
|
||||||
|
if ($NF) ess[$NF]
|
||||||
|
next
|
||||||
|
}
|
||||||
|
$NF in ess {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
}
|
||||||
|
' FS='[/\\\\]' setup/{essential,$pkg}.lst
|
||||||
|
esn=$?
|
||||||
|
if [ $esn = 0 ]
|
||||||
|
then
|
||||||
echo Removing $pkg
|
echo Removing $pkg
|
||||||
|
if [ -e preremove/"$pkg".sh ]
|
||||||
# run preremove scripts
|
|
||||||
|
|
||||||
if [ -e /etc/preremove/"$pkg".sh ]
|
|
||||||
then
|
then
|
||||||
/etc/preremove/"$pkg".sh
|
preremove/"$pkg".sh
|
||||||
rm /etc/preremove/"$pkg".sh
|
rm preremove/"$pkg".sh
|
||||||
fi
|
fi
|
||||||
gzip -cd /etc/setup/"$pkg".lst.gz | sed '\./$.d;s.^./.' | xargs rm -f
|
mapfile dt < setup/"$pkg".lst
|
||||||
rm /etc/setup/"$pkg".lst.gz
|
for each in ${dt[*]}
|
||||||
rm -f /etc/postinstall/$pkg.sh.done
|
do
|
||||||
awk '$1 != pkg' pkg="$pkg" /etc/setup/installed.db > /tmp/awk.$$
|
[ -f /$each ] && rm /$each
|
||||||
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
done
|
||||||
mv /tmp/awk.$$ /etc/setup/installed.db
|
for each in ${dt[*]}
|
||||||
|
do
|
||||||
|
[ -d /$each ] && rmdir --i /$each
|
||||||
|
done
|
||||||
|
rm -f setup/"$pkg".lst.gz postinstall/"$pkg".sh.done
|
||||||
|
awk -i inplace '$1 != ENVIRON["pkg"]' setup/installed.db
|
||||||
echo Package $pkg removed
|
echo Package $pkg removed
|
||||||
|
fi
|
||||||
|
rm setup/"$pkg".lst
|
||||||
|
if [ $esn = 1 ]
|
||||||
|
then
|
||||||
|
warn apt-cyg cannot remove package $pkg, exiting
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue