This repository was archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_arch.sh
More file actions
executable file
·145 lines (117 loc) · 4.8 KB
/
setup_arch.sh
File metadata and controls
executable file
·145 lines (117 loc) · 4.8 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
#!/bin/bash
# Set colors
LIGHTGREEN='\033[1;32m'
LIGHTRED='\033[1;91m'
WHITE='\033[1;97m'
MAGENTA='\033[1;35m'
CYAN='\033[1;96m'
BLUE='\033[1;34m'
# Set starting directory
script_dir=$(pwd)
./test_network.sh
cd ..
start_dir=$(pwd) # Should be equal to $HOME ?
if [ "$?" != "0" ]; then
exit 1
fi
timedatectl set-ntp true
printf ${WHITE}"### Getting storage devices\n"
fdisk -l >> devices
sed -e '\#Disk /dev/ram#,+5d' -i devices
sed -e '\#Disk /dev/loop#,+5d' -i devices
cat devices
while true; do
printf ${CYAN}"Enter the device name you want to install arch on (ex, ${MAGENTA}sda${CYAN} for /dev/sda and ${MAGENTA}nvme0n1${CYAN} for /dev/nvme0n1)\n>"
read disk
disk="${disk,,}"
printf ${CYAN}"Does this script need to add a \"p\" character before the partition number\nFor example this is needed for NVMe drives (Wrong: /dev/nvme0n11) (Correct: /dev/nvme0n1p1)\n\nEnter y to add the character or n to not add it\n>"
read add_p
if [ "$add_p" != "y" ] && [ "$add_p" != "n" ]; then
printf ${LIGHTRED}"%s is an invalid answer, do it correctly" $add_p
printf ${WHITE}".\n"
sleep 2
continue
fi
partition_count="$(grep -o $disk devices | wc -l)"
disk_chk=("/dev/${disk}")
if grep "$disk_chk" devices; then
if [ "$add_p" = "y" ]; then
printf ${WHITE}"Would you like to use the default settings for \"%s\"? \n This will create a GPT partition scheme where\n%s1 = 550 MiB boot partition\n%s2 = 8192 MiB swap partition\n%s3 = the rest of the hard disk\n\nEnter y to continue with the default settings or n to customize \n>" $disk_chk ${disk_chk}p ${disk_chk}p ${disk_chk}p
else
printf ${WHITE}"Would you like to use the default settings for \"%s\"? \n This will create a GPT partition scheme where\n%s1 = 550 MiB boot partition\n%s2 = 8192 MiB swap partition\n%s3 = the rest of the hard disk\n\nEnter y to continue with the default settings or n to customize \n>" $disk_chk $disk_chk $disk_chk $disk_chk
fi
read auto_part_ans
if [ "$auto_part_ans" = "y" ]; then
wipefs -a $disk_chk
parted -a optimal $disk_chk --script mklabel gpt
mem_size=8192
esp_size=550
mem_offset=$(( $esp_size + $mem_size ))
mem_offset_str=${mem_offset}"MiB"
parted $disk_chk --script mkpart ESP fat32 1MiB ${esp_size}MiB
parted $disk_chk --script set 1 esp on
parted $disk_chk --script mkpart swap linux-swap ${esp_size}MiB $mem_offset_str
parted $disk_chk --script mkpart root ext4 ${mem_offset_str} 100%
rm -rf devices
sleep 2
elif [ "$auto_part_ans" = "n" ]; then
wipefs -a $disk_chk
cfdisk
printf ${CYAN}"Do you want to start the partitioning over?\n>"
read restart_part
if [ "$restart_part" = "y" ]; then
printf ${LIGHTRED}"### Starting over\n"${WHITE}
continue
elif [ "$restart_part" = "n" ]; then
printf ""
else
printf ${LIGHTRED}"%s is an invalid answer, do it correctly" $restart_part
printf ${WHITE}".\n"
sleep 2
continue
fi
else
printf ${LIGHTRED}"%s is an invalid answer, do it correctly" $auto_part_ans
printf ${WHITE}".\n"
sleep 2
continue
fi
if [ "$add_p" = "y" ]; then
part_1=("${disk_chk}p1")
part_2=("${disk_chk}p2")
part_3=("${disk_chk}p3")
else
part_1=("${disk_chk}1")
part_2=("${disk_chk}2")
part_3=("${disk_chk}3")
fi
mkfs.fat -F32 $part_1
mkswap $part_2
swapon $part_2
mkfs.ext4 $part_3
break
else
printf ${LIGHTRED}"%s is an invalid device, try again with a correct one\n" $disk_chk
printf ${WHITE}".\n"
sleep 5
clear
cat devices
fi
done
printf ${WHITE}"### Beginning installation\n"
printf ${WHITE}"### Mounting filesystems\n"
mkdir /mnt/arch
echo p3: $part_3
echo p1: $part_1
mount --source ${part_3} --target /mnt/arch
mkdir /mnt/arch/boot
mkdir /mnt/arch/boot/efi
mount --source ${part_1} --target /mnt/arch/boot/efi
printf ${WHITE}"### Installing base, base-devel, linux, linux-firmware and vim packages to a newly created partition\n"
pacstrap /mnt/arch base base-devel linux linux-firmware vim
printf ${WHITE}"### Generating fstab\n"
genfstab -U /mnt/arch >> /mnt/arch/etc/fstab
printf ${WHITE}"### Chrooting\n"
cp ${script_dir}/post_chroot.sh /mnt/arch
cd /mnt/arch
arch-chroot /mnt/arch /post_chroot.sh