131 lines
3.4 KiB
Bash
Executable File
131 lines
3.4 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
|
|
udevadm trigger --subsystem-match=input --action=change
|
|
service keyboard-setup.sh restart
|
|
|
|
lsblk
|
|
read -p "Device (ALL DATA WILL BE ERASED): " DEVICE
|
|
|
|
# Create partitions
|
|
echo "Creating partitions ..."
|
|
wipefs --all "$DEVICE"
|
|
sgdisk -n 1::+1M -c 1:"BIOS boot partition" -t 1:ef02 "$DEVICE"
|
|
sgdisk -n 2::+250M -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 ..."
|
|
fallocate -l 512M "/media/install/swap"
|
|
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"
|
|
|
|
# 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
|
|
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 |