1
|
#!/bin/sh
|
2
|
#
|
3
|
# build_snapshots.sh
|
4
|
#
|
5
|
# Copyright (c) 2007-2015 Electric Sheep Fencing, LLC
|
6
|
# All rights reserved
|
7
|
#
|
8
|
# Redistribution and use in source and binary forms, with or without
|
9
|
# modification, are permitted provided that the following conditions
|
10
|
# are met:
|
11
|
#
|
12
|
# 1. Redistributions of source code must retain the above copyright
|
13
|
# notice, this list of conditions and the following disclaimer.
|
14
|
#
|
15
|
# 2. Redistributions in binary form must reproduce the above copyright
|
16
|
# notice, this list of conditions and the following disclaimer in the
|
17
|
# documentation and/or other materials provided with the distribution.
|
18
|
#
|
19
|
# THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
20
|
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
22
|
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
23
|
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
25
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
28
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
30
|
# OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
#
|
32
|
|
33
|
export BUILDER_TOOLS=$(realpath $(dirname ${0}))
|
34
|
export BUILDER_ROOT=$(realpath "${BUILDER_TOOLS}/..")
|
35
|
|
36
|
NO_UPLOAD=""
|
37
|
LOOPED_SNAPSHOTS=""
|
38
|
export minsleepvalue=${minsleepvalue:-"28800"}
|
39
|
export maxsleepvalue=${maxsleepvalue:-"86400"}
|
40
|
|
41
|
# Handle command line arguments
|
42
|
while test "$1" != "" ; do
|
43
|
case $1 in
|
44
|
--noupload|-u)
|
45
|
NO_UPLOAD="-u"
|
46
|
;;
|
47
|
--looped|-l)
|
48
|
LOOPED_SNAPSHOTS="true"
|
49
|
esac
|
50
|
shift
|
51
|
done
|
52
|
|
53
|
# Keeps track of how many time builder has looped
|
54
|
BUILDCOUNTER=0
|
55
|
|
56
|
git_last_commit() {
|
57
|
export CURRENT_COMMIT=$(git -C ${BUILDER_ROOT} log -1 --format='%H')
|
58
|
export CURRENT_AUTHOR=$(git -C ${BUILDER_ROOT} log -1 --format='%an')
|
59
|
}
|
60
|
|
61
|
# This routine is called in between runs. We
|
62
|
# will sleep for a bit and check for new commits
|
63
|
# in between sleeping for short durations.
|
64
|
snapshots_sleep_between_runs() {
|
65
|
COUNTER=0
|
66
|
while [ $COUNTER -lt $maxsleepvalue ]; do
|
67
|
sleep 60
|
68
|
# Update this repo
|
69
|
git -C "${BUILDER_ROOT}" pull -q
|
70
|
git_last_commit
|
71
|
if [ "${LAST_COMMIT}" != "${CURRENT_COMMIT}" ]; then
|
72
|
${BUILDER_ROOT}/build.sh --snapshot-update-status ">>> New commit: $CURRENT_AUTHOR - $CURRENT_COMMIT .. No longer sleepy."
|
73
|
COUNTER=$(($maxsleepvalue + 60))
|
74
|
export LAST_COMMIT="${CURRENT_COMMIT}"
|
75
|
fi
|
76
|
COUNTER=$(($COUNTER + 60))
|
77
|
done
|
78
|
if [ $COUNTER -ge $maxsleepvalue ]; then
|
79
|
${BUILDER_ROOT}/build.sh --snapshot-update-status ">>> Sleep timer expired. Restarting build."
|
80
|
maxsleepvalue=0
|
81
|
COUNTER=0
|
82
|
fi
|
83
|
}
|
84
|
|
85
|
git_last_commit
|
86
|
|
87
|
# Main builder loop
|
88
|
while [ /bin/true ]; do
|
89
|
BUILDCOUNTER=$((${BUILDCOUNTER}+1))
|
90
|
|
91
|
${BUILDER_ROOT}/build.sh --clean-builder | while read LINE; do
|
92
|
${BUILDER_ROOT}/build.sh --snapshot-update-status "${LINE}"
|
93
|
done
|
94
|
|
95
|
${BUILDER_ROOT}/build.sh ${NO_UPLOAD} --flash-size '1g 2g 4g' --snapshots | while read LINE; do
|
96
|
${BUILDER_ROOT}/build.sh --snapshot-update-status "${LINE}"
|
97
|
done
|
98
|
|
99
|
if [ -z "${LOOPED_SNAPSHOTS}" ]; then
|
100
|
# only one build required, exiting
|
101
|
exit
|
102
|
fi
|
103
|
|
104
|
# Initialize variables that keep track of last commit
|
105
|
[ -z "${LAST_COMMIT}" ] \
|
106
|
&& export LAST_COMMIT=${CURRENT_COMMIT}
|
107
|
|
108
|
${BUILDER_ROOT}/build.sh --snapshot-update-status ">>> Sleeping for at least $minsleepvalue, at most $maxsleepvalue in between snapshot builder runs. Last known commit ${LAST_COMMIT}"
|
109
|
${BUILDER_ROOT}/build.sh --snapshot-update-status ">>> Freezing build process at $(date)."
|
110
|
sleep $minsleepvalue
|
111
|
${BUILDER_ROOT}/build.sh --snapshot-update-status ">>> Thawing build process and resuming checks for pending commits at $(date)."
|
112
|
|
113
|
# Count some sheep or wait until a new commit turns up
|
114
|
# for one days time. We will wake up if a new commit
|
115
|
# is detected during sleepy time.
|
116
|
snapshots_sleep_between_runs $maxsleepvalue
|
117
|
done
|