###ArchInstall1.sh
#!/bin/bash
networkcheck(){
ping -c 1 39.156.66.18
if [ $? -eq 0 ];then
echo 'Network is connected'
###shell里面没布尔类型
ifnetworkconnect=OK
else
echo 'Network is not connected'
ifnetworkconnect=NO
fi
}
networkconnect(){
networkcheck
if [[ $ifnetworkconnect == "OK" ]]
then
echo "Your network is connected. Do you want to continue with network configuration?[y/n]"
read -p "->" ifnetsetting
case $ifnetsetting in
Y|y)
echo "netsetting=OK"
;;
N|n)
echo "netsetting=NO"
netstatus=OK
return
;;
*)
echo "Your input is incorrect and we will assume that you need to configure the network."
echo "netsetting=OK"
;;
esac
else
echo "netsetting=OK"
fi
echo "Are you using a wired or wireless connection?[1/2]"
echo "1:wired connection"
echo "2:wireless connection"
read -p "->" connectionmethod
case $connectionmethod in
1)
echo "Please set it yourself and we will wait for your good news."
echo "Once connected, remember to perform the first item: network check."
return
;;
2)
echo "You will use nmtui to connect to a wireless network."
rfkill unblock wifi
dhcpcd
while [[ $netstatus != "OK" ]]
do
nmtui
networkcheck
case $ifnetworkconnect in
OK)
echo "Congratulations, your network connection is successful."
netstatus=OK
;;
NO)
echo "We're sorry, but your network is still down."
netstatus=NO
;;
esac
if [[ $netstatus != "OK" ]]
then
echo "Your network connection failed. Would you like to try again?[y/n]"
read -p "->" tryagainnet
case $tryagainnet in
Y|y)
echo "We hope you will succeed in your next attempt."
;;
N|n)
echo "Be aware that your network will most likely still be disconnected!"
break
;;
*)
echo "Your input is incorrect and we will assume you want to try again."
;;
esac
else
echo "Good luck!"
fi
done
;;
*)
echo "Your input is incorrect. You will not be able to configure the network."
echo "Note that this is not enough to say that your network is available!"
return
;;
esac
}
diskpart(){
while [[ $ifdiskcorrect != "OK" ]]
do
fdisk -l
echo "Enter the name of your target disk, for example, /dev/nvme0n1"
read -p "->" diskname
echo "Do you want to use cfdisk for disk partitioning?"
echo "Please note that you can only use cfdisk in this script, if you refuse, we will assume that you have partitioned the hard disk."
echo "[y/n]"
read -p "->" ifcfdisk
case $ifcfdisk in
Y|y)
cf='cfdisk'
echo 'Do you need to add the parameter "-z" to the cfdisk command?'
echo 'Note that this option causes cfdisk to initialize your partition table!'
echo "[y/n]"
read -p "->" ifcfz
case $ifcfz in
Y|y)
cf+=" -z ${diskname}"
;;
*)
cf+=" ${diskname}"
;;
esac
${cf}
;;
N|n)
echo "You may have already partitioned your disk."
;;
*)
echo "Your input is incorrect."
echo "You may have already partitioned your disk."
;;
esac
echo "The following is the final result of your partition:"
fdisk -l
echo "Is that correct?[y/n]"
read -p "->" diskcorrect
case $diskcorrect in
Y|y)
ifdiskcorrect=OK
echo "Good luck!"
;;
N|n)
ifdiskcorrect=NO
echo "I'm sorry to hear that."
;;
*)
ifdiskcorrect=NO
echo "Your input is incorrect and we will assume that your partition is incorrectly configured."
;;
esac
if [[ $ifdiskcorrect != "OK" ]]
then
echo "Do you want to try it again?[y/n]"
read -p "->" tryagaindisk
case $tryagaindisk in
Y|y)
echo "We hope your next attempt will be successful."
;;
N|n)
echo "Please note that this does not mean that your partition configuration is correct!"
break
;;
*)
echo "Your input is incorrect, we will consider you need to try again!"
;;
esac
else
echo "Good luck!"
fi
done
}
partformat(){
case $ifdiskcorrect in
OK)
echo "Test passed! You can do this step."
pretestformat=OK
;;
NO)
echo "The test failed! You are advised not to proceed with this step!"
pretestformat=NO
;;
*)
echo "You probably haven't done the disk partitioning step yet!"
pretestformat=NO
;;
esac
if [[ $pretestformat != "OK" ]]
then
echo "We strongly do not recommend this step, do you want to exit this step?[y/n]"
read -p "->" exitformat
case $exitformat in
Y|y)
return
;;
N|n)
echo "Well, hopefully your partitioning job has been done ."
;;
*)
echo "You entered incorrectly and we will assume that you want to exit."
return
;;
esac
else
echo "We look forward to your success in this step as well."
fi
while [[ $ifpartformat != "OK" ]]
do
fdisk -l
while [[ $ifformatyorn != "OK" ]]
do
echo "Please enter your partition name, e.g. sda1."
read -p "->" formattarget
echo "Which format do you want to use?"
echo "1.xfs"
echo "2.ext4"
echo "3.btrfs"
echo "4.f2fs"
echo "5.vfat"
echo "6.swap"
read -p "->" formatuse
case $formatuse in
1)
mkfs.xfs /dev/$formattarget -f
;;
2)
mkfs.ext4 /dev/$formattarget
;;
3)
mkfs.btrfs /dev/$formattarget -f
;;
4)
mkfs.f2fs /dev/$formattarget -f
;;
5)
mkfs.vfat /dev/$formattarget
;;
6)
mkswap /dev/$formattarget
swapon /dev/$formattarget
;;
*)
echo "Your input is incorrect."
;;
esac
echo "Do you still need to do formatting?[y/n]"
read -p "->" stillformat
case $stillformat in
Y|y)
echo "We hope you will be as successful this time as the last time."
;;
N|n)
ifformatyorn=OK
echo "Good Luck!"
;;
*)
echo "Your input is incorrect and we will assume that you are still formatting."
;;
esac
done
echo "Is everything done at this stage?[y/n]"
read -p "->" ifformatdone
case $ifformatdone in
Y|y)
ifpartformat=OK
echo "Good Luck!"
checkformat=OK
;;
N|n)
ifpartformat=NO
ifformatyorn=NO
checkformat=NO
;;
*)
echo "Your input is incorrect and we will consider you incomplete."
ifpartformat=NO
ifformatyorn=NO
checkformat=NO
;;
esac
if [[ $checkformat == "NO" ]]
then
echo "Do you want to force an exit step?[y/n]"
read -p "->" exitaftercheckformat
case $exitaftercheckformat in
Y|y)
break
;;
*)
echo "Hope you can succeed next time!"
;;
esac
else
echo "Good luck!"
fi
done
}
partmount(){
case $ifpartformat in
OK)
echo "We hope you can complete this step successfully."
pretestmount=OK
;;
NO)
pretestmount=NO
echo "We do not recommend you to perform this step!"
echo "Please finish formatting first!"
;;
*)
pretestmount=NO
echo "You probably haven't done the formatting yet!"
echo "Please finish the formatting operation first!"
;;
esac
if [[ $pretestmount != "OK" ]]
then
echo "Do you want to quit this step?[y/n]"
read -p "->" exitmount
case $exitmount in
Y|y)
return
;;
N|n)
echo "Well, we don't recommend it, though."
;;
*)
echo "Your input is incorrect, we will assume that you want to exit this step!"
return
;;
esac
else
echo "Good Luck!"
fi
lsblk
while [[ $rootmount != "0" ]]
do
echo "Enter your target root partition, for example,sda2."
read -p "->" rootpart
mount /dev/${rootpart} /mnt
rootmount=$?
if [[ $rootmount != "0" ]]
then
echo "ERROR! please try again!"
fi
done
echo "Running ls /mnt"
ls /mnt
mkdir -p /mnt/boot
mkdir /mnt/home
echo "We mounted your root partition to /mnt"
echo "We created some folders: /mnt/boot and /mnt/home"
echo "Next, you will mount some partitions."
while [[ $ifmount != "OK" ]]
do
lsblk
while [[ $ifpartmountyorn != "OK" ]]
do
echo 'Do you want to create a folder before performing the "mount" operation?'
echo '[y/n]'
read -p "->" createfolder
case $createfolder in
Y|y)
echo 'Enter a specific path, for example, /mnt/boot/abc'
read -p "->" folderPath
mkdir -p ${folderPath}
;;
esac
echo "Please enter the partition you want to mount. For example, sda3"
read -p "->" mountpart
echo "Enter the mount target, for example, /mnt/boot/EFI"
read -p "->" mounttarget
mount /dev/$mountpart $mounttarget
lsblk
echo "Do you still have partitions to mount?"
echo "[y/n]"
read -p "->" stillhavemount
case $stillhavemount in
Y|y)
ifpartmountyorn=NO
;;
N|n)
ifpartmountyorn=OK
echo "Good Luck!"
;;
*)
echo "Your input is incorrect and we will assume that you need to mount as well."
ifpartmountyorn=NO
;;
esac
done
lsblk
echo "Is all the work done for this step?[y/n]"
read -p "->" alldonemount
case $alldonemount in
Y|y)
echo "Good luck!"
ifmount=OK
checkmount=OK
;;
N|n)
ifmount=NO
ifpartmountyorn=NO
checkmount=NO
;;
*)
echo "Your input is incorrect and we will consider that you still need to proceed with this step."
ifmount=NO
ifpartmountyorn=NO
checkmount=NO
;;
esac
if [[ $checkmount == "NO" ]]
then
echo "Do you want to force an exit step?[y/n]"
read -p "->" aftercheckexitmount
case $aftercheckexitmount in
Y|y)
break
;;
*)
echo "I look forward to your success next time."
;;
esac
else
echo "Good luck!"
fi
done
}
mirrors(){
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
touch /etc/pacman.d/mirrorlist
echo 'Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist
echo 'Server = https://mirror.sjtu.edu.cn/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist
pacman -Sy
case $? in
0)
checkmirrors=OK
echo "Check is done! pacman works!"
;;
*)
echo "There seems to be a problem with the network."
checkmirrors=NO
;;
esac
}
packageinstall(){
networkcheck
case $ifnetworkconnect in
NO)
echo "Your network is not connected yet, you cannot perform this step!"
return
;;
*)
echo "Good luck! Your network is available!"
;;
esac
mkdir /mnt/Base_Pkg_Install
touch /mnt/Base_Pkg_Install/Install_BPKG
echo "base base-devel linux linux-firmware linux-headers dhcpcd networkmanager ntfs-3g xfsprogs btrfs-progs f2fs-tools wget" >> /mnt/Base_Pkg_Install/Install_BPKG
echo $(cat /mnt/Base_Pkg_Install/Install_BPKG)
echo "We will install the software listed above"
echo "Do you have anything to add?[y/n]"
read -p "->" base_appsadd
case $base_appsadd in
Y|y)
read -p "Please enter what you want to install" bappss
echo " $bappss" >> /mnt/Base_Pkg_Install/Install_BPKG
;;
N|n)
echo "I wish you good luck"
;;
*)
echo "Your input is wrong, but I wish you well anyway."
;;
esac
pacstrap -i /mnt $(cat /mnt/Base_Pkg_Install/Install_BPKG)
case $? in
0)
checkbpkginstall=OK
echo "Congratulations to you! The basic system is deployed successfully!"
;;
*)
checkbpkginstall=NO
echo "I'm sorry to tell you that the base package installation failed"
;;
esac
}
fstab(){
genfstab -U /mnt >> /mnt/etc/fstab
}
archchroot(){
if [[ $ifpartformat == "OK" && $ifmount == "OK" && $checkbpkginstall == "OK" ]]
then
echo "Check is done! You can perform the chroot operation!"
else
echo "The test failed! You must not do this!"
return
fi
cd /mnt
pacman -S wget
wget https://gitee.com/chen-197/arch-install/raw/master/ArchInstall2.sh
echo "Once inside chroot, you can complete the rest of the installation by running bash ArchInstall2.sh"
arch-chroot /mnt bash ArchInstall2.sh
}
### Here is the main part of the code
while true
do
echo "Welcome to the Arch Linux installation script!"
echo "Author: Chen-197"
echo "Make sure you use this script in the latest Archlinux official image!"
echo "**********************************************************************"
if [[ $onefunc != "OK" && $netstatus != "OK" ]]
then
echo "< >1.Configure the network connection."
elif [[ $onefunc == "OK" && $netstatus == "OK" ]]
then
echo -e "< ""\033[32mOK\033[0m"" >""1.Configure the network connection."
else
echo -e "< ""\033[31mFailed\033[0m"" >""1.Configure the network connection."
fi
if [[ $twofunc != "OK" && $ifdiskcorrect != "OK" ]]
then
echo "< >2.Configure disk partitions."
elif [[ $twofunc == "OK" && $ifdiskcorrect == "OK" ]]
then
echo -e "< ""\033[32mOK\033[0m"" >""2.Configure disk partitions."
else
echo -e "< ""\033[31mFailed\033[0m"" >""2.Configure disk partitions."
fi
if [[ $threefunc != "OK" && $ifpartformat != "OK" ]]
then
echo "< >3.Configure partition formatting."
elif [[ $threefunc == "OK" && $ifpartformat == "OK" ]]
then
echo -e "< ""\033[32mOK\033[0m"" >""3.Configure partition formatting."
else
echo -e "< ""\033[31mFailed\033[0m"" >""3.Configure partition formatting."
fi
if [[ $fourfunc != "OK" && $ifmount != "OK" ]]
then
echo "< >4.Configure partition mounting."
elif [[ $fourfunc == "OK" && $ifmount == "OK" ]]
then
echo -e "< ""\033[32mOK\033[0m"" >""4.Configure partition mounting."
else
echo -e "< ""\033[31mFailed\033[0m"" >""4.Configure partition mounting."
fi
if [[ $fivefunc != "OK" && $checkmirrors != "OK" ]]
then
echo "< >5.Configure mirror sources."
elif [[ $fivefunc == "OK" && $checkmirrors == "OK" ]]
then
echo -e "< ""\033[32mOK\033[0m"" >""5.Configure mirror sources."
else
echo -e "< ""\033[31mFailed\033[0m"" >""5.Configure mirror sources."
fi
if [[ $sixfunc != "OK" && $checkbpkginstall != "OK" ]]
then
echo "< >6.Deploy the basic system."
elif [[ $sixfunc == "OK" && $checkbpkginstall == "OK" ]]
then
echo -e "< ""\033[32mOK\033[0m"" >""6.Deploy the basic system."
else
echo -e "< ""\033[31mFailed\033[0m"" >""6.Deploy the basic system."
fi
if [[ $sevenfunc != "OK" ]]
then
echo "< >7.Generate the fstab file."
else
echo -e "< ""\033[32mOK\033[0m"" >""7.Generate the fstab file."
fi
if [[ $eightfunc != "OK" ]]
then
echo "< >8.Chroot Logs in to the new system"
else
echo -e "< ""\033[32mOK\033[0m"" >""8.Chroot Logs in to the new system."
fi
echo "9.Exit"
echo "Please enter the serial number."
read -p "->" numberch
case $numberch in
1)
networkconnect
onefunc=OK
;;
2)
diskpart
twofunc=OK
;;
3)
partformat
threefunc=OK
;;
4)
partmount
fourfunc=OK
;;
5)
mirrors
fivefunc=OK
;;
6)
packageinstall
sixfunc=OK
;;
7)
fstab
sevenfunc=OK
;;
8)
archchroot
eightfunc=OK
;;
9)
echo "Are you sure you want to quit?[y/n]"
read -p "->" exitall
case $exitall in
Y|y)
break
;;
N|n)
echo "Wish you a happy use!"
;;
*)
echo "Your input is incorrect, the script will not exit!"
;;
esac
;;
esac
done
###ArchInstall2.sh
#!/bin/bash
# Test the network connection
echo "Make sure you are in a chroot environment!"
echo "Make sure you have a good Internet connection!"
ping -c 1 39.156.66.18 > /dev/null 2>&1
if [ $? -eq 0 ];then
echo 'Network is connected'
else
echo 'Network is not connected'
echo 'ERROR!'
exit 1
fi
# Install the necessary software
mkdir /InstallAPPS
touch /InstallAPPS/appsinstall
echo "What desktop environment do you choose to install?"
echo "1.KDE Plasma"
echo "2.Gnome"
echo "3.Xfce"
echo "4.DDE"
echo "5.Other desktop environments or window managers"
read -p "[1,2,3,4,5]" DE
case $DE in
1)
echo "plasma kde-applications" >> /InstallAPPS/appsinstall
;;
2)
echo "gnome gnome-extra" >> /InstallAPPS/appsinstall
;;
3)
echo "xfce4 xfce4-goodies sddm" >> /InstallAPPS/appsinstall
;;
4)
echo "deepin deepin-extra" >> /InstallAPPS/appsinstall
;;
5)
echo "Please enter the package you want to install"
read -p "->" selfDE
echo "$selfDE" >> /InstallAPPS/appsinstall
;;
*)
echo "Please enter the package you want to install"
read -p "->" selfDE
echo "$selfDE" >> /InstallAPPS/appsinstall
;;
esac
echo "xorg nano vim dosfstools grub efibootmgr os-prober firefox ttf-dejavu wqy-microhei networkmanager " >> /InstallAPPS/appsinstall
echo `cat /InstallAPPS/appsinstall`
echo "We will install the software listed above"
echo "Do you have anything to add?"
read -p "[y/n]" appsadd
case $appsadd in
Y|y)
read -p "Please enter what you want to install" appsss
echo "$appsss" >> /InstallAPPS/appsinstall
;;
N|n)
echo "I wish you good luck"
;;
esac
for ((i=1;i<=3;i++))
do
pacman -S `cat /InstallAPPS/appsinstall`
if [[ $? == "0" ]]; then
break
fi
if [[ $i == "3" ]]; then
echo "Some mistakes may well have occurred"
read -p "Do you intend to proceed with the installation?[y/n]" continue
case $continue in
Y|y)
i=2
;;
N|n)
echo "ERROR!!!"
exit
;;
*)
echo "ERROR!!!"
exit
;;
esac
fi
done
# Set the System Language
cat /etc/locale.gen | grep "UTF-8"
echo "Which language will you use for default language?"
echo "If it is simplified Chinese or American English, you can use our provide simple configuration"
echo "1.Simplified Chinese."
echo "2.American English."
echo "3.By you to configure the/etc/locale.gen"
read -p "[1,2,3]" language
case $language in
1)
echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=zh_CN.UTF-8" >> /etc/locale.conf
;;
2)
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
;;
3)
vim /etc/locale.gen
locale-gen
vim /etc/locale.conf
;;
*)
echo "You enter a wrong number"
echo "You will use vim to edit this file!"
sleep 3s
vim /etc/locale.gen
locale-gen
vim /etc/locale.conf
;;
esac
# Set the time zone
ls /usr/share/zoneinfo/
while [[ $timezone1 != "0" ]]
do
read -p "Where are you?Please enter your location." location1
for l in $(ls /usr/share/zoneinfo/)
do
if [[ $location1 == "$l" ]]; then
timezone1=0
fi
done
if [[ $timezone1 != "0" ]]; then
echo "What you entered is wrong, please enter it again"
fi
done
ls /usr/share/zoneinfo/${location1}
while [[ $timezone2 != "0" ]]
do
read -p "Where are you?Please enter your location." location2
for l in $(ls /usr/share/zoneinfo/${location1})
do
if [[ $location2 == "$l" ]]; then
timezone2=0
fi
done
if [[ $timezone2 != "0" ]]; then
echo "What you entered is wrong, please enter it again"
fi
done
ln -sf /usr/share/zoneinfo/${location1}/${location2} /etc/localtime
# Install grub
echo "Is ESP located on a removable device?"
echo '[y/n]'
read -p "->" ifremovable
echo "Which way do you want to boot up your computer?"
echo "1.Legacy"
echo "2.UEFI"
read -p "[1/2]" boot
case $boot in
1)
while [[ $grubb != "0" ]]
do
read -p "Please enter the hard disk where this system resides.For example, /dev/sda" disk
grub-install --target=i386-pc $disk
grub-mkconfig -o /boot/grub/grub.cfg
grubb=${?}
if [[ $grubb != "0" ]]; then
echo "ERROR!"
fi
done
;;
2)
while [[ $grubb != "0" ]]
do
read -p "Please enter the mount location of your ESP. For example, /boot/EFI)" esp
ingrub="grub-install --target=x86_64-efi --efi-directory=${esp} --recheck"
case $ifremovable in
Y|y)
ingrub+=' --removable'
;;
esac
${ingrub}
grub-mkconfig -o /boot/grub/grub.cfg
grubb=${?}
if [[ $grubb != "0" ]]; then
echo "ERROR!"
fi
done
;;
*)
echo "ERROR!"
;;
esac
# Set a password for root
while [[ $passwdroot != "0" ]]
do
echo "Please enter your root password"
passwd
passwdroot=${?}
if [[ $passwdroot != "0" ]]; then
echo "What you entered is wrong, please enter it again"
fi
done
# Creat a New user
while [[ $usernm != "0" ]]
do
echo "Please enter your user name"
read -p "->" username
useradd -m -g users -s /bin/bash ${username}
usernm=${?}
if [[ $usernm != "0" ]]; then
echo "What you entered is wrong, please enter it again"
fi
done
# Set a password for the user
while [[ $passwduser != "0" ]]
do
echo "Please enter your user password"
passwd ${username}
passwduser=${?}
if [[ $passwduser != "0" ]]; then
echo "What you entered is wrong, please enter it again"
fi
done
# Give the new user sudo permission
echo "${username} ALL=(ALL) ALL" >> /etc/sudoers
# Start some necessary system services
systemctl enable NetworkManager
case $DE in
1)
systemctl enable sddm
;;
2)
systemctl enable gdm
;;
3)
systemctl enable sddm
;;
4)
systemctl enable lightdm
;;
5)
echo "You will manually start some system services later"
;;
*)
echo "You will manually start some system services later"
;;
esac
echo "The installation has completed successfully"
exit
# enjoy!