-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·265 lines (215 loc) · 5.77 KB
/
Copy pathinstaller.sh
File metadata and controls
executable file
·265 lines (215 loc) · 5.77 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/sh
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
CONFIG="./config.sh"
# Load config or create defaults
if [ -f "$CONFIG" ]; then
. "$CONFIG"
else
cat > "$CONFIG" <<EOF
BOOT_PART="/dev/sda1"
MAIN_PART="/dev/sda2"
HOSTNAME="antonio-pc"
USERNAME="antonio"
INSTALL_NVIDIA_DRIVERS=false
IS_DUAL_BOOT=false
IS_LAPTOP=false
USE_GRUB_REMOVABLE=false
BLUETOOTH=false
GIT_USERNAME="Antônio Carlos"
GIT_EMAIL="antonioocarlos@proton.me"
ROOT_PASS=""
USER_PASS=""
EOF
. "$CONFIG"
fi
save_config() {
cat > "$CONFIG" <<EOF
BOOT_PART="$BOOT_PART"
MAIN_PART="$MAIN_PART"
HOSTNAME="$HOSTNAME"
USERNAME="$USERNAME"
INSTALL_NVIDIA_DRIVERS=$INSTALL_NVIDIA_DRIVERS
IS_DUAL_BOOT=$IS_DUAL_BOOT
IS_LAPTOP=$IS_LAPTOP
USE_GRUB_REMOVABLE=$USE_GRUB_REMOVABLE
BLUETOOTH=$BLUETOOTH
GIT_USERNAME="$GIT_USERNAME"
GIT_EMAIL="$GIT_EMAIL"
ROOT_PASS="$ROOT_PASS"
USER_PASS="$USER_PASS"
EOF
}
# Dialog helpers
ask() {
dialog --inputbox "$1" 10 50 "$2" 2>&1 >/dev/tty
}
ask_password() {
dialog --insecure --passwordbox "$1" 10 50 2>&1 >/dev/tty
}
ask_yesno() {
if dialog --yesno "$1" 7 50 >/dev/tty 2>/dev/null; then
printf '%s\n' true
else
printf '%s\n' false
fi
}
select_disk() {
set -- # reset positional parameters
while IFS= read -r line; do
NAME=$(printf '%s\n' "$line" | awk '{print $1}')
SIZE=$(printf '%s\n' "$line" | awk '{print $2}')
MODEL=$(printf '%s\n' "$line" | cut -d' ' -f3-)
[ -z "$MODEL" ] && MODEL="unknown"
set -- "$@" "$NAME" "$SIZE - $MODEL"
done <<EOF
$(lsblk -dn -o NAME,SIZE,MODEL)
EOF
if [ "$#" -eq 0 ]; then
dialog --msgbox "No disks detected." 7 40
return 1
fi
dialog --clear --stdout \
--title "Select Disk" \
--menu "Choose a disk to partition:" 15 70 6 \
"$@"
}
# Menu Actions
partition_disks() {
DISK=$(select_disk) || return 1
cfdisk "/dev/$DISK" </dev/tty >/dev/tty 2>/dev/tty
}
edit_partitions() {
BOOT_PART=$(ask "Boot partition (EFI)" "$BOOT_PART")
MAIN_PART=$(ask "Root partition" "$MAIN_PART")
save_config
}
edit_user_info() {
HOSTNAME=$(ask "Hostname" "$HOSTNAME")
USERNAME=$(ask "Username" "$USERNAME")
save_config
}
edit_passwords() {
ROOT_PASS=$(ask_password "Root password")
USER_PASS=$(ask_password "User password")
save_config
}
edit_git_info() {
GIT_USERNAME=$(ask "Git username" "$GIT_USERNAME")
GIT_EMAIL=$(ask "Git email" "$GIT_EMAIL")
save_config
}
edit_system_flags() {
INSTALL_NVIDIA_DRIVERS=$(ask_yesno "Install NVIDIA drivers?")
IS_DUAL_BOOT=$(ask_yesno "Is this a dual-boot system?")
IS_LAPTOP=$(ask_yesno "Is this a laptop?")
USE_GRUB_REMOVABLE=$(ask_yesno "Install GRUB as removable (fallback)?")
BLUETOOTH=$(ask_yesno "Enable Bluetooth support?")
save_config
}
show_summary() {
if [ -n "$ROOT_PASS" ] && [ -n "$USER_PASS" ]; then
PASS_STATUS="set"
else
PASS_STATUS="not set"
fi
dialog --msgbox "
Partitions:
BOOT: $BOOT_PART
ROOT: $MAIN_PART
Users:
Hostname: $HOSTNAME
Username: $USERNAME
Passwords: $PASS_STATUS
Options:
NVIDIA drivers: $INSTALL_NVIDIA_DRIVERS
Dual Boot: $IS_DUAL_BOOT
Laptop: $IS_LAPTOP
GRUB Removable: $USE_GRUB_REMOVABLE
Bluetooth: $BLUETOOTH
Git:
Username: $GIT_USERNAME
Email: $GIT_EMAIL
" 27 60
}
do_install() {
if [ -z "$ROOT_PASS" ] || [ -z "$USER_PASS" ]; then
dialog --title "Missing Passwords" \
--msgbox "Root and user passwords are not set.\n\nPlease set BOTH passwords before installing." \
9 60
clear
return 1
fi
clear
LOGFILE="/tmp/installer.log"
: > "$LOGFILE"
# Run installer with live output + logging
(
./1-install.sh
echo $? > /tmp/.install_status
) 2>&1 | tee "$LOGFILE"
INSTALL_STATUS=$(cat /tmp/.install_status)
rm -f /tmp/.install_status
if [ "$INSTALL_STATUS" -ne 0 ]; then
dialog --title "Installation Failed" \
--textbox "$LOGFILE" 20 80
dialog --title "Installer Error" \
--msgbox "The installer exited with an error.\n\nLog saved to:\n$LOGFILE\n\nYou are still in live mode." \
10 60
clear
return 1
fi
while true; do
CHOICE=$(dialog --clear --stdout \
--title "Installation Complete!" \
--menu "Choose what to do next:" 15 60 5 \
1 "Exit installer (stay in live system)" \
2 "Reboot system now" \
3 "Continue in chroot")
case "$CHOICE" in
1)
clear
exit 0
;;
2)
clear
reboot
;;
3)
clear
. config.sh
mount "$MAIN_PART" /mnt
mkdir -p /mnt/boot/efi
mount "$BOOT_PART" /mnt/boot/efi
swapon /mnt/swapfile || true
xchroot /mnt /bin/sh
;;
esac
done
}
# Main Menu
main_menu() {
while true; do
CHOICE=$(dialog --clear --stdout --title "Installer Menu" --menu "Choose an option:" 18 60 10 \
1 "Partition Disks (cfdisk)" \
2 "Edit Partition Paths" \
3 "User + Hostname" \
4 "Edit Passwords" \
5 "Git Configuration" \
6 "System Options" \
7 "Show Summary" \
8 "Install" \
9 "Exit")
case "$CHOICE" in
1) partition_disks ;;
2) edit_partitions ;;
3) edit_user_info ;;
4) edit_passwords ;;
5) edit_git_info ;;
6) edit_system_flags ;;
7) show_summary ;;
8) do_install ;;
9) clear; exit 0 ;;
esac
done
}
main_menu