-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate
More file actions
executable file
·308 lines (270 loc) · 8.59 KB
/
update
File metadata and controls
executable file
·308 lines (270 loc) · 8.59 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env bash
# Author: Goldie Lin
# Requirements: git, repo (Android git-repo)
# Usage: Simply run `./update.sh`
set -eo pipefail
# Variable definitions
# ====================
# command options
declare -gr git_gc_enable="no" # yes or no
declare -gra git_gc_opt=() # (empty) or --aggressive
declare -gra git_pull_opt=()
declare -gra repo_sync_opt=( -q -f --prune )
# git clone list: title, url
declare -grA git_clone_list=(
["vimrc"]="https://github.com/goldie-lin/vimrc.git"
["dotfiles"]="https://github.com/goldie-lin/dotfiles.git"
["binfiles"]="https://github.com/goldie-lin/binfiles.git"
["repo"]="https://gerrit.googlesource.com/git-repo"
["bash-completion-android"]="https://github.com/mbrubeck/android-completion.git"
["urxvt-perls"]="https://github.com/muennich/urxvt-perls.git"
["icdiff"]="https://github.com/jeffkaufman/icdiff.git"
["abs"]="https://github.com/18z/abs.git"
["Linux-tips"]="https://github.com/18z/Linux-tips.git"
["busybox-android-ndk"]="https://github.com/tias/android-busybox-ndk.git"
["busybox"]="https://github.com/mirror/busybox.git"
["crosstool-ng"]="https://github.com/crosstool-ng/crosstool-ng.git"
["git"]="https://github.com/git/git.git"
["linux"]="https://github.com/torvalds/linux.git"
["shellcheck"]="https://github.com/koalaman/shellcheck.git"
["crash"]="https://github.com/crash-utility/crash.git"
["tmux-bash-completion"]="https://github.com/imomaliev/tmux-bash-completion.git"
["tmuxinator"]="https://github.com/tmuxinator/tmuxinator.git"
["git-lfs"]="https://github.com/github/git-lfs.git"
["bomr"]="https://github.com/jamesqo/bomr.git"
["ag"]="https://github.com/ggreer/the_silver_searcher.git"
["rg"]="https://github.com/BurntSushi/ripgrep.git"
["tomorrow-theme"]="https://github.com/chriskempson/tomorrow-theme.git"
["pcmanx"]="https://github.com/pcman-bbs/pcmanx.git"
["git-blame-someone-else"]="https://github.com/jayphelps/git-blame-someone-else.git"
["git-prebase"]="https://gist.github.com/5893d2d969ccb6b8341d.git"
["git-standup"]="https://github.com/kamranahmedse/git-standup.git"
["completion-ruby"]="https://github.com/mernen/completion-ruby.git"
)
# git pull list: title, path
declare -grA git_pull_list=(
["vimrc"]="${HOME}/opt/vimrc"
["dotfiles"]="${HOME}/opt/dotfiles"
["binfiles"]="${HOME}/opt/binfiles"
["repo"]="${HOME}/opt/git-repo"
["bash-completion-android"]="${HOME}/opt/android-completion"
["urxvt-perls"]="${HOME}/opt/urxvt-perls"
["icdiff"]="${HOME}/opt/icdiff"
["abs"]="${HOME}/opt/abs"
["Linux-tips"]="${HOME}/opt/Linux-tips"
["busybox-android-ndk"]="${HOME}/opt/busybox/android-busybox-ndk"
["busybox"]="${HOME}/opt/busybox/busybox"
["crosstool-ng"]="${HOME}/opt/crosstool-ng/src"
["git"]="${HOME}/opt/git"
["linux"]="${HOME}/opt/linux"
["shellcheck"]="${HOME}/opt/shellcheck"
["crash"]="${HOME}/opt/crash"
["tmux-bash-completion"]="${HOME}/opt/tmux-bash-completion"
["tmuxinator"]="${HOME}/opt/tmuxinator"
["git-lfs"]="${HOME}/opt/git-lfs"
["bomr"]="${HOME}/opt/bomr"
["ag"]="${HOME}/opt/the_silver_searcher"
["rg"]="${HOME}/opt/ripgrep"
["tomorrow-theme"]="${HOME}/opt/tomorrow-theme"
["pcmanx"]="${HOME}/opt/pcmanx"
["git-blame-someone-else"]="${HOME}/opt/git-blame-someone-else"
["git-prebase"]="${HOME}/opt/git-prebase"
["git-standup"]="${HOME}/opt/git-standup"
["completion-ruby"]="${HOME}/opt/completion-ruby"
)
# repo init list: title, url
declare -grA repo_init_list=(
["00 Android AOSP mirror"]="https://android.googlesource.com/mirror/manifest --mirror"
["01 Android AOSP working"]="https://android.googlesource.com/platform/manifest"
)
# repo sync list: title, path
declare -grA repo_sync_list=(
["00 Android AOSP mirror"]="${HOME}/opt/android-aosp-mirror"
["01 Android AOSP working"]="${HOME}/opt/android-aosp"
)
# color code
declare -grx cClean=$'\e[0m'
declare -grx cBlack=$'\e[30m'
declare -grx cDarkRed=$'\e[31m'
declare -grx cDarkGreen=$'\e[32m'
declare -grx cDarkYellow=$'\e[33m'
declare -grx cDarkBlue=$'\e[34m'
declare -grx cDarkPurple=$'\e[35m'
declare -grx cDarkCyan=$'\e[36m'
declare -grx cLightGray=$'\e[37m'
declare -grx cGray=$'\e[30;1m'
declare -grx cRed=$'\e[31;1m'
declare -grx cGreen=$'\e[32;1m'
declare -grx cYellow=$'\e[33;1m'
declare -grx cBlue=$'\e[34;1m'
declare -grx cPurple=$'\e[35;1m'
declare -grx cCyan=$'\e[36;1m'
declare -grx cWhite=$'\e[37;1m'
# Function definitions
# ====================
echo_title() {
echo -e "\\n${cGreen}${*}${cClean}"
}
_get_linux_distro_name() {
local _os=""
_os="$(uname -s)"
if [[ "${_os}" = "Linux" ]]; then
if hash "lsb_release" &>/dev/null; then
lsb_release -s -i
elif [[ -r /etc/lsb-release ]]; then
( source /etc/lsb-release && echo "$DISTRIB_ID")
elif [[ -f /etc/arch-release ]]; then
echo "Arch"
elif [[ -f /etc/debian_version ]]; then
echo "Debian"
elif [[ -f /etc/fedora-release ]]; then
echo "Fedora"
elif [[ -f /etc/redhat-release ]]; then
echo "RedHat"
elif [[ -f /etc/centos-release ]]; then
echo "CentOS"
elif [[ -f /etc/oracle-release ]]; then
echo "Oracle"
elif [[ -f /etc/SuSE-release ]]; then
echo "SuSE"
elif [[ -r /etc/os-release ]]; then
( source /etc/os-release && echo "$ID")
else
echo "Unknown"
fi
else
echo "NonLinux"
fi
}
_get_python_variant_for_repo() {
local _python="python"
local _python_version=""
local _returncode="0"
# Current repo utility only support Python verion 2.6 - 2.7
# TODO: Maybe need to update this version check in the future.
_python_version="$(python -V |& sed 's/Python//g;s/\s\+//g')"
if [[ ! "${_python_version}" =~ ^2\.(6|7)\..*$ ]]; then
if hash "python2.7" &>/dev/null; then
_python="python2.7"
elif hash "python2.6" &>/dev/null; then
_python="python2.6"
else
echo "Unaccepted version of $(python -V) for repo utility" >&2
_returncode="1"
fi
fi
echo "${_python}"
return "${_returncode}"
}
git_clone() {
local -r _url="$1"
local -r _path="$2"
git clone --recurse-submodules -- "${_url}" "${_path}"
git -C "${_path}" config --unset branch.master.rebase
}
git_pull() {
local -r _path="$1"
git -C "${_path}" pull --recurse-submodules "${git_pull_opt[@]}"
if [[ "${git_gc_enable}" == "yes" ]]; then
git -C "${_path}" gc "${git_gc_opt[@]}" || true # Do not abort, ignore exit code
fi
}
repo_init() {
local -r _path="$1"
local -r _url="$2"
local _repo=""
local _python=""
# shellcheck disable=SC2230
_repo="$(which repo)"
_python="$(_get_python_variant_for_repo)"
mkdir -p -- "${_path}"
(cd -- "${_path}" && "${_python}" "${_repo}" init -u "${_url}")
}
repo_sync() {
local -r _path="$1"
local _repo=""
local _python=""
# shellcheck disable=SC2230
_repo="$(which repo)"
_python="$(_get_python_variant_for_repo)"
(cd -- "${_path}" && "${_python}" "${_repo}" sync "${repo_sync_opt[@]}")
}
do_git_pull_list() {
local _title=""
local _path=""
local _url=""
for _title in "${!git_pull_list[@]}"; do
_path="${git_pull_list[$_title]}"
_url="${git_clone_list[$_title]}"
echo_title "${_title}"
if [[ -d "${_path}" ]]; then
git_pull "${_path}"
else
git_clone "${_url}" "${_path}"
fi
done
}
do_repo_sync_list() {
local _title=""
local _path=""
local _url=""
if [[ -f ./venv/bin/activate && -r ./venv/bin/activate ]]; then
# shellcheck disable=SC1091
source ./venv/bin/activate
fi
for _title in "${!repo_sync_list[@]}"; do
_path="${repo_sync_list[$_title]}"
_url="${repo_init_list[$_title]}"
echo_title "${_title}"
if [[ ! -d "${_path}" ]]; then
repo_init "${_path}" "${_url}"
fi
repo_sync "${_path}"
done
}
do_update_vim_plugins() {
echo_title "vim plugins"
# update via junegunn/vim-plug plugin manager
vim +PlugUpdate +q +q
}
do_update_nvim_plugins() {
echo_title "neovim plugins"
# update via junegunn/vim-plug plugin manager
nvim +PlugUpdate +q +q
}
do_update_sys_pkgs() {
local _distro=""
_distro="$(_get_linux_distro_name)"
case "${_distro}" in
"Arch")
if hash "yay" &>/dev/null; then
echo_title "yay"
yay -Syu
elif hash "trizen" &>/dev/null; then
echo_title "trizen"
trizen -Syu
elif hash "yaourt" &>/dev/null; then
echo_title "yaourt"
yaourt -Syu
else
echo_title "pacman"
sudo pacman -Syu
fi
;;
"Ubuntu")
echo_title "apt"
sudo apt update && sudo apt full-upgrade
;;
*)
echo_title "Error: Unknown disro '${_distro}' to update system packages!"
;;
esac
}
main() {
do_update_sys_pkgs
do_update_vim_plugins
#do_update_nvim_plugins
do_git_pull_list
#do_repo_sync_list
}
main "$@"