]>
Commit | Line | Data |
---|---|---|
fd9f9810 MT |
1 | #!/bin/bash -l |
2 | ||
3 | BASEDIR="/build/nightly" | |
d2b7a495 | 4 | LOCKFILE="/tmp/.nightly-builds.lock" |
fd9f9810 MT |
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 | break | |
27 | fi | |
28 | done 2>/dev/null | |
29 | ||
30 | rm -rf "${tmpdir}" | |
31 | } | |
32 | ||
33 | build() { | |
34 | local dir="${1}" | |
35 | shift | |
36 | ||
fb8a369c MT |
37 | # Check if this actually source of IPFire 2 |
38 | [ -x "${dir}/make.sh" ] || return 1 | |
39 | ||
fd9f9810 MT |
40 | pushd "${dir}" |
41 | ||
42 | local branch="$(git config build.branch)" | |
43 | [ -z "${branch}" ] && branch="master" | |
44 | ||
45 | local commit_old="$(git rev-parse HEAD)" | |
46 | git fetch | |
47 | ||
48 | # If the branch was not updated, we won't build | |
49 | local commit_new="$(git rev-parse origin/${branch})" | |
50 | [ "${commit_old}" = "${commit_new}" ] && return 2 | |
51 | ||
52 | # Checkout the latest commit | |
53 | git reset --hard "${commit_new}" | |
54 | ||
55 | #local now="$(date -u +"%Y-%m-%d-%H:%M")" | |
56 | local now="$(git log --format="%cI" -1 "${commit_new}")" | |
57 | ||
58 | local targets="$(git config build.targets)" | |
59 | [ -z "${targets}" ] && targets="i586" | |
60 | ||
61 | local target | |
62 | for target in ${targets}; do | |
c42b9259 MT |
63 | local build_path="${UPLOAD_DIR}/${branch}/${now}-${commit_new:0:8}" |
64 | local build="${build_path}/${target}" | |
fd9f9810 MT |
65 | |
66 | # Ready for build | |
67 | ./make.sh --target="${target}" clean | |
68 | ||
69 | # Download the toolchain if required | |
70 | ./make.sh --target="${target}" gettoolchain || continue | |
71 | ||
72 | # Download all sources | |
73 | ./make.sh --target="${target}" downloadsrc || continue | |
74 | ||
75 | # Execute the build | |
76 | mkdir -p "${build}" | |
77 | ./make.sh --target="${target}" build | tee "${build}/build.log" | |
78 | local ret=${PIPESTATUS[0]} | |
79 | ||
80 | # Save the result | |
81 | if [ "${ret}" = "0" ]; then | |
82 | mv -v *.iso *.img.gz *.tar.bz2 *.md5 packages/ "${build}" | |
83 | extract_installer_from_iso "${build}" | |
84 | touch "${build}/.success" | |
85 | fi | |
86 | mv -v log/ "${build}" | |
87 | ||
88 | # Upload the result | |
89 | sync | |
90 | ||
91 | # Cleanup in the end | |
92 | ./make.sh --target="${target}" clean | |
c42b9259 | 93 | rm -rf "${build_path}" |
fd9f9810 MT |
94 | done |
95 | ||
96 | popd | |
97 | } | |
98 | ||
99 | sync() { | |
100 | mkdir -p "${UPLOAD_DIR}" | |
101 | ||
102 | rsync -avHz --progress ${RSYNC_ARGS} \ | |
103 | "${UPLOAD_DIR}/" "${UPLOAD_TO}" | |
104 | } | |
105 | ||
d2b7a495 MT |
106 | is_locked() { |
107 | [ -e "${LOCKFILE}" ] | |
108 | } | |
109 | ||
110 | lock() { | |
111 | touch "${LOCKFILE}" | |
112 | } | |
113 | ||
114 | unlock() { | |
115 | rm -f "${LOCKFILE}" | |
116 | } | |
117 | ||
118 | ||
119 | # Don't start again if the script is already running | |
120 | if is_locked; then | |
121 | exit 0 | |
122 | fi | |
123 | ||
124 | # Lock | |
125 | trap unlock EXIT | |
126 | lock | |
127 | ||
6c6991a8 | 128 | for repo in $(find ${BASEDIR} -maxdepth 3 -type d -name ".git"); do |
fd9f9810 MT |
129 | [ -d "${repo}" ] || continue |
130 | ||
131 | build "$(dirname ${repo})" | |
132 | done | |
d2b7a495 MT |
133 | |
134 | exit 0 |