| 1 |
#!/bin/sh |
| 2 |
[ -f /etc/default/aptitude-robot ] && . /etc/default/aptitude-robot |
| 3 |
|
| 4 |
if [ ! -x /usr/sbin/aptitude-robot ]; then |
| 5 |
exit # aptitude-robot has been deinstalled but not purged |
| 6 |
fi |
| 7 |
|
| 8 |
if fuser -s /var/lib/dpkg/lock ; then |
| 9 |
echo 'another package manager is running. Exiting.' 1>&2 |
| 10 |
exit 1 |
| 11 |
fi |
| 12 |
|
| 13 |
if [ -n "$LOG_SESSION" ] ; then |
| 14 |
# the session log is made unique with a PID ending |
| 15 |
# so as to not overwrite an old log of a crashed aptitude-robot process |
| 16 |
LOG_SESSION="$LOG_SESSION".$$ |
| 17 |
touch "$LOG_SESSION" |
| 18 |
# only redirect STDOUT+STDERR if session log is available |
| 19 |
if [ -f "$LOG_SESSION" ]; then |
| 20 |
exec 1>"$LOG_SESSION" 2>&1 |
| 21 |
fi |
| 22 |
fi |
| 23 |
|
| 24 |
cleanup () { |
| 25 |
# finish session log |
| 26 |
echo "aptitude-robot ended at" $(date --rfc-3339=seconds) |
| 27 |
echo "" |
| 28 |
if [ -n "$LOG_SESSION" -a -f "$LOG_SESSION" ]; then |
| 29 |
# append session log to permanent log file |
| 30 |
if [ -n "$LOGFILE" ]; then |
| 31 |
touch "$LOGFILE" # create the log file if necessary |
| 32 |
if [ -f "$LOGFILE" ]; then |
| 33 |
cat "$LOG_SESSION" >> "$LOGFILE" |
| 34 |
fi |
| 35 |
fi |
| 36 |
# optionally process session log for reporting |
| 37 |
if [ -x "$SESSION_REPORT_COMMAND" ]; then |
| 38 |
"$SESSION_REPORT_COMMAND" "$LOG_SESSION" |
| 39 |
fi |
| 40 |
rm "$LOG_SESSION" |
| 41 |
fi |
| 42 |
} |
| 43 |
trap cleanup INT TERM QUIT HUP EXIT |
| 44 |
set -e |
| 45 |
|
| 46 |
echo "aptitude-robot started at" $(date --rfc-3339=seconds) |
| 47 |
|
| 48 |
# prevent infinite loops by limiting log file sizes |
| 49 |
MAX_LOGFILES_SIZE_BLOCKS=$(($MAX_LOGFILES_SIZE_BLOCKS + 0)) # force number |
| 50 |
[ $MAX_LOGFILES_SIZE_BLOCKS -gt 0 ] && ulimit -f $MAX_LOGFILES_SIZE_BLOCKS |
| 51 |
|
| 52 |
# called from a script aptitude should ask as few questions as possible |
| 53 |
# and just take the defaults. We expect the configuration management |
| 54 |
# to have provided the necessary config options beforehand |
| 55 |
DEBIAN_FRONTEND=noninteractive |
| 56 |
export DEBIAN_FRONTEND |
| 57 |
DEBIAN_PRIORITY=critical |
| 58 |
export DEBIAN_PRIORITY |
| 59 |
|
| 60 |
# -q (for --quiet) suppresses percentage reporting for downloads |
| 61 |
# but leaves most regular output to be collected in the log file |
| 62 |
/usr/bin/aptitude -q update |
| 63 |
|
| 64 |
if egrep -q '[EW]: Failed to fetch ' "$LOG_SESSION"; then |
| 65 |
echo "E: aptitude-robot failed to fetch some APT repositories. Aborting." |
| 66 |
exit 2 |
| 67 |
fi |
| 68 |
|
| 69 |
touch /var/lib/apt/update_success |
| 70 |
|
| 71 |
/usr/sbin/aptitude-robot -y -q "$@" \ |
| 72 |
-o DPkg::Options::=--force-confdef \ |
| 73 |
-o DPkg::Options::=--force-confold \ |
| 74 |
< /dev/null |
| 75 |
|
| 76 |
if [ -n "$POST_SESSION_HOOK" ]; then |
| 77 |
$POST_SESSION_HOOK |
| 78 |
fi |