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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
From: Marc Haber
Index: src/cron-apt
===================================================================
--- src/cron-apt (revision 1926)
+++ src/cron-apt (working copy)
@@ -93,51 +93,61 @@
CONFIG=/etc/cron-apt/config
fi
+############################## lib and tmp dirs ###############################
+
+LIBDIR="/var/lib/cron-apt"
+CONFIGDIRNAME="$(echo $CONFIG | sed 's|/|_-_|g')"
+TMPDIR="/tmp/cron-apt/$$"
+
+INITLOG="$TMPDIR/initlog"
+RUNERROR="$TMPDIR/runerror"
+RUNSYSLOG="$TMPDIR/runsyslog"
+RUNLOG="$TMPDIR/runlog"
+RUNMAIL="$TMPDIR/runmail"
+ACTIONERROR="$TMPDIR/actionerror"
+ACTIONSYSLOG="$TMPDIR/actionsyslog"
+ACTIONLOG="$TMPDIR/actionlog"
+ACTIONMAIL="$TMPDIR/actionmail"
+TEMP="$TMPDIR/temp"
+MAIL="$TMPDIR/mail"
+DIFF="$TMPDIR/difftemp"
+STATUS="$TMPDIR/status"
+
+LOCKFILE="$LIBDIR/lockfile"
+MAILCHDIR="$LIBDIR/$CONFIGDIRNAME/mailchanges"
+ERROR="$TMPDIR/$CONFIGDIRNAME/error"
+
############################## defaults #######################################
-ACTIONDIR=/etc/cron-apt/action.d
-ACTIONCONFDIR=/etc/cron-apt/config.d
-MAILMSGDIR=/etc/cron-apt/mailmsg.d
-MAILONMSGSDIR=/etc/cron-apt/mailonmsgs
-SYSLOGONMSGSDIR=/etc/cron-apt/syslogonmsgs
-ERRORMSGDIR=/etc/cron-apt/errormsg.d
-SYSLOGMSGDIR=/etc/cron-apt/syslogmsg.d
-LOGMSGDIR=/etc/cron-apt/logmsg.d
-RUNERROR=/var/lib/cron-apt/runerror
-ACTIONERROR=/var/lib/cron-apt/actionerror
-ERROR=/var/log/cron-apt/error
-TEMP=/var/lib/cron-apt/temp
-RUNMAIL=/var/lib/cron-apt/runmail
-ACTIONMAIL=/var/lib/cron-apt/actionmail
-MAIL=/var/log/cron-apt/mail
-RUNSYSLOG=/var/lib/cron-apt/runsyslog
-RUNLOG=/var/lib/cron-apt/runlog
-ACTIONSYSLOG=/var/lib/cron-apt/actionsyslog
-ACTIONLOG=/var/lib/cron-apt/actionlog
-INITLOG=/var/lib/cron-apt/initlog
-LOG=/var/log/cron-apt/log
-DIFF=/var/lib/cron-apt/difftemp
-DIFFONCHANGES=prepend
-MAILCHDIR=/var/lib/cron-apt/mailchanges
-STATUS=/var/lib/cron-apt/status
-MAILTO=root
+
+ACTIONDIR="/etc/cron-apt/action.d"
+ACTIONCONFDIR="/etc/cron-apt/config.d"
+MAILMSGDIR="/etc/cron-apt/mailmsg.d"
+MAILONMSGSDIR="/etc/cron-apt/mailonmsgs"
+SYSLOGONMSGSDIR="/etc/cron-apt/syslogonmsgs"
+ERRORMSGDIR="/etc/cron-apt/errormsg.d"
+SYSLOGMSGDIR="/etc/cron-apt/syslogmsg.d"
+LOGMSGDIR="/etc/cron-apt/logmsg.d"
+LOG="/var/log/cron-apt/log"
+DIFFONCHANGES="prepend"
+MAILTO="root"
# error, always, never
-SYSLOGON=upgrade
+SYSLOGON="upgrade"
# error, always
-MAILON=error
+MAILON="error"
# error, never
-EXITON=error
+EXITON="error"
# verbose, error
-DEBUG=verbose
+DEBUG="verbose"
# general options
-OPTIONS=-q
+OPTIONS="-q"
# do always run as default
-DONTRUN=
+DONTRUN=""
# Random sleep time before run
-RUNSLEEP=3600
+RUNSLEEP="3600"
-export DEBIAN_FRONTEND=noninteractive
-export LANG=C
-export LC_ALL=C
+export DEBIAN_FRONTEND="noninteractive"
+export LANG="C"
+export LC_ALL="C"
# Read configuration.
if [ -f "$CONFIG" ] ; then
@@ -193,6 +203,10 @@
mail -s "$SUBJECT" "$MAILTO" < "$MAIL"
rm -f "$MAIL"
fi
+ TMPDIR=$(echo $TMPDIR | sed 's|^/tmp/cron-apt||')
+ if [ -e "/tmp/cron-apt/$TMPDIR" ]; then
+ rm -rf "/tmp/cron-apt/$TMPDIR"
+ fi
}
# Do the actual msg transfer. This reduce some duplications.
@@ -296,6 +310,12 @@
############################### check #########################################
+if ! [ -d "$LIBDIR/$CONFIGDIRNAME" ]; then
+ mkdir -p "$LIBDIR/$CONFIGDIRNAME"
+fi
+if ! [ -d "$MAILCHDIR" ]; then
+ mkdir -p "$MAILCHDIR"
+fi
if [ -e "$ERROR" ] && [ "$DONTRUN" = "error" ] ; then
echo "Error in last update. Fix the problem and remove $ERROR."
exit
@@ -309,6 +329,11 @@
############################### sleep #########################################
+if [ -e "$TMPDIR" ]; then
+ echo "Error: $TMPDIR does already exist."
+ exit
+fi
+mkdir -p "$TMPDIR"
echo "CRON-APT RUN [$CONFIG]: $(date)" > $INITLOG
if [ -n "$RUNSLEEP" ] ; then
if [ $RUNSLEEP -gt 0 ] ; then
@@ -345,7 +370,15 @@
grep -v "^[[:space:]]*$" | {
while read LINE ; do
echo "CRON-APT LINE: $LINE" > "$TEMP"
- if ! apt-get $OPTIONS $LINE >> $TEMP 2>&1 ; then
+ if ! dotlockfile -l -p -r 10 $LOCKFILE; then
+ echo > $TEMP "cannot acquire apt lock."
+ RET=1
+ else
+ apt-get $OPTIONS $LINE >> $TEMP 2>&1
+ RET=$?
+ fi
+ dotlockfile -u $LOCKFILE
+ if [ $RET -ne 0 ]; then
# ---
# An error has occured.
createerrorinfo $ACTIONF
|