From 2a1a511ee52f5ccb457ce3f985b7bbb1712ff531 Mon Sep 17 00:00:00 2001 From: Li hanzhang Date: Sat, 23 May 2026 18:21:51 +0800 Subject: v1 --- iarch | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 iarch (limited to 'iarch') diff --git a/iarch b/iarch new file mode 100644 index 0000000..b5ad124 --- /dev/null +++ b/iarch @@ -0,0 +1,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" -- cgit v1.3.1