-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
update.sh
executable file
·57 lines (47 loc) · 1.5 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
#!/bin/bash
#
# Show update instruction for installed tools.
#
# VERSION :0.1.2
# DATE :2015-07-06
# AUTHOR :Viktor Szépe <[email protected]>
# LICENSE :The MIT License (MIT)
# URL :https://github.com/szepeviktor/debian-server-tools
# BASH-VERSION :4.2+
# DEPENDS :apt-get install colordiff
# Show also colorized diffs.
#
# ./update.sh -d
Get_meta() {
# defaults to self
local FILE="${1:-$0}"
# defaults to "VERSION"
local META="${2:-VERSION}"
local VALUE
VALUE="$(head -n 30 "$FILE" | grep -m 1 "^# ${META}\\s*:" | cut -d ":" -f 2-)"
if [ -z "$VALUE" ]; then
VALUE="(unknown)"
fi
echo "$VALUE"
}
PARAM="$1"
hash colordiff 2>/dev/null || unset PARAM
#Input_motd Get_meta input/update-motd.d - Get_meta /etc/update-motd.d/update-motd.d
D="$(dirname "$0")"
find . -type f -size -100k -not -name README.md -not -path "*/.git*" -printf '%P\n' \
| while read -r FILE; do
SCRIPT="$(Get_meta "$FILE" LOCATION)"
if [ -z "$SCRIPT" ] || [ "$SCRIPT" == "(unknown)" ] || [ ! -f "$SCRIPT" ]; then
continue
fi
OLD_VERSION="$(Get_meta "$SCRIPT")"
CURRENT_VERSION="$(Get_meta "$FILE")"
if [ "$OLD_VERSION" == "$CURRENT_VERSION" ]; then
continue
fi
echo "# Update ${FILE}: ${OLD_VERSION} -> ${CURRENT_VERSION}"
echo "${D}/install.sh ${FILE}"
if [ "$PARAM" == "-d" ]; then
colordiff -w -B "$SCRIPT" "$FILE"
fi
done