-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
get
547 lines (482 loc) · 11.9 KB
/
get
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
#!/usr/bin/env bash
##############################
# archibold.io (C) 2016-2020 #
##############################
# first ting: update the time or HTTPS won't work
if [ "$(which ntpdate 2> /dev/null)" != "" ]; then
sudo ntpdate pool.ntp.org
sudo timedatectl set-local-rtc 1
fi
source <(curl -s https://archibold.io/require)
require echomd
require partid
echoWithHeader() {
echomd "
# archibold.io
$@
"
}
welcomeMessage() {
echoWithHeader '
Welcome to Archibold installer.'
}
updatePacman() {
echoWithHeader '
Updating *pacman*, the default ArchLinux package manager'
sudo pacman -Sy --noconfirm archlinux-keyring
sudo pacman-db-upgrade
sudo pacman-key --init
sudo pacman-key --populate archlinux
}
grabDiskSize() {
local found=0
local size=
for size in $(lsblk --output SIZE $1); do
if [ "$found" = "0" ]; then
found=1
else
echo $size
return
fi
done
}
findTheDisk() {
local i=0
local choice=
local disks=
local disk=
echoWithHeader '
Please select the disk you would like to use
to install Arch Linux (pick a number).
*Please note:* #red(all data) in the chosen disk will be #red(lost).'
for disk in $(lsblk --output NAME); do
if [ "$(echo $disk | sed -e 's/^[a-z]//')" != "$disk" ] && [ "$(echo $disk | grep loop)" = "" ]; then
((i=i+1))
disks="$disks $disk"
printf " $(tput bold)$i$(tput sgr0) %-24s %-6s\n" /dev/$disk $(grabDiskSize /dev/$disk)
fi
done
echo ''
read -n1 -s choice
if [ "$choice" -gt "0" ] && [ "$choice" -le "$i" ]; then
i=0
for disk in $disks; do
((i=i+1))
if [ "$i" = "$choice" ]; then
DISK="/dev/$disk"
fi
done
else
echomd " #red(*Nope*), let's try again ... "
sleep 2 && clear && findTheDisk
fi
}
askAboutEncryption() {
local choice=
echoWithHeader "
Would you like to use *encryption* ? [Y/n]"
read -n1 -s choice
if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
ENCRYPTION=no
else
ENCRYPTION=yes
fi
}
askAboutGNOME() {
local choice=
echoWithHeader "
Would you like to also install *GNOME* ? [Y/n]"
read -n1 -s choice
if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
GNOME=no
else
GNOME=yes
fi
}
askAboutUEFI() {
local choice=
echoWithHeader "
Is *${DISK}* installed for a system
compatible with *UEFI* ? [Y/n]
"
read -n1 -s choice
if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
UEFI="no"
else
UEFI="64"
fi
}
askAboutUEFILike() {
local choice=
echoWithHeader "
Would you like regardless an *UEFI* like
partition *boot structure* ? [Y/n]"
read -n1 -s choice
if [ "$choice" != "n" ] && [ "$choice" != "N" ]; then
UEFI=yes
fi
}
askAboutEDD() {
local choice=
echoWithHeader "
Can this system use standard *EDD* settings ? [Y/n]
"
echomd " BIOS Enhanced Disk Drive Services
is usually available in modern systems."
read -n1 -s choice
if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
EDD=" edd=off"
fi
}
askAboutSWAP() {
local choice=
echoWithHeader "
How much *swap* do you need?
Please specify an amount and press enter.
Valid options can be 0, 100M or 1G or 2Gi, etc"
read choice
SWAP=$(echo $choice | sed -r 's/^([0-9]+[A-Z]i)[bB]$/\1/' | numfmt --from=auto)
if [[ $? -ne 0 ]] ; then
echo ''
echomd " #red(*Nope*), $choice is not valid, let's try again ... "
sleep 2 && clear && askAboutSWAP
fi
}
encryptPartition() {
local partition="$1"
local name="$2"
local uuid=$(partid $partition)
mkdir -p /run/cryptsetup
echo "$PASSWORD" | cryptsetup -v --uuid=$uuid luksFormat $partition
echo "$PASSWORD" | cryptsetup open $partition $name
}
createPartitions() {
local start=2048s
local part=
echoWithHeader "
Preparing *$DISK*"
sudo dd if=/dev/zero of=$DISK bs=1 count=2048 > /dev/null 2>&1
sync
if [ "$UEFI" = "no" ] || [ "$UEFI" = "yes" ]; then
echomd ' with an *msdos* label'
echo ''
sudo parted --script $DISK mklabel msdos > /dev/null 2>&1
else
echomd ' with UEFI *gpt* label'
echo ''
sudo parted --script $DISK mklabel gpt > /dev/null 2>&1
fi
if [ "$UEFI" != "no" ]; then
echomd ' with 512MiB *boot* partition'
echo ''
sudo parted --script --align optimal $DISK mkpart primary fat16 $start 512MiB > /dev/null 2>&1
sudo parted $DISK set 1 boot on
start=512MiB
fi
if [ "$SWAP" = "0" ]; then
echomd ' *without swap* partition'
echo ''
sudo parted --script --align optimal $DISK mkpart primary ext4 $start 100% > /dev/null 2>&1
else
echomd " with *$(numfmt --to=si $SWAP) swap* partition"
((SWAP=SWAP+$(numfmt --from=auto ${start:0:-1})))
SWAP=$(numfmt --to=si $SWAP)
echo ''
sudo parted --script --align optimal $DISK mkpart primary linux-swap $start $SWAP > /dev/null 2>&1
sudo parted --script --align optimal $DISK mkpart primary ext4 $SWAP 100% > /dev/null 2>&1
fi
sleep 2
clear
echoWithHeader "
The *$DISK* will be partitioned as such:
"
BOOT=
ROOT=
for part in $(ls ${DISK}*); do
if [[ "$part" =~ ^([a-z/]+([0-9]n)?[0-9]p|[a-z/]+)[0-9]$ ]]; then
if [ "$part" != "$DISK" ]; then
if [ "$UEFI" != "no" ] && [ "$BOOT" = "" ]; then
BOOT=$part
echo " boot: $(tput bold)$BOOT$(tput sgr0)"
elif [ "$UEFI" = "no" ] && [ "$SWAP" = "0" ]; then
ROOT=$part
echo " root: $(tput bold)$ROOT$(tput sgr0)"
elif [ "$SWAP" != "0" ] && [ "$ROOT" = "" ]; then
SWAP=$part
ROOT=$part
echo " swap: $(tput bold)$SWAP$(tput sgr0)"
else
ROOT=$part
echo " root: $(tput bold)$ROOT$(tput sgr0)"
break
fi
fi
fi
done
if [ "$ROOT" = "" ]; then
echo 'unable to find the partition'
exit 1
fi
clear
echoWithHeader "
targeting partitions:
"
if [ "$BOOT" != "" ]; then
echo " boot: $BOOT"
fi
if [ "$SWAP" != "0" ]; then
if [ "$ENCRYPTION" = "yes" ]; then
echo " swap: $SWAP (encrypted)"
else
echo " swap: $SWAP"
fi
fi
if [ "$ROOT" != "" ]; then
if [ "$ENCRYPTION" = "yes" ]; then
echo " root: $ROOT (encrypted)"
else
echo " root: $ROOT"
fi
fi
sleep 2
if [ "$BOOT" != "" ]; then
clear
echoWithHeader "
formatting *boot* partition"
if [ "$UEFI" = "yes" ]; then
sudo bash -c "mkfs.ext2 -F $BOOT"
else
sudo bash -c "mkfs.fat -F32 $BOOT"
fi
sleep 2
fi
if [ "$SWAP" != "0" ]; then
clear
echoWithHeader "
creating *swap* partition"
sudo bash -c "mkfs.ext2 -F $SWAP"
partid create $SWAP
sudo bash -c "yes y | mkswap $SWAP"
if [ "$ENCRYPTION" = "yes" ]; then
encryptPartition $SWAP swap
sudo bash -c "yes y | mkswap /dev/mapper/swap"
fi
sleep 2
fi
clear
echoWithHeader "
creating *root* partition"
if [ "$BOOT" = "" ] && [ "$(uname -m)" = "x86_64" ]; then
echomd ' *disabling* pure *64bit* mode'
if [ "$ENCRYPTION" = "yes" ]; then
echomd ' *warning* encryption not supported without /boot'
sleep 2
fi
echo ''
sudo bash -c "mkfs.ext4 -F -O ^64bit $ROOT"
partid create $ROOT
else
sudo bash -c "mkfs.ext4 -F $ROOT"
partid create $ROOT
if [ "$ENCRYPTION" = "yes" ]; then
encryptPartition $ROOT root
mkfs.ext4 -F /dev/mapper/root
fi
fi
sleep 2
}
askAboutQUIET() {
local choice=
echoWithHeader "
Would you like a *quiet boot* ? [Y/n]"
read -n1 -s choice
if [ "$choice" = "n" ] || [ "$choice" = "N" ]; then
QUIET=no
else
QUIET=yes
fi
}
askAboutLANGUAGE() {
local choice=
echoWithHeader "
Which *language* do you need ?
Pleas specify just 2 chars like: en, or de, or it ...
"
read choice
if [[ "$choice" =~ ^([a-z][a-z])$ ]]; then
LANGUAGE="$choice"
else
echo ''
echomd " #red(*Nope*), $choice is not valid, let's try again ... "
sleep 2 && clear && askAboutLANGUAGE
fi
}
askAboutLTS() {
local choice=
echoWithHeader "
Would you like an *LTS kernel* ? [y/N]"
read -n1 -s choice
if [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then
LTS=yes
else
LTS=no
fi
}
askForUser() {
local choice=
echoWithHeader "
Which *user name* would you like to use ?
Write one and press enter.
Please note *only lowercase* letters are valid."
read choice
if [ "$choice" = "root" ] || [ "$(echo $choice | sed -e 's/[a-z]//g')" != "" ]; then
echo ''
echomd " #red(*Nope*), $choice is not valid, let's try again ... "
sleep 2 && clear && askForUser
else
USER="$choice"
fi
}
askForPassword() {
local choice=
echoWithHeader "
Which *password* would you like to use ?
Write one and press enter.
Please note it will be used as *both* *root* and *${USER}* password,
and you can change it at any time via _passwd_ command."
if [ "$ENCRYPTION" = "yes" ]; then
echo ''
echomd " *Encryption Warning*"
echomd " * the same password will also be used to *unlock* the disk"
echomd " * it is *not possible to change* the disk password later on"
fi
echo ''
read -r choice
if [ "$choice" = "" ]; then
PASSWORD="Passw0rd!"
echomd "
Password set automatically as *${PASSWORD}*"
sleep 3
else
PASSWORD="$choice"
fi
}
# The Archibold Installer
clear && welcomeMessage && sleep 2
clear && updatePacman && sleep 2
if [ "$INTEL" = "" ] && [ "$(lscpu | grep GenuineIntel)" != "" ]; then
INTEL="yes"
fi
if [ "$ENCRYPTION" = "" ]; then
clear && askAboutEncryption
fi
if [ "$USER" = "root" ] || [ "$USER" = "" ] || [ "$(echo $USER | sed -e 's/[a-z]//g')" != "" ]; then
clear && askForUser
fi
if [ "$PASSWORD" = "" ]; then
clear && askForPassword
fi
if [ "$LTS" = "" ]; then
clear && askAboutLTS
fi
if [ "$GNOME" = "" ]; then
clear && askAboutGNOME
fi
if [ "$DISK" = "" ]; then
clear && findTheDisk
fi
sudo umount ${DISK}* 2> /dev/null
if [ "$UEFI" != "32" ] && [ "$UEFI" != "64" ] && [ "$UEFI" != "yes" ]; then
if [ "$UEFI" = "" ]; then
clear && askAboutUEFI
if [ "$UEFI" = "no" ]; then
clear && askAboutUEFILike
fi
else
UEFI=no
fi
fi
if [ "$UEFI" = "32" ] || [ "$UEFI" = "64" ]; then
UEFI="efi${UEFI}"
else
if [ "$EDD" = "" ]; then
clear && askAboutEDD
else
EDD=" edd=$EDD"
fi
fi
if [ "$SWAP" = "" ]; then
clear && askAboutSWAP
fi
if [ "$QUIET" = "" ]; then
clear && askAboutQUIET
fi
if [ "$QUIET" = "yes" ]; then
# QUIET=" quiet splash loglevel=0 console=tty2"
QUIET=" quiet splash"
else
QUIET=""
fi
if [ "$LANGUAGE" = "" ]; then
clear && askAboutLANGUAGE
fi
clear && createPartitions
if [ -d archibold.env ]; then
sudo rm -rf archibold.env
fi
mkdir -p archibold.env
sleep 1
sync
if [ "$ENCRYPTION" = "yes" ]; then
sudo mount /dev/mapper/root archibold.env
else
sudo mount $ROOT archibold.env
fi
if [ "$BOOT" != "" ]; then
sudo mkdir -p archibold.env/boot
sudo mount $BOOT archibold.env/boot
fi
clear
echoWithHeader "
Bootstrapping *Arch Linux* via pacstrap
"
sudo pacstrap archibold.env arch-install-scripts base gptfdisk
clear
echoWithHeader "
Creating basic installation via *arch-chroot*
"
echo "#!/usr/bin/env bash
LABEL=archibold
LANGUAGE=$LANGUAGE
LTS=$LTS
DISK=$DISK
BOOT=$BOOT
SWAP=$SWAP
ROOT=$ROOT
UEFI=$UEFI
USER='$USER'
PASSWORD='$PASSWORD'
EDD='$EDD'
QUIET='$QUIET'
ENCRYPTION='$ENCRYPTION'
GNOME='$GNOME'
" > /tmp/install
curl -Ls -o /tmp/install-chroot https://archibold.io/setup-utils/get
cat /tmp/install-chroot >> /tmp/install
rm /tmp/install-chroot
sudo chmod a+x /tmp/install
sudo mv /tmp/install archibold.env/archibold.install
sudo arch-chroot archibold.env /archibold.install
rm -rf archibold.env/archibold.install
sudo umount archibold.env/boot
sudo umount archibold.env
echoWithHeader "
Congratulations. Arch Linux is ready.
These are your user/pass credentials:
*${USER}*: *${PASSWORD}*
If you installed GNOME, please open the terminal
once you are connected to the internet, to complete
the setup (it's a one/off operation).
Please type #green(shutdown -h now) and
remove the media before rebooting.
"