created fresh install script and library

This commit is contained in:
l0sted 2018-09-17 23:40:30 +03:00
parent f3455980be
commit a64f373006
3 changed files with 151 additions and 7 deletions

View File

@ -0,0 +1,76 @@
#!/bin/bash
#host os should be arch or arch based
source lib.sh
installDistro() {
case "$targetDistro" in
"1")
read -p "Enter packages/pkg groups you need:" targetPkgs
[ $targetBoot == "1" ] && targetPkgs+="grub"
pacstrap /mnt $targetPkgs
;;
"2")
[ -z `pacman -Qqs debootstrap`] && pacman -Syu debootstrap --noconfirm #install debootstrap if not found
read -p "stable/unstable/testing?" debVersion #ask for version
debootstrap $debVersion /mnt http://deb.debian.org/debian/
;;
"3")
#install gentoo
echo "WIP"
;;
*)
echo "no such distro"
;;
esac
}
postInstall() {
#genfstab, install bootloader
genfstab -U /mnt >> /mnt/etc/fstab
#check for efi
case "$targetBoot" in
"1")
#grub
cat << EOF |arch-chroot /mnt
grub-mkconfig -o /boot/grub/grub.cfg
grub-install
exit
EOF
;;
"2")
#systemd-boot
cat << EOF | arch-chroot /mnt
bootctl install
exit
EOF
# bootctl --path=/mnt/boot/efi install
;;
*)
echo "wtf"
;;
}
#distro
echo -e "Choose distro:\n1. arch\n2. debian (based)\n3. gentoo"
read targetDistro
until [ $targetDistro -le 3]
do
read -p "Incorrect number:" targetDistro
done
#loader
echo -e "Choose loader:\n1. grub\n2. systemd-boot"
read targetBoot
until [ $targetBoot -le 2]
do
read -p "Incorrect number:" targetBoot
done
#work
requestPartTable
setPartitions
installDistro
postInstall
echo "Now, theoretically system should work"

78
lib.sh
View File

@ -1,4 +1,4 @@
partition() {
requestPartTable() {
lsblk -o NAME,LABEL,FSTYPE,SIZE,MOUNTPOINT,MODEL
until [ ! -f $targetDrive ]
do
@ -15,10 +15,78 @@ partition() {
done
#get swap size
swapSize=$(free -m | grep "Mem" | awk '{print $2}')
read -p "Enter extra amount of swap (empty == 512):" swapExtra
if [ -z "$swapExtra" ] && swapExtra=512
let "swapSize += swapExtra" #add 512 mbs to swap for
swapSize=$(free -m | grep "Mem" | awk '{print $2}') #get ram size
read -p "Enter extra amount of swap (empty == 512):" swapExtra #request extra swap above ram size
[ -z "$swapExtra" ] && swapExtra=512
let "swapSize += swapExtra" #add 512 mbs to swap
swapSize=$swapSize"M"
return $TRUE
}
setPartitions(){
##clear mbr for sure
dd if=/dev/zero of=$targetDrive count=512
# partition scheme:
# 1. swap
# 2. boot
# 3. root
##fdisk
echo "==> Partitioning..."
(
echo o # Create a new empty DOS partition table
echo n # Add a new partition
echo # Primary partition
echo # Partition number
echo # First sector (Accept default: 1)
echo +$swapSize # Last sector (Accept default: varies)
echo y #remove sign
echo n
echo
echo
echo
echo +$bootSize
echo y
echo n
echo
echo
echo
echo
echo w
) | fdisk $targetDrive
# IMHO this ^ is less obfuscated way
##mkfs's
echo "==> Making filesystems..."
mkswap $targetDrive"1"
mkfs.vfat $targetDrive"2"
if $encryptedDevice #how to push password?
then
cryptsetup luksFormat -v $targetDrive"3"
cryptsetup open $targetDrive"3" targetLuks
mkfs.ext4 /dev/mapper/targetLuks
else
mkfs.ext4 $targetDrive"3"
fi
##get disk's uuid
echo "==> Getting UUIDs..."
UUIDS=($(blkid $targetDrive"1" $targetDrive"2" $targetDrive"3" -o value -s UUID)) #created array of swap/boot/root UUIDs
if $encryptedDevice
then
UUIDS[3]=UUIDS[2]
UUIDS[2]=`blkid /dev/mapper/targetLuks -o value -s UUID`
fi #now we have swap/boot/root/luks UUIDs
##mount disks
echo "==> Mounting..."
[ $encryptedDevice ] && mount /dev/mapper/targetLuks /mnt || mount $targetDrive"3" /mnt
mkdir /mnt/boot
mount $targetDrive"2" /mnt/boot
}

View File

@ -55,7 +55,7 @@ done
swapSize=$(free -m | grep "Mem" | awk '{print $2}')
read -p "Enter extra amount of swap (empty == 512):" swapExtra
if [ -z "$swapExtra" ] && swapExtra=512
let "swapSize += swapExtra" #add 512 mbs to swap for
let "swapSize += swapExtra" #add 512 mbs to swap for swap, not only hibernation
swapSize=$swapSize"M"
#DEPLOY
@ -150,7 +150,7 @@ mv /mnt/etc/fstab /mnt/etc/fstab.orig
cat /mnt/etc/fstab.orig | grep "ext4" | sed 's/UUID=[A-Fa-f0-9-]*/UUID='${UUIDS[2]}'/' > /mnt/etc/fstab
cat /mnt/etc/fstab.orig | grep "vfat" | sed 's/UUID=[A-Fa-f0-9-]*/UUID='${UUIDS[1]}'/' >> /mnt/etc/fstab
cat /mnt/etc/fstab.orig | grep "swap" | sed 's/UUID=[A-Fa-f0-9-]*/UUID='${UUIDS[0]}'/' >> /mnt/etc/fstab
rm /mnt/etc/fstab.orig
rm /mnt/etc/fstab.orig #TODO OFC we need to check mountpoint, not only type of FS
echo "==> Result:"
cat /mnt/etc/fstab