-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy patharmbian-config
executable file
·172 lines (151 loc) · 3.94 KB
/
armbian-config
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
#!/bin/bash
tput init
#
# Language-based variable assignment for script directory path
# This serves as a Rosetta Stone for developers,
# allowing them to use the variable name they are most comfortable with.
# allows CTRL c to exit
trap "exit" INT TERM
[[ $EUID != 0 ]] && exec sudo "$0" "$@"
#
# Get the script directory
script_dir="$(dirname "$0")"
[[ -d "$script_dir/../tools" ]] && tools_dir="$script_dir/../tools"
[[ ! -d "$script_dir/../lib" && -n "$tools_dir" ]] && echo -e "Please run\nbash "$tools_dir/config-assemble.sh" to build the lib directory\n" && exit 1
# 'whiptail' is a simple dialog box utility that works well with Bash. It doesn't have all the features of some other dialog box utilities, but it does everything we need for this script.
[[ -x "$(command -v whiptail)" ]] && DIALOG="whiptail"
# Define the lib directory one level up from the script directory
lib_dir="$script_dir/../lib/armbian-config"
doc_dir="$script_dir/../share/doc/armbian-config"
json_file="$lib_dir/config.jobs.json"
#
# Load The Bash procedure Objects
json_data=$(<"$json_file")
#
# Prepare the module options array
declare -A module_options
#
# Load configng core functions and module options array
source "$lib_dir/config.functions.sh"
set_runtime_variables
check_distro_status
echo "Loaded Runtime variables..." #| show_infobox ;
#set_newt_colors 2
echo "Loaded Dialog..." #| show_infobox ;
source "$lib_dir/config.docs.sh"
echo "Loaded Docs..." #| show_infobox ;
source "$lib_dir/config.system.sh"
echo "Loaded System helpers..." #| show_infobox ;
source "$lib_dir/config.network.sh"
echo "Loaded Network helpers..." #| show_infobox ;
source "$lib_dir/config.software.sh"
echo "Loaded Software helpers..." #| show_infobox ;
#
# Loads the variables from beta armbian-config for runtime handling
source "$lib_dir/config.runtime.sh"
echo "Loaded Runtime conditions..." #| show_infobox ;
clear
case "$1" in
"--help")
if [[ -n "$2" ]]; then
see_cmd_list "$2"
echo ""
exit 0
fi
echo "Usage: armbian-config --[option]
Options:
--help [category] Use [category] to filter specific menu options.
--cmd [option] Run a command from the menu (simple)
--api [option] Run a helper command (advanced)
--doc Generate the README.md file
Examples:
armbian-config --help [cmd||System||Software||Network||Localisation]
armbian-config --cmd help
armbian-config --api help
"
exit 0
;;
"--doc")
generate_readme
exit 0
;;
"--cmd")
INPUTMODE="cmd"
shift
if [[ -z "$1" || "$1" == "help" ]]; then
see_cmd_list
exit 0
fi
args=$(sanitize_input "$@")
execute_command "$args"
exit 0
;;
"--api")
shift
if [[ -z "$1" || "$1" == "help" ]]; then
see_use
exit 0
fi
option="$1"
shift
args=$(sanitize_input "$@")
# echo -e "\"$option\" \"$args\""
"$option" "$args"
exit 0
;;
"main=help" | "main=Help")
see_cli_legacy
echo ""
exit 0
;;
"main="*)
declare -A main_map
main_map=(
# map name to menu category
["System"]="S"
["Software"]="I"
["Network"]="N"
["Localisation"]="L"
)
main_value="${1#main=}"
main_value="${main_map[$main_value]}"
if [ -z "$main_value" ]; then
echo "Error: Invalid List $1"
exit 1
fi
declare -A select_map
# map name to menu number
select_map=(
["Headers"]="04"
["Headers_install"]="04"
["Headers_remove"]="05"
["Firmware"]="06"
["Nightly"]="07"
)
select_value="${2#selection=}"
select_value="${select_map[$select_value]}"
if [ -z "$select_value" ]; then
echo "Error: Invalid Option $2"
exit 1
fi
echo "$main_value""$select_value"
execute_command "$main_value""$select_value"
exit 0
;;
*)
if [[ $EUID != 0 ]]; then
echo -e "error: Exiting \nTry: 'sudo armbian-config'\n or: 'armbian-config --help' for More info\n\n"
exit 0
fi
;;
esac
#
# Generate the top menu with the modified Object data
set_colors 4
generate_top_menu "$json_data"
#
# Exit the script with a success status code
#
# Show about this tool on exit
about_armbian_configng
exit 0