common 3.6 KB
Newer Older
J
Joerg Jaspert 已提交
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
# log something (basically echo it together with a timestamp)
#
# Set $PROGRAM to a string to have it added to the output.
function log () {
        if [ -z "${PROGRAM}" ]; then
                echo "$(date +"%b %d %H:%M:%S") $(hostname -s) [$$] $@"
        else
                echo "$(date +"%b %d %H:%M:%S") $(hostname -s) ${PROGRAM}[$$]: $@"
        fi
}

# 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
                echo "$@" | mail -e -s "[$PROGRAM@$(hostname -s)] ERROR [$$]" ${MAILTO}
        fi
}

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

J
buildd  
Joerg Jaspert 已提交
28 29 30 31 32
function wbtrigger() {
    MODE=${1:-"often"}
    SSHOPT="-o BatchMode=yes -o ConnectTimeout=30 -o SetupTimeout=240"
    if lockfile -r 3 -l 3600 "${LOCK_BUILDD}"; then
        if [ "x${MODE}x" = "xdailyx" ]; then
J
Joerg Jaspert 已提交
33
            ssh ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.daily || echo "W-B trigger.daily failed" | mail -s "W-B Daily trigger failed" ftpmaster@ftp-master.debian.org
J
buildd  
Joerg Jaspert 已提交
34 35 36 37 38 39
        elif [ "x${MODE}x" = "xoftenx" ]; then
            ssh -q -q ${SSHOPT} wbadm@buildd /org/wanna-build/trigger.often
        else
            log_error "Unknown wb trigger mode called"
        fi
    fi
J
Joerg Jaspert 已提交
40
    rm -f "${LOCK_BUILDD}"
J
buildd  
Joerg Jaspert 已提交
41 42
}

J
Joerg Jaspert 已提交
43 44
# used by cron.dinstall *and* cron.unchecked.
function make_buildd_dir () {
45
    dak manage-build-queues -a
J
Joerg Jaspert 已提交
46

M
Mark Hymers 已提交
47 48 49 50 51
    cd ${incoming}
    mkdir -p tree/${STAMP}
    cp -al ${incoming}/buildd/. tree/${STAMP}/
    ln -sfT tree/${STAMP} ${incoming}/builddweb
    find ./tree -mindepth 1 -maxdepth 1 -not -name "${STAMP}" -type d -print0 | xargs --no-run-if-empty -0 rm -rf
M
Mark Hymers 已提交
52 53 54 55 56 57 58 59 60

    for dist in experimental
    do
        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 已提交
61
}
J
Joerg Jaspert 已提交
62 63 64 65 66 67 68 69

# 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 已提交
70
    UNCHECKED_WITHOUT_LOCK=${UNCHECKED_WITHOUT_LOCK:-""}
J
Joerg Jaspert 已提交
71

72
    echo "$timestamp": ${changes:-"Nothing to do"}  >> $report
J
cron  
Joerg Jaspert 已提交
73
    dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$unchecked" >> $report
J
Joerg Jaspert 已提交
74 75
}

J
Joerg Jaspert 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88
# Do the newstage processing, in case we have files.
function do_newstage () {
    cd $newstage

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

    echo "$timestamp": ${changes:-"Nothing to do in newstage"}  >> $report
    dak process-upload -a ${UNCHECKED_WITHOUT_LOCK} -d "$newstage" >> $report
}

J
Joerg Jaspert 已提交
89 90
function sync_debbugs () {
    # sync with debbugs
91
    echo "--" >> $report
J
Joerg Jaspert 已提交
92 93 94 95 96 97 98 99
    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
}