-
Notifications
You must be signed in to change notification settings - Fork 2
/
update.sh
executable file
·122 lines (94 loc) · 2.18 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
if [ ! -z $@ ]
then
if [ -e $@ ]
then
source $@
else
name=$1
url=$2
dl=$3
upd=$4
fi
else
source ./update.conf
fi
url="$url$dl"
declare -a shas
declare -a pkgs
declare -a vers
dir=$PWD
update_ver (){
cd $dir
counter=0
for i in ${pkgs[@]} ; do
cd ${pkgs[$counter]} 2> /dev/null ; if [ "$?" -eq 0 ] ; then
new_ver=${vers[$counter]}
sed -i -e "s/pkgver=\${_ver}.*/pkgver=\${_ver}.$new_ver/g" ./PKGBUILD
old_sha=$(cat PKGBUILD | grep sha1sums= | sed -e 's/sha1sums=//g' | tr -d "''()")
new_sha=${shas[$counter]}
sed -i -e "s/$old_sha/$new_sha/g" ./PKGBUILD
cd ..
fi
counter=$((counter + 1))
done
if [ "$counter" -gt 1 ] ; then
export copular_verb='were'
else
export copular_verb='was'
fi
}
notify_user () {
counter=0
for i in ${pkgs[@]} ; do
echo $i' ' "${shas[$counter]}" >> $dir/maintain-$name.txt
counter=$((counter + 1))
done
}
mod_pkg () {
new_pkg=$(echo $@ | tr -d '[:digit:].' | sed -e 's/-tarxz//g')
pkgs=( ${pkgs[@]} $new_pkg )
new_ver=$(echo $@ | tr -d '[:alpha:]-' | cut -d '.' -f 3)
vers=( ${vers[@]} $new_ver )
}
manipulate () {
hackyhack=$(echo $@ | tr -d ' >')
if [ -z $hackyhack ]
then
echo Same > $dir/maintain-$name.txt
rm ~/.cache/notify-$name/$dl
return 2
fi
echo "$name was updated" > $dir/maintain-$name.txt
while true; do
case $1 in
'' ) break ;;
'>' ) shift ;;
*-* ) mod_pkg $1 ; shift ;;
* ) shas=( ${shas[@]} $1 ) ; shift ;;
esac
done
}
if [ ! -e ~/.cache/notify-$name ] ; then mkdir ~/.cache/notify-$name
first_run=1 ; fi
cd ~/.cache/notify-$name
if [ "$first_run" == '1' ]
then wget $url 2> /dev/null
echo First run
mv ~/.cache/notify-$name/$dl ~/.cache/notify-$name/$dl.old
exit 3
fi
wget $url 2> /dev/null
manipulate $(diff ~/.cache/notify-$name/$dl.old ~/.cache/notify-$name/$dl | grep '>') ; if [ ! "$?" = 2 ]
then
if [ "$upd" == "yes" ]
then update_ver
rm ~/.cache/notify-$name/$dl.old
mv ~/.cache/notify-$name/$dl ~/.cache/notify-$name/$dl.old
echo Will commit
git commit -a -m "$(echo ${pkgs[@]}) $copular_verb updated"
git push
else rm ~/.cache/notify-$name/$dl
fi
notify_user
fi
cat $dir/maintain-$name.txt