]> git.ipfire.org Git - people/ms/nightly-builds.git/blob - build.sh
Retry uploads
[people/ms/nightly-builds.git] / build.sh
1 #!/bin/bash -l
2
3 BASEDIR="/build/nightly"
4 LOCKFILE="/tmp/.nightly-builds.lock"
5
6 UPLOAD_DIR="${BASEDIR}/upload"
7 UPLOAD_TO="pakfire@git.ipfire.org:/pub/nightly"
8 RSYNC_ARGS="--bwlimit=1M"
9
10 export MAKETUNING="-j2"
11
12 extract_installer_from_iso() {
13 local dir="${1}"
14
15 local tmpdir="$(mktemp -d)"
16 mkdir -p "${dir}/images"
17
18 local file
19 for file in ${dir}/*.iso; do
20 if mount -o loop,ro "${file}" "${tmpdir}"; then
21 local f
22 for f in vmlinuz instroot; do
23 cp -f "${tmpdir}/boot/isolinux/${f}" "${dir}/images"
24 done
25 umount "${tmpdir}"
26
27 local ext
28 for ext in "" ".md5"; do
29 ln -s --relative "${file}${ext}" \
30 "${dir}/images/installer.iso${ext}"
31 done
32 break
33 fi
34 done 2>/dev/null
35
36 rm -rf "${tmpdir}"
37 }
38
39 build() {
40 local dir="${1}"
41 shift
42
43 # Check if this actually source of IPFire 2
44 [ -x "${dir}/make.sh" ] || return 1
45
46 pushd "${dir}"
47
48 local branch="$(git config build.branch)"
49 [ -z "${branch}" ] && branch="master"
50
51 local commit_old="$(git rev-parse HEAD)"
52 git fetch
53
54 # If the branch was not updated, we won't build
55 local commit_new="$(git rev-parse origin/${branch})"
56 [ "${commit_old}" = "${commit_new}" ] && return 2
57
58 # Checkout the latest commit
59 git reset --hard "${commit_new}"
60
61 #local now="$(date -u +"%Y-%m-%d-%H:%M")"
62 local now="$(git log --format="%cI" -1 "${commit_new}")"
63
64 local targets="$(git config build.targets)"
65 [ -z "${targets}" ] && targets="i586"
66
67 local target
68 for target in ${targets}; do
69 local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}"
70 local build="${build_path}/${target}"
71
72 # Ready for build
73 ./make.sh --target="${target}" clean
74
75 # Download the toolchain if required
76 ./make.sh --target="${target}" gettoolchain || continue
77
78 # Download all sources
79 ./make.sh --target="${target}" downloadsrc || continue
80
81 # Execute the build
82 mkdir -p "${build}"
83 ./make.sh --target="${target}" build | tee "${build}/build.log"
84 local ret=${PIPESTATUS[0]}
85
86 # Save the changelog
87 git log -50 > "${build}/changelog.txt"
88
89 # Save the result
90 if [ "${ret}" = "0" ]; then
91 mv -v *.iso *.img.gz *.tar.bz2 *.md5 packages/ "${build}"
92 extract_installer_from_iso "${build}"
93 touch "${build}/.success"
94 fi
95 mv -v log/ "${build}"
96
97 # Cleanup the build environment
98 ./make.sh --target="${target}" clean
99
100 # Upload the result
101 # If that failed, we will keep the result and it will
102 # be retried with the next build. If that succeeded, the
103 # build will be removed from disk.
104 if sync; then
105 rm -rf "${build_path}"
106 fi
107 done
108
109 popd
110 }
111
112 sync() {
113 mkdir -p "${UPLOAD_DIR}"
114
115 rsync -avHz --progress ${RSYNC_ARGS} \
116 "${UPLOAD_DIR}/" "${UPLOAD_TO}"
117 }
118
119 is_locked() {
120 [ -e "${LOCKFILE}" ]
121 }
122
123 lock() {
124 touch "${LOCKFILE}"
125 }
126
127 unlock() {
128 rm -f "${LOCKFILE}"
129 }
130
131
132 # Don't start again if the script is already running
133 # or if an other build script is running
134 if is_locked || pgrep make.sh >/dev/null; then
135 exit 0
136 fi
137
138 # Lock
139 trap unlock EXIT
140 lock
141
142 for repo in $(find ${BASEDIR} -maxdepth 3 -type d -name ".git"); do
143 [ -d "${repo}" ] || continue
144
145 build "$(dirname ${repo})"
146 done
147
148 exit 0