#!/bin/bash # $HeadURL$ $LastChangedRevision$ # Modules . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } # Configurable stuff # Other globals export DEBIAN_FRONTEND=noninteractive EATMYDATA_SHLIB=/usr/lib/x86_64-linux-gnu/libeatmydata.so APT_GET_FILTER_REGEXPS=( '^.* is a disabled or a static unit, not starting it\.$' '^Adding user .* to group .*$' '^Configuration file .*, does not exist on system\.$' '^Created symlink /etc/systemd/system/.*\.$' '^Creating config file .* with new version$' '^Executing: /lib/systemd/systemd-sysv-install .*$' '^File descriptor .* \(/dev/tty.*\) leaked on lvs invocation\. .*$' '^Installing new config file as you requested\.$' '^Leaving .diversion of .* to .* by .*.$' '^Preconfiguring packages \.\.\.$' '^Preparing to unpack \.\.\.$' '^Processing triggers for .* \.\.\.$' '^Reading database \.\.\.$' '^Selecting previously unselected package$' '^Setting up .* \.\.\.$' '^Synchronizing state of .* with SysV service script with .*$' '^Unpacking .* \.\.\.$' '^Unpacking .* over .* \.\.\.$' '^update-alternatives: using .* to provide .* \(.*\) in auto mode$' '^update-initramfs: Generating /boot/.*$' '^update-initramfs: deferring update \(trigger activated\)$' '^Installing new version of config file /etc/.* \.\.\.$' '^Skipping profile in /etc/apparmor.d/disable: .*$' ) main() { local MY_ARGS local VERB PKG # Defaults for options VERBOSELEVEL=2 # Process options miniade_process_options --help-handler=help MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments [ $# -ge 1 ] || miniade_bad_usage VERB=$1 shift # Sanity checks and derivations if [ $VERB = upgrade ]; then VERB=dist-upgrade miniade_warning "'upgrade' argument remapped to 'dist-upgrade'" fi case $VERB in install|remove|update|dist-upgrade|autoremove|foster|orphan) : ;; *) miniade_bad_usage ;; esac # Guts miniade_debug 10 "main: calling [$VERB $*] ..." ${VERB//-/_} "$@" miniade_debug 10 "main: done" } help() { local PROGNAME miniade_get_progname PROGNAME echo "Usage: $PROGNAME [ ] {install|remove|update|dist-upgrade|autoremove} [ >" exit 0 } package_is_installed() { local PKG PKG=$1 miniade_debug 10 "package_is_installed: PKG=$PKG" #[ -f /var/lib/dpkg/info/$PKG.list ] || return 1 { dpkg-query -f '${binary:Package}\n' -W | fgrep -qx -e $PKG -e $PKG:amd64 -e $PKG:i386; } || return 1 } install() { local PKG PKG=$1 # Install package if necessary if ! package_is_installed $PKG; then filter_apt_get_blurb eatmydata_if_possible apt-get -y -qq --purge --reinstall --no-install-recommends -o DPkg::options::=--force-confmiss,confnew install $PKG < /dev/null package_is_installed $PKG || miniade_error "$PKG: tried to install but failed (hints: see messages above)" fi # touch needed so make can reference time of installation. touch /var/lib/dpkg/info/$PKG.list foster $PKG } foster() { local PKG PKG=$1 mkdir -p /var/lib/debfoster . $(pcms-config PCMS_SHARE_PREFIX)/scripts/lineinfile --after=EOF --text=$PKG --file=/var/lib/debfoster/keepers } orphan() { local PKG PKG=$1 mkdir -p /var/lib/debfoster cat /var/lib/debfoster/keepers /dev/null > /tmp/package.$$.keepers 2>/dev/null || true fgrep -vx $PKG /tmp/package.$$.keepers > /var/lib/debfoster/keepers || true rm -f /tmp/package.$$.keepers } remove() { local PKG PKG=$1 miniade_debug 10 "remove: PKG=$PKG" # Remove package if necessary miniade_debug 10 "remove: checking if package is installed ..." if package_is_installed $PKG; then miniade_debug 10 "remove: package is installed; removing it ..." filter_apt_get_blurb eatmydata_if_possible apt-get -y -qq --purge autoremove $PKG < /dev/null { ! package_is_installed $PKG; } || miniade_error "$PKG: tried to remove but failed (hints: see messages above)" fi orphan $PKG } update() { filter_apt_get_blurb eatmydata_if_possible apt-get -qq update < /dev/null } dist_upgrade() { filter_apt_get_blurb eatmydata_if_possible apt-get -y -qq -o DPkg::options::=--force-confdef,confold dist-upgrade < /dev/null } autoremove() { filter_apt_get_blurb eatmydata_if_possible apt-get -y -qq --purge autoremove < /dev/null } filter_apt_get_blurb() { local RC miniade_debug 10 "filter_apt_get_blurb: calling [$*] ..." "$@" > /tmp/package.$$.stdout 2>/tmp/package.$$.stderr || RC=$? egrep -v -f <(printf '%s\n' "${XS[@]}") /tmp/package.$$.stdout || true cat /tmp/package.$$.stderr >&2 rm -f /tmp/package.$$.stdout /tmp/package.$$.stderr return $RC } eatmydata_if_possible() { if [ -f $EATMYDATA_SHLIB ]; then LD_PRELOAD=$EATMYDATA_SHLIB "$@" else miniade_warning "eatmydata library not found (this should not happen); acting without it ..." "$@" fi } main "$@"