]> git.ipfire.org Git - people/ms/nightly-builds.git/blob - build.sh
build.sh: Cleanup code for removing the result
[people/ms/nightly-builds.git] / build.sh
1 #!/bin/bash -l
2
3 BASEDIR="/build/nightly"
4
5 UPLOAD_DIR="${BASEDIR}/upload"
6 UPLOAD_TO="pakfire@git.ipfire.org:/pub/nightly"
7 RSYNC_ARGS="--bwlimit=1M"
8
9 export MAKETUNING="-j2"
10
11 extract_installer_from_iso() {
12 local dir="${1}"
13
14 local tmpdir="$(mktemp -d)"
15 mkdir -p "${dir}/images"
16
17 local file
18 for file in ${dir}/*.iso; do
19 if mount -o loop,ro "${file}" "${tmpdir}"; then
20 local f
21 for f in vmlinuz instroot; do
22 cp -f "${tmpdir}/boot/isolinux/${f}" "${dir}/images"
23 done
24 umount "${tmpdir}"
25 break
26 fi
27 done 2>/dev/null
28
29 rm -rf "${tmpdir}"
30 }
31
32 build() {
33 local dir="${1}"
34 shift
35
36 pushd "${dir}"
37
38 local branch="$(git config build.branch)"
39 [ -z "${branch}" ] && branch="master"
40
41 local commit_old="$(git rev-parse HEAD)"
42 git fetch
43
44 # If the branch was not updated, we won't build
45 local commit_new="$(git rev-parse origin/${branch})"
46 [ "${commit_old}" = "${commit_new}" ] && return 2
47
48 # Checkout the latest commit
49 git reset --hard "${commit_new}"
50
51 #local now="$(date -u +"%Y-%m-%d-%H:%M")"
52 local now="$(git log --format="%cI" -1 "${commit_new}")"
53
54 local targets="$(git config build.targets)"
55 [ -z "${targets}" ] && targets="i586"
56
57 local target
58 for target in ${targets}; do
59 local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}"
60 local build="${build_path}/${target}"
61
62 # Ready for build
63 ./make.sh --target="${target}" clean
64
65 # Download the toolchain if required
66 ./make.sh --target="${target}" gettoolchain || continue
67
68 # Download all sources
69 ./make.sh --target="${target}" downloadsrc || continue
70
71 # Execute the build
72 mkdir -p "${build}"
73 ./make.sh --target="${target}" build | tee "${build}/build.log"
74 local ret=${PIPESTATUS[0]}
75
76 # Save the result
77 if [ "${ret}" = "0" ]; then
78 mv -v *.iso *.img.gz *.tar.bz2 *.md5 packages/ "${build}"
79 extract_installer_from_iso "${build}"
80 touch "${build}/.success"
81 fi
82 mv -v log/ "${build}"
83
84 # Upload the result
85 sync
86
87 # Cleanup in the end
88 ./make.sh --target="${target}" clean
89 rm -rf "${build_path}"
90 done
91
92 popd
93 }
94
95 sync() {
96 mkdir -p "${UPLOAD_DIR}"
97
98 rsync -avHz --progress ${RSYNC_ARGS} \
99 "${UPLOAD_DIR}/" "${UPLOAD_TO}"
100 }
101
102 for repo in $(find ${BASEDIR} -maxdepth 2 -type d -name ".git"); do
103 [ -d "${repo}" ] || continue
104
105 build "$(dirname ${repo})"
106 done