-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_setup.sh
executable file
·106 lines (84 loc) · 3.19 KB
/
auto_setup.sh
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
#!/bin/bash
work_dir=$(pwd)
get_ram() {
# Get RAM size B K M G
echo "RAM: $(lsmem -nb -o SIZE -J | jq '[ .memory[].size ] '| jq 'add / 1024 / 1024 / 1024')"
}
get_disk(){
# Variables
local boot_part root_part home_part swap_part
# install dependencies
[[ ! -e /usr/bin/jq ]] && echo "JQ is not installed: Exited!" && exit
# Get all install disk
InternalDiskOnly=$(lsblk -J -o NAME,RM,SIZE | jq '
.blockdevices[] |
if .rm == false then
if .children | length > 0 then
{ name, children: [ .children[] | {name: .name, size: .size} ] }
else
empty
end
else
empty
end
');
diskName=$(echo $InternalDiskOnly | jq '.name' -r);
# Iterate over disks
echo "Creating GPT partition table on: ${diskName}"
parted /dev/$diskName mklabel gpt --script
for((i=1;i<5;i++)) {
[[ $i -eq 1 ]] &&
echo -e "/dev/$diskName => 512M" &&
parted /dev/$diskName mkpart "EFI" fat32 0% 512M --script &&
parted /dev/$diskName set 1 esp on;
[[ $i -eq 2 ]] &&
echo -e "/dev/$diskName => 30%" &&
parted /dev/$diskName mkpart "ROOT" ext4 512M 30% --script;
[[ $i -eq 3 ]] &&
echo -e "/dev/$diskName => 93%" &&
parted /dev/$diskName mkpart "HOME" ext4 30% 93% --script;
[[ $i -eq 4 ]] &&
echo -e "/dev/$diskName => 100%" &&
parted /dev/$diskName mkpart "SWAP" linux-swap 93% 100% --script;
}
partitionList=($(echo $InternalDiskOnly | jq '.children[].name' -r));
partitionCount=$(echo $InternalDiskOnly | jq '.children | length');
echo -e "Formatting file system for each partition..."
for((i=0;i<${#partitionList[@]};i++)){
[[ $i -eq 0 ]] &&
echo -e "/dev/${partitionList[$i]}" &&
mkfs.fat -F32 "/dev/${partitionList[$i]}" &&
boot_part="/dev/${partitionList[$i]}";
[[ $i -eq 1 ]] &&
echo -e "/dev/${partitionList[$i]}" &&
mkfs.ext4 -F "/dev/${partitionList[$i]}" &&
root_part="/dev/${partitionList[$i]}";
[[ $i -eq 2 ]] &&
echo -e "/dev/${partitionList[$i]}" &&
mkfs.ext4 -F "/dev/${partitionList[$i]}" &&
home_part="/dev/${partitionList[$i]}";
[[ $i -eq 3 ]] &&
echo -e "/dev/${partitionList[$i]}" &&
mkswap "/dev/${partitionList[$i]}" &&
swapon "/dev/${partitionList[$i]}" &&
swap_part="/dev/${partitionList[$i]}";
}
echo -e "Mounting file system..."
echo $boot_part $root_part $home_part $swap_part
# Mount root partition
mount "${root_part}" /mnt
# Create home directory
mkdir -p /mnt/home
# mount home partition
mount "${home_part}" /mnt/home
# Mount efi
mkdir -p /mnt/boot/efi
mount "${boot_part}" /mnt/boot/efi
unsquashfs -f -d /mnt /run/archiso/bootmnt/arch/x86_64/airootfs.sfs
genfstab -U -p /mnt >> /mnt/etc/fstab
arch-chroot /mnt /usr/bin/oem_setup.sh
}
get_disk
echo -e "Unsquashing ROOT system..."
umount -a
reboot