]> git.decadent.org.uk Git - dak.git/blob - config/debian/common
Use /srv instead of /org
[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 [$$]" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ${MAILTO}
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 /srv/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     # Stick a last modified date in the page footer
42     echo "<p>Last updated: `date -u`</p>" > ${incoming}/web/README.html
43
44     # Tell the mirrors that we've updated
45     chronic /usr/local/bin/static-update-component incoming.debian.org
46 }
47
48 # Process (oldstable)-proposed-updates "NEW" queue
49 function punew_do() {
50     local queue="$1"
51     local qdir="$2"
52     local to="${3}"
53
54     date -u -R >> REPORT
55     dak process-policy "${queue}" | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in ${queue}" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" "${to}"
56     echo >> REPORT
57
58     dak generate-packages-sources2 -s "${queue}"
59
60     STAMP=${STAMP:-$(date "+%Y%m%d%H%M")}
61
62     local exportdir="${qdir}/tree/${STAMP}"
63     local targetdir="${qdir}/export"
64     mkdir -p -- ${exportdir}
65     dak export -q "${queue}" -d "${exportdir}" --all
66     ln -sfT ${exportdir} ${targetdir}
67     find "${qdir}/tree" -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
68 }
69
70 # These versions used in dinstall
71 function punew() {
72     if [ "${PROGRAM}" = "dinstall" ]; then
73         log "Doing automated p-u-new processing"
74     fi
75     cd "${queuedir}/p-u-new"
76     punew_do "$1" "${queuedir}/p-u-new" "debian-release@lists.debian.org"
77 }
78
79 function opunew() {
80     if [ "${PROGRAM}" = "dinstall" ]; then
81         log "Doing automated o-p-u-new processing"
82     fi
83     cd "${queuedir}/o-p-u-new"
84     punew_do "$1" "${queuedir}/o-p-u-new" "debian-release@lists.debian.org"
85 }
86
87 function backports_policy() {
88     local queue="backports-policy"
89     local qdir="/srv/backports-master.debian.org/queue/policy"
90     local to="backports-team@debian.org"
91
92     if [ "${PROGRAM}" = "dinstall" ]; then
93         log "Doing automated ${queue} processing"
94     fi
95
96     cd "${qdir}"
97     punew_do "${queue}" "${qdir}" "${to}"
98 }
99
100 # Do the unchecked processing, in case we have files.
101 function do_unchecked () {
102     cd $unchecked
103
104     changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
105     report=$queuedir/REPORT
106     timestamp=$(date "+%Y-%m-%d %H:%M")
107     UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
108
109     echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
110     dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
111     dak process-commands -d "$unchecked" >> $report
112 }
113
114 # process NEW policy queue
115 function do_new () {
116     if [ "${PROGRAM}" = "dinstall" ]; then
117         log "Doing NEW processing"
118     fi
119     (dak process-policy new; dak process-policy byhand) | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND processing" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
120
121     dak process-policy backports-new | mail -a "X-Debian: DAK" -e -s "NEW processing for backports-new" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" backports-team@debian.org
122
123     dak clean-suites -a new,backports-new
124 }
125
126 function sync_debbugs () {
127     # sync with debbugs
128     echo "--" >> $report
129     timestamp=$(date "+%Y-%m-%d-%H:%M")
130     mkdir -p $queuedir/bts_version_track_archive/${timestamp}
131     rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
132     rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
133     rsync -aq -e "ssh -o Batchmode=yes -o ConnectTimeout=30 -o SetupTimeout=30" --remove-source-files  $queuedir/bts_version_track/ bugs-sync:/srv/bugs.debian.org/versions/queue/ftp-master/ 2>/dev/null && touch $lockdir/synced_bts_version || true
134     NOW=$(date +%s)
135     TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
136     DIFF=$(( NOW - TSTAMP ))
137     if [ $DIFF -ge 259200 ]; then
138         log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
139     fi
140 }
141
142 function clean_debbugs () {
143     # Delete files older than 60 days
144     find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
145     # Delete empty directories
146     find $queuedir/bts_version_track_archive/ -empty -type d -delete
147 }
148
149 function reports() {
150     # Send a report on NEW/BYHAND packages
151     log "Nagging ftpteam about NEW/BYHAND packages"
152     dak queue-report | mail -a "X-Debian: DAK" -e -s "NEW and BYHAND on $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
153     dak queue-report -d backports-new,backports-policy | mail -a "X-Debian: DAK" -e -s "NEW and POLICY on $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" backports-team@debian.org
154     # and one on crufty packages
155     log "Sending information about crufty packages"
156     dak cruft-report -R > $webdir/cruft-report-daily.txt
157     dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt
158     cat $webdir/cruft-report-daily.txt | mail -a "X-Debian: DAK" -e -s "Debian archive cruft report for $(date +%D)" -a "From: Debian FTP Masters <ftpmaster@ftp-master.debian.org>" ftpmaster@ftp-master.debian.org
159 }
160
161 function pg_timestamp() {
162     tsname=${1:-"unknown"}
163     log "Saving postgres transaction id for ${tsname}"
164     psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
165 }
166
167 function get_archiveroot() {
168     local archivename="$1"
169     local query="SELECT path FROM archive WHERE name='${archivename}'"
170     local archiveroot="$(psql -tAc "${query}")"
171     if [ -z "${archiveroot}" ]; then
172         echo "get_archiveroot: couldn't get archiveroot for '${archivename}'" >&2
173         return 1
174     fi
175     echo "${archiveroot}"
176 }