-
Notifications
You must be signed in to change notification settings - Fork 5
/
Grub2InstallerGUI
executable file
·278 lines (224 loc) · 6.97 KB
/
Grub2InstallerGUI
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
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
VERSION="1.0"
TITULO="GRUB2 Installer GUI $VERSION - By geminis_demon"
LOGO="/usr/share/pixmaps/Grub2InstallerGUI/logo.png"
LOGO_ERROR="/usr/share/pixmaps/Grub2InstallerGUI/error.png"
LOGO_STOP="/usr/share/pixmaps/Grub2InstallerGUI/stop.png"
LOGO_OK="/usr/share/pixmaps/Grub2InstallerGUI/ok.png"
TMP="/tmp/Grub2InstallerGUI"
### Error print ###
function print_error_and_exit() {
yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO_ERROR" \
--button "OK:0" \
--text-align "center" \
--text "\n\n\n $1"
exit 1
}
### Error print ###
if [ -d /sys/firmware/efi ]; then
MODO=UEFI
EFI=0
else
EFI=1
MODO=BIOS
fi
if [ ! -d "/mnt/live/memory/changes" ]; then
yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO_STOP" \
--button "OK:0" \
--text-align "center" \
--text "\n\n\n Para utilizar este instalador debes iniciar Wifislax64 en modo live \n"
exit
fi
rm -rf "$TMP" && mkdir -p "$TMP"
(yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO" \
--no-buttons \
--progress --pulsate \
--text-align "center" \
--text "\n\n\n Buscando instalaciones de Wifislax64... \n" \
& echo $! >"$TMP/pid")
os-prober 2>/dev/null|grep ":Wifislax64" >"$TMP/os-prober"
if [ -z "$(cat "$TMP/os-prober")" ]; then
kill $(cat "$TMP/pid")
yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO_STOP" \
--button "Abrir instalador de Wifislax64:0" \
--button "Cerrar:1" \
--text-align "center" \
--text "\n\n\n Primero debes instalar Wifislax64 \n"
case $? in
0) WifislaxInstallerGUI; $0;;
*) exit;;
esac
fi
umount -a 2>/dev/null
cat "$TMP/os-prober"|cut -d: -f-2|sed 's/:/ /'|\
while read DEV SO SO_VER; do
MNT="$(echo "$DEV"|sed 's/dev/mnt/')"
[ ! -d "$MNT" ] && mkdir -p "$MNT"
mount -t ext4 "$DEV" "$MNT"
GB="$(df -H "$DEV"|awk '{print $2}'|tail -1|sed 's/G$//')"
echo "$DEV | ${GB}GB | $SO $SO_VER"
unset DEV MNT GB SO
done|tr '\n' '!' >"$TMP/menu_particiones"
kill $(cat "$TMP/pid")
if [ $(cat "$TMP/os-prober"|wc -l) -eq 1 ]; then
DEV="$(cat "$TMP/os-prober"|cut -d':' -f1)"
else
yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO" \
--button "OK:0" \
--button "Cancelar:1" \
--text "\n\n Selecciona una partición: \n" \
--text-align "center" \
--form --field="":CB "$(cat "$TMP/menu_particiones")" \
>"$TMP/return"
DEV="$(cat "$TMP/return"|cut -d' ' -f1)"
[ -z "$DEV" ] && exit
fi
if [ $EFI -eq 0 ]; then
if echo $DEV | grep -q '/dev/mmc'; then #Tablets fix
DEVICE=$(echo $DEV |grep -E 'mmcblk[0-9]+' -o)
elif echo $DEV | grep -q '/dev/nvme' ; then
DEVICE=$(echo $DEV |cut -b 1-12)
else
DEVICE=${DEV//[0-9]}
fi
echo modo UEFI
echo $DEVICE
UUID=$(blkid $DEV -o value -s UUID)
#EFI_PART=$(fdisk -l | grep -E "${DEVICE}[0-9]+" | grep "EFI" | cut -d" " -f 1)
ROOT_PART=${DEV: -1}
EFI_TMP=$(mktemp)
# Scan for EFI partitions:
for drive in sda sdb sdc sdd sde sdf sdg sdh sdi sdj sdk sdl sdm sdn sdo sdp mmcblk0 nvme0n1; do
if LANG=C fdisk -l /dev/$drive 2> /dev/null | grep -q "Disklabel type: gpt" ; then
gdisk -l /dev/$drive 2> /dev/null | grep -w EF00 | while read efisp ; do
if echo $drive | grep -q -E "mmc|nvme" ; then
echo /dev/${drive}p$(expr $(echo "$efisp" | cut -b 1-4)) >> $EFI_TMP
else
echo /dev/$drive$(expr $(echo "$efisp" | cut -b 1-4)) >> $EFI_TMP
fi
done
fi
done
if [ "$(cat $EFI_TMP)" = "" ]; then # No EFI partitions
rm -f $EFI_TMP
print_error_and_exit "No se han detectado particiones EFI. Cree una partición FAT32 de +100MB con los flags \"boot\" y \"esp\""
fi
# Initially, we will just take the first EFI partition found, which
# will probably be on /dev/sda:
EFI_PART="$(cat $EFI_TMP | head -n 1)"
echo "EFI_PART=$EFI_PART"
# This file is no longer needed:
rm -f $EFI_TMP
else
yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO" \
--button "OK:0" \
--button "Cancelar:1" \
--text-align "center" \
--text "\nSelecciona donde se instalará el cargador de arranque: " \
--list --no-headers \
--column "" "MBR" "Se instalará en ${DEV//[0-9]} (Recomendado)" \
--column "" "ROOT" "Se instalará en $DEV (Experto)" \
>"$TMP/return"
[ ! "$(cat "$TMP/return")" ] && exit
DEVICE="$(cat "$TMP/return"|awk '{print $4}')"
fi
(yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO" \
--no-buttons \
--progress --pulsate \
--text-align "center" \
--text "\n\n\n Instalando cargador de arranque GRUB2... \n\n" \
& echo $! >"$TMP/pid")
MNT="$(echo "$DEV"|sed 's/dev/mnt/')"
mount|grep "^/dev/"|egrep -v "^$DEV|^/dev/sr[0-9]"|cut -d' ' -f1|xargs -i umount {}
mount --bind /dev "$MNT"/dev
mount --bind /dev/pts "$MNT"/dev/pts
mount --bind /proc "$MNT"/proc
mount --bind /sys "$MNT"/sys
[ -f "$MNT/boot/grub/i386-pc/core.img" ] && chattr -i "$MNT/boot/grub/i386-pc/core.img"
if [ $EFI -eq 0 ]; then
EFI_MOUNT=$(mktemp -d)
mount $EFI_PART $EFI_MOUNT
echo "grub-install --root-directory=$MNT --recheck --efi-directory=$EFI_MOUNT --force "$DEVICE""
grub-install --root-directory=$MNT --recheck --efi-directory=$EFI_MOUNT --force "$DEVICE"
salida=$?
umount -l $EFI_MOUNT
rmdir $EFI_MOUNT
else
echo "chroot "$MNT" grub-install --recheck --force "$DEVICE""
chroot "$MNT" grub-install --recheck --force "$DEVICE"
salida=$?
fi
if [ $salida -ne 0 ]; then
kill $(cat "$TMP/pid")
umount "$MNT"/sys
umount "$MNT"/proc
umount "$MNT"/dev/pts
umount "$MNT"/dev
umount "$MNT"
print_error_and_exit "Ocurrió un error durante la instalación (grub-install), no se puede continuar \n"
fi
[ "$(cat /proc/cmdline|grep "nomodeset")" ] && sed -i 's/="vga=788"/="vga=788 nomodeset"/' "$MNT/etc/default/grub"
chroot "$MNT" update-grub
if [ $? -ne 0 ]; then
kill $(cat "$TMP/pid")
umount "$MNT"/sys
umount "$MNT"/proc
umount "$MNT"/dev/pts
umount "$MNT"/dev
umount "$MNT"
print_error_and_exit "Ocurrió un error durante la instalación (update-grub), no se puede continuar \n"
fi
umount "$MNT"/sys
umount "$MNT"/proc
umount "$MNT"/dev/pts
umount "$MNT"/dev
umount "$MNT"
kill $(cat "$TMP/pid")
yad --on-top --center \
--width 500 \
--height 190 \
--title "$TITULO" \
--window-icon "$LOGO" \
--image "$LOGO_OK" \
--button "OK:0" \
--text-align "center" \
--text "\n\n La instalación en modo $MODO ha finalizado, ahora ya puedes
reiniciar el sistema y arrancar Wifislax64
desde el disco duro. \n
Saludos desde www.seguridadwireless.net \n"
exit