-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.zsh
More file actions
86 lines (74 loc) · 2.02 KB
/
update.zsh
File metadata and controls
86 lines (74 loc) · 2.02 KB
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
#!/bin/zsh
# Check for updates
echo '-Check for dotfile updates-'
CURRENT_UPDATE_DIRECTORY=${PWD}
UPDATE_LOG_FILE=${DOTFILES}/update.logfile
cd ${DOTFILES}
# Check if the timout command exists
timeout 1 sleep 0.1 > /dev/null 2>&1
do_update=$?
if [[ ${do_update} == 0 ]]; then
# Use timeout
timeout 3 wget -qO /dev/null --no-check-certificate 'https://github.com/'
do_update=$?
else
# Check if the gtimout command exists
gtimeout 1 sleep 0.1 > /dev/null 2>&1
do_update=$?
if [[ ${do_update} == 0 ]]; then
# Use timeout
gtimeout 3 curl -so /dev/null 'https://github.com/'
do_update=$?
else
echo 'Update failed! No timeout or gtimeout command found!'
fi
fi
# If successful check for updates, else dont
if [[ ${do_update} == 0 ]]; then
git fetch --dry-run 1>${UPDATE_LOG_FILE} 2>&1
# Check if you need to update
do_stat=false
do_gstat=false
stat -c%s ${UPDATE_LOG_FILE} > /dev/null 2>&1
if [[ $? == 0 ]]; then
do_stat=true
do_gstat=false
fi
gstat -c%s ${UPDATE_LOG_FILE} > /dev/null 2>&1
if [[ $? == 0 ]]; then
do_stat=false
do_gstat=true
fi
if [[ $do_stat = true ]]; then
size=$(stat -c%s ${UPDATE_LOG_FILE})
elif [[ $do_gstat = true ]]; then
size=$(gstat -c%s ${UPDATE_LOG_FILE})
else
size=0
fi
if [[ ${size} > 4 ]]; then
echo 'Update available! Do you want to update? [y/n]'
read input
if [[ $input == 'y' ]]; then
git pull
else
echo 'Skip update'
fi
else
echo 'No update available'
fi
# Update submodules
echo 'Update submodules'
git submodule update
if [[ -d ${DOTFILES}/vim-install ]];then
# Update vim Plugins
echo 'Update vim plugins'
vim +PluginUpdate +qall
fi
else
echo 'Update failed!'
fi
# Delete temp file and reset update counter
rm ${UPDATE_LOG_FILE} > /dev/null 2>&1
echo 1 > ${UPDATE_ZSH_COUNT_FILE}
cd ${CURRENT_UPDATE_DIRECTORY}