-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·92 lines (71 loc) · 1.73 KB
/
install
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
#!/usr/bin/env bash
declare HEADLESS
prompt_boolean() {
local var_name="$1"
local message="$2"
local default=${3:-1}
yn="$([ "$default" -eq 0 ] && echo -n "[y/N]" || echo -n '[Y/n]')"
echo -n "$message $yn " && read -r input
[ "$input" = "y" ] || [ "$input" = "Y" ] && {
eval "$var_name=1"
return
}
[ "$input" = "n" ] || [ "$input" = "N" ] && {
eval "$var_name=0"
return
}
[ "$input" = "" ] && {
eval "$var_name=$default"
return
}
prompt_boolean "$1" "$2" "$3"
}
get_config() {
prompt_boolean 'HEADLESS' 'Do you want to install on a headless machine?'
export HEADLESS
}
execute_with_privilege() {
local base_dir="$1"
[ "$base_dir" = 'system' ] && {
sudo ${@:2}
return $?
} || {
${@:2}
return $?
}
}
get_destination_dir() {
local base_dir="$1"
[ $base_dir = 'system' ] && echo -n "/" || echo -n "$HOME"
}
assert_destination_directories() {
local base_dir="$1"
local dest_dir=$(get_destination_dir "$base_dir")
find "$base_dir" -type d | while read dir; do
local path="$dest_dir/$(echo "$dir" | sed "s/$base_dir//")"
execute_with_privilege "$base_dir" mkdir -p "$path" 2>/dev/null
done
}
setup_symlinks() {
local base_dir="$1"
assert_destination_directories "$base_dir"
execute_with_privilege "$base_dir" stow -t "$(get_destination_dir "$base_dir")" "$base_dir"
return $?
}
main() {
get_config
setup_symlinks user || exit 1
setup_symlinks system || exit 1
./setup/setup-nnn || exit 1
{
[ "$HEADLESS" -eq 0 ] && ./setup/setup-keyboard
} || exit 1 && echo 'keyboard setup [ok]'
{
[ "$HEADLESS" -eq 0 ] && ./setup/setup-fonts
} || exit 1 && echo 'font setup [ok]'
{
[ "$HEADLESS" -eq 0 ] && ./setup/setup-system
} || exit 1 && echo 'system setup [ok]'
sudo locale-gen || exit 1
}
main