aboutsummaryrefslogtreecommitdiff
path: root/Tools/portbuild/scripts/dosetupnode
blob: 33a6044a627f207a29996953dc045a5acba09816 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
#
# XXX Use a worker pool that only runs N setups at once to avoid
# raping the server.  Hard to do in shell?

# -norsync|-nocopy : Don't copy files, just clean up builds
#
# -queue : update queue once we finish setting up
#
# -force : force file copying/extraction even if it appears it is
#          up-to-date
#
# NB: branch or buildid might be "-" to specify only to set up the
# scripts/ and ${arch}/ directories (e.g. after client reboot)

# configurable variables
pb=/var/portbuild
arch=$1
branch=$2
buildid=$3
nodelist=$4
shift 4

if [ -f ${pb}/${arch}/portbuild.conf ]; then
    . ${pb}/${arch}/portbuild.conf
else
    echo "Invalid arch ${arch}"
    exit 1
fi
. ${pb}/scripts/buildenv

# Check for non-fatal rsync errors
checkerror() {
    error=$?

    case $error in
	0)
	    return 0
	    ;;
	23)
	    echo "Continuing..."	 
	    return 0
	    ;;
	*)
	    echo "Aborting..."
	    return 1
	    ;;
    esac
}

setup() {
    node=$1

    echo "setting up of $node started at $(date)"

    . ${pb}/${arch}/portbuild.conf
    . ${pb}/${arch}/portbuild.${node}

    ${scp_cmd} -q -p ${pb}/scripts/setupnode ${client_user}@${node}:/tmp || return 1

    client_setup="${ssh_cmd} -n ${client_user}@${node} sh /tmp/setupnode ${pb} ${arch} ${branch} ${buildid} ${scratchdir} \"${portsmd5}\" \"${srcmd5}\" \"${bindistmd5}\""
    args="${nocopy} ${force}"

    ${client_setup} pre-copy ${args} || (echo "pre-copy for ${node} failed"; return 1)

    if [ "${norsync}" -eq 0 ]; then

	rsync ${rsync_gzip} -e "${ssh_cmd}" -r -l -p --delete ${pb}/scripts \
	    ${client_user}@${node}:${pb}/
	checkerror $? || (echo "Copying scripts to ${node} failed"; return 1)

	rsync ${rsync_gzip} -e "${ssh_cmd}" -r -l -p --delete ${pb}/${arch}/portbuild* \
	    ${client_user}@${node}:${pb}/${arch}
	checkerror $? || (echo "copying portbuild.conf files to ${node} failed"; return 1)

	if [ -f "${pb}/${arch}/clients/bindist-${node}.tar" ]; then
	    rsync ${rsync_gzip} -e "${ssh_cmd}" -r -L -p --delete \
		${pb}/${arch}/clients/bindist-${node}.tar \
		${client_user}@${node}:${pb}/${arch}/clients/
	    checkerror $? || (echo "Copying bindist-${node}.tar to ${node} failed"; return 1)
	else
	    echo "Host customization file not found: ${pb}/${arch}/clients/bindist-${node}.tar"
	    return 1
	fi

	if [ "${buildid}" != "-" ]; then
	    rsync ${rsync_gzip} -e "${ssh_cmd}" -r -L -p \
		${builddir}/ports-${buildid}.tbz \
		${builddir}/ports-${buildid}.tbz.md5 \
		${builddir}/src-${buildid}.tbz \
		${builddir}/src-${buildid}.tbz.md5 \
		${builddir}/bindist.tbz \
		${builddir}/bindist.tbz.md5 \
		${client_user}@${node}:${builddir}/ 
	    checkerror $? || (echo "Copying build tarballs to ${node} failed"; return 1)
	fi
    fi

    ${client_setup} post-copy ${args} || (echo "post-copy for ${node} failed"; return 1)

    if [ "${queue}" -eq 1 ]; then
	lockf -k ${pb}/${arch}/queue/.lock \
	    ${pb}/scripts/pollmachine ${arch}/${node} -queue
    fi
    echo "setting up of $node ended at $(date)"
}

pbab=${pb}/${arch}/${branch}

norsync=0
queue=0

while [ $# -ge 1 ]; do
    case $1 in
	-norsync|-nocopy)
	    norsync=1
	    nocopy=-nocopy
	    ;;
	-queue)
	    queue=1
	    ;;
	-force)
	    force=-force
	    ;;
    esac
    shift
done

if [ "${norsync}" -eq 0 ]; then
    if [ "${branch}" != "-" -a "${buildid}" != "-" ]; then
	buildid=$(resolve ${pb} ${arch} ${branch} ${buildid})

	if [ -z "${buildid}" ]; then
	    echo "Invalid build ID ${buildid}"
	    exit 1
	fi

	builddir=${pbab}/builds/${buildid}

	if [ ! -f ${builddir}/ports-${buildid}.tbz.md5 ]; then
	    echo "ports-${buildid}.tbz.md5 not found"
	    exit 1
	else
	    portsmd5=$(awk '{print $4}' ${builddir}/ports-${buildid}.tbz.md5)
	fi
	
	if [ ! -f ${builddir}/src-${buildid}.tbz.md5 ]; then
	    echo "src-${buildid}.tbz.md5 not found"
	    exit 1
	else
	    srcmd5=$(awk '{print $4}' ${builddir}/src-${buildid}.tbz.md5)
	fi
	
	if [ ! -f ${builddir}/bindist.tbz.md5 ]; then
	    echo "bindist.tbz.md5 not found"
	    exit 1
	else
	    bindistmd5=$(awk '{print $4}' ${builddir}/bindist.tbz.md5)
	fi
    fi
fi

if [ "${nodelist}" = "all" ]; then
    nodelist=$(cat ${pb}/${arch}/mlist)
fi

for node in ${nodelist}; do
    setup ${node} &
done
wait