-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdot-update
More file actions
executable file
·170 lines (145 loc) · 4.9 KB
/
Copy pathdot-update
File metadata and controls
executable file
·170 lines (145 loc) · 4.9 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
#!/usr/bin/env bash
# Quick script to handle updating our dotfiles
# A better class of script...
set -o errexit # Exit on most errors (see the manual)
set -o errtrace # Make sure any error trap is inherited
set -o nounset # Disallow expansion of unset variables
set -o pipefail # Use last non-zero exit code in a pipeline
#set -o xtrace # Trace the execution of the script (debug)
# Path to the dot-manage script
DOT_MANAGE='dot-manage'
# DESC: Usage help
# ARGS: None
# OUTS: None
function script_usage() {
cat << EOF
Usage:
-h|--help Displays this help
-v|--verbose Displays verbose output
-nc|--no-colour Disables colour output
Update Options:
-a|--all Update all the things
-b|--bin Update binaries
-e|--vim Update Vim plug-ins
-g|--git Update Git sources (default)
-s|--stow Run dot-manage (default)
EOF
}
# DESC: Parameter parser
# ARGS: $@ (optional): Arguments provided to the script
# OUTS: Variables indicating command-line parameters and options
function parse_params() {
local param
while [[ $# -gt 0 ]]; do
param="$1"
shift
case $param in
-h | --help)
script_usage
exit 0
;;
-v | --verbose)
verbose=true
;;
-nc | --no-colour)
no_colour=true
;;
-a | --all)
bin_update=true
git_update=true
stow_update=true
vim_update=true
;;
-b | --bin)
bin_update=true
;;
-e | --vim)
vim_update=true
;;
-g | --git)
git_update=true
;;
-s | --stow)
stow_update=true
;;
*)
echo "Invalid parameter was provided: $param"
exit 1
;;
esac
done
if [[ -z ${bin_update-} &&
-z ${git_update-} &&
-z ${stow_update-} &&
-z ${vim_update-} ]]; then
default_update=true
fi
}
# DESC: Find some important paths we need before script_init() is called
# ARGS: None
# OUTS: $script_real_path: The full canonicalized path to the script
# $script_real_dir: The canonicalized directory path of the script
# $script_real_name: The canonicalized file name of the script
# $dotfiles_path: The dotfiles directory path
# $dotfiles_name: The dotfiles directory name
# shellcheck disable=SC2034
function early_init() {
# Determine the physical directory this script resides in. This approach is
# necessarily clumsy as simple methods like "readlink -f" and "realpath"
# are not platform independent. We have to work on Linux, BSD, OS X, etc...
script_real_path="$(perl -MCwd -le 'print Cwd::abs_path(shift)' "${BASH_SOURCE[0]}")"
script_real_dir="$(dirname "$script_real_path")"
script_real_name="$(basename "$script_real_path")"
readonly script_real_path script_real_dir script_real_name
# Dotfiles directory path & name
dotfiles_path="$(cd -P "$script_real_dir/../../" && pwd)"
dotfiles_name="$(basename "$dotfiles_path")"
readonly dotfiles_path dotfiles_name
}
# DESC: Main control flow
# ARGS: $@ (optional): Arguments provided to the script
# OUTS: None
function main() {
early_init
# shellcheck source=scripts/lib/bash-template.sh
source "$dotfiles_path/scripts/lib/bash-template.sh"
trap script_trap_err ERR
trap script_trap_exit EXIT
script_init "$@"
parse_params "$@"
colour_init
cd "$dotfiles_path"
if [[ -n ${default_update-} || -n ${git_update-} ]]; then
pretty_print '*** Updating Git sources ...'
check_binary 'git' 'fatal'
# Default to the upstream branch for an unqualified merge
git config merge.defaultToUpstream true
git fetch
git merge --ff-only
git submodule sync
git submodule update --init
fi
if [[ -n ${default_update-} || -n ${stow_update-} ]]; then
"./$DOT_MANAGE"
fi
if [[ -n ${bin_update-} ]]; then
pretty_print '*** Updating binaries ...'
scripts/bin/dl-gitleaks || true
# shellcheck disable=SC2310
if check_binary docker; then
scripts/bin/dl-hadolint || true
fi
scripts/bin/dl-shellcheck || true
scripts/bin/dl-shfmt || true
scripts/bin/dl-yq || true
fi
if [[ -n ${vim_update-} ]]; then
pretty_print '*** Updating Vim plug-ins ...'
check_binary 'vim' 'fatal'
vim +PlugUpdate +qall
vim +PlugClean +qall
fi
}
# Update all the things!
main "$@"
# vim: syntax=sh cc=80 tw=79 ts=4 sw=4 sts=4 et sr