-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·105 lines (84 loc) · 1.92 KB
/
installer.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
#!/usr/bin/env bash
# Bail on any error.
set -e
set -o pipefail
# Convenience function for calling special dotfiles git.
function dots() {
git \
--git-dir="$HOME/$DOTS_DIR" \
--work-tree="$HOME" \
"$@"
}
function install() {
cd
if [[ -d "$HOME/$DOTS_DIR" ]]; then
echo "${HOME}/${DOTS_DIR} already exists."
else
# Use https for CI.
if [[ -z "$CI" ]]; then
REPO_PREFIX='git@github.com:'
else
REPO_PREFIX='https://github.com/'
fi
# Clone to a throw-away location as Git requires a destination and the
# destination can't exist (/dev/null doesn't work).
git clone \
--recursive \
--separate-git-dir="$HOME/$DOTS_DIR" \
"$REPO_PREFIX"nhoag/dotfiles.git \
"$(mktemp -d)"
fi
dots config status.showUntrackedFiles no
# Require 'force' to overwrite the home directory.
if [[ "$FORCE" == true ]]; then
dots checkout .
else
echo 'Dotfiles installed but not checked out.'
echo 'Review pending changes with:'
# shellcheck disable=SC2016
echo ' git --git-dir="$HOME/'"$DOTS_DIR"'" --work-tree="$HOME" diff'
fi
[[ -z "$CI" ]] && {
# Switch the default shell to zsh (requires sudo) - no effect until login.
# Disable for CI.
chsh -s "$(command -v zsh)"
# Use zsh right now (and trigger zgen build).
zsh
}
cd -
}
# Main installer function.
function main() {
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-f | --force)
FORCE=true
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
local DOTS_DIR=${1:-'.dotfiles'}
requirements \
curl \
git \
vim \
zsh
install
}
# Check requirements are satisfied.
function requirements() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo >&2 "I require $cmd but it's not installed. Aborting."
exit 1
}
done
}
main "$@"