Created
June 30, 2017 06:05
-
-
Save fgoinai/636dcd3163e97cf75f1132efb646d587 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#check network connection | |
con=$(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error) | |
if [ $con == "error" ]; then | |
exit -1 | |
fi | |
timedatectl set-ntp true | |
lsblk | |
dest_disk="" | |
while [[ ! $dest_disk =~ ^sd[a-z]$ ]]; do # while $dest_disk != ^sd?$ | |
read -p "Please select the disk you want to install ArchLinux [sda,sdb...]" dest_disk | |
done | |
cgdisk /dev/$dest_disk | |
# function part_init { | |
# local __flag="" | |
# read -p "Have $1? [y/n]" __flag | |
# if [ $__flag == "y" ]; then | |
# local __part_flag="" | |
# while [[ ! $__part_flag =~ ^sd[a-z][0-9]$ ]]; do | |
# read -p "Please provide $1 partition [sda1/sdb2...]" __part_flag | |
# done | |
# echo $__part_flag | |
# else | |
# echo "" | |
# fi | |
# } | |
# eg fmt_part sda1 swap | |
# eg2 fmt_part sda2 / btrfs | |
function fmt_part { | |
#syntax checked in main | |
local __part=$1 | |
# won't check mnt pt syntax | |
if [ $2=="swap" ]; then | |
mkswap /dev/$__part | |
swapon /dev/$__part | |
else | |
mkfs.$3 /dev/$__part | |
fi | |
} | |
#hash table of mount_point-partition | |
declare -A mnt_part_table | |
#format partition | |
fin_part=() | |
choice="" | |
fs_list=$(ls /bin|grep '^mkfs.'|cut -d '.' -f 2) | |
mnt_list=("/boot","swap","/","/home") | |
while [ $choice!="y" ] || [ $choice!="Y" ]; do | |
lsblk | |
local __part="" | |
while [[ ! $__part =~ ^sd[a-z][0-9]$ ]]; do | |
read -p "Please choose the partition [sda1,sdb2...]" __part | |
done | |
local __mnt="" | |
read -p "What is the mount point? [${mnt_list[*]}]" __mnt | |
local __fs="" | |
read -p "What is the file system of /dev/$__part? [${fs_list[*]}]" __fs | |
fmt_part $__part $__mnt $__fs | |
fin_part+=($__part) | |
mnt_part_table+=(["$__mnt"]="$__part") | |
echo "Finished parts: ${fin_part[*]}" | |
done | |
# mount: root -> boot -> home | |
mount /dev/${mnt_part_table["/"]} /mnt | |
mkdir /mnt/boot | |
mkdir /mnt/home | |
mount /dev/${mnt_part_table["/boot"]} /mnt/boot | |
mount /dev/${mnt_part_table["/home"]} /mnt/home | |
#sort the mirrorlist according to their speed first | |
rankmirrors -g | |
pacstrap /mnt base base-devel | |
genfstab -U /mnt >> /mnt/etc/fstab | |
cp part2.sh /mnt/part2.sh | |
arch-chroot /mnt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment