debian support

This commit is contained in:
Patrick 2024-11-10 18:03:47 +01:00
parent de19951611
commit f31aa555e7
12 changed files with 203 additions and 56 deletions

View file

@ -0,0 +1,9 @@
{
"identifier": "debian-bookworm-gnome-amd64",
"rootfs_type": "debootstrap",
"download_link": "http://deb.debian.org/debian/",
"download_name": "bookworm",
"packages": "grub-pc linux-image-amd64 task-gnome-desktop",
"script": "configs/scripts/install.sh",
"package_manager": "apt"
}

View file

@ -0,0 +1,9 @@
{
"identifier": "debian-bookworm-kde-amd64",
"rootfs_type": "debootstrap",
"download_link": "http://deb.debian.org/debian/",
"download_name": "bookworm",
"packages": "grub-pc linux-image-amd64 task-kde-desktop",
"script": "configs/scripts/install.sh",
"package_manager": "apt"
}

View file

@ -0,0 +1,9 @@
{
"identifier": "debian-bookworm-server-amd64",
"rootfs_type": "debootstrap",
"download_link": "http://deb.debian.org/debian/",
"download_name": "bookworm",
"packages": "nginx grub-pc linux-image-amd64",
"script": "configs/scripts/install.sh",
"package_manager": "apt"
}

View file

@ -1,7 +0,0 @@
{
"identifier": "noble-kubuntu-amd64",
"link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz",
"packages": "grub-pc linux-image-generic kubuntu-desktop",
"script": "install.sh"
}

View file

@ -1,7 +0,0 @@
{
"identifier": "noble-server-amd64",
"link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz",
"packages": "nginx grub-pc linux-image-generic",
"script": "install.sh"
}

View file

@ -1,7 +0,0 @@
{
"identifier": "noble-ubuntu-amd64",
"link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz",
"packages": "grub-pc linux-image-generic ubuntu-desktop",
"script": "install.sh"
}

View file

@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
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%
@ -34,8 +36,43 @@ mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
if command -v grub2-mkconfig &>/dev/null; then
chroot /mnt /bin/bash -c "grub2-mkconfig -o /boot/grub/grub.cfg"
elif command -v grub-mkconfig &>/dev/null; then
chroot /mnt /bin/bash -c "grub-mkconfig -o /boot/grub/grub.cfg"
fi
if command -v grub2-install &>/dev/null; then
chroot /mnt /bin/bash -c "grub2-install /dev/sda"
elif 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
umount -R /mnt

View file

@ -0,0 +1,9 @@
{
"identifier": "ubuntu-noble-gnome-amd64",
"rootfs_type": "download",
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz",
"packages": "grub-pc linux-image-generic ubuntu-desktop",
"script": "configs/scripts/install.sh",
"package_manager": "apt"
}

View file

@ -0,0 +1,9 @@
{
"identifier": "ubuntu-noble-kde-amd64",
"rootfs_type": "download",
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz",
"packages": "grub-pc linux-image-generic kubuntu-desktop",
"script": "configs/scripts/install.sh",
"package_manager": "apt"
}

View file

@ -0,0 +1,9 @@
{
"identifier": "ubuntu-noble-server-amd64",
"rootfs_type": "download",
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz",
"packages": "nginx grub-pc linux-image-generic",
"script": "configs/scripts/install.sh",
"package_manager": "apt"
}

113
main.py
View file

@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python3
# linux-deployment-scripts
# Copyright (C) 2024 VM-Experiments
@ -20,20 +20,21 @@ import subprocess
import sys
import os
import json
import shutil
downloads = "downloads/"
output = "output/"
chroot = "chroot/"
resources = "resources/"
installer_packages = "linux-image-generic grub-pc parted tar dosfstools util-linux e2fsprogs arch-install-scripts"
installer_amd64 = (
"https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz"
)
installer_amd64_name = "noble-base-amd64.tar.gz"
installer_packages = "linux-image-amd64 grub-pc parted tar dosfstools util-linux e2fsprogs arch-install-scripts"
installer_amd64 = "http://deb.debian.org/debian/"
installer_amd64_name = "bookworm"
not_verbose = True
clean_tarballs = False
def command(command):
result = subprocess.run(command, capture_output=False, text=True, shell=True)
result = subprocess.run(command, capture_output=not_verbose, text=True, shell=True)
return result
@ -78,8 +79,12 @@ def rootfs_package(filename, installer):
command(f"sudo rm -rf '{chroot}'")
command(f"sudo mkdir '{chroot}'")
rootfs_downloader(installer_amd64, installer_amd64_name)
command(
f"sudo debootstrap --arch amd64 {installer_amd64_name} {chroot} {installer_amd64}"
)
command(f"sudo cp '{infile}' '{chroot}/rootfs.tar.gz'")
if clean_tarballs:
command(f"sudo rm '{infile}'")
prepare_chroot()
do_chroot_command("apt update")
@ -93,29 +98,81 @@ def rootfs_package(filename, installer):
)
do_chroot_command("systemctl daemon-reload")
do_chroot_command("systemctl enable getty@tty1.service")
do_chroot_command("echo 'localmachine' > /etc/hostname")
close_chroot()
command(f"sudo cp '{resources}/grub.cfg' '{chroot}/boot/grub/grub.cfg'")
command(f"sudo cp '{resources}/{installer}' '{chroot}/root'")
command(f"echo './{installer}' | sudo tee -a '{chroot}/root/.profile'")
command(f"echo './{installer}' | sudo tee -a '{chroot}/root/.bashrc'")
command(f"sudo cp '{installer}' '{chroot}/root/install.sh'")
command(f"echo './install.sh' | sudo tee -a '{chroot}/root/.profile'")
command(f"echo './install.sh' | sudo tee -a '{chroot}/root/.bashrc'")
if shutil.which("grub-mkrescue"):
command(f"sudo grub-mkrescue -o '{outfile}' '{chroot}'")
elif shutil.which("grub2-mkrescue"):
command(f"sudo grub2-mkrescue -o '{outfile}' '{chroot}'")
command(f"sudo chown $(logname):$(logname) {outfile}")
# distro specific
def ubuntu_rootfs_prepare(link, filename, packages, outputname, script):
rootfs_downloader(link, filename)
def ubuntu_rootfs_prepare(
download_link, download_name, packages, identifier, script, package_manager
):
rootfs_downloader(download_link, download_name)
generic_rootfs_prepare(packages, identifier, script, package_manager)
def debian_rootfs_prepare(
download_link, download_name, packages, identifier, script, package_manager
):
command(f"sudo debootstrap --arch amd64 {download_name} {chroot} {download_link}")
generic_rootfs_prepare(packages, identifier, script, package_manager)
def generic_rootfs_prepare(packages, identifier, script, package_manager):
prepare_chroot()
do_chroot_command("apt update -y")
do_chroot_command("apt full-upgrade -y")
do_chroot_command(f"DEBIAN_FRONTEND=noninteractive apt install -y {packages}")
do_chroot_command(
f"DEBIAN_FRONTEND=noninteractive {package_manager} install -y {packages}"
)
do_chroot_command("echo 'localmachine' > /etc/hostname")
close_chroot()
rootfs_creator(f"{outputname}.tar.gz")
rootfs_package(f"{output}{outputname}", script)
rootfs_creator(f"{identifier}.tar.gz")
rootfs_package(f"{output}{identifier}", script)
# main
def main():
global not_verbose
global clean_tarballs
for index, arg in enumerate(sys.argv):
match arg:
case "-v":
not_verbose = False
case "--verbose":
not_verbose = False
case "-ct":
clean_tarballs = True
case "--clean-tarballs":
clean_tarballs = True
case "-h":
print("")
print("Help for Linux Deployment Scripts:")
print("")
print("-h / --help - Shows this menu.")
print(
"-v / --verbose - Displays the outputs of the different commands."
)
print(
"-ct / --clean-tarballs - Delete the tar.gz leftovers from the iso generation."
)
print("")
exit()
case "--help":
clean_tarballs = True
case _:
if index == 0:
continue
@ -127,13 +184,33 @@ def main():
filename = arg
data = json.load(open(filename, "r"))
link = data["link"]
rootfs_type = data["rootfs_type"]
download_link = data["download_link"]
download_name = data["download_name"]
packages = data["packages"]
identifier = data["identifier"]
script = data["script"]
package_manager = data["package_manager"]
ubuntu_rootfs_prepare(link, download_name, packages, identifier, script)
match rootfs_type:
case "download":
ubuntu_rootfs_prepare(
download_link,
download_name,
packages,
identifier,
script,
package_manager,
)
case "debootstrap":
debian_rootfs_prepare(
download_link,
download_name,
packages,
identifier,
script,
package_manager,
)
close_chroot()
command(f"sudo rm -rf '{chroot}'")

View file

@ -2,6 +2,6 @@ set timeout=0
set default=0
menuentry "Linux" {
linux /boot/vmlinuz root=/dev/sr0
initrd /boot/initrd.img
linux /vmlinuz root=/dev/sr0
initrd /initrd.img
}