]> git.donarmstrong.com Git - dak.git/blob - config/debian/common
88cb6abf090a0efb3da5ab090f5d212f09588bf2
[dak.git] / config / debian / common
1 # -*- mode:sh -*-
2 # log something (basically echo it together with a timestamp)
3 #
4 # Set $PROGRAM to a string to have it added to the output.
5 function log () {
6         local prefix=${PROGRAM:-}
7         echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${prefix}[$$]: $@"
8 }
9
10 # log the message using log() but then also send a mail
11 # to the address configured in MAILTO (if non-empty)
12 function log_error () {
13         log "$@"
14         if [ -z "${MAILTO}" ]; then
15                 echo "$@" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}  -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
16         fi
17 }
18
19 # debug log, only output when DEBUG=1
20 function debug () {
21     if [ $DEBUG -eq 1 ]; then
22         log "$*"
23     fi
24 }
25
26 function wbtrigger() {
27     SSHOPT="-o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
28     if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
29         ssh -q -q ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.often
30     fi
31     rm -f "${LOCK_BUILDD}"
32 }
33
34 # used by cron.dinstall *and* cron.unchecked.
35 function make_buildd_dir () {
36     # We generate straight into the static mirror location for incoming
37     dak manage-build-queues -a
38     dak generate-packages-sources2 -a build-queues
39     dak generate-releases -a build-queues >/dev/null
40
41     # And set up all of the top level symlinks people seem to like
42     find ${incoming}/web -maxdepth 1 -type l -delete
43     dak export-suite -r -s "accepted" -d "$incoming/web"
44
45     # For now, we still create the local incoming.d.o setup
46     ${scriptsdir}/update-buildd-archive ${incoming}/web/debian-buildd ${incoming}/debian-buildd
47     rm -f ${incoming}/public/*
48     dak export-suite -s "accepted" -d "$incoming/public"
49
50     # Tell the mirrors that we've updated
51     chronic /usr/local/bin/static-update-component incoming.debian.org
52 }
53
54 # Process (oldstable)-proposed-updates "NEW" queue
55 function punew_do() {
56     local queue="$1"
57     local qdir="$2"
58     local to="${3}"
59
60     date -u -R >> REPORT
61     dak process-policy "${queue}" | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in ${queue}" "${to}" -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
62     echo >> REPORT
63
64     dak generate-packages-sources2 -s "${queue}"
65
66     STAMP=${STAMP:-$(date "+%Y%m%d%H%M")}
67
68     local exportdir="${qdir}/tree/${STAMP}"
69     local targetdir="${qdir}/export"
70     dak export -q "${queue}" -d "${exportdir}" --all
71     ln -sfT ${exportdir} ${targetdir}
72     find "${qdir}/tree" -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
73 }
74
75 # These versions used in dinstall
76 function punew() {
77     if [ "${PROGRAM}" = "dinstall" ]; then
78         log "Doing automated p-u-new processing"
79     fi
80     cd "${queuedir}/p-u-new"
81     punew_do "$1" "${queuedir}/p-u-new" "debian-release@lists.debian.org"
82 }
83
84 function opunew() {
85     if [ "${PROGRAM}" = "dinstall" ]; then
86         log "Doing automated o-p-u-new processing"
87     fi
88     cd "${queuedir}/o-p-u-new"
89     punew_do "$1" "${queuedir}/o-p-u-new" "debian-release@lists.debian.org"
90 }
91
92 function backports_policy() {
93     local queue="backports-policy"
94     local qdir="/srv/backports-master.debian.org/queue/policy"
95     local to="backports-team@debian.org"
96
97     if [ "${PROGRAM}" = "dinstall" ]; then
98         log "Doing automated ${queue} processing"
99     fi
100
101     cd "${qdir}"
102     punew_do "${queue}" "${qdir}" "${to}"
103 }
104
105 # Do the unchecked processing, in case we have files.
106 function do_unchecked () {
107     cd $unchecked
108
109     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
110     report=$queuedir/REPORT
111     timestamp=$(date "+%Y-%m-%d %H:%M")
112     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
113
114     echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
115     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
116     dak process-commands -d "$unchecked" >> $report
117 }
118
119 # process NEW policy queue
120 function do_new () {
121     if [ "${PROGRAM}" = "dinstall" ]; then
122         log "Doing NEW processing"
123     fi
124     (dak process-policy new; dak process-policy byhand) | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND processing" ftpmaster@ftp-master.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
125
126     dak process-policy backports-new | mail -a "X-Debian: DAK" -e -s "NEW processing for backports-new" backports-team@debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
127
128     dak clean-suites -a new,backports-new
129 }
130
131 function sync_debbugs () {
132     # sync with debbugs
133     echo "--" >> $report
134     timestamp=$(date "+%Y-%m-%d-%H:%M")
135     mkdir -p $queuedir/bts_version_track_archive/${timestamp}
136     rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
137     rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
138     rsync -aq -e "ssh -o Batchmode=yes -o ConnectTimeout=30 -o SetupTimeout=30" --remove-source-files  $queuedir/bts_version_track/ bugs-sync:/org/bugs.debian.org/versions/queue/ftp-master/ 2>/dev/null && touch $lockdir/synced_bts_version || true
139     NOW=$(date +%s)
140     TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
141     DIFF=$(( NOW - TSTAMP ))
142     if [ $DIFF -ge 259200 ]; then
143         log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
144     fi
145 }
146
147 function clean_debbugs () {
148     # Delete files older than 60 days
149     find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
150     # Delete empty directories
151     find $queuedir/bts_version_track_archive/ -empty -type d -delete
152 }
153
154 function reports() {
155     # Send a report on NEW/BYHAND packages
156     log "Nagging ftpteam about NEW/BYHAND packages"
157     dak queue-report | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND on $(date +%D)" ftpmaster@ftp-master.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
158     dak queue-report -d backports-new,backports-policy | mail -a "X-Debian: DAK" -e -s "NEW and POLICY on $(date +%D)" backports-team@debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
159     # and one on crufty packages
160     log "Sending information about crufty packages"
161     dak cruft-report -R > $webdir/cruft-report-daily.txt
162     dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt
163     cat $webdir/cruft-report-daily.txt | mail -a "X-Debian: DAK" -e -s "Debian archive cruft report for $(date +%D)" ftpmaster@ftp-master.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
164 }
165
166 function pg_timestamp() {
167     tsname=${1:-"unknown"}
168     log "Saving postgres transaction id for ${tsname}"
169     psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
170 }
171
172 function get_archiveroot() {
173     local archivename="$1"
174     local query="SELECT path FROM archive WHERE name='${archivename}'"
175     local archiveroot="$(psql -tAc "${query}")"
176     if [ -z "${archiveroot}" ]; then
177         echo "get_archiveroot: couldn't get archiveroot for '${archivename}'" >&2
178         return 1
179     fi
180     echo "${archiveroot}"
181 }