#/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" 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" 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 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 #Add user useradd -m olivia -G wheel 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 curl https://sh.lihanzhang.cn/arch/fail2ban.conf -so /etc/fail2ban/jail.conf 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"