summaryrefslogtreecommitdiff
blob: e5348ec2d619fdc7cb1e82f4dd5e861aef26d09d (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Check if the mirror is alive and not lagging.
# The script performs three checks, and it proceeds only when the check fails:
# 1) Check if the mirror is fully clean, else proceed
# 2) Check if the latest attempts where clean (five for distfiles, one for
#    rsync), else proceed
# 3) Check if it had more than 10 failed attempts. If it does, then print
#    the mirror, else skip

. /etc/init.d/functions.sh

if [[ $1 != "distfiles" ]] && [[ $1 != "rsync" ]]; then
    echo "Need to specify distfiles or rsync"
    exit 1
fi

STATE_FILE="/var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/$1_mirrors/var/mirmon.state"

count_bad_status() {
    BAD_STATUS_COUNT=0
    i=0
    while (( i++ < ${#FULL_STATUS} )); do
        echo $(expr substr "$FULL_STATUS" $i 1) | grep -v -q s && \
            BAD_STATUS_COUNT=$((BAD_STATUS_COUNT + 1))
    done
    [ $BAD_STATUS_COUNT -ge 10 ] && echo $NAME
}

while read mirror; do
    NAME=`echo $mirror | cut -d' ' -f1`
    FULL_STATUS=`echo $mirror | cut -d' ' -f6 | cut -d'-' -f2`
    if [[ $1 == "distfiles" ]]; then
        LATEST_STATUS="${FULL_STATUS:9:5}"
        LATEST_STATUS_EXP="sssss"
    elif [[ $1 == "rsync" ]]; then
        LATEST_STATUS="${FULL_STATUS:13:1}"
        LATEST_STATUS_EXP="s"
    fi
    if [[ $FULL_STATUS != "ssssssssssssss" ]]; then
        if [[ $LATEST_STATUS != $LATEST_STATUS_EXP ]]; then
            count_bad_status
        fi
    fi
done < $STATE_FILE