summaryrefslogtreecommitdiff
path: root/arch_config.sh
diff options
context:
space:
mode:
authorLi hanzhang <me@lihanzhang.cn>2026-05-23 18:21:51 +0800
committerLi hanzhang <me@lihanzhang.cn>2026-05-23 18:21:51 +0800
commit2a1a511ee52f5ccb457ce3f985b7bbb1712ff531 (patch)
tree3815f045fbcbee755cbb73b17e660ef10a42ba74 /arch_config.sh
parent0418c20c9696b9256d853c4d8e9f253ea4b875a1 (diff)
Diffstat (limited to 'arch_config.sh')
-rw-r--r--arch_config.sh162
1 files changed, 162 insertions, 0 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"