#!/bin/sh [ -f /etc/default/aptitude-robot ] && . /etc/default/aptitude-robot if [ ! -x /usr/sbin/aptitude-robot ]; then exit # aptitude-robot has been deinstalled but not purged fi if fuser -s /var/lib/dpkg/lock ; then echo 'another package manager is running. Exiting.' 1>&2 exit 1 fi if [ -n "$LOG_SESSION" ] ; then # the session log is made unique with a PID ending # so as to not overwrite an old log of a crashed aptitude-robot process LOG_SESSION="$LOG_SESSION".$$ touch "$LOG_SESSION" # only redirect STDOUT+STDERR if session log is available if [ -f "$LOG_SESSION" ]; then exec 1>"$LOG_SESSION" 2>&1 fi fi cleanup () { # finish session log echo "aptitude-robot ended at" $(date --rfc-3339=seconds) echo "" if [ -n "$LOG_SESSION" -a -f "$LOG_SESSION" ]; then # append session log to permanent log file if [ -n "$LOGFILE" ]; then touch "$LOGFILE" # create the log file if necessary if [ -f "$LOGFILE" ]; then cat "$LOG_SESSION" >> "$LOGFILE" fi fi # optionally process session log for reporting if [ -x "$SESSION_REPORT_COMMAND" ]; then "$SESSION_REPORT_COMMAND" "$LOG_SESSION" fi rm "$LOG_SESSION" fi } trap cleanup INT TERM QUIT HUP EXIT set -e echo "aptitude-robot started at" $(date --rfc-3339=seconds) # prevent infinite loops by limiting log file sizes MAX_LOGFILES_SIZE_BLOCKS=$(($MAX_LOGFILES_SIZE_BLOCKS + 0)) # force number [ $MAX_LOGFILES_SIZE_BLOCKS -gt 0 ] && ulimit -f $MAX_LOGFILES_SIZE_BLOCKS # called from a script aptitude should ask as few questions as possible # and just take the defaults. We expect the configuration management # to have provided the necessary config options beforehand DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND DEBIAN_PRIORITY=critical export DEBIAN_PRIORITY # -q (for --quiet) suppresses percentage reporting for downloads # but leaves most regular output to be collected in the log file /usr/bin/aptitude -q update if egrep -q '[EW]: Failed to fetch ' "$LOG_SESSION"; then echo "E: aptitude-robot failed to fetch some APT repositories. Aborting." exit 2 fi touch /var/lib/apt/update_success /usr/sbin/aptitude-robot -y -q "$@" \ -o DPkg::Options::=--force-confdef \ -o DPkg::Options::=--force-confold \ < /dev/null if [ -n "$POST_SESSION_HOOK" ]; then $POST_SESSION_HOOK fi