-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
85 lines (68 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
#!/usr/bin/env sh
set -eu
# =============================================================================
# Utils
# =============================================================================
DOTFILES_DIR=$HOME/.local/share/dotfiles/git
dotfiles() {
git --git-dir="$DOTFILES_DIR" --work-tree="$HOME" "$@"
}
heading() {
echo
echo "====================[ $1 ]===================="
echo
}
task() {
heading "$1"
shift
"$@"
echo "Done"
}
confirm() {
printf "\n%s [y/n]: " "$1"
read -r ANSWER </dev/tty
if [ "$ANSWER" != y ] && [ "$ANSWER" != Y ]; then
echo >&2 "Installation canceled!"
exit 1
fi
}
# =============================================================================
# Tasks
# =============================================================================
clone_repo() {
if [ -d "$DOTFILES_DIR" ]; then
confirm "$DOTFILES_DIR already exits! Delete it?"
rm -rf "$DOTFILES_DIR"
fi
git clone --bare https://github.com/jpikl/dotfiles.git "$DOTFILES_DIR"
}
checkout_files() {
# Force native symlinks on windows (requires developer mode to be enabled).
dotfiles config core.symlinks true
if ! dotfiles checkout; then
confirm "Git checkout failed! Try again with '--force'?"
dotfiles checkout --force
fi
}
update_env() {
export PATH="$PATH:$HOME/.local/bin"
}
update_submodules() {
# Switch from SSH to HTTPS for now (we do not have SSH configured yet)
dotfiles submodule set-url .local/share/dotfiles/modules/pm https://github.com/jpikl/pm.git
dotfiles submodule set-url .local/share/dotfiles/modules/sshctl https://github.com/jpikl/sshctl.git
dotfiles submodule update --init
}
post_install() {
runner ~/.config/admin.d/ </dev/tty
}
# =============================================================================
# Run
# =============================================================================
task "Clone repository" clone_repo
task "Checkout files" checkout_files
task "Update environment" update_env
task "Update submodules" update_submodules
task "Post-install" post_install
heading "Success"
echo "Logout and login for all changes to take effect!"