-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
55 lines (54 loc) · 1.13 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/sh
for f in Formula/*.rb
do
project=`basename $f .rb`
url=https://kristaps.bsd.lv/$project/snapshots/$project
suffix=tar.gz
ftp $url.$suffix
if [ $? -eq 1 ]
then
suffix=tgz
ftp $url.$suffix
fi
if [ $? -eq 1 ]
then
echo "$project: cannot fetch" 1>&2
continue
fi
lead=`tar ztf $project.$suffix | head -n1`
if [ '.' == "$lead" ]
then
version=`tar ztf $project.$suffix | sed -n 2p | cut -d "-" -f 2`
else
version=`tar ztf $project.$suffix | sed -n 1p | cut -d "-" -f 2`
fi
if [ -z $version ]
then
echo "$project.$suffix: cannot get version" 1>&2
rm -f $project.$suffix
continue
fi
sha=`sha256 -q $project.$suffix`
echo "Current version: $version"
echo "Current SHA: $sha"
sed -e "s!^[ ]*url .*! url \"$url-$version.$suffix\"!" \
-e "s!^[ ]*sha256 .*! sha256 \"$sha\"!" $f > $f.bak
cmp -s $f $f.bak
if [ $? -eq 0 ]
then
echo "Project is up to date."
rm -f $project.$suffix
rm -f $f.bak
continue
fi
diff -u $f $f.bak
read choice?'Overwrite [y/n] (n)? '
if [ -z $choice -o $choice == 'n' ]
then
rm -f $f.bak
rm -f $project.$suffix
continue
fi
mv -f $f.bak $f
rm -f $project.$suffix
done