## tidy loose ends... set -e # fix mark auto-installed essential packages and their dependencies _pkgdeps(){ set -e chroot /target dpkg-query -Wf=',${Pre-Depends},${Depends},${Recommends}\n' $* 2>/dev/null|sed -r -e 's/[,|] *([a-z0-9.+-]+)?(:\s+)?( *[^|,]*)?/\1\n/g'|sed '/^$/d'|sort -u; } _pkg2re(){ set -e echo $*|sed -r -e 's/\s+/\|/g;s/^\|//;s/([.+-])/\\\1/g;s/\|$//'; } _pkgreal(){ set -e chroot /target dpkg-query -Wf='${Package},${Provides},\n'|sed -r "/,,/d;s/^([a-z0-9.+-]+).*[,|] *($(_pkg2re $*))[ :,]/\1/;/,/d"; } _pkganddeepdeps(){ set -e local rest=$* local all=$rest for i in 1 2 3 4 5 do local deps=$(_pkgdeps $rest) rest="$deps $(_pkgreal $deps)" all="$all $rest" done echo $all|sed -r 's/\s+/\n/g'|sort -u; } essentials=$(chroot /target dpkg-query -Wf='${Package}%${Essential}\n'|sed -r 's/(.*)%yes/\1/;/%/d') chroot /target apt-mark auto $(_pkganddeepdeps $essentials apt linux-image-*) # fix mark auto-installed d-i installed packages unusable on their own chroot /target apt-mark auto aptitude-common grub-common isc-dhcp-common tasksel-data vim-common # keep backup of any tweaked (i.e. edited or created) config file _backup(){ set -e [ -e "$1.orig" ] || if [ -e "$1" ]; then cp -a "$1" "$1.orig" else touch "$1.orig" fi; } _clone(){ set -e _backup "$2" cp -a "$1" "$2"; } _setvar(){ set -e _backup "$1" sed -i -r -e "s,^#?($2)=.*,\\1=$3," "$1"; } ## non-technical operation # auto-repair inconsistent filesystems during boot _setvar /target/etc/default/rcS FSCKFIX yes