]> git.ipfire.org Git - people/ms/nightly-builds.git/blob - build.sh
Initial import
[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="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}/${target}"
60
61 # Ready for build
62 ./make.sh --target="${target}" clean
63
64 # Download the toolchain if required
65 ./make.sh --target="${target}" gettoolchain || continue
66
67 # Download all sources
68 ./make.sh --target="${target}" downloadsrc || continue
69
70 # Execute the build
71 mkdir -p "${build}"
72 ./make.sh --target="${target}" build | tee "${build}/build.log"
73 local ret=${PIPESTATUS[0]}
74
75 # Save the result
76 if [ "${ret}" = "0" ]; then
77 mv -v *.iso *.img.gz *.tar.bz2 *.md5 packages/ "${build}"
78 extract_installer_from_iso "${build}"
79 touch "${build}/.success"
80 fi
81 mv -v log/ "${build}"
82
83 # Upload the result
84 sync
85
86 # Cleanup in the end
87 ./make.sh --target="${target}" clean
88 rm -rf "$(dirname "${build}")"
89 done
90
91 popd
92 }
93
94 sync() {
95 mkdir -p "${UPLOAD_DIR}"
96
97 rsync -avHz --progress ${RSYNC_ARGS} \
98 "${UPLOAD_DIR}/" "${UPLOAD_TO}"
99 }
100
101 for repo in $(find ${BASEDIR} -maxdepth 2 -type d -name ".git"); do
102 [ -d "${repo}" ] || continue
103
104 build "$(dirname ${repo})"
105 done