1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#!/bin/sh
# postrm script for di-netboot-assistant
set -eu
DL_CACHE=/var/cache/di-netboot-assistant/
STATUS_LIB=/var/lib/di-netboot-assistant
TFTP_ROOT=/var/lib/tftpboot
N_A_DIR=d-i/n-a
if [ -e /etc/di-netboot-assistant/di-netboot-assistant.conf ] ; then
. /etc/di-netboot-assistant/di-netboot-assistant.conf
fi
if [ -f $STATUS_LIB/.old-conf-for-purge ]; then
# shellcheck source=/dev/null
. $STATUS_LIB/.old-conf-for-purge
fi
#This function should be kept in sync with function "uninstall_repo" in di-netboot-assistant
uninstall_repo() {
dist_conf="$1" # Repository's .conf file
local s metadatabasename expand_dir dist_dir
metadatabasename="${dist_conf%.conf}"
expand_dir="$(grep -E "^[[:blank:]]*expand_dir=" "$dist_conf" | sed -e 's/^[[:blank:]]*expand_dir=//')"
[ "$expand_dir" != "/" ] && [ -d "$expand_dir" ] && rm -Rf "$expand_dir"
dist_dir=$(dirname "$expand_dir")
rmdir --ignore-fail-on-non-empty "$dist_dir"
s="$metadatabasename.pxelinux.menu.fragment"
[ -f "$s" ] && rm "$s"
s="$metadatabasename.uboot.menu.fragment"
[ -f "$s" ] && rm "$s"
s="$metadatabasename.grub.menu.fragment"
[ -f "$s" ] && rm "$s"
s="$metadatabasename.pxelinux.menu.serial-9600.fragment"
[ -f "$s" ] && rm "$s"
rm "$dist_conf"
}
#This function should be kept in sync with function "url2filename" in di-netboot-assistant
url2filename() {
sed -e 's#//\+#/#g' -e 's#[^[:alnum:]@+_~\.-]#_#g'
}
#This function should be kept in sync with function "remove_repocache" in di-netboot-assistant
remove_repocache() {
local metadatafile="$1" # repository to uncache
local base file
base="${metadatafile%~~*}"
sed -n -e 's/^[[:blank:]]*dl_file=[[:blank:]]*//p' "$metadatafile" | while read -r file ; do
rm "${base}_$(echo "$file" | url2filename)"
done
#Purge remaing files (MD5SUMs...) if there are no more cached
#distribution from the same repository.
if ! echo "${base}~~"*.meta | grep -qv "$metadatafile" ; then
rm "${base}"_*
fi
[ -f "$metadatafile" ] && rm "$metadatafile"
}
case "$1" in
purge)
if [ -d $STATUS_LIB ]; then
for x in "$STATUS_LIB"/*.conf ; do
[ -f "$x" ] || continue
uninstall_repo "$x"
done
if [ -d "$DL_CACHE" ]; then
for metadatafile in "$DL_CACHE"/*~~*--*.meta ; do
remove_repocache "$metadatafile"
done
fi
for lnk in grubx64.efi grub ; do
if [ "$TFTP_ROOT/$lnk" -ef "$TFTP_ROOT/$N_A_DIR/$lnk" ] ; then
rm "$TFTP_ROOT/$lnk" || true
fi
done
for x in pxelinux.0 elilo.conf elilo.efi README.txt boot.ipxe \
pxelinux.cfg/default pxelinux.cfg/default.mig-bak \
pxelinux.cfg/menu.c32 pxelinux.cfg/vesamenu.c32 \
ldlinux.c32 libcom32.c32 libutil.c32 \
bootnetx64.efi grubx64.efi \
; do
f="$TFTP_ROOT/$N_A_DIR/$x"
if [ -f "$f" ] || [ -L "$f" ] ; then
rm "$f" || true
fi
done
# shellcheck disable=SC2015
[ -d "$TFTP_ROOT/$N_A_DIR/grub" ] && rm -r "$TFTP_ROOT/$N_A_DIR/grub" || true
for x in $N_A_DIR/pxelinux.cfg $N_A_DIR ; do
f="$TFTP_ROOT/$x"
# shellcheck disable=SC2015
[ -d "$f" ] && rmdir --ignore-fail-on-non-empty "$f" || true
done
if [ -f $STATUS_LIB/.old-conf-for-purge ]; then
rm $STATUS_LIB/.old-conf-for-purge || true
fi
rmdir --ignore-fail-on-non-empty $STATUS_LIB
fi
;;
remove)
if [ -f /etc/di-netboot-assistant/di-netboot-assistant.conf ]; then
[ ! -d $STATUS_LIB ] && mkdir $STATUS_LIB
sed -e "1s/^/#BACKUP, to purge our TFTP stuff when purged\n/" \
< /etc/di-netboot-assistant/di-netboot-assistant.conf \
> $STATUS_LIB/.old-conf-for-purge
fi
;;
upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
|