windvn/mods/live-installer/data/bin/login
2022-09-12 08:48:57 +02:00

148 lines
4.0 KiB
Bash
Executable File

#!/bin/bash
export PATH="/sbin:/usr/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
function wdvn-chroot {
(
set -e
mount -o bind "/dev" "$1/dev"
mount -o bind "/dev/pts" "$1/dev/pts"
mount -o bind "/sys" "$1/sys"
mount -t proc none "$1/proc"
chroot "$1" ${@:2}
)
if [ $? != 0 ]; then
wdvn-chroot-end "$1"
exit 1
fi
wdvn-chroot-end "$1"
}
function wdvn-chroot-end {
umount -l "$1/proc"
umount -l "$1/sys"
umount -l "$1/dev/pts"
umount -l "$1/dev"
}
CHOICE=1
while true; do
echo "Welcome to windvn!"
echo "1: Fast install"
echo "2: Open bash"
echo "3: Shut down"
read -p "Choice: " CHOICE
echo ""
if [ "$CHOICE" == "1" ]; then
(
set -e
dpkg-reconfigure keyboard-configuration
service console-setup.sh restart
udevadm trigger --subsystem-match=input --action=change
service keyboard-setup.sh restart
YN="n"
while [ "$YN" == "n" ]; do
echo ""
lsblk -d -o PATH,SIZE
read -p "Device: " DEVICE
echo ""
lsblk "$DEVICE" -o NAME,SIZE,FSTYPE,PARTLABEL
read -p "All data on this disk will be erased! Continue? [y,n]: " YN
YN="$(echo "$YN" | tr "[:upper:]" "[:lower:]")"
if [ "$YN" != "y" ]; then
YN="n"
fi
done
# Create partitions
echo "Creating partitions ..."
wipefs --all "$DEVICE"
sgdisk -n 1:2048:+1M -c 1:"BIOS boot partition" -t 1:ef02 "$DEVICE"
sgdisk -n 2::+512M -c 2:"EFI System" -t 2:ef00 "$DEVICE"
sgdisk -n 3::-0 -c 3:"Linux filesystem" -t 3:8300 "$DEVICE"
sgdisk --hybrid=1:2:3 "$DEVICE"
PART_EFI="$(echo "${DEVICE}"*2)"
PART_DATA="$(echo "${DEVICE}"*3)"
# Format partitions
echo "Formatting partitions ..."
mkfs.fat -F32 "$PART_EFI"
mkfs.ext4 "$PART_DATA"
# Mount target partition
echo "Mounting partitions ..."
mkdir -p "/media/install"
mount "$PART_DATA" "/media/install"
mkdir -p "/media/install/efi"
mount "$PART_EFI" "/media/install/efi"
# Creating swap
echo "Creating swap ..."
dd if=/dev/zero of="/media/install/swap" bs=1M count=512 status=progress
chmod 600 "/media/install/swap"
mkswap "/media/install/swap"
swapon "/media/install/swap"
# Add files
echo "Adding files ..."
unsquashfs -f -d "/media/install" "/lib/live/mount/medium/live/filesystem.squashfs"
# Set hostname
echo "Setting hostname ..."
echo "$(head -c4 </dev/urandom|xxd -p -u)" >"/media/install/etc/hostname"
# Write fstab
echo "Writing fstab ..."
echo "UUID=$(blkid -o value -s UUID "$PART_DATA") / ext4 errors=remount-ro 0 1" >>"/media/install/etc/fstab"
echo "/swap none swap sw 0 0" >>"/media/install/etc/fstab"
# Remove live-specific packages
echo "Removing live-specific packages ..."
wdvn-chroot "/media/install" apt -y remove live-boot live-boot-initramfs-tools
wdvn-chroot "/media/install" apt -y autoremove
wdvn-chroot "/media/install" update-initramfs -u
rm "/media/install/bin/login"
mv "/media/install/bin/login.oobe" "/media/install/bin/login"
# Install GRUB
echo "Installing grub ..."
wdvn-chroot "/media/install" grub-install --target=i386-efi --uefi-secure-boot --efi-directory="/efi" --boot-directory="/boot" "$DEVICE"
wdvn-chroot "/media/install" grub-install --target=x86_64-efi --uefi-secure-boot --efi-directory="/efi" --boot-directory="/boot" "$DEVICE"
wdvn-chroot "/media/install" grub-install --target=i386-pc --boot-directory="/boot" "$DEVICE"
wdvn-chroot "/media/install" update-grub
# Unmount
echo "Unmounting ..."
swapoff "/media/install/swap"
umount -l "/media/install/efi"
rmdir "/media/install/efi"
umount -l "/media/install"
rmdir "/media/install"
echo Done.
read
)
if [ "$?" != "0" ]; then
echo ERROR. Cleaning up...
swapoff "/media/install/swap"
umount -l "/media/install/efi"
umount -l "/media/install"
echo An error occured.
read
fi
fi
if [ "$CHOICE" == "2" ]; then
bash
fi
if [ "$CHOICE" == "3" ]; then
poweroff
exit
fi
echo ""
done