summaryrefslogtreecommitdiff
path: root/iarch
blob: b5ad1247ce7fcd50d72fa6393c47b9bec2fb4de7 (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
#!/bin/bash
clear
echo '-------------------------------------'
echo '|Welcome to use Arch linux Installer|'
echo '-------------------------------------'
# ------------------ Display Device ------------------
echo -e "\e[32m$(lsblk)\e[0m"

if [[ -b /dev/sda && ! -b /dev/sda1 ]]; then
    echo -e "\e[31mVirtual detected\e[0m"
    read -p "Hostname             (e.g. bob): " name1
    my_disk=/dev/sda
    encrypt_disk=NO
    root_size=NO
    fs_swap=2
    efi1=YES
    packages=NO
    Virtual=true
else
    # ------------------ User Input ------------------
    read -rp "Install Disk    (e.g. /dev/sda): " my_disk
    read -p "Enable Encryption?     (YES/NO): " encrypt_disk
    read -p "Specify ROOT size?     (YES/NO): " root_size
    read -p "SWAP size in GB        (e.g. 2): " fs_swap
    read -p "Pure EFIstub?          (YES/NO): " efi1
    read -p "Small Install?         (YES/NO): " packages
    read -p "Hostname             (e.g. bob): " name1
    # ------------------ Specify ROOT Size ------------------
    if [[ $root_size == YES ]];then
        read -p "ROOT size in GB      (e.g. 20) : " fs_root
        #List size of partitions
        echo -e "\e[32mThe         root         size  = ${fs_root}GB\e[0m"
    else
        echo -e "\e[32mThe         root         size  = remaining space\e[0m"
    fi

    #List size of partitions
    echo -e "\e[32mThe         boot         size  = ${fs_boot}MB\e[0m"
    echo -e "\e[32mThe         swap         size  = ${fs_swap}GB\e[0m"
fi

fs_boot=500
dv=$(echo ${my_disk} | awk -F\/ '{print $3}')

#Confirmation
read -rp "Are you sure?(YES/NO): " confirmation
if [[ $confirmation != YES ]];then
    echo -e "\e[31mAborted...\e[0m"
    exit 1
fi

# ------------------ Create boot partition ------------------
echo -e "\e[33mCreating boot partition...\e[0m"
printf "n\np\n\n\n+${fs_boot}M\nw\n" | fdisk "$my_disk" >/dev/null 2>&1
udevadm settle

# ------------------ Create partitions ------------------
#Whether Encrypt
if [[ $encrypt_disk == YES ]];then
    #Specify ROOT Size
    if [[ $root_size == YES ]];then
        total=$((fs_swap + fs_root))
        printf "n\np\n\n\n+${total}G\nw\n" | fdisk "$my_disk" >/dev/null 2>&1
        sleep 1            #Encryption Specified root
    else
        printf "n\np\n\n\n\nw\n" | fdisk "$my_disk" >/dev/null 2>&1
        sleep 1             #Encryption
    fi
    #Define encryption partition
    echo -e "\e[32m$(lsblk | grep "$dv")\e[0m"
    echo -e "\e[31mAttention        to        typy: xxxxxxxxx\e[0m"
    read -rp "Encrypt               Partition: " encryption_path
    read -rp "Boot                  Partition: " boot_path
    #Encrypt partition
    echo -e "\e[32mEncrypting $encryption_path\e[0m"
    cryptsetup luksFormat "$encryption_path" --type luks2 --pbkdf argon2id -s 512 -h sha512 --iter-time 10000 -c aes-xts-plain64
    #Open encryption partition
    echo -e "\e[32mOpening $encryption_path\e[0m"
    cryptsetup luksOpen "$encryption_path" crypt_device
    #Create logical volume and volume group
    pvcreate /dev/mapper/crypt_device
    vgcreate OS /dev/mapper/crypt_device
    lvcreate -L "${fs_swap}G" OS -n SWAP
    lvcreate -l 100%FREE OS -n ROOT
    echo -e "\e[33mWait......\e[0m"
    #Format partitions
    mkfs.fat -F32 "$boot_path"
    udevadm settle
    mkfs.ext4 -q /dev/mapper/OS-ROOT
    udevadm settle
    mkswap /dev/mapper/OS-SWAP
    udevadm settle
    #Mount partitions
    mount /dev/mapper/OS-ROOT /mnt
    mkdir -p /mnt/boot
    mount "$boot_path" /mnt/boot
    swapon /dev/mapper/OS-SWAP
else
    #Specify ROOT Size
    if [[ $root_size == YES ]];then
        printf "n\np\n\n\n+${fs_swap}G\nw\n" | fdisk "$my_disk" >/dev/null 2>&1          #swap
        printf "n\np\n\n\n+${fs_root}G\nw\n" | fdisk "$my_disk" >/dev/null 2>&1          #root
        sleep 1
    else
        printf "n\np\n\n\n+${fs_swap}G\nw\n" | fdisk "$my_disk" >/dev/null 2>&1          #swap
        printf "n\np\n\n\n\nw\n" | fdisk "$my_disk" >/dev/null 2>&1                      #root
        sleep 1
    fi
    #Virtual machine
    if [[ $Virtual == true ]]; then
        boot_path=/dev/sda1
        swap_path=/dev/sda2
        root_path=/dev/sda3
    else
        #Define partitions of boot swap root
        echo -e "\e[32m$(lsblk | grep "$dv")\e[0m"
        echo -e "\e[31mAttention        to        typy: xxxxxxxxx\e[0m"
        read -rp "Boot                  Partition: " boot_path
        read -rp "Swap                  Partition: " swap_path
        read -rp "Root                  Partition: " root_path
    fi
    echo -e "\e[33mWait......\e[0m"
    #Format partitions
    mkfs.fat -F32 "$boot_path"
    udevadm settle
    mkfs.ext4 -q "$root_path"
    udevadm settle
    mkswap "$swap_path"
    udevadm settle
   #Mount partitions
    mount "$root_path" /mnt
    mkdir -p /mnt/boot
    mount "$boot_path" /mnt/boot
    swapon "$swap_path"
fi

#List partitioins infomation
echo -e "\e[33mFormat and mount successful\e[0m"
echo -e "\e[32m$(lsblk | grep "$dv")\e[0m"

#Change my source
curl https://sh.lihanzhang.cn/mirrorlist -so /etc/pacman.d/mirrorlist

#Install software packages
echo ''
echo -e "\e[33mBegin to install packges......\e[0m"

sleep 1
#GRUB
if [[ $efi1 = YES ]]; then
    p1=''
else
    p1='grub'
fi
#lvm2
if [[ $encrypt_disk = YES ]]; then
    p2='lvm2'
else
    p2=''
fi
#Install packages
if [[ $packages = YES ]]; then
    pacstrap -K /mnt base linux-lts linux-firmware efibootmgr networkmanager openssh vim sudo zsh zsh-autosuggestions zsh-syntax-highlighting zsh-completions terminus-font ${p1} ${p2}
else
    pacstrap -K /mnt base linux-lts linux-firmware efibootmgr networkmanager openssh vim sudo zsh zsh-autosuggestions zsh-syntax-highlighting zsh-completions \
    terminus-font reflector certbot unzip zip nmap screen wget go git base-devel hexedit duf docker docker-compose docker-buildx netcat nginx \
    fail2ban hyfetch qrencode ${p1} ${p2}
fi
genfstab -U /mnt >> /mnt/etc/fstab

#Download system configuration
curl https://sh.lihanzhang.cn/arch/arch_config.sh -o /mnt/arch_config.sh
chmod +x /mnt/arch_config.sh
#--------------------------------------Create info
part_n=$(echo $boot_path | awk '{print substr($0,length($0),1)}')
echo "$name1 Hostname" > /root/info
echo "$my_disk The Disk. The next is Boot partition" >> /root/info
echo "$part_n Boot number" >> /root/info
#--------------------------------------
if [[ $encrypt_disk == YES ]]; then
    euuid2=$(blkid | grep $encryption_path | awk -F\" '{print $2}' )
    echo '1 Enable encrypt' >> /root/info
    echo "$euuid2" >> /root/info
else
    echo '0 Disable encrypt' >> /root/info
    echo '0 Disable e-uuid' >> /root/info
fi
#--------------------------------------
if [[ $efi1 == YES ]]; then
    echo '1 Enable EFI stub' >> /root/info
else
    echo '0 Disable EFI stub' >> /root/info
fi
#--------------------------------------
if [[ $packages == YES ]]; then
    echo '1 Enable Mini install' >> /root/info
else
    echo '0 Disable Mini install' >> /root/info
fi
#--------------------------------------
if [[ $encrypt_disk == YES ]]; then
    echo '0 No Root path' >> /root/info
else
    echo "$root_path" >> /root/info
fi
cp /root/info /mnt/root/info
#Complete
echo -e "\e[32mAll software packages installed\e[0m"
echo -e "\e[32mExrcute arch-chroot /mnt\e[0m"
echo -e "\e[32mExecute /arch_config.sh\e[0m"