linux-deployment-scripts/configs/scripts/install.sh
2024-11-11 07:39:40 +01:00

62 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# This file is part of VM-Experiments.
# Licensed under the GPL-3.0-or-later. See LICENSE for details.
trap '' SIGINT SIGTERM
parted -s /dev/sda mklabel msdos
parted -s /dev/sda mkpart primary linux-swap 0% 2GiB
parted -s /dev/sda mkpart primary ext4 2GiB 100%
mkswap /dev/sda1
mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt
swapon /dev/sda1
tar -xzvf /rootfs.tar.gz -C /mnt
genfstab -U /mnt >>/mnt/etc/fstab
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
if chroot /mnt /bin/bash -c "command -v grub2-mkconfig &>/dev/null;" then
chroot /mnt /bin/bash -c "grub2-mkconfig -o /boot/grub/grub.cfg"
elif chroot /mnt /bin/bash -c "command -v grub-mkconfig &>/dev/null;" then
chroot /mnt /bin/bash -c "grub-mkconfig -o /boot/grub/grub.cfg"
fi
if chroot /mnt /bin/bash -c "command -v grub2-install &>/dev/null;" then
chroot /mnt /bin/bash -c "grub2-install /dev/sda"
elif chroot /mnt /bin/bash -c "command -v grub-install &>/dev/null;" then
chroot /mnt /bin/bash -c "grub-install /dev/sda"
fi
while true; do
read -p "Enter a username (lowercase letters, digits, underscores and hyphens): " username
chroot /mnt /bin/bash -c "useradd -m '$username'"
if [ $? -eq 0 ]; then
break
fi
done
while true; do
chroot /mnt /bin/bash -c "passwd '$username'"
if [ $? -eq 0 ]; then
break
fi
done
while true; do
read -p "Enter the hostname: " hostname
chroot /mnt /bin/bash -c "echo $hostname > /etc/hostname"
if [ $? -eq 0 ]; then
break
fi
done