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