forked from AiursoftWeb/AnduinOS-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuconfig.sh
More file actions
executable file
·167 lines (158 loc) · 6.07 KB
/
Copy pathmenuconfig.sh
File metadata and controls
executable file
·167 lines (158 loc) · 6.07 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
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
#!/bin/bash
# menuconfig.sh — TUI for editing AnduinOS build configuration (args.sh)
set -euo pipefail
DIALOG=${DIALOG:-whiptail}
ARGS_FILE="$(dirname "$(readlink -f "$0")")/args.sh"
BACKUP_FILE=$(mktemp)
SAVE_CHANGES=false
cp -- "$ARGS_FILE" "$BACKUP_FILE"
cleanup() {
if [ "$SAVE_CHANGES" != true ]; then
cp -- "$BACKUP_FILE" "$ARGS_FILE"
fi
rm -f -- "$BACKUP_FILE"
}
trap cleanup EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
# ---------------------------------------------------------------------------
# Helpers: get current value, set new value
# ---------------------------------------------------------------------------
get() {
local key="$1"
(
# Evaluate computed defaults without leaking args.sh environment
# changes (HOME, locale, etc.) into the menuconfig process.
# shellcheck disable=SC1090
source "$ARGS_FILE"
printf '%s\n' "${!key}"
)
}
set_val() {
local key="$1" val="$2"
# Escape forward slashes for sed
local escaped
escaped=$(printf '%s\n' "$val" | sed 's/[\/&]/\\&/g')
sed -i "s|^export ${key}=.*|export ${key}=\"${escaped}\"|" "$ARGS_FILE"
}
# ---------------------------------------------------------------------------
# Dialog wrapper
# ---------------------------------------------------------------------------
inputbox() {
local title="$1" text="$2" init="$3"
local rc=0
result=$($DIALOG --title "$title" --inputbox "$text" 10 60 "$init" 3>&1 1>&2 2>&3) || rc=$?
return $rc
}
menubox() {
local title="$1" text="$2"
shift 2
local rc=0
result=$($DIALOG --title "$title" --menu "$text" 0 0 0 "$@" 3>&1 1>&2 2>&3) || rc=$?
return $rc
}
msg() {
$DIALOG --title "$1" --msgbox "$2" 0 0
}
# ---------------------------------------------------------------------------
# Sub-menus
# ---------------------------------------------------------------------------
edit_os() {
while true; do
result=""
menubox "OS Information" "Select to edit:" \
"codename" "Ubuntu codename [$(get TARGET_UBUNTU_VERSION)]" \
"name" "OS short name [$(get TARGET_NAME)]" \
"business" "OS display name [$(get TARGET_BUSINESS_NAME)]" \
"version" "Build version [$(get TARGET_BUILD_VERSION)]" \
"back" "< Back"
case "$result" in
codename)
inputbox "Ubuntu Codename" "Release codename (jammy/noble/oracular/plucky/questing/resolute):" "$(get TARGET_UBUNTU_VERSION)" || continue
set_val TARGET_UBUNTU_VERSION "$result" ;;
name)
inputbox "OS Short Name" "Lowercase, no spaces/special chars:" "$(get TARGET_NAME)" || continue
set_val TARGET_NAME "$result" ;;
business)
inputbox "OS Display Name" "Business name, no special chars:" "$(get TARGET_BUSINESS_NAME)" || continue
set_val TARGET_BUSINESS_NAME "$result" ;;
version)
inputbox "Build Version" "Version string (e.g. 2.0.0, 2.0.0-beta1):" "$(get TARGET_BUILD_VERSION)" || continue
set_val TARGET_BUILD_VERSION "$result" ;;
back|"") return ;;
esac
done
}
edit_repos() {
while true; do
result=""
menubox "Repositories" "Select to edit:" \
"apt" "APT mirror [$(get APT_SOURCE)]" \
"apkg" "APKG server [$(get APKG_SERVER)]" \
"cert" "APKG cert name [$(get APKG_CERT_NAME)]" \
"aptcfg" "APT config package [$(get APT_CONFIG_PACKAGE)]" \
"back" "< Back"
case "$result" in
apt)
inputbox "APT Mirror" "Ubuntu mirror URL:" "$(get APT_SOURCE)" || continue
set_val APT_SOURCE "$result" ;;
apkg)
local choice
choice=$($DIALOG --title "APKG Server" --menu "Choose:" 0 0 2 \
"https://packages.anduinos.com" "Production" \
"https://apkg-dev.aiursoft.com" "Development" 3>&1 1>&2 2>&3) && set_val APKG_SERVER "$choice"
;;
cert)
inputbox "APKG Cert" "GPG certificate name:" "$(get APKG_CERT_NAME)" || continue
set_val APKG_CERT_NAME "$result" ;;
aptcfg)
local choice
choice=$($DIALOG --title "APT Config Package" --menu "Choose:" 0 0 2 \
"anduinos-apt-config" "Production" \
"anduinos-apt-config-dev" "Development" 3>&1 1>&2 2>&3) && set_val APT_CONFIG_PACKAGE "$choice"
;;
back|"") return ;;
esac
done
}
edit_build() {
while true; do
result=""
menubox "Build Options" "Select to edit:" \
"arch" "Target architecture [$(get TARGET_ARCH)]" \
"back" "< Back"
case "$result" in
arch)
local choice
choice=$($DIALOG --title "Target Architecture" --menu "Choose CPU architecture:" 0 0 2 \
"amd64" "Intel / AMD 64-bit (x86_64)" \
"arm64" "ARM 64-bit (Snapdragon, Apple Silicon, Raspberry Pi)" 3>&1 1>&2 2>&3) && set_val TARGET_ARCH "$choice"
;;
back|"") return ;;
esac
done
}
# ---------------------------------------------------------------------------
# Main loop
# ---------------------------------------------------------------------------
while true; do
result=""
menubox "AnduinOS Build Configuration" "make menuconfig — edit args.sh" \
"os" "OS Information" \
"repos" "Repositories" \
"build" "Build Options" \
"save" "Save & Exit" \
"exit" "Exit without saving"
case "$result" in
os) edit_os ;;
repos) edit_repos ;;
build) edit_build ;;
save)
SAVE_CHANGES=true
msg "Saved" "Configuration saved to args.sh.\nRun 'make' to build."
exit 0 ;;
exit|"")
exit 0 ;;
esac
done