summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch_config.sh162
-rw-r--r--iarch210
-rw-r--r--test.sh1
3 files changed, 372 insertions, 1 deletions
diff --git a/arch_config.sh b/arch_config.sh
new file mode 100644
index 0000000..6c49dbc
--- /dev/null
+++ b/arch_config.sh
@@ -0,0 +1,162 @@
+#/bin/bash
+clear
+#************************************************************************************Print old information
+if [[ -f "/root/info" ]]; then
+ name1=$(awk 'NR==1 {print $1}' /root/info)
+ disk1=$(awk 'NR==2 {print $1}' /root/info)
+ boot1=$(awk 'NR==3 {print $1}' /root/info)
+ encrypt1=$(awk 'NR==4 {print $1}' /root/info)
+ euuid=$(sed -n '5p' /root/info)
+ efistub=$(awk 'NR==6 {print $1}' /root/info)
+ minisys=$(awk 'NR==7 {print $1}' /root/info)
+ root1=$(sed -n '8p' /root/info)
+
+ echo '--------------System Information--------------'
+ if [[ -d "/sys/firmware/efi" ]]; then
+ echo 'UEFI = ON'
+ else
+ echo 'UEFI = OFF'
+ fi
+ if [[ $efistub = 1 ]]; then
+ echo 'EFIstub = ON'
+ else
+ echo 'EFIstub = OFF'
+ fi
+ if [[ $minisys = 1 ]]; then
+ echo 'Minisys = ON'
+ else
+ echo 'Minisys = OFF'
+ fi
+ if [[ $encrypt1 = 1 ]]; then
+ echo 'Encrypt = ON'
+ echo "Enc UUID = $(sed -n '5p' /root/info)"
+ else
+ echo 'Encrypt = OFF'
+ fi
+ echo -e "HOOKs = \e[33m$(sed -n '55p' /etc/mkinitcpio.conf | awk -F= '{print $2}')\e[0m"
+ echo -e "SSH file = \e[33m$(sed -n '33p' /etc/ssh/sshd_config)\e[0m"
+ echo -e "Localtime = \e[33m$(date +%H:%M\ \ \ %Y/%m/%d)\e[0m"
+ echo -e "Sudoers = \e[33m$(sed -n '125p' /etc/sudoers)\e[0m"
+ echo -e "Shell = \e[33m$(echo $SHELL)\e[0m"
+ if [[ -f "/etc/default/grub" ]]; then
+ echo -e "GRUB time = \e[33m$(sed -n '4p' /etc/default/grub)\e[0m"
+ echo -e "GRUB UUID = \e[33m$(sed -n '7p' /etc/default/grub)\e[0m"
+ fi
+ if [[ -f "/etc/vconsole.conf" ]]; then
+ echo -e "Font size = \e[33m$(cat /etc/vconsole.conf)\e[0m"
+ fi
+ echo '----------------------------------------------'
+else
+ echo 'No info file'
+ exit 1
+fi
+read -p 'Continue: (YES/NO) ' ask_continue
+if [[ $ask_continue != YES ]]; then
+ echo -e "\e[31mAborted ...\e[0m"
+ exit 1
+fi
+#************************************************************************************Change information
+if [[ -f "/root/info" ]]; then
+ if [[ $efistub = 1 ]]; then #----------------------------------------------------------EFI Stub
+ if [[ $encrypt1 = 1 ]]; then #-------------------------------EFI Stub Encrypt
+ efibootmgr --create --disk $disk1 --part $boot1 --label "Arch Linux LTS" --loader \vmlinuz-linux-lts --unicode "rd.luks.name=${euuid}=system root=/dev/mapper/OS-ROOT rw rd.luks.options=password-echo=no initrd=\initramfs-linux-lts.img"
+ echo "efibootmgr --create --disk $disk1 --part $boot1 --label \"Arch Linux LTS\" --loader \vmlinuz-linux-lts --unicode \"rd.luks.name=${euuid}=system root=/dev/mapper/OS-ROOT rw rd.luks.options=password-echo=no initrd=\initramfs-linux-lts.img\"" > /boot/EFIstub
+ sed -i '55d' /etc/mkinitcpio.conf
+ sed -i '55i HOOKS=(base systemd autodetect microcode modconf kms keyboard keymap sd-vconsole block sd-encrypt lvm2 filesystems fsck)' /etc/mkinitcpio.conf
+ else #-------------------------------------------------------EFI Stub
+ efibootmgr --create --disk $disk1 --part $boot1 --label "Arch Linux LTS" --loader \vmlinuz-linux-lts --unicode "root=${root1} rw initrd=\initramfs-linux-lts.img"
+ echo "efibootmgr --create --disk $disk1 --part $boot1 --label \"Arch Linux LTS\" --loader \vmlinuz-linux-lts --unicode \"root=${root1} rw initrd=\initramfs-linux-lts.img\"" > /boot/EFIstub
+ fi
+ else #---------------------------------------------------------------------------------GRUB
+ sed -i '4d' /etc/default/grub
+ sed -i '4i GRUB_TIMEOUT=0' /etc/default/grub
+ if [[ $encrypt1 = 1 ]]; then #-------------------------------GEUB Encrypt
+ sed -i '7d' /etc/default/grub
+ sed -i "7i GRUB_CMDLINE_LINUX=cryptdevice=UUID=${euuid}:SYSTEM root=/dev/mapper/os-root" /etc/default/grub
+ sed -i '55d' /etc/mkinitcpio.conf
+ sed -i '55i HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems fsck)' /etc/mkinitcpio.conf
+ fi
+ if [ -d "/sys/firmware/efi" ]; then #------------------------UEFI
+ echo -e "\e[32mUEFI\e[0m"
+ grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Unix
+ echo -e "\e[32mgrub installed\e[0m"
+ grub-mkconfig -o /boot/grub/grub.cfg
+ echo -e "\e[32mgrub.cfg installed\e[0m"
+ else #-------------------------------------------------------BIOS
+ echo -e "\e[32mBIOS\e[0m"
+ grub-install --target=i386-pc /dev/vda
+ echo -e "\e[32mgrub installed\e[0m"
+ grub-mkconfig -o /boot/grub/grub.cfg
+ echo -e "\e[32mgrub.cfg installed\e[0m"
+ fi
+ fi
+ if [[ $minisys != 1 ]]; then
+ #systemctl enable docker >/dev/null 2>&1
+ #systemctl enable fail2ban >/dev/null 2>&1
+ #systemctl enable nginx >/dev/null 2>&1
+ mkdir /etc/nginx/conf.d
+ sed -i '22a \ \ \ \ include /etc/nginx/conf.d/*.conf;' /etc/nginx/nginx.conf
+ curl https://sh.lihanzhang.cn/arch/fail2ban.conf -so /etc/fail2ban/jail.conf
+ fi
+else
+ echo 'No info file'
+fi
+
+#------------------------------------------------------------------------------Common Services
+#Change SSH
+sed -i '33d' /etc/ssh/sshd_config
+sed -i '33i PermitRootLogin yes' /etc/ssh/sshd_config
+#Change issue
+echo Welcome back > /etc/issue
+#Change hostname
+echo $name1 > /etc/hostname
+#Change time
+ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+#Change font
+echo 'FONT=ter-v28b' > /etc/vconsole.conf
+#Change sudoers file
+sed -i '125d' /etc/sudoers
+sed -i '125i %wheel ALL=(ALL:ALL) ALL' /etc/sudoers
+#enable ssh networkmanager
+systemctl enable sshd >/dev/null 2>&1
+systemctl enable NetworkManager >/dev/null 2>&1
+#Add my key
+bash <(curl -sL sh.lihanzhang.cn/pub)
+chsh -s /bin/zsh
+ln -s /bin/vim /bin/vi
+#Create my folder
+mkdir /file
+mkdir /www/log -p
+mkdir /frp
+#arch environment
+mkdir -p ~/.local/bin
+curl https://sh.lihanzhang.cn/arch/profile -so ~/.local/bin/.bashrc
+curl https://sh.lihanzhang.cn/arch/zshrc -so ~/.zshrc
+curl https://sh.lihanzhang.cn/arch/vimrc -so ~/.vimrc
+#Add user
+useradd -m olivia -G wheel
+mkdir -p /home/olivia/.local/bin
+curl https://sh.lihanzhang.cn/arch/profile -so /home/olivia/.local/bin/.bashrc
+curl https://sh.lihanzhang.cn/arch/zshrc -so /home/olivia/.zshrc
+curl https://sh.lihanzhang.cn/arch/vimrc -so /home/olivia/.vimrc
+chsh -s /bin/zsh olivia
+
+mkinitcpio -p linux-lts
+#************************************************************************************Print Changed information
+echo '--------------System Information--------------'
+echo -e "HOOKs = \e[33m$(sed -n '55p' /etc/mkinitcpio.conf | awk -F= '{print $2}')\e[0m"
+echo -e "SSH file = \e[33m$(sed -n '33p' /etc/ssh/sshd_config)\e[0m"
+echo -e "Issue = \e[33m$(cat /etc/issue)\e[0m"
+echo -e "Hostname = \e[33m$(cat /etc/hostname)\e[0m"
+echo -e "Localtime = \e[33m$(date +%H:%M\ \ \ %Y/%m/%d)\e[0m"
+echo -e "Sudoers = \e[33m$(sed -n '125p' /etc/sudoers)\e[0m"
+echo -e "Shell = \e[33m$(echo $SHELL)\e[0m"
+echo -e "Font size = \e[33m$(cat /etc/vconsole.conf)\e[0m"
+if [[ -f "/etc/default/grub" ]]; then
+ echo -e "GRUB time = \e[33m$(sed -n '4p' /etc/default/grub)\e[0m"
+ echo -e "GRUB UUID = \e[33m$(sed -n '7p' /etc/default/grub)\e[0m"
+fi
+echo '----------------------------------------------'
+rm -rf /root/info
+rm -rf /arch_config.sh
+echo -e "\e[32m------Please change password------\e[0m"
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"
diff --git a/test.sh b/test.sh
deleted file mode 100644
index ce01362..0000000
--- a/test.sh
+++ /dev/null
@@ -1 +0,0 @@
-hello