From 329e93fbd275c3d525ca1cd3d092bfbd8c771522 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 10 Aug 2022 18:34:29 +0200 Subject: [PATCH] Add live-installer --- modlists/hardware-live | 1 - modlists/live | 2 + mods/live-installer/data/bin/login | 128 +++++++++++++++++++++++++++++ mods/live-installer/modscript | 4 + 4 files changed, 134 insertions(+), 1 deletion(-) delete mode 100644 modlists/hardware-live create mode 100644 modlists/live create mode 100755 mods/live-installer/data/bin/login create mode 100644 mods/live-installer/modscript diff --git a/modlists/hardware-live b/modlists/hardware-live deleted file mode 100644 index 56573d1..0000000 --- a/modlists/hardware-live +++ /dev/null @@ -1 +0,0 @@ -live-boot \ No newline at end of file diff --git a/modlists/live b/modlists/live new file mode 100644 index 0000000..dba0bed --- /dev/null +++ b/modlists/live @@ -0,0 +1,2 @@ +live-boot +live-installer \ No newline at end of file diff --git a/mods/live-installer/data/bin/login b/mods/live-installer/data/bin/login new file mode 100755 index 0000000..1371b59 --- /dev/null +++ b/mods/live-installer/data/bin/login @@ -0,0 +1,128 @@ +#!/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 + + lsblk + read -p "Device (ALL DATA WILL BE ERASED): " DEVICE + + # Create partitions + echo "Creating partitions ..." + ( + echo n + echo e + echo + echo + echo +256M + echo t + echo swap + echo n + echo p + echo + echo + echo + echo t + echo + echo linux + echo w + echo + echo + ) | fdisk "$DEVICE" + + # Format partitions + echo "Formatting partitions ..." + mkswap "${DEVICE}1" + mkfs.ext4 "${DEVICE}2" + + # Mount target partition + echo "Mounting partitions ..." + mkdir -p "/media/install" + mount "${DEVICE}2" "/media/install" + + # 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 "${DEVICE}1") none swap sw 0 0" >"/media/install/etc/fstab" + echo "UUID=$(blkid -o value -s UUID "${DEVICE}2") / ext4 errors=remount-ro 0 1" >>"/media/install/etc/fstab" + + # Remove live-specific packages + echo "Removing live-specific packages ..." + wdvn-chroot "/media/install" apt autoremove --purge 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 ..." + #echo "GRUB_DISABLE_OS_PROBER=true" >>"/media/install/etc/default/grub" + wdvn-chroot "/media/install" grub-install --boot-directory="/boot" --modules=part_msdos "$DEVICE" + wdvn-chroot "/media/install" update-grub + #sed -i 's/GRUB_DISABLE_OS_PROBER=true/# GRUB_DISABLE_OS_PROBER=true/' "/media/install/etc/default/grub" + + # Unmount + echo "Unmounting ..." + umount -l "/media/install" + rmdir "/media/install" + + echo Done. + read + ) + if [ "$?" != "0" ]; then + echo ERROR. Cleaning up... + 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 \ No newline at end of file diff --git a/mods/live-installer/modscript b/mods/live-installer/modscript new file mode 100644 index 0000000..cd19cf5 --- /dev/null +++ b/mods/live-installer/modscript @@ -0,0 +1,4 @@ +#!/bin/bash +export WDVN_PACKAGES="$WDVN_PACKAGES squashfs-tools" +export WDVN_REMOVE="$WDVN_REMOVE squashfs-tools" +cp "$1/bin/login" "$1/bin/login.oobe" \ No newline at end of file