aboutsummaryrefslogtreecommitdiffstats
path: root/arch-installer.sh
blob: b5976bb7e854e400175e3216850152be31ffd180 (plain)
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#!/bin/bash

#==================================================================================================#
#------------------------------------ VARIABLES DECLARATION ---------------------------------------#
#==================================================================================================#
ltskern=false
utils=false
extras=false
usrpwd=""
usrusrpwd="fade"
hstnm=""
isusr=false
isusrsudo=false
intelamdcpu="none"
intelamdgpu="none"
numregex='^[0-9]+$'
if [ ! -r /sys/firmware/efi/efivars ]; then
	efimode=false
else
	efimode=true
fi
if lscpu | grep -q Intel; then
	intelamdcpu="intel"
elif lscpu | grep -q AMD; then
	intelamdcpu="amd"
fi
if lspci | grep -q Intel; then
	intelamdgpu="intel"
elif lspci | grep -q AMD; then
	intelamdgpu="amd"
fi
#==================================================================================================#
#--------------------------------------- SOME FUNCTIONS -------------------------------------------#
#==================================================================================================#
jo_goodbye() {
	dialog --title "Aborting"\
		   --infobox "Thank you for using Joe's Arch Linux installer.\nAborting..."\
		   5 30
	sleep 4
	clear
	exit
}
#==================================================================================================#
#--------------------------------------- INTERNET CHECK -------------------------------------------#
#==================================================================================================#
jo_chk_internet() {
	dialog --infobox "Verifying that you are connected to the Internet, please wait..." 4 40
	sleep 1
	if ! wget -q --spider https://www.archlinux.org/; then
		dialog --title "ERROR"\
			   --msgbox "Critical error:\n\nIt seems that you are not connected to the internet,\
therefore Joe's installer is forced to abort.\nPlease connect to the Internet and retry."\
			   12 30
		jo_goodbye
	else
		dialog --msgbox "Success!" 5 12
	fi
}
#==================================================================================================#
#---------------------------------------- HOSTNAME SETUP ------------------------------------------#
#==================================================================================================#
jo_get_hstnm() {
	gogogo=false
	while [ "$gogogo" = false ]; do
		hstnm=$(dialog\
					--nocancel --title "$1"\
					--inputbox "Please choose a hostname for this machine.\
\n\nIf you are running on a managed network, \
please ask your network administrator for an appropriate name."\
					12 53\
					3>&1 1>&2 2>&3 3>&-)
		if [ "$hstnm" = "" ]; then
			dialog --infobox "Hostname is empty, retrying..." 3 34
			sleep 2
			gogogo=false
		else
			gogogo=true
		fi
	done
}
#==================================================================================================#
#------------------------------------ LTS AND XORG SETUP ------------------------------------------#
#==================================================================================================#
jo_get_options() {
	sel=$(dialog --nocancel --title "$1" --checklist "Choose optional system \
components to install:" 10 50 3 \
				   linux-lts "LTS Kernel" on \
				   utils "Utils (zip, vim, git...)" on \
				   extras "Extras (Xorg, gst-plugins...)" off \
				   3>&1 1>&2 2>&3 3>&-)
	if echo -n "$sel" | grep -q linux-lts; then
		ltskern=true
	fi
	if echo -n "$sel" | grep -q utils; then
		utils=true
	fi
	if echo -n "$sel" | grep -q extras; then
		extras=true
	fi
}
#==================================================================================================#
#------------------------------------------ DISK SETUP --------------------------------------------#
#==================================================================================================#
jo_get_disk() {
	rm -f blkline > /dev/null
	dn=$(lsblk | grep -c disk)
	id=1
	while [[ $dn != 0 ]]; do
		echo -n "$id $(lsblk | grep disk | \
awk '{print $1"-------("$4")";}' | sed -n "$id"p) " >> blkline
		((dn--))
		((id++))
	done
	sel=$(dialog --nocancel --title "$1"\
				 --menu "Choose the drive on which Arch Linux should be installed:" 12 55 4\
				 $(cat blkline)\
				 3>&1 1>&2 2>&3 3>&-)
	drv="/dev/"$(lsblk | grep disk | awk '{print $1}' | sed -n "$sel"p)
	rm -f blkline > /dev/null
}

jo_get_swap_size() {
	gogogo=false
	while [ "$gogogo" = false ]; do
		swps=$(dialog\
				   --nocancel --title "$1"\
				   --inputbox "Please enter your swap partition desired size: (__G)"\
				   7 65\
				   "4"\
				   3>&1 1>&2 2>&3 3>&-)
		if [ "$swps" = "" ]; then
			dialog --msgbox "Can't be empty. Retrying..." 5 32
			gogogo=false
		elif ! [[ $swps =~ $numregex ]]; then
			dialog --msgbox "Illegal value, please enter only numerical values. Retrying..." 6 38
			gogogo=false
		else
			gogogo=true
		fi
	done
}

jo_get_root_size() {
	gogogo=false
	while [ "$gogogo" = false ]; do
		rts=$(dialog\
				   --nocancel --title "$1"\
				   --inputbox "Please enter your root partition desired size: (__G)"\
				   7 65\
				   "25"\
				   3>&1 1>&2 2>&3 3>&-)
		if [ "$rts" = "" ]; then
			dialog --msgbox "Can't be empty. Retrying..." 5 32
			gogogo=false
		elif ! [[ $rts =~ $numregex ]]; then
			dialog --msgbox "Illegal value, please enter only numerical values. Retrying..." 6 38
			gogogo=false
		else
			gogogo=true
		fi
	done
}

jo_get_disk_config() {
	answr=false
	while [ "$answr" = false ]; do
		answr=false
		btsze="128M"
		swps=""
		rts=""
		jo_get_disk "$1"
		jo_get_swap_size "$1"
		jo_get_root_size "$1"
		rtsze=$rts"G"
		swpsze=$swps"G"
		drv1="$drv""1"
		drv2="$drv""2"
		drv3="$drv""3"
		drv4="$drv""4"
		if dialog --title "Confirm this is correct"\
				  --yesno "\
Drive to use:$drv\n\
\n\
boot partition ($drv1) - $btsze\n\
swap partition ($drv2) - $swpsze\n\
root partition ($drv3) - $rtsze\n\
home partition ($drv4) - All that remains"\
				  10 50; then
			answr=true
		else
			answr=false
		fi
	done
}

jo_warn_wiping() {
	if ! dialog --title "WARNING"\
		 --yesno "Warning: disk $drv will be wiped. \
Are you sure you wish to continue?"\
		 6 45; then
		jo_goodbye
	fi
}
#==================================================================================================#
#------------------------------------ USERS AND ROOT SETUP ----------------------------------------#
#==================================================================================================#
jo_get_root_config() {
	gogogo=false
	while [ "$gogogo" = false ]; do
		rtpwd=$(dialog --nocancel --title "$1"\
					   --passwordbox "Enter your desired root password:"\
					   7 40\
					   3>&1 1>&2 2>&3 3>&-)
		rtrtpwd=$(dialog --nocancel --title "$1"\
						 --passwordbox "Confirm root password:"\
						 7 40\
						 3>&1 1>&2 2>&3 3>&-)
		if ! [ "$rtrtpwd" = "$rtpwd" ]; then
			dialog --msgbox "Password mismatch" 5 22
			gogogo=false
		elif [ "$rtpwd" = "" ]; then
			dialog --msgbox "Password can't be empty" 5 28
			gogogo=false
		else
			gogogo=true
		fi
	done
}

jo_get_usr_config() {
	gogogo=false
	while [ "$gogogo" = false ]; do
		usr=$(dialog\
				  --nocancel --title "$1"\
				  --inputbox "Enter your desired username:"\
				  7 40\
				  3>&1 1>&2 2>&3 3>&-)
		if [ "$usr" = "" ]; then
			dialog --msgbox "Username can't be empty" 5 28
			gogogo=false
		else
			usr=$(echo "$usr" | tr '[:upper:]' '[:lower:]')
			gogogo=true
		fi
	done
	isusr=true
	gogogo=false
	while [ "$gogogo" = false ]; do
		usrpwd=$(dialog --nocancel --title "$1"\
						  --passwordbox "Enter your desired password for $usr:"\
						  7 50\
						  3>&1 1>&2 2>&3 3>&-)
		usrusrpwd=$(dialog --nocancel --title "$1"\
							 --passwordbox "Confirm $usr password:"\
							 7 50\
							 3>&1 1>&2 2>&3 3>&-)
		if ! [ "$usrusrpwd" = "$usrpwd" ]; then
			dialog --msgbox "Password mismatch" 5 22
			gogogo=false
		elif [ "$usrpwd" = "" ]; then
			dialog --msgbox "Password can't be empty" 5 28
			gogogo=false
		else
			gogogo=true
		fi
	done
	if dialog --title "$1"\
				--yesno "Should $usr be sudo?"\
				5 45; then
		isusrsudo=true
	fi
	usrshell=$(dialog --title "$1"\
						--menu "Choose a shell for $usr:"\
						11 40 4\
						"zsh" "The Z Shell"\
						"dash" "The Debian Almquist Shell"\
						"bash" "The Bourne-again Shell"\
						"sh" "The OG shell"\
						3>&1 1>&2 2>&3 3>&-)
}
#==================================================================================================#
#------------------------------------------- NTP DATE ---------------------------------------------#
#==================================================================================================#
jo_set_timedate() {
	dialog --title "$1"\
		   --infobox "Setting date via ntp"\
		   3 28
	timedatectl set-ntp true > /dev/null 2>&1
	sleep 2
}
#==================================================================================================#
#------------------------------------------- WIPEFS -----------------------------------------------#
#==================================================================================================#
jo_wipefs() {
	dialog --title "$1"\
		   --infobox "Wiping filesystem"\
		   3 28
	wipefs --all --force "$drv" > /dev/null 2>&1
	sleep 2
}
#==================================================================================================#
#---------------------------------------- PARTITIONING DISK ---------------------------------------#
#==================================================================================================#
jo_part_disk() {
	dialog --title "$1"\
		   --infobox "Partitioning disk"\
		   3 28
	if [ "$efimode" = true ]; then
		fdisk --wipe-partition always "$drv" << FDISK_EFI_INPUT > /dev/null 2>&1
g
n
1

+$btsze
n
2

+$swpsze
n
3

+$rtsze
n
4


t
2
19
w
FDISK_EFI_INPUT
	else
		fdisk --wipe-partition always "$drv" << FDISK_BIOS_INPUT > /dev/null 2>&1
o
n
p
1

+$btsze
n
p
2

+$swpsze
n
p
3

+$rtsze
n
p


w
FDISK_BIOS_INPUT
	fi
	sleep 2
}

jo_make_filesystem() {
	dialog --title "$1"\
		   --infobox "Making filesystem"\
		   3 28
	if [ "$efimode" = true ]; then
		mkfs.fat -F32 "$drv""1" > /dev/null 2>&1
	else
		mkfs.ext2 "$drv""1" > /dev/null 2>&1
	fi
	mkswap "$drv""2" > /dev/null 2>&1
	mkfs.ext4 "$drv""3" > /dev/null 2>&1
	mkfs.ext4 "$drv""4" > /dev/null 2>&1
	sleep 2
	dialog --title "$1"\
		   --infobox "Mounting partitions"\
		   3 28
	mkdir -p /mnt/arch > /dev/null 2>&1
	swapon "$drv""2" > /dev/null 2>&1
	mount "$drv""3" /mnt/arch > /dev/null 2>&1
	mkdir -p /mnt/arch/boot > /dev/null 2>&1
	mkdir -p /mnt/arch/boot/efi > /dev/null 2>&1
	if [ "$efimode" = true ]; then
		mount "$drv""1" /mnt/arch/boot/efi > /dev/null 2>&1
	else
		mount "$drv""1" /mnt/arch/boot > /dev/null 2>&1
	fi
	mkdir -p /mnt/arch/home > /dev/null 2>&1
	mount "$drv""4" /mnt/arch/home > /dev/null 2>&1
	sleep 2
}
#==================================================================================================#
#-------------------------------------------- PACSTRAP --------------------------------------------#
#==================================================================================================#
jo_pacstrap() {
	paclen=$(echo -n "$1" | wc -c)
	diaglen=$(echo "15 + $paclen" | bc)
	dialog --title "$1" --infobox "Installing $1" 3 "$diaglen"
	if pacstrap /mnt/arch "$1" > /dev/null 2>&1; then
		dialog --title "$1" --infobox "$1 installed" 3 "$diaglen"
		sleep 0.5
	fi
}

jo_fstab() {
	dialog --title "$1"\
		   --infobox "Generating fstab"\
		   3 28
	genfstab -U -p /mnt/arch > /mnt/arch/etc/fstab
	sleep 2
}
#==================================================================================================#
#--------------------------------------------- START ----------------------------------------------#
#==================================================================================================#
clear
dialog --title "Welcome" --msgbox "Welcome to Joe's Arch Linux installation utility!" 6 35
jo_chk_internet
jo_get_hstnm "I. CORE SETUP"
jo_get_options "I. CORE SETUP"
jo_get_disk_config "II. DISK SETUP"
jo_warn_wiping
jo_get_root_config "III. USERS SETUP"
if dialog --title "III. USERS SETUP"\
			--yesno "Would you like to add a user to the system?"\
			6 45; then
	jo_get_usr_config "III. USERS SETUP"
fi
#==================================================================================================#
#-------------------------------------- THE ACTUAL INSTALL ----------------------------------------#
#==================================================================================================#
jo_set_timedate "IV. INSTALLING LINUX"
jo_wipefs "IV. INSTALLING LINUX"
jo_part_disk "IV. INSTALLING LINUX"
jo_make_filesystem "IV. INSTALLING LINUX"
#==================================================================================================#
#-------------------------------------- BASE DOWNLOAD ---------------------------------------------#
#==================================================================================================#
jo_pacstrap base
jo_pacstrap base-devel
jo_pacstrap pacman-contrib
jo_pacstrap networkmanager
jo_pacstrap syslog-ng
jo_pacstrap mtools
jo_pacstrap dostools
jo_pacstrap lsb-release
jo_pacstrap ntfs-3g
jo_pacstrap exfat-utils
jo_pacstrap ntp
if [ "$isusr" = true ]; then
	if [ "$usrshell" = "zsh" ]; then
		jo_pacstrap zsh
	elif [ "$usrshell" = "dash" ]; then
		jo_pacstrap dash
	fi
fi
jo_pacstrap os-prober
if [ "$efimode" = true ]; then
	jo_pacstrap efibootmgr
fi
jo_pacstrap grub
jo_pacstrap mkinitcpio
if [ "$ltskern" = true ]; then
	jo_pacstrap linux-lts
	jo_pacstrap linux-lts-headers
else
	jo_pacstrap linux
	jo_pacstrap linux-headers
fi
if [ "$intelamdcpu" = "intel" ]; then
	jo_pacstrap intel-ucode
elif [ "$intelamdcpu" = "amd" ]; then
	jo_pacstrap amd-ucode
fi
dialog --title "IV. INSTALLING LINUX"\
	   --infobox "Base packages installed"\
	   3 28
sleep 4
#==================================================================================================#
#--------------------------------------- UTILS DOWNLOAD -------------------------------------------#
#==================================================================================================#
if [ "$utils" = true ]; then
	jo_pacstrap zip
	jo_pacstrap unzip
	jo_pacstrap p7zip
	jo_pacstrap vim
	jo_pacstrap mc
	jo_pacstrap alsa-utils
	jo_pacstrap git
	jo_pacstrap cronie
	dialog --title "IV. INSTALLING LINUX"\
		   --infobox "Utils installed"\
		   3 28
	sleep 4
fi
#==================================================================================================#
#---------------------------------------- EXTRA DOWNLOAD ------------------------------------------#
#==================================================================================================#
if [ "$extras" = true ]; then
	jo_pacstrap gst-plugins-{base,good,bad,ugly}
	jo_pacstrap gst-libav
	jo_pacstrap xorg-{server,xinit,apps}
	jo_pacstrap xf86-input-{mouse,keyboard}
	jo_pacstrap xdg-user-dirs
	jo_pacstrap mesa
	if [ "$intelamdgpu" = "intel" ]; then
		jo_pacstrap xf86-video-intel
	elif [ "$intelamdgpu" = "amd" ]; then
		jo_pacstrap xf86-video-amdgpu
	fi
	dialog --title "IV. INSTALLING LINUX"\
		   --infobox "Extra packages installed"\
		   4 28
	sleep 4
fi
#==================================================================================================#
#------------------------------------------- FSTAB CONFIG  ----------------------------------------#
#==================================================================================================#
jo_fstab "IV. INSTALLING LINUX"
#==================================================================================================#
#-------------------------------------------- ARCH-CHROOT -----------------------------------------#
#==================================================================================================#
dialog --title "V. CONFIGURING LINUX"\
	   --infobox "Finishing configuration"\
	   3 30
sleep 4
echo "\
#!/bin/bash

ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
hwclock --systohc
sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
echo \"LANG=en_US.UTF-8\" > /etc/locale.conf
echo \"$hstnm\" > /etc/hostname
echo \"127.0.0.1 localhost\" > /etc/hosts
echo \"::1 localhost\" >> /etc/hosts
echo \"127.0.1.1 $hstnm.localdomain $hstnm\" >> /etc/hosts
passwd
$rtpwd
$rtpwd
systemctl enable NetworkManager
sed -i 's/#ForwardToSyslog=no/ForwardToSyslog=yes/' /etc/systemd/journald.conf\
" > finishit.sh
if [ "$isusr" = true ]; then
	if [ "$isusrsudo" = true ]; then
			echo "\
useradd -m -g wheel -s /bin/$usrshell $usr
sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers\
" >> finishit.sh
	else
			echo "useradd -m -s /bin/$usrshell $usr" >> finishit.sh
	fi
		echo "passwd $usr
$usrpwd
$usrpwd\
" >> finishit.sh
fi
if [ "$ltskern" = false ]; then
	echo "mkinitcpio -p linux" >> finishit.sh
else
	echo "mkinitcpio -p linux-lts" >> finishit.sh
fi
if [ "$efimode" = true ]; then
	echo "\
grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot/efi --recheck
mkdir -p /boot/grub
grub-mkconfig -o /boot/grub/grub.cfg
" >> finishit.sh
else
	echo "\
grub-install --target=i386-pc $drv
grub-mkconfig -o /boot/grub/grub.cfg
" >> finishit.sh
fi
chmod +x finishit.sh
arch-chroot /mnt/arch <<EOF
./../../finishit.sh
EOF
#arch-chroot /mnt/arch << ARCH_CHROOT_CMDS
#	ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
#	hwclock --systohc
#	sed -i 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
#	locale-gen
#	echo "LANG=en_US.UTF-8" > /etc/locale.conf
#	echo "$hstnm" > /etc/hostname
#	echo "127.0.0.1 localhost" > /etc/hosts
#	echo "::1 localhost" >> /etc/hosts
#	echo "127.0.1.1 $hstnm.localdomain $hstnm" >> /etc/hosts
#	passwd
#$rtpwd
#$rtpwd
#	systemctl enable NetworkManager
#	sed -i 's/#ForwardToSyslog=no/ForwardToSyslog=yes/' /etc/systemd/journald.conf
#ARCH_CHROOT_CMDS
#if [ "$isusr" = true ]; then
#	if [ "$isusrsudo" = true ]; then
#		arch-chroot /mnt/arch << ARCH_CHROOT_CMDS
#			useradd -m -g wheel -s /bin/$usrshell $usr
#			sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers
#ARCH_CHROOT_CMDS
#	else
#		arch-chroot /mnt/arch << ARCH_CHROOT_CMDS
#			useradd -m -s /bin/$usrshell $usr
#ARCH_CHROOT_CMDS
#	fi
#	arch-chroot /mnt/arch << ARCH_CHROOT_CMDS
#		passwd $usr
#$usrpwd
#$usrpwd
#ARCH_CHROOT_CMDS
#fi
#arch-chroot /mnt/arch << ARCH_CHROOT_CMDS
#	if [ $ltskern = false ]; then mkinitcpio -p linux; else mkinitcpio -p linux-lts; fi
#	if [ $efimode = true ]; then grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot/efi --recheck; mkdir -p /boot/grub; grub-mkconfig -o /boot/grub/grub.cfg; mkdir -p /boot/efi/EFI/BOOT; cp /boot/efi/EFI/GRUB/grubx64.efi /boot/efi/EFI/BOOT/BOOTX64.EFI; echo "bcf boot add 1 fs0:\\EFI\\GRUB\\grubx64.efi \"GRUB bootloader\"" > /boot/efi/startup.nsh; echo "exit" >> /boot/efi/startup.nsh; else grub-install --target=i386-pc $drv; grub-mkconfig -o /boot/grub/grub.cfg; fi
#ARCH_CHROOT_CMDS
sleep 2
dialog --title "WORK COMPLETE"\
	   --msgbox "\
Arch Linux is now installed\n\
on this terminal.\n\
Thank you for using Joe's\n
ARCH LINUX INSTALLER.\n\
\n
Your system will now reboot"\
	   10 32
umount -R /mnt/arch
reboot