1 |
ccflib |
1.5 |
#!/bin/bash |
2 |
ccflib |
1.1 |
# |
3 |
|
|
# + fetch CCF deliveries from the ftp site |
4 |
|
|
# + perform basic checks on the packages |
5 |
|
|
# + move them to accept/reject directory |
6 |
|
|
# |
7 |
|
|
# Exit codes (<0 informational) |
8 |
|
|
# -1 (255): no new CCF deliveries |
9 |
|
|
# |
10 |
ccflib |
1.6 |
# $Id: getdeliveries,v 1.5 2014/12/02 14:47:48 ccflib Exp $ |
11 |
ccflib |
1.1 |
|
12 |
ccflib |
1.6 |
#set -e (if set it will not produce any output) |
13 |
ccflib |
1.1 |
|
14 |
|
|
cleanup () { |
15 |
|
|
cd ~ |
16 |
|
|
/bin/rm -fr $tmpdir |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
me=`basename $0` |
20 |
|
|
|
21 |
ccflib |
1.6 |
echo |
22 |
|
|
echo "-> $me running at "`date` |
23 |
|
|
echo |
24 |
|
|
|
25 |
ccflib |
1.3 |
uploaddir=~/incoming |
26 |
ccflib |
1.1 |
pkgdir=~/deliveries/packages |
27 |
|
|
builtdir=~/deliveries/built |
28 |
|
|
rejdir=~/deliveries/rejected |
29 |
|
|
tmpdir=~/tmp/tmp$$ |
30 |
|
|
logfile=~/deliveries/DELIVERY_LOG |
31 |
|
|
|
32 |
|
|
trap cleanup EXIT |
33 |
|
|
|
34 |
|
|
mkdir -p $tmpdir $pkgdir $rejdir |
35 |
ccflib |
1.6 |
|
36 |
ccflib |
1.1 |
cd $pkgdir |
37 |
ccflib |
1.6 |
|
38 |
ccflib |
1.1 |
DATE=`date '+%Y%m%d'` |
39 |
|
|
|
40 |
ccflib |
1.2 |
cp $uploaddir/* $tmpdir/ 2> /dev/null |
41 |
ccflib |
1.1 |
|
42 |
|
|
cd $tmpdir |
43 |
|
|
|
44 |
|
|
flist=`ls *.tgz 2> /dev/null` |
45 |
ccflib |
1.6 |
|
46 |
ccflib |
1.1 |
if [ -z "$flist" ] ; then |
47 |
ccflib |
1.6 |
echo "$me: No new CCF deliveries." |
48 |
|
|
echo |
49 |
ccflib |
1.1 |
exit -1 |
50 |
|
|
fi |
51 |
|
|
|
52 |
|
|
for p in *.tgz |
53 |
|
|
do |
54 |
|
|
echo New CCF delivery $p |
55 |
|
|
|
56 |
|
|
trouble=0 |
57 |
|
|
discard=1 |
58 |
|
|
|
59 |
|
|
pack_name=`basename $p | sed -e 's/-[^-]*\.tgz//'` |
60 |
|
|
pack_vers=`basename $p | sed -e 's/^.*-//' -e 's/\.tgz//'` |
61 |
|
|
pack_md5=`md5sum $p | awk '{print $1}'` |
62 |
|
|
|
63 |
|
|
if [ -e $pkgdir/$p -o -e $builtdir/$p ] ; then |
64 |
|
|
echo ERROR: $p - already delivered |
65 |
|
|
trouble=1 |
66 |
|
|
else |
67 |
|
|
|
68 |
|
|
tar xzf $p |
69 |
|
|
if [ $? -ne 0 ] ; then |
70 |
|
|
echo ERROR: $p ignored - may still be uploading |
71 |
|
|
discard=0 |
72 |
|
|
else |
73 |
|
|
echo Package $pack_name $pack_vers |
74 |
|
|
|
75 |
|
|
cd $pack_name |
76 |
|
|
|
77 |
|
|
version=`cat VERSION` || discard=1 |
78 |
|
|
cd .. |
79 |
|
|
rm -fr $pack_name |
80 |
|
|
fi |
81 |
|
|
fi |
82 |
|
|
|
83 |
|
|
if [ $trouble -ne 0 ] ; then |
84 |
|
|
echo ERROR: $p is rejected |
85 |
|
|
mv -f $p $rejdir |
86 |
|
|
echo $pack_md5 $DATE $p " - REJECTED" >> $logfile |
87 |
|
|
else |
88 |
|
|
echo $p is accepted |
89 |
|
|
mv -f $p $pkgdir |
90 |
|
|
echo $pack_md5 $DATE $p >> $logfile |
91 |
|
|
fi |
92 |
|
|
|
93 |
|
|
if [ $discard -eq 1 ] ; then |
94 |
|
|
echo $p removed from upload area |
95 |
ccflib |
1.2 |
rm -f $uploaddir/$p |
96 |
ccflib |
1.1 |
fi |
97 |
|
|
|
98 |
|
|
done |