-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate
executable file
·56 lines (49 loc) · 1.22 KB
/
update
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
#!/bin/bash
. "$(dirname "$0")/libupd"
is_changed() {
sumcmd=$(which sha256sum sha1sum md5sum cksum | head -1)
updatebefore="$($sumcmd "$0")"
libbefore="$($sumcmd "$(dirname "$0")/libupd")"
pushd "$(dirname "$0")" &>/dev/null
echo "------ Updating upd ------"
require git && git pull
popd &>/dev/null
updateafter="$($sumcmd "$0")"
libafter="$($sumcmd "$(dirname "$0")/libupd")"
[ "$updatebefore" != "$updateafter" -o "$libbefore" != "$libafter" ]
}
update() {
for ITEM in $(ls "$(dirname "$0")"/enabled/* | sort)
do
$ITEM --update
done
}
parse_args "${@}"
echo
echo ================== Starting $(whoami)@$(hostname) ==================
if [ -z "$RESTARTED" ] && is_changed
then
echo "Restarting $0"
"$0" --modified "${@}"
else
update
echo ================== Finished $(whoami)@$(hostname) ==================
echo ================== $(date) ==================
fi
if [ ! -z "$REMOTE" -a -e ~/.upd-remote ]
then
while read -u9 host dir
do
echo
echo
echo "Updating ${host} via ${dir}/upd/update"
ssh $host ${dir}/upd/update
done 9< ~/.upd-remote
while read -u9 host dir
do
if [ ! -z "$dir" ]
then
ssh $host ${dir}/upd/needs_reboot
fi
done 9< ~/.upd-remote
fi