]> git.ipfire.org Git - people/ms/nightly-builds.git/blame - build.sh
build.sh: Set the correct branch name
[people/ms/nightly-builds.git] / build.sh
CommitLineData
fd9f9810
MT
1#!/bin/bash -l
2
3BASEDIR="/build/nightly"
d2b7a495 4LOCKFILE="/tmp/.nightly-builds.lock"
fd9f9810
MT
5
6UPLOAD_DIR="${BASEDIR}/upload"
7899475b 7UPLOAD_TO="pakfire@fs01.haj.ipfire.org:/pub/nightly"
33e0dd1c 8RSYNC_ARGS=( "--delay-updates" )
fd9f9810 9
fd9f9810
MT
10extract_installer_from_iso() {
11 local dir="${1}"
12
13 local tmpdir="$(mktemp -d)"
14 mkdir -p "${dir}/images"
15
16 local file
17 for file in ${dir}/*.iso; do
18 if mount -o loop,ro "${file}" "${tmpdir}"; then
19 local f
20 for f in vmlinuz instroot; do
21 cp -f "${tmpdir}/boot/isolinux/${f}" "${dir}/images"
22 done
23 umount "${tmpdir}"
81a5283c
MT
24
25 local ext
26 for ext in "" ".md5"; do
27 ln -s --relative "${file}${ext}" \
28 "${dir}/images/installer.iso${ext}"
29 done
fd9f9810
MT
30 break
31 fi
32 done 2>/dev/null
33
34 rm -rf "${tmpdir}"
35}
36
37build() {
38 local dir="${1}"
39 shift
40
fb8a369c
MT
41 # Check if this actually source of IPFire 2
42 [ -x "${dir}/make.sh" ] || return 1
43
fd9f9810
MT
44 pushd "${dir}"
45
46 local branch="$(git config build.branch)"
47 [ -z "${branch}" ] && branch="master"
48
49 local commit_old="$(git rev-parse HEAD)"
50 git fetch
51
ecab61ba
MT
52 # Search for the latest core branch
53 if [ "${branch}" = "core" ]; then
54 branch=$(git branch -r | awk -F/ '{ print $NF }' | grep ^core | sort --version-sort | tail -n1)
55 fi
56
fd9f9810
MT
57 # If the branch was not updated, we won't build
58 local commit_new="$(git rev-parse origin/${branch})"
59 [ "${commit_old}" = "${commit_new}" ] && return 2
60
dc1916d9
MT
61 local current_branch="$(git rev-parse --abbrev-ref HEAD)"
62 if [ "${current_branch}" != "${branch}" ]; then
63 git checkout -b "${branch}" "${commit_new}"
64 fi
65
fd9f9810
MT
66 # Checkout the latest commit
67 git reset --hard "${commit_new}"
68
e685e88f 69 local now="$(git log --format="%ci" -1 "${commit_new}")"
fd9f9810
MT
70
71 local targets="$(git config build.targets)"
72 [ -z "${targets}" ] && targets="i586"
73
74 local target
75 for target in ${targets}; do
c42b9259
MT
76 local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}"
77 local build="${build_path}/${target}"
fd9f9810
MT
78
79 # Ready for build
80 ./make.sh --target="${target}" clean
81
82 # Download the toolchain if required
83 ./make.sh --target="${target}" gettoolchain || continue
84
85 # Download all sources
86 ./make.sh --target="${target}" downloadsrc || continue
87
88 # Execute the build
89 mkdir -p "${build}"
90 ./make.sh --target="${target}" build | tee "${build}/build.log"
91 local ret=${PIPESTATUS[0]}
92
83c069b6
MT
93 # Save the changelog
94 git log -50 > "${build}/changelog.txt"
95
fd9f9810
MT
96 # Save the result
97 if [ "${ret}" = "0" ]; then
36213bbc 98 mv -v *.iso *.img.gz *.img.xz *.tar.bz2 *.md5 packages/ "${build}"
fd9f9810
MT
99 extract_installer_from_iso "${build}"
100 touch "${build}/.success"
101 fi
102 mv -v log/ "${build}"
103
ef1ba4c9 104 # Cleanup the build environment
fd9f9810 105 ./make.sh --target="${target}" clean
ef1ba4c9
MT
106
107 # Upload the result
108 # If that failed, we will keep the result and it will
109 # be retried with the next build. If that succeeded, the
110 # build will be removed from disk.
111 if sync; then
7a0fb04f 112 rm -rf "${UPLOAD_DIR}"
ef1ba4c9 113 fi
fd9f9810
MT
114 done
115
116 popd
117}
118
119sync() {
120 mkdir -p "${UPLOAD_DIR}"
121
7899475b
MT
122 # Acquire a Kerberos ticket for authentication
123 if ! klist &>/dev/null; then
124 kinit -k -t /etc/krb5.keytab "host/${HOSTNAME}"
125 fi
126
f267213e 127 rsync -avH --progress "${RSYNC_ARGS[@]}" \
fd9f9810
MT
128 "${UPLOAD_DIR}/" "${UPLOAD_TO}"
129}
130
d2b7a495
MT
131is_locked() {
132 [ -e "${LOCKFILE}" ]
133}
134
135lock() {
136 touch "${LOCKFILE}"
137}
138
139unlock() {
140 rm -f "${LOCKFILE}"
141}
142
d2b7a495 143# Don't start again if the script is already running
b9def775
MT
144# or if an other build script is running
145if is_locked || pgrep make.sh >/dev/null; then
d2b7a495
MT
146 exit 0
147fi
148
149# Lock
150trap unlock EXIT
151lock
152
6c6991a8 153for repo in $(find ${BASEDIR} -maxdepth 3 -type d -name ".git"); do
fd9f9810
MT
154 [ -d "${repo}" ] || continue
155
156 build "$(dirname ${repo})"
157done
d2b7a495 158
555260fa
MT
159# Try to sync even nothing was built for retrying failed uploads
160sync
161
d2b7a495 162exit 0