-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·205 lines (178 loc) · 5.77 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env bash
# {[} Setup and variables
# For debugging use
# set -eEuxo pipefail
# set -uxo pipefail
SCRIPTDIR_CMD_BASE='$(cd $( dirname "${BASH_SOURCE[0]}" ) && pwd)'
SCRIPTDIR_CMD="eval echo $SCRIPTDIR_CMD_BASE"
SCRIPTDIR="$($SCRIPTDIR_CMD)"
export DOTFILES_DIR="$SCRIPTDIR"
source "$SCRIPTDIR/shell/functions.sh"
source "$SCRIPTDIR/shell/script_functions.sh"
# if compareVersionNum $BASH_VERSION_CLEAN '>' 4.2 ; then
source "$SCRIPTDIR/shell/bash/colour_variables.sh"
if command -v setxkdmap > /dev/null 2>&1; then
setxkbmap us,us -variant "colemak," && \
printLine "${Green}Keyboard set to colemak."
fi
if substrInStr "darwin" "$OSTYPE"; then
export XDG_CONFIG_HOME="$HOME/.config"
fi
# $XDG_CONFIG_HOME_DEFAULT="$HOME/.config"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
mkdir -p "$XDG_CONFIG_HOME"
echo "$DOTFILES_DIR" > "$XDG_CONFIG_HOME/.dotfiles_dir"
OK="[ ${Green}OK${NC} ]"
Error="[ ${Red}ERROR${NC} ]"
ALL=0
# Just does a quick setup of dots.
LITE=0
GUISYSTEM=0
source "$DOTFILES_DIR/editors/vim/install.sh"
source "$DOTFILES_DIR/editors/emacs/install.sh"
source "$DOTFILES_DIR/font_install.sh"
source "$DOTFILES_DIR/git/install.sh"
source "$DOTFILES_DIR/shell/install.sh"
source "$DOTFILES_DIR/system/x11/install.sh"
source "$DOTFILES_DIR/system/OSX/install.sh"
source "$DOTFILES_DIR/system/packages/install.sh"
source "$DOTFILES_DIR/system/ssh/install.sh"
source "$DOTFILES_DIR/terminal/install.sh"
source "$DOTFILES_DIR/windowManagers/install.sh"
source "$DOTFILES_DIR/misc/install.sh"
source "$DOTFILES_DIR/nix/install.sh"
source "$DOTFILES_DIR/nix/home/install.sh"
# Need to change vscode's installer to not autorun. Or maybe leave to only run manually...
# source "$DOTFILES_DIR/editors/vscode/install.sh"
# # Source every `install.sh` file in env
# # Problematic because some of the installers are recursive.
# find "$DOTFILES_DIR" -name "install.sh" -print0 |
# while read installer; do
# source "$installer"
# done
# {]} Setup and variables
uninstall() {
if askQuestionYN "Really uninstall?"; then
set_up="Remove custom"
installStr="Uninstall"
readSettings
for installer in $installers; do
un$installer
done
rm -f "$XDG_CONFIG_HOME/.dotfiles_dir"
# Remove self
if askQuestionYN "Delete repo directory?"; then
rm -rf "$($SCRIPTDIR_CMD)"
fi
# Reset bash
exec bash
fi
}
installers=""
readSettings() {
# May be set to "uninstall" rather than defaults set here.
set_up="${set_up:-Set up}"
installStr="${installStr:-Install}"
# Order is designed so that things that may prompt for input
# within installer are done first, and within those, the ones that may
# take a while (eg downloading things) are last.
# Put $installers after to bump something to the front of the queue.
# Functions must be called "do[X]", with a corresponding "undo[X]" to uninstall.
# Pretty much always want these, and most are fairly low-cost (mostly just dotfiles)
installers="$installers doShell"
installers="$installers doVim"
installers="$installers doTmux"
installers="$installers doGit"
installers="$installers doEmacs"
installers="$installers doMisc"
installers="$installers doTerminals"
if [ "$LITE" = 1 ]; then
return
fi
# Asks for gitlab login for shared server repo, so put early.
if [ "$ALL" = 1 ] || askQuestionYN "$set_up SSH server config from gitlab?" ; then
installers="$installers doSSH"
fi
# if [ "$ALL" = 1 ] || askQuestionYN "$set_up emacs?" ; then
# installers="$installers doEmacs"
# fi
# Install brew if OS X or no sudo. Otherwise use normal packages.
if ! substrInStr "nixos" "$(uname -a)" && \
([ "$ALL" = 1 ] || \
askQuestionYN "$installStr packages (May require sudo and take a while)?"); then
if substrInStr "darwin" "$OSTYPE" || ! sudo -v ; then
installers="$installers installBrew"
fi
installers="$installers doPackages"
fi
if ! substrInStr "Android" "$(uname -a)" && [ "$OSTYPE" != "msys" ]; then
if ([ "$ALL" = 1 ] || askQuestionYN "Will this be a GUI system?"); then
GUISYSTEM=1
installers="$installers doFonts"
if [ "$OSTYPE" = "linux-gnu" ]; then
installers="$installers doX11"
elif substrInStr "darwin" "$OSTYPE"; then
installers="$installers doOSX"
fi
installers="$installers doWM"
fi
fi
if [ "$ALL" = 1 ] || askQuestionYN "Install home-manager?" ; then
installers="$installers doHomeManager"
if [ "$ALL" = 1 ] || askQuestionYN "Install packages with home-manager?" ; then
installers="$installers doHomeManagerPackages"
fi
fi
# if [ "$ALL" = 1 ] || askQuestionYN "Install VSCode extensions?" ; then
# installers="$installers vscodeExtensions"
# fi
}
main() {
readSettings
for installer in $installers; do
printErr "${Yellow} Installing $installer"
"$installer" "${1:-}"
done
printErr "${Green} Install Complete${NC}"
# Restart shell
exec "$SHELL"
}
# set default arg to avoid warnings
arg1=${1:-}
# echo 'arg' $arg1
case "$arg1" in
"-h")
echo '-l: lite (just dots); -u: uninstall (partially supported); -a: all (sortof)'
;;
"-l")
LITE=1
;;
"-a")
ALL=1
;;
"-u")
uninstall
exit
;;
*)
;;
esac
if [[ $arg1 =~ ^--?[aA][lL]{2}?$ ]]; then
ALL=1
fi
if [ "$OSTYPE" = "linux-gnu" ]; then
printErr "[$Green Linux ${NC}]"
elif substrInStr "darwin" "$OSTYPE"; then
printErr "[$Green OSX ${NC}]"
elif [ "$OSTYPE" = "msys" ]; then
printErr "[$Green Win (git bash) ${NC}]"
else
printErr "OS not detected..."
if askQuestionYN "Continue anyway?" ; then
true
else
printErr "Exiting without change."
exit
fi
fi
main "${1:-}"