-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarble.sh
executable file
·64 lines (52 loc) · 1.29 KB
/
marble.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
#!/usr/bin/env bash
MARBLE="$(basename $0)"
STATIC_DIR="./static"
ACTIONS_DIR="./actions"
# Helper functions (might make porting to other distros easier)
pkg_install() {
xbps-install -y $@
}
pkg_remove() {
xbps-remove -y $@
}
service_enable() {
ln -s /etc/sv/"$1" /var/service
}
service_disable() {
rm /var/service/"$1"
}
# Source action, exit if any command fails
execute_action() {
set -e
source "$1"
}
# Determine privelege level
if [ $(id -u) -eq 0 ]; then
ROLE="root"
else
ROLE="noroot"
fi
for action in $ACTIONS_DIR/$ROLE/*; do
description="$(head -n 1 "$action" | cut -c3-)"
ACTIONS+=("$action" "$description")
done
# Welcome screen
whiptail --title "$MARBLE" --ok-button "Proceed" \
--msgbox "Welcome to Marble! An automated ricing solution. Please make sure your system is up to date before proceeding." \
0 0
# Main loop
while true; do
# Get user selection
choice=$(whiptail --title "$MARBLE" --ok-button "Select" --cancel-button "Exit" --notags \
--menu "You are running Marble as ${ROLE}. The following options are available:" \
0 0 0 "${ACTIONS[@]}" 3>&1 1>&2 2>&3)
code=$?
# Exit if the user wishes to
if [ $code -ne 0 ]; then
break
fi
# Carry out chosen action
execute_action "$choice"
read -n 1 -s -r -p "Press any key to continue."
echo
done