#!/bin/bash #------------------------------------------------------------------------------- #Created by helmuthdu mailto: helmuthdu[at]gmail[dot]com #------------------------------------------------------------------------------- #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License. #------------------------------------------------------------------------------- # Modified for ArchBang by Mr Green mrgreen(at)archbang(dot)org # Modified by chuanjang(at)gmail(dot)com # #Usage: #curl -O https://diii.neocities.org/install.txt #nano install.txt OR vim install.txt #sh install.txt # COLORS Bold=$(tput bold) Underline=$(tput sgr 0 1) Reset=$(tput sgr0) # Regular Colors Red=$(tput setaf 1) Green=$(tput setaf 2) Yellow=$(tput setaf 3) Blue=$(tput setaf 4) Purple=$(tput setaf 5) Cyan=$(tput setaf 6) White=$(tput setaf 7) # Bold BRed=${Bold}$(tput setaf 1) BGreen=${Bold}$(tput setaf 2) BYellow=${Bold}$(tput setaf 3) BBlue=${Bold}$(tput setaf 4) BPurple=${Bold}$(tput setaf 5) BCyan=${Bold}$(tput setaf 6) BWhite=${Bold}$(tput setaf 7) arch_chroot() { #{{{ arch-chroot /mnt /bin/bash -c "${1}" } #}}} check_root() { #{{{ if [[ "$(id -u)" != "0" ]]; then error_msg "ERROR! You must execute the script as the 'root' user." fi } #}}} print_line() { #{{{ printf "%$(tput cols)s\n"|tr ' ' '-' } #}}} print_title() { #{{{ clear print_line echo -e "# ${Bold}$1${Reset}" print_line echo "" } #}}} 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..." } #}}} print_warning() { #{{{ T_COLS=`tput cols` echo -e "${BYellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 )) } #}}} error_msg() { #{{{ local _msg="${1}" echo -e "${_msg}" exit 1 } #}}} create_new_user(){ #{{{ print_title "CREATE USER HAVE $(tput setaf 2)SUDO $(tput sgr0)$(tput bold)PRIVILEGES" while [[ -z "$username" ]]; do read -p "username: " username username=`echo $username | tr '[:upper:]' '[:lower:]'` if [ -z "$username" ] ; then print_warning "username empty, 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 "visudo" arch_chroot "chmod 777 /etc/sudoers" arch_chroot "echo '%wheel ALL=(ALL:ALL) ALL' >> /etc/sudoers" arch_chroot "chmod 440 /etc/sudoers" } #}}} # Verify the boot mode if [[ -d "/sys/firmware/efi/" ]]; then echo -e "${Cyan}UEFI${Reset} Mode detected\n" UEFI=true else echo -e "${Cyan}BIOS Mode${Reset} detected\n" UEFI=false fi pause_function # Connect to the internet ip link # Verify connection ping -c 1 archlinux.org echo -e "\n${Cyan}Connection${Reset} verified" read_input_text "Continue or not" if [[ $OPTION != y ]]; then echo -e "\n\nExit" exit 0 fi # Ensure the system clock is accurate: #timedatectl # Partition the disks. To identify these devices, use lsblk #fdisk /dev/sda if $UEFI ; then echo -e "\n${Purple}UEFI${Reset}. Format and mount\n" mkfs.fat -F32 /dev/sda1 mkfs.ext4 -F /dev/sda2 mount /dev/sda2 /mnt mount --mkdir /dev/sda1 /mnt/boot else echo -e "\n${Purple}BIOS${Reset}. Format and mount\n" BOOT_MNT="/dev/sda" mkfs.ext4 -F /dev/sda1 mount /dev/sda1 /mnt fi # Select the mirrors - https://archlinux.org/mirrors/status/ echo -e "\n\n" PS3="Select ${Purple}mirror region${Reset}: " items=("China" "Taiwan") select item in "${items[@]}" do case $REPLY in 1) reflector --verbose --latest 10 --sort rate --country china --save /etc/pacman.d/mirrorlist break ;; 2) reflector --verbose --latest 10 --sort rate --country taiwan --save /etc/pacman.d/mirrorlist break ;; #$((${#items[@]}+1))) echo -e "\n${Red}Cancel${Reset}"; break;; *) echo -e "Invalid option ${Red}$REPLY${Reset}";; esac done # Install essential packages and ... pacstrap /mnt base linux linux-firmware sudo networkmanager wget nano vim dhcpcd # Configure the system genfstab -U /mnt >> /mnt/etc/fstab echo -e "\n\nChange root into the new system and ..." pause_function #Set the time zone #arch_chroot "ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime" #arch_chroot "ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime" #Assumes the hardware clock is set to localtime #arch_chroot "hwclock --systohc --localtime" #Set language U.S. English arch_chroot "sed -i '/#en_US.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 archlinux > /etc/hostname" # Configure mkinitcpio arch_chroot "mkinitcpio -p linux" echo -e "\nSet the root password" arch_chroot "passwd" # Enable NetworkManager arch_chroot "systemctl enable NetworkManager" # Enable network connect echo -e "\nEnable Ethernet plug in the cable\n" arch_chroot "systemctl enable dhcpcd" create_new_user # Install Grub read_input_text "Install GRUB boot loader:" if [[ $OPTION != y ]]; then #arch-chroot /mnt echo -e "\n\n${Red}Must${Reset} install boot loader.\n" exit 0 fi # Microcode must be loaded by the boot loader, Intel processors or AMD processors arch_chroot "pacman -S intel-ucode amd-ucode --noconfirm" arch_chroot "pacman -S grub os-prober efibootmgr --noconfirm" if $UEFI ; then arch_chroot "grub-install --target=x86_64-efi --efi-directory=/boot --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