summaryrefslogtreecommitdiffstats
path: root/etc/sbuild-debian-developer-setup-update-all
blob: 9605e45e70bf4acf8df5f1f8d37ca743f618a0ac (plain)
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
#!/bin/sh
# Example script for automatically updating sbuild chroots
#
# Simply create a crontab /etc/cron.d/sbuild-update-all and specify the
# schedule that you want to use. The behaviour of this script can be influenced
# by the following evironment variables:
#
#   PATTERN     glob pattern to match the chroot config name against, in
#               directory /etc/schroot/chroot.d/.
#
#               Default: *-sbuild
#
#   UPDATEARGS  The arguments with which sbuild-update will be invoked.
#
#               Default: --update --dist-upgrade --autoclean --autoremove
#
#   LOGFILE     Log file to write to. These files are not rotated, you must set
#               this up yourself. See logrotate(8)
#
#               Default: /var/log/sbuild-update-all.log
#
# This script will refuse to run if another instance of it is running. In fact,
# it will refuse to run if there is an active chroot session (regardless of
# whether it is related to the matched patterns or not). Care for this must be
# taken when scheduling cron jobs, as crontabs are processed sequentially (with
# regards to variable assignment), but jobs are executed in parallel. 
#
# Examples
# ========
#
# 1. Update all sbuild chroots four times a day (at 00:15/06:15/12:15/18:15):
#
#     15 */6 * * * root /usr/share/doc/sbuild/examples/sbuild-debian-developer-setup-update-all
#
# 2. Update all sid sbuild chroots daily, and all jessie sbuild chroots weekly,
#    and log the latter to a separate file:
#
#     PATTERN = sid-*-sbuild
#     @daily    root /usr/share/doc/sbuild/examples/sbuild-debian-developer-setup-update-all
#
#     PATTERN = jessie-*-sbuild
#     LOGFILE = /var/log/wheezy-chroot-update.log
#     @weekly   root /usr/share/doc/sbuild/examples/sbuild-debian-developer-setup-update-all
#
# The following will NOT work. Both of these jobs are executed at 00:15, so
# the second one will refuse to run:
#
#     PATTERN = foo-*
#     15 0  * * * root /usr/share/doc/sbuild/examples/sbuild-debian-developer-setup-update-all
#
#     PATTERN = bar-*
#     15 0  * * * root /usr/share/doc/sbuild/examples/sbuild-debian-developer-setup-update-all


# Output of sbuild-update invocations will be written to this file
LOGFILE=${LOGFILE:-/var/log/sbuild-update-all.log}

# Arguments passed to sbuild-update
UPDATEARGS=${UPDATEARGS:-"--update --dist-upgrade --autoclean --autoremove"}

# chroot config names are identified by this pattern
PATTERN=${PATTERN:-*-sbuild-*}


# Open logfile for output, make sure we're the only instance active
exec 8>>$LOGFILE
if ! flock -x -n 8
then
	echo "$0: another instance is already running"
	exit 1
fi
# Redirect stdout to logfile
exec 9>&1
exec 1>&8

if ! ls /etc/schroot/chroot.d/$PATTERN >/dev/null 2>&1
then
	echo "No chroots defined"
	exit 0
fi

for fullname in /etc/schroot/chroot.d/$PATTERN
do
	confname=`basename $fullname | sed -e "s/-sbuild-.*//"`
    
	# Check for *any* active session and skip if there is one.
	# chroots can share common factors, for example an LVM volume, so it's
	# better to be safe than sorry.
	if  [ -n "`schroot -l --all-sessions`" ]
	then
		echo "Active schroot session, will not continue"
		break
	fi

	echo "****** `date` ******"
	echo "Action: sbuild-update $UPDATEARGS $confname"

	if ! sbuild-update $UPDATEARGS $confname
	then
		echo "ERROR: failed to update $confname"
		continue
	fi
done

# Release lock and undo redirections
exec 8>&- 1>&9 9>&-