-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteractive.bash
More file actions
executable file
·117 lines (96 loc) · 2.06 KB
/
Copy pathinteractive.bash
File metadata and controls
executable file
·117 lines (96 loc) · 2.06 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
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
#!/usr/bin/env bash
set -e
usage() {
LESS=-FEXR less <<HELP
interactive.bash [OPTIONS]
Install and configure almost everything after a fresh install
-a do everything
-b install binary scripts
-h show this help
HELP
}
declare -A colors
colors[red]=$(tput setaf 1)
colors[green]=$(tput setaf 2)
colors[blue]=$(tput setaf 4)
colors[reset]=$(tput sgr0)
declare distro
declare everything
declare custom
declare binaries
color() {
local c
c="$1"
shift
printf '%s' "${colors[$c]}"
printf '%s\n' "$@"
printf '%s' "${colors[reset]}"
}
err() {
color red "$@" >&2
}
die() {
[[ -n "$1" ]] && err "$1"
exit 1
}
should_do() {
[[ -n "$1" || -n "$everything" ]] && return 0
[[ -n "$custom" ]] && return 1
while true; do
read -rp "$2 (Y/n) " answer
case $answer in
Y | y | yes | "") return 0 ;;
N | n | no) return 1 ;;
*) err "Invalid answer" ;;
esac
done
}
verify_distro() {
if [[ -r /etc/os-release ]]; then
distro=$(awk -F'=' '"NAME" == $1 { gsub("\"", "", $2); print tolower($2); }' /etc/os-release)
distro="${distro%% *}"
fi
case "$distro" in
manjaro | ubuntu | arch)
color green "Found distro: $distro"
return 0
;;
*) die "Unknown distro '$distro' :(" ;;
esac
}
while getopts 'abh' opt; do
case "$opt" in
a) everything=1 ;;
b)
binaries=1
custom=1
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
shift "$((OPTIND - 1))"
install_binary_scripts() {
echo "==================================="
echo "Installing binaries scripts"
echo "==================================="
bin=~/.local/bin
mkdir -p $bin
cd ~/dotfiles
while IFS= read -r -d '' script; do
basename "$script"
ln -fs -- "$PWD/$script" "$bin"
done < <(find bin -type f -perm -+x -print0)
}
main() {
verify_distro
(should_do "$binaries" "Install binary scripts?") && install_binary_scripts
return 0
}
main