forked from peter-m-shi/ztool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_update.sh
79 lines (61 loc) · 1.59 KB
/
check_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
#!/usr/bin/env zsh
TOOLS_FOLDER="$HOME/ztool"
zmodload zsh/datetime
function _current_epoch() {
echo $(( $EPOCHSECONDS / 60 / 60 ))
}
function _update_time() {
echo "LAST_EPOCH=$(_current_epoch)" >! $TOOLS_FOLDER/.tools-timestamp
}
function _upgrade_tools() {
env ZSH=$ZSH /bin/sh $TOOLS_FOLDER/update.sh
# update the tools file
_update_time
}
epoch_target=$PGTOOLS_AUTO_HOURS
if [[ -z "$epoch_target" ]]; then
# Default to old behavior
epoch_target=1
fi
# Cancel upgrade if the current user doesn't have write permissions for the
#检查更新
if [ -f $TOOLS_FOLDER/.tools-timestamp ]
then
. $TOOLS_FOLDER/.tools-timestamp
if [[ -z "$LAST_EPOCH" ]]; then
_update_time && return 0;
fi
epoch_diff=$(($(_current_epoch) - $LAST_EPOCH))
if [ $epoch_diff -gt $epoch_target ]
then
if [ "$PGTOOLS_AUTO_CHECK" = "false" ]
then
else
env ZSH=$ZSH /bin/sh $TOOLS_FOLDER/check_changes.sh &
_update_time
fi
fi
else
# create the tools file
_update_time
fi
#提示更新
if [ -f $TOOLS_FOLDER/.tools-changes ]
then
log=$(cat $TOOLS_FOLDER/.tools-changes)
if [[ -n "$log" ]]; then
echo "[ztool] has one or more updates:"
echo "----------------------------"
sh "$TOOLS_FOLDER/utility/echoColor.sh" "-yellow" "$log"
echo "----------------------------"
echo "Would you like to update for ztool?"
str="\033[32mY\033[0m"
echo "Type $str to update: \c"
read line
if [ "$line" = Y ] || [ "$line" = y ]; then
_upgrade_tools
fi
fi
rm -rf $TOOLS_FOLDER/.tools-changes
exec zsh
fi