-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·116 lines (97 loc) · 3.61 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#===================================================================================
# BUNSENLABS POSTINSTALL SCRIPT
# FILE: install
# DESCRIPTION: find and exec .sh scripts from bunsen-scripts project
# AUTHOR: Leonardo Marco
# VERSION: 1.0
# CREATED: 2018.05.10
#===================================================================================
#=== FUNCTION ======================================================================
# NAME: help
# DESCRIPTION: Show command help
#===================================================================================
function help() {
echo -e 'Install configs and themes scripts in BunsenLabs '"$bunsen_ver"'
Usage: '$(basename $0)' [-h] [-l] [-a <actions>] [-y] [-d]
\e[1m-l\e[0m\t\tOnly list actions
\e[1m-a <actions>\e[0m\tOnly do selected actions (e.g: -a 5,6,10-15)
\e[1m-y\e[0m\t\tAuto-answer yes to all actions
\e[1m-d\e[0m\t\tAuto-answer default to all actions
\e[1m-h\e[0m\t\tShow this help'
exit 0
}
#=== FUNCTION ======================================================================
# NAME: ask_action
# DESCRIPTION: ask for a action and determine if do it or not do
# EXIT CODE:
# 0-> do the action
# 1-> dont do de action
#===================================================================================
n=0
function ask_action() {
action="$1"
info="$2"
default="${3,,}"; default="${default:0:1}";
[ "$default" != "n" ] && default="y"
n=$((n+1))
# Skip action if not in -a
[ "$actions" ] && { echo "$actions" | grep -w "$n" &> /dev/null || return 1; }
[ "$list" ] && echo -e "[$n] $action ($default)" && return 1
# Show action
[ "${default,,}" = "y" ] && q="(Y/n)?" || q="(y/N))?"
echo -en "\n\e[33m${info}\n\e[39m\e[1m[$n] \e[4m${action}\e[0m $q "
case "$yes" in
allyes) q="y"; echo "$q" ;;
default) q="$default"; echo "$q" ;;
*) read q; q="${q,,}"; q="${q:0:1}" ;;
esac
[ "$q" != "n" ] && [ "$q" != "y" ] && q="$default"
[ "${q,,}" != "n" ] && return 0
return 1
}
#=== PARAMS ========================================================================
while getopts ":hlyda:" o; do
case "$o" in
h) help ;;
l) list="true" ;;
y) yes="allyes" ;;
d) yes="default" ;;
a) for a in $(echo "$OPTARG" | tr "," " "); do
# Is a range
echo "$a" | grep -E "[0-9]"*-"[0-9]" &> /dev/null && actions="$actions $(eval echo {$(echo $a|sed "s/-/../")})"
# Is a number
[ "$a" -eq 0 ] &>/dev/null; [ $? -le 1 ] && actions="$actions $a"
done
;;
esac
done
#=== CHECKS =======================================================================
[ ! "$list" ] && [ "$(id -u)" -ne 0 ] && echo "Administrative privileges needed" && exit 1
if ! cat /etc/*release | grep -i bunsenlabs &> /dev/null; then
echo "Seems you are not running BunsenLabs distro"
echo "Some actions may fail. Cross your fingers and press enter..."
read
fi
#=== EXEC-ACTIONS ==================================================================
base_dir="$(dirname "$(readlink -f "$0")")"
n=0
# For each .sh file
IFS=$'\n\t'
for script in $(ls "$base_dir"/*/*.sh); do
head="$(head -10 "$script")"
# Get ACTION field:
action="$(echo "$head" | grep "#[[:blank:]]*ACTION:" | sed 's/#[[:blank:]]*ACTION:[[:blank:]]*//')"
[ ! "$action" ] && continue
# Get INFO field:
info="$(echo "$head" | grep "#[[:blank:]]*INFO:" | sed 's/#[[:blank:]]*INFO:[[:blank:]]*//')"
# Get DEFAULTfield:
default="$(echo "$head" | grep "#[[:blank:]]*DEFAULT:" | sed 's/#[[:blank:]]*DEFAULT:[[:blank:]]*//')"
if ask_action "$action" "$info" "$default"; then
bash "$script" # EXEC SCRIPT
fi
done
if [ ! "$list" ] && [ ! "$actions" ] && ask_action "Reboot" "" "n"; then
reboot
fi
echo