2022-08-10 16:34:29 +00:00
|
|
|
#!/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
|
2022-08-19 05:42:46 +00:00
|
|
|
service console-setup.sh restart
|
2022-08-25 19:07:03 +00:00
|
|
|
udevadm trigger --subsystem-match=input --action=change
|
|
|
|
service keyboard-setup.sh restart
|
2022-08-10 16:34:29 +00:00
|
|
|
|
2022-08-26 06:54:16 +00:00
|
|
|
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
|
2022-08-10 16:34:29 +00:00
|
|
|
|
|
|
|
# Create partitions
|
|
|
|
echo "Creating partitions ..."
|
2022-08-15 06:31:02 +00:00
|
|
|
wipefs --all "$DEVICE"
|
2022-08-23 11:06:46 +00:00
|
|
|
sgdisk -n 1:2048:+1M -c 1:"BIOS boot partition" -t 1:ef02 "$DEVICE"
|
2022-08-26 06:55:10 +00:00
|
|
|
sgdisk -n 2::+512M -c 2:"EFI System" -t 2:ef00 "$DEVICE"
|
2022-08-15 06:31:02 +00:00
|
|
|
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)"
|
2022-08-10 16:34:29 +00:00
|
|
|
|
|
|
|
# Format partitions
|
|
|
|
echo "Formatting partitions ..."
|
2022-08-15 06:31:02 +00:00
|
|
|
mkfs.fat -F32 "$PART_EFI"
|
|
|
|
mkfs.ext4 "$PART_DATA"
|
2022-08-10 16:34:29 +00:00
|
|
|
|
|
|
|
# Mount target partition
|
|
|
|
echo "Mounting partitions ..."
|
|
|
|
mkdir -p "/media/install"
|
2022-08-15 06:31:02 +00:00
|
|
|
mount "$PART_DATA" "/media/install"
|
|
|
|
mkdir -p "/media/install/efi"
|
|
|
|
mount "$PART_EFI" "/media/install/efi"
|
|
|
|
|
|
|
|
# Creating swap
|
|
|
|
echo "Creating swap ..."
|
2022-08-26 09:50:58 +00:00
|
|
|
dd if=/dev/zero of="/media/install/swap" bs=1M count=512 status=progress
|
2022-08-15 06:31:02 +00:00
|
|
|
chmod 600 "/media/install/swap"
|
|
|
|
mkswap "/media/install/swap"
|
|
|
|
swapon "/media/install/swap"
|
2022-08-10 16:34:29 +00:00
|
|
|
|
|
|
|
# Add files
|
|
|
|
echo "Adding files ..."
|
|
|
|
unsquashfs -f -d "/media/install" "/lib/live/mount/medium/live/filesystem.squashfs"
|
|
|
|
|
2022-08-22 09:11:14 +00:00
|
|
|
# Set hostname
|
|
|
|
echo "Setting hostname ..."
|
|
|
|
echo "$(head -c4 </dev/urandom|xxd -p -u)" >"/media/install/etc/hostname"
|
|
|
|
|
2022-08-10 16:34:29 +00:00
|
|
|
# Write fstab
|
|
|
|
echo "Writing fstab ..."
|
2022-08-15 06:31:02 +00:00
|
|
|
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"
|
2022-08-10 16:34:29 +00:00
|
|
|
|
|
|
|
# Remove live-specific packages
|
|
|
|
echo "Removing live-specific packages ..."
|
2022-08-10 22:20:53 +00:00
|
|
|
wdvn-chroot "/media/install" apt -y remove live-boot live-boot-initramfs-tools
|
2022-08-25 10:10:10 +00:00
|
|
|
wdvn-chroot "/media/install" update-initramfs.orig.initramfs-tools -u
|
2022-08-10 16:34:29 +00:00
|
|
|
rm "/media/install/bin/login"
|
|
|
|
mv "/media/install/bin/login.oobe" "/media/install/bin/login"
|
|
|
|
|
|
|
|
# Install GRUB
|
|
|
|
echo "Installing grub ..."
|
2022-08-15 06:31:02 +00:00
|
|
|
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"
|
2022-08-10 16:34:29 +00:00
|
|
|
wdvn-chroot "/media/install" update-grub
|
|
|
|
|
|
|
|
# Unmount
|
|
|
|
echo "Unmounting ..."
|
2022-08-15 06:31:02 +00:00
|
|
|
swapoff "/media/install/swap"
|
|
|
|
umount -l "/media/install/efi"
|
|
|
|
rmdir "/media/install/efi"
|
2022-08-10 16:34:29 +00:00
|
|
|
umount -l "/media/install"
|
|
|
|
rmdir "/media/install"
|
|
|
|
|
|
|
|
echo Done.
|
|
|
|
read
|
|
|
|
)
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo ERROR. Cleaning up...
|
2022-08-15 06:31:02 +00:00
|
|
|
swapoff "/media/install/swap"
|
|
|
|
umount -l "/media/install/efi"
|
2022-08-10 16:34:29 +00:00
|
|
|
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
|