aboutsummaryrefslogtreecommitdiff
blob: f7f968f876d82553010a347b9445541620c4bf21 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# $Id: update-seeds.sh,v 0.2.1 2014/10/12 dolsen Exp $

# configuration to run from a checkout with a custom config
cwd=$(pwd)
source ${cwd}/update-seeds.conf
source ${cwd}/testpath

eval `keychain --noask --eval ${SSH_KEY} ${GPG_KEY}`

die(){ echo "$@" 1>&2; exit 1; }
success(){ echo "$@"; exit 0; }

clone_api(){
    local target=dirname ${API_DIR}
    cd target
    git clone ${API_URL}
}

clone_gkey_seeds(){
    local target=dirname ${GKEY_SEEDS_DIR}
    cd target
    git clone ${GKEY_SEEDS_URL}
}

# start update process
echo "Beginning seed file update"

echo " *** updating gkey-seeds repo"
# update api checkout
if [[ ! -d ${GKEY_SEEDS_DIR} ]]; then
    clone_gkey_seeds
else
    cd ${GKEY_SEEDS_DIR} && git pull
fi

echo " *** updating api.gentoo.org repo"
# update api checkout
if [[ ! -d ${API_DIR} ]]; then
    clone_api
else
    cd ${API_DIR} && git pull
fi

echo " *** Fetching new seeds from LDAP"
cd ${GKEYS_DIR}
gkeys-ldap update-seeds -C gentoo-devs || die "Seed file generation failed... aborting"

echo " *** Checking if seed files are up-to-date"
if ! diff -q ${GKEYS_DIR}/${GKEYS_SEEDS} ${GKEY_SEEDS_DIR}/${GKEY_SEEDS} > /dev/null ;then
    echo " *** Spotted differences"
    echo " *** Updating old seeds with a new one"
    # copy seeds to gkey-seeds
    echo "  ... cp ${GKEYS_SEEDS} ${API_DIR}/${API_SEEDS}"
    cp ${GKEYS_SEEDS} ${GKEY_SEEDS_DIR}/${GKEY_SEEDS}
else
    success " *** No changes detected"
    exit 0
fi

echo "Signing new developers.seeds file"
gkeys sign -n ${GKEYS_SIGN} -F ${GKEY_SEEDS_DIR}/${GKEY_SEEDS} || die " *** Signing failed... exiting"

echo "Committing changes to gkey-seeds repo..."
cd ${GKEY_SEEDS_DIR}
git add ${GKEY_SEEDS}  || die " *** Failed to add modified ${GKEYS_SEEDS} file"
git add ${GKEY_SEEDS}.${GKEYS_SIG} || die " *** Failed to add ${GKEYS_SEEDS}.sig file"
git commit -m "${GKEYS_COMMIT_MSG}" || die " *** Failed to commit updates"
git push --signed origin master || die " *** git push failed"
cd ..

echo "Committing changes to api repo..."
cp ${GKEY_SEEDS_DIR}/${GKEY_SEEDS} ${API_DIR}/${API_SEEDS} || die " *** Failed to copy modified ${GKEYS_SEEDS} file"
cp ${GKEY_SEEDS_DIR}/${GKEY_SEEDS}.${GKEYS_SIG} ${API_DIR}/${API_SEEDS}.${GKEYS_SIG} || die " *** Failed to copy modified ${GKEYS_SEEDS}.${GKEYS_SIG} file"
cd ${API_DIR}
git add ${API_SEEDS}  || die " *** Failed to add modified ${GKEYS_SEEDS} file"
git add ${API_SEEDS}.${GKEYS_SIG} || die " *** Failed to add ${GKEYS_SEEDS}.sig file"
git commit -m "${GKEYS_COMMIT_MSG}" || die " *** Failed to commit updates"
git push --signed origin master || die " *** git push failed"

echo "Pushing the log file to ${LOG_UPLOAD_URL}"
LOG_FILE=$( cat "${LOG_DIR}/gkeys-ldap-lastlog" )
scp "${LOG_DIR}/${LOG_FILE}" "${LOG_UPLOAD_URL}"  || die "Failed to upload logfile: ${LOG_FILE}"

success "Successfully updated developer.seeds"