-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·116 lines (96 loc) · 2.17 KB
/
install.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
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
#!/usr/bin/env bash
set -Eeufo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [options]
Install dotfiles.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-c, --chezmoi Only install chezmoi
-r, --remote Perform installation remotely
--no-color No colors
EOF
exit
}
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
}
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m'
else
NOFORMAT='' GREEN='' BLUE='' YELLOW=''
fi
}
msg() {
echo >&2 -e "${1-}"
}
info() {
msg "${BLUE}>${NOFORMAT} $*"
}
warn() {
msg "${YELLOW}! $*${NOFORMAT}"
}
completed() {
msg "${GREEN}✓${NOFORMAT} $*"
}
die() {
local msg=$1
local code=${2-1}
msg "$msg"
exit "$code"
}
parse_params() {
only_chezmoi=0
remote_install=0
while :; do
case "${1-}" in
-h | --help) usage;;
-v | --verbose) set -x;;
-c | --chezmoi) only_chezmoi=1;;
-r | --remote) remote_install=1;;
--no-color) NO_COLOR=1;;
-?*) die "Unknown option: $1";;
*) break;;
esac
shift
done
return 0
}
has() {
type "$1" > /dev/null 2>&1
}
install() {
if ! chezmoi="$(command -v chezmoi)"; then
bin_dir="${HOME}/.local/bin"
chezmoi="${bin_dir}/chezmoi"
if has "curl" || has "wget"; then
info "Installing chezmoi to '${chezmoi}'"
if has "curl"; then
chezmoi_install_script="$(curl -fsLS get.chezmoi.io)"
else
chezmoi_install_script="$(wget -qO- get.chezmoi.io)"
fi
else
die "curl or wget required."
fi
sh -c "${chezmoi_install_script}" -- -b "${bin_dir}"
unset chezmoi_install_script bin_dir
fi
if [[ "${only_chezmoi}" == 0 ]]; then
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
info "Installing dotfiles..."
if [[ "${remote_install}" == 0 ]]; then
"${chezmoi}" init --apply --source="${script_dir}"
else
"${chezmoi}" init --apply h3y6e
fi
fi
completed "All done."
return 0
}
parse_params "$@"
setup_colors
install