common 6.6 KB
Newer Older
J
Joerg Jaspert 已提交
1
# -*- mode:sh -*-
J
Joerg Jaspert 已提交
2 3 4 5
# log something (basically echo it together with a timestamp)
#
# Set $PROGRAM to a string to have it added to the output.
function log () {
6 7
        local prefix=${PROGRAM:-}
        echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${prefix}[$$]: $@"
J
Joerg Jaspert 已提交
8 9 10 11 12 13 14
}

# log the message using log() but then also send a mail
# to the address configured in MAILTO (if non-empty)
function log_error () {
        log "$@"
        if [ -z "${MAILTO}" ]; then
J
Joerg Jaspert 已提交
15
                echo "$@" | mail -a "X-Debian: DAK" -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}  -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
J
Joerg Jaspert 已提交
16 17 18 19 20 21 22 23 24
        fi
}

# debug log, only output when DEBUG=1
function debug () {
    if [ $DEBUG -eq 1 ]; then
        log "$*"
    fi
}
J
Joerg Jaspert 已提交
25

J
buildd  
Joerg Jaspert 已提交
26 27 28
function wbtrigger() {
    SSHOPT="-o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
    if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
J
Joerg Jaspert 已提交
29
        ssh -q -q ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.often
J
buildd  
Joerg Jaspert 已提交
30
    fi
J
Joerg Jaspert 已提交
31
    rm -f "${LOCK_BUILDD}"
J
buildd  
Joerg Jaspert 已提交
32 33
}

J
Joerg Jaspert 已提交
34 35
# used by cron.dinstall *and* cron.unchecked.
function make_buildd_dir () {
36
    dak manage-build-queues -a
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
    dak generate-packages-sources2 -a build-queues
    dak generate-releases -a build-queues

    for suite in unstable experimental; do
	rm -rf "$incoming/dists/$suite/buildd"
	dak export-suite -s "buildd-$suite" -d "$incoming/dists/$suite/buildd"
    done

    # export to old build queue directories
    # XXX: Remove once the buildds use the version generated above.
    for suite in $(ls -1 $incoming/dists/); do
        # Skip project trace directory
        if [ "${suite}x" = "projectx" ]; then continue; fi
        cd ${incoming}/dists/${dist}/buildd

	dpkg-scanpackages . $overridedir/override.sid.all3 >Packages
	gzip -9c --rsyncable <Packages >Packages.gz
	dpkg-scansources . $override/override.sid.all3.src >Sources
	gzip -9c --rsyncable <Sources >Sources.gz

	rm -f buildd/Release
	cd ..
	apt-ftparchive -qq -o APT::FTPArchive::Release::Origin="Debian" -o APT::FTPArchive::Release::Label="Debian" -o APT::FTPArchive::Release::Description="buildd $suite incoming" -o APT::FTPArchive::Release::Architectures="$archs" release buildd >Release
	if [ "$suite" = "experimental" ]; then
	    echo "NotAutomatic: yes" >>Release
	fi

	gpg --secret-keyring /srv/ftp-master.debian.org/s3kr1t/dot-gnupg/secring.gpg --keyring /srv/ftp-master.debian.org/s3kr1t/dot-gnupg/pubring.gpg --no-options --batch --no-tty --armour --default-key 473041FA --detach-sign -o Release.gpg Release

	mv Release Release.gpg buildd/
    done
68 69 70 71 72 73 74 75 76 77

    for dist in $(ls -1 ${incoming}/dists/); do
        # Skip project trace directory
        if [ "${dist}x" = "projectx" ]; then continue; fi
        cd ${incoming}/dists/${dist}
        mkdir -p tree/${STAMP}
        cp -al ${incoming}/dists/${dist}/buildd/. tree/${STAMP}/
        ln -sfT tree/${STAMP} ${incoming}/dists/${dist}/current
        find ./tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
    done
J
Joerg Jaspert 已提交
78
}
J
Joerg Jaspert 已提交
79

80 81
# Process (oldstable)-proposed-updates "NEW" queue
function punew_do() {
82
    local queue="$1"
83
    date -u -R >> REPORT
84
    dak process-policy "${queue}" | tee -a REPORT | mail -a "X-Debian: DAK" -e -s "NEW changes in ${queue}" debian-release@lists.debian.org -- -F "Debian FTP Masters" -f ftpmaster@ftp-master.debian.org
85
    echo >> REPORT
86 87 88 89 90 91

    dak generate-packages-sources2 -s "${queue}"

    local exportdir="${queuedir}/${queue}/export"
    rm -rf "${exportdir}"
    dak export -q "${queue}" -d "${exportdir}" --all
92 93 94 95
}

# These versions used in dinstall
function punew() {
M
Mark Hymers 已提交
96 97 98
    if [ "${PROGRAM}" = "dinstall" ]; then
        log "Doing automated p-u-new processing"
    fi
99 100 101 102 103
    cd "${queuedir}/p-u-new"
    punew_do "$1"
}

function opunew() {
M
Mark Hymers 已提交
104 105 106
    if [ "${PROGRAM}" = "dinstall" ]; then
        log "Doing automated o-p-u-new processing"
    fi
107 108 109 110
    cd "${queuedir}/o-p-u-new"
    punew_do "$1"
}

J
Joerg Jaspert 已提交
111 112 113 114 115 116 117
# Do the unchecked processing, in case we have files.
function do_unchecked () {
    cd $unchecked

    changes=$(find . -maxdepth 1 -mindepth 1 -type f -name \*.changes | sed -e "s,./,," | xargs)
    report=$queuedir/REPORT
    timestamp=$(date "+%Y-%m-%d %H:%M")
J
Joerg Jaspert 已提交
118
    UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
J
Joerg Jaspert 已提交
119

120
    echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
J
cron  
Joerg Jaspert 已提交
121
    dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
J
Joerg Jaspert 已提交
122 123
}

124 125 126 127 128
# process NEW policy queue
function do_new () {
    if [ "${PROGRAM}" = "dinstall" ]; then
	log "Doing NEW processing"
    fi
129
    (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
130
    dak clean-suites -a new
J
Joerg Jaspert 已提交
131 132
}

J
Joerg Jaspert 已提交
133 134
function sync_debbugs () {
    # sync with debbugs
135
    echo "--" >> $report
J
meh  
Joerg Jaspert 已提交
136
    timestamp=$(date "+%Y-%m-%d-%H:%M")
J
Joerg Jaspert 已提交
137
    mkdir -p $queuedir/bts_version_track_archive/${timestamp}
138
    rsync -aq $queuedir/bts_version_track/ $queuedir/bts_version_track_archive/${timestamp}
J
Joerg Jaspert 已提交
139
    rmdir --ignore-fail-on-non-empty $queuedir/bts_version_track_archive/${timestamp} # remove if empty.
J
Joerg Jaspert 已提交
140 141 142 143 144 145 146 147
    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
    NOW=$(date +%s)
    TSTAMP=$(stat -c %Y $lockdir/synced_bts_version)
    DIFF=$(( NOW - TSTAMP ))
    if [ $DIFF -ge 259200 ]; then
        log "Kids, you tried your best and you failed miserably. The lesson is, never try. (Homer Simpson)"
    fi
}
J
Joerg Jaspert 已提交
148

149 150 151 152 153 154 155
function clean_debbugs () {
    # Delete files older than 60 days
    find $queuedir/bts_version_track_archive/ -mtime +60 -type f -delete
    # Delete empty directories
    find $queuedir/bts_version_track_archive/ -empty -type d -delete
}

J
Joerg Jaspert 已提交
156 157 158
function reports() {
    # Send a report on NEW/BYHAND packages
    log "Nagging ftpteam about NEW/BYHAND packages"
J
Joerg Jaspert 已提交
159
    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
J
Joerg Jaspert 已提交
160 161
    # and one on crufty packages
    log "Sending information about crufty packages"
162 163
    dak cruft-report -R > $webdir/cruft-report-daily.txt
    dak cruft-report -R -s experimental >> $webdir/cruft-report-daily.txt
J
Joerg Jaspert 已提交
164
    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
J
Joerg Jaspert 已提交
165
}
J
Joerg Jaspert 已提交
166 167 168 169 170 171

function pg_timestamp() {
    tsname=${1:-"unknown"}
    log "Saving postgres transaction id for ${tsname}"
    psql -tAc 'select txid_current();' > $base/backup/txid_${tsname}_$(date +%Y.%m.%d-%H:%M:%S)
}