-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·59 lines (46 loc) · 1.47 KB
/
install.sh
File metadata and controls
executable file
·59 lines (46 loc) · 1.47 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
#!/usr/bin/env bash
# =============================================================================
# Install and configure system
# =============================================================================
#######################################
# Install chezmoi if it doesn't exist
# Globals:
# HOME
# Arguments:
# None
# Outputs:
# Writes install location to stdout
#######################################
function install_chezmoi {
local bin_dir="${HOME}/.local/bin"
local chezmoi install_script
# Check if chezmoi is already installed
if chezmoi="$(command -v chezmoi)"; then
echo "$chezmoi"
return
fi
chezmoi="${bin_dir}/chezmoi"
# Get install script
if command -v curl >/dev/null; then
install_script="$(curl -fsSL https://chezmoi.io/get)"
elif command -v wget >/dev/null; then
install_script="$(wget -qO- https://chezmoi.io/get)"
else
echo "To install chezmoi, you must have curl or wget installed." >&2
exit 1
fi
sh -c "${install_script}" -- -b "${bin_dir}"
echo "$chezmoi"
}
#################### Main Program ####################
# -e: exit on error
# -u: exit on unset variables
set -eu
# Get chezmoi
chezmoi="$(install_chezmoi)"
# POSIX way to get script's dir: https://stackoverflow.com/a/29834779/12156188
script_dir="$(cd -P -- "$(dirname -- "$(command -v -- "$0")")" && pwd -P)"
set -- init --apply --source="${script_dir}"
# Replace current process with chezmoi
echo "Running 'chezmoi $*'" >&2
exec "$chezmoi" "$@"