1 |
#! /bin/bash |
2 |
# |
3 |
# + fetch new CCF deliveries |
4 |
# + build latest files |
5 |
# + move new files to CCF repository |
6 |
# |
7 |
# $Id: autobuild,v 1.11 2021/06/28 15:19:36 ccflib Exp $ |
8 |
# |
9 |
|
10 |
# Name and initialize $LOG file |
11 |
|
12 |
LOG=$HOME/autobuild.log |
13 |
[ -f "$LOG" ] && rm -f $LOG |
14 |
touch $LOG |
15 |
|
16 |
# Name and initialize HEAD_MESSAGE and MESSAGE to be sued for mail |
17 |
|
18 |
HEAD_MESSAGE="$HOME/head_message" |
19 |
MESSAGE="$HOME/MESSAGE" |
20 |
|
21 |
[ -f "$HEAD_MESSAGE" ] && rm -f $HEAD_MESSAGE |
22 |
[ -f "$MESSAGE" ] && rm -f $MESSAGE |
23 |
|
24 |
touch $HEAD_MESSAGE $MESSAGE |
25 |
|
26 |
echo "CCF autobuild run at `date` on `hostname`" >> $HEAD_MESSAGE |
27 |
echo "-----------------------------------------------------------------------" >> $HEAD_MESSAGE |
28 |
|
29 |
cat $HEAD_MESSAGE >> $MESSAGE |
30 |
|
31 |
me=`basename $0` |
32 |
|
33 |
|
34 |
# Redirects stderr (2) to stdout (1) |
35 |
|
36 |
exec 2>&1 |
37 |
|
38 |
# Redirects the stdout to $LOG for the whole script |
39 |
|
40 |
exec > $LOG |
41 |
|
42 |
echo "-> $me running on "`date` |
43 |
echo |
44 |
|
45 |
|
46 |
# Source configuration settings |
47 |
|
48 |
. $HOME/bin/ccflib.cfg |
49 |
|
50 |
# Add $HOME/bin to $PATH |
51 |
|
52 |
export PATH=$HOME/bin:$PATH |
53 |
|
54 |
# Name the lock file and define function unlock |
55 |
|
56 |
LOCK=$HOME/autobuild.lck |
57 |
unlock () { |
58 |
rm -f $LOCK |
59 |
} |
60 |
|
61 |
# Do the work |
62 |
|
63 |
count=0 |
64 |
maxcount=10 |
65 |
trap unlock EXIT |
66 |
|
67 |
while [ -e $LOCK -a $count -lt $maxcount ] ; do |
68 |
count=$[count + 1] |
69 |
echo $me: $LOCK exists. Sleeping 60s [$count] |
70 |
sleep 60 |
71 |
done |
72 |
|
73 |
if [ $count -lt $maxcount ] ; then |
74 |
touch $LOCK |
75 |
# trap unlock EXIT |
76 |
# Get nay new CCF from incoming |
77 |
getdeliveries |
78 |
# Let do the two next steps in this way so as |
79 |
# the acceptbuild will be done ONLY when buildlatest |
80 |
# exits with return state 0. For example, if |
81 |
# buildlatest has nothing to build the exit state is -1 |
82 |
# therefore acceptbuild is not executed. |
83 |
buildlatest && acceptbuild |
84 |
else |
85 |
echo $me: $LOCK exists, and slept enough. Giving up. |
86 |
exit 1 |
87 |
fi |
88 |
|
89 |
# Reset redicrections to avoid unexpected results |
90 |
|
91 |
exec 1>&2 2>&- |
92 |
|
93 |
|
94 |
# Notify by email to all only if there is something to build |
95 |
# Otherwise, notify only the ccflib administrator, |
96 |
# by the time being: eduardo.ojero@sciops.esa.int |
97 |
|
98 |
nothingtobuild=`cat $LOG | grep -c "Nothing to build"` |
99 |
|
100 |
cat $LOG >> $MESSAGE |
101 |
|
102 |
|
103 |
# Define mail subject |
104 |
|
105 |
subject="CCF autobuild run at `date` on `hostname`" |
106 |
|
107 |
# Use mailx to send messages instead of sendmail |
108 |
|
109 |
if [ "$nothingtobuild" != "0" ] ; then |
110 |
mailx -s "$subject" eduardo.ojero@sciops.esa.int < $MESSAGE |
111 |
else |
112 |
mailx -s "$subject" ccf@sciops.esa.int < $MESSAGE |
113 |
fi |