#!/bin/bash #------------------------------------------------------------------------------- #Created by helmuthdu mailto: helmuthdu[at]gmail[dot]com #Contribution: flexiondotorg #------------------------------------------------------------------------------- #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program. If not, see . #------------------------------------------------------------------------------- # Modified for ArchBang by Mr Green mrgreen(at)archbang(dot)org # 2021/12/24 First release. Modified by chuanjang(at)gmail(dot)com # Read https://wiki.archlinux.org/title/Installation_guide before installtion, there are maybe some important difference to this script. # wget: command not found. Install it. # pacman -Syu wget # Download: wget https://diii.neocities.org/inst_cn.txt # Edit: nano inst_cn.txt OR vim inst_cn.txt OR Notepad++(Wndows OS) # Best method: save inst_cn.txt to HDD or USB stick, then mount. # Usage: sh inst_cn.txt # COLORS Reset=$(tput sgr0) # Regular Colors Red=$(tput setaf 1) Green=$(tput setaf 2) Yellow=$(tput setaf 3) Purple=$(tput setaf 5) Cyan=$(tput setaf 6) arch_chroot() { #{{{ arch-chroot /mnt /bin/bash -c "${1}" } #}}} check_root() { #{{{ if [[ "$(id -u)" != "0" ]]; then echo -e "ERROR! You must execute the script as the 'root' user." fi } #}}} print_line() { #{{{ printf "%$(tput cols)s\n"|tr ' ' '-' } #}}} read_input_text() { #{{{ read -p "$1 [y/N]: " OPTION OPTION=`echo "$OPTION" | tr '[:upper:]' '[:lower:]'` } #}}} pause_function() { #{{{ print_line read -e -sn 1 -p "Press enter to continue..." } #}}} create_new_user(){ #{{{ echo -e "CREATE USER HAVE ${Red}SUDO PRIVILEGES${Reset}" print_line while [[ -z "$username" ]]; do read -p "username: " username username=`echo $username | tr '[:upper:]' '[:lower:]'` if [ -z "$username" ] ; then echo -e "username ${Red}empty${Reset}, don't create user.\n" fi done arch_chroot "useradd -m -g users -G wheel -s /bin/bash ${username}" #arch_chroot "chfn ${username}" arch_chroot "passwd ${username}" while [[ $? -ne 0 ]]; do arch_chroot "passwd ${username}" done arch_chroot "chmod 777 /etc/sudoers" arch_chroot "sed -i '/# %wheel ALL=(ALL) NOPASSWD: ALL/{s/#//}' /etc/sudoers" arch_chroot "chmod 440 /etc/sudoers" } #}}} # Verify the boot mode if [[ -d "/sys/firmware/efi/" ]]; then echo -e "${Cyan}UEFI Mode${Reset} detected" else echo -e "${Cyan}BIOS Mode${Reset} detected" fi # Connect to the internet ip link # Verify connection ping -c 2 archlinux.org read_input_text "Verify connection, continue or not" if [[ $OPTION != y ]]; then echo -e "\n\nExit" exit 0 fi # Partition the disks. To identify these devices, use lsblk #cfdisk /dev/sda # Create a mirrorlist based on location. mirror="China" if [[ -d "/sys/firmware/efi/" ]]; then # For UEFI/GPT EFI_MNT="/boot" # Set EFI mountpoint, can be EFI_MNT="/boot/efi" # Format the partitions and mount. #mkfs.fat -F32 /dev/sda1 #mkswap /dev/sda2 #swapon /dev/sda2 #mkfs.ext4 /dev/sda3 #mount /dev/sda3 /mnt # root volume #mkdir -p "/mnt${EFI_MNT}" #mount /dev/sda1 "/mnt${EFI_MNT}" else # For BIOS/MBR BOOT_MNT="/dev/sda" # /dev/sda is the disk (not a partition) where GRUB is to be installed. # Format the partitions and mount. #mkswap /dev/sda1 #swapon /dev/sda1 #mkfs.ext4 /dev/sda2 #mount /dev/sda2 /mnt # root volume fi # Create a mirrorlist based on location, may not be fastest servers but nearest.. pacman -Sy --noconfirm wget wget https://archlinux.org/mirrorlist/all/ -O /etc/pacman.d/mirrorlist sed -i "s/#Server/Server/g" /etc/pacman.d/mirrorlist sed -i -n -r "/${mirror}/,/^\s*$/p" /etc/pacman.d/mirrorlist # Install essential packages and ... pacstrap /mnt base linux linux-firmware sudo networkmanager wget nano vim # Configure the system genfstab -U /mnt >> /mnt/etc/fstab echo -e "\n\nChange root into the new system and ..." print_line pause_function #Set the time zone arch_chroot "ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime" #Localization. arch_chroot "sed -i '/#zh_CN.UTF-8 UTF-8/{s/#//}' /etc/locale.gen" arch_chroot "sed -i '/#en_US.UTF-8 UTF-8/{s/#//}' /etc/locale.gen" arch_chroot "locale-gen" arch_chroot "echo 'LANG=en_US.UTF-8' > /etc/locale.conf" #Create the hostname file arch_chroot "echo myhostname > /etc/hostname" # Configure mkinitcpio arch_chroot "mkinitcpio -P" # Enable NetworkManager arch_chroot "systemctl enable NetworkManager" # Enable network connect arch_chroot "pacman -S --noconfirm dhcpcd" arch_chroot "systemctl enable dhcpcd" echo -e "\nSet the ${Cyan}root password${Reset}" print_line arch_chroot "passwd" create_new_user # Install Grub read_input_text "Install GRUB boot loader:" if [[ $OPTION != y ]]; then arch-chroot /mnt echo -e "Must install boot loader by yourself.\n" echo -e "Then, type\n${Cyan}exit\numount -R /mnt\nreboot${Reset}" exit 0 fi # Microcode must be loaded by the boot loader, Intel processors or AMD processors arch_chroot "pacman -S --noconfirm intel-ucode amd-ucode" arch_chroot "pacman -S --noconfirm grub os-prober efibootmgr" if [[ -d "/sys/firmware/efi/" ]]; then arch_chroot "grub-install --target=x86_64-efi --efi-directory=${EFI_MNT} --bootloader-id=GRUB" else arch_chroot "grub-install --target=i386-pc ${BOOT_MNT}" fi arch_chroot "grub-mkconfig -o /boot/grub/grub.cfg" # Installation finished read_input_text "Installation finished. Reboot system" if [[ $OPTION != y ]]; then arch-chroot /mnt exit 0 fi umount -R /mnt reboot exit 0