This commit is contained in:
Patrick_Pluto 2024-11-11 16:42:53 +01:00
parent bf2cc0886b
commit 71c9178747
6 changed files with 86 additions and 14 deletions

View file

@ -4,6 +4,7 @@
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz",
"repositories": [], "repositories": [],
"replace_repositories": "False",
"packages": "grub-pc linux-image-generic ubuntu-desktop", "packages": "grub-pc linux-image-generic ubuntu-desktop",
"scripts": [ "scripts": [
"configs/scripts/install.sh", "configs/scripts/install.sh",

View file

@ -4,6 +4,7 @@
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz",
"repositories": [], "repositories": [],
"replace_repositories": "False",
"packages": "grub-pc linux-image-generic kubuntu-desktop", "packages": "grub-pc linux-image-generic kubuntu-desktop",
"scripts": [ "scripts": [
"configs/scripts/install.sh", "configs/scripts/install.sh",

View file

@ -4,6 +4,7 @@
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz",
"repositories": [], "repositories": [],
"replace_repositories": "False",
"packages": "grub-pc linux-image-generic lubuntu-desktop", "packages": "grub-pc linux-image-generic lubuntu-desktop",
"scripts": [ "scripts": [
"configs/scripts/install.sh", "configs/scripts/install.sh",

View file

@ -4,6 +4,7 @@
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz",
"repositories": [], "repositories": [],
"replace_repositories": "False",
"packages": "grub-pc linux-image-generic ubuntu-mate-desktop", "packages": "grub-pc linux-image-generic ubuntu-mate-desktop",
"scripts": [ "scripts": [
"configs/scripts/install.sh", "configs/scripts/install.sh",

View file

@ -4,6 +4,7 @@
"download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz",
"download_name": "noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz",
"repositories": [], "repositories": [],
"replace_repositories": "False",
"packages": "nginx grub-pc linux-image-generic", "packages": "nginx grub-pc linux-image-generic",
"scripts": [ "scripts": [
"configs/scripts/install.sh", "configs/scripts/install.sh",

95
main.py
View file

@ -58,7 +58,7 @@ def rootfs_creator(filename):
# packaging rootfs # packaging rootfs
def rootfs_package(identifier, scripts): def rootfs_package(identifier, scripts, extra_files):
infile = f"{identifier}.tar.gz" infile = f"{identifier}.tar.gz"
outfile = f"{identifier}.iso" outfile = f"{identifier}.iso"
@ -95,6 +95,9 @@ def rootfs_package(identifier, scripts):
command(f"echo './{result}' | sudo tee -a '{chroot}/root/.profile'") command(f"echo './{result}' | sudo tee -a '{chroot}/root/.profile'")
command(f"echo './{result}' | sudo tee -a '{chroot}/root/.bashrc'") command(f"echo './{result}' | sudo tee -a '{chroot}/root/.bashrc'")
for extra_file in extra_files:
command(f"sudo cp '{extra_file}' '{chroot}'")
command(f"echo 'umount -R /mnt' | sudo tee -a '{chroot}/root/.profile'") command(f"echo 'umount -R /mnt' | sudo tee -a '{chroot}/root/.profile'")
command(f"echo 'umount -R /mnt' | sudo tee -a '{chroot}/root/.bashrc'") command(f"echo 'umount -R /mnt' | sudo tee -a '{chroot}/root/.bashrc'")
command(f"echo 'reboot' | sudo tee -a '{chroot}/root/.profile'") command(f"echo 'reboot' | sudo tee -a '{chroot}/root/.profile'")
@ -109,31 +112,83 @@ def rootfs_package(identifier, scripts):
# distro specific # distro specific
def ubuntu_rootfs_prepare( def download_rootfs_prepare(
download_link, download_name, packages, identifier, scripts, package_manager download_link,
download_name,
packages,
repositories,
replace_repositories,
keyrings,
identifier,
scripts,
package_manager,
extra_files,
): ):
rootfs_downloader(download_link, download_name) rootfs_downloader(download_link, download_name)
generic_rootfs_prepare(packages, identifier, scripts, package_manager) apt_rootfs_prepare(
repositories, replace_repositories, packages, identifier, scripts, extra_files
)
def debian_rootfs_prepare( def debootstrap_rootfs_prepare(
download_link, download_name, packages, identifier, scripts, package_manager download_link,
download_name,
packages,
repositories,
replace_repositories,
keyrings,
identifier,
scripts,
package_manager,
extra_files,
): ):
command(f"sudo debootstrap --arch amd64 {download_name} {chroot} {download_link}") command(f"sudo debootstrap --arch amd64 {download_name} {chroot} {download_link}")
generic_rootfs_prepare(packages, identifier, scripts, package_manager) apt_rootfs_prepare(
repositories,
replace_repositories,
keyrings,
packages,
identifier,
scripts,
extra_files,
)
def generic_rootfs_prepare(packages, identifier, scripts, package_manager): def apt_rootfs_prepare(
repositories,
replace_repositories,
keyrings,
packages,
identifier,
scripts,
extra_files,
):
prepare_chroot() prepare_chroot()
if replace_repositories:
overwritten = False
else:
overwritten = True
for repository in repositories:
if overwritten:
do_chroot_command(f"echo '{repository}' >>/etc/apt/sources.list")
else:
do_chroot_command(f"echo '{repository}' >/etc/apt/sources.list")
overwritten + True
for download, name in keyrings:
do_chroot_command(f"wget {download}")
do_chroot_command(f"dpkg -i {name}")
do_chroot_command(f"rm {name}")
do_chroot_command("apt update -y") do_chroot_command("apt update -y")
do_chroot_command("apt full-upgrade -y") do_chroot_command("apt full-upgrade -y")
do_chroot_command( do_chroot_command(f"DEBIAN_FRONTEND=noninteractive apt install -y {packages}")
f"DEBIAN_FRONTEND=noninteractive {package_manager} install -y {packages}"
)
do_chroot_command("echo 'localmachine' > /etc/hostname") do_chroot_command("echo 'localmachine' > /etc/hostname")
close_chroot() close_chroot()
rootfs_creator(f"{identifier}.tar.gz") rootfs_creator(f"{identifier}.tar.gz")
rootfs_package(f"{output}{identifier}", scripts) rootfs_package(f"{output}{identifier}", scripts, extra_files)
# main # main
@ -182,28 +237,40 @@ def main():
download_link = data["download_link"] download_link = data["download_link"]
download_name = data["download_name"] download_name = data["download_name"]
packages = data["packages"] packages = data["packages"]
repositories = data["repositories"]
replace_repositories = bool(data["replace_repositories"])
keyrings = data["keyrings"]
identifier = data["identifier"] identifier = data["identifier"]
scripts = data["scripts"] scripts = data["scripts"]
package_manager = data["package_manager"] package_manager = data["package_manager"]
extra_files = data["extra_files"]
match rootfs_type: match rootfs_type:
case "download": case "download":
ubuntu_rootfs_prepare( download_rootfs_prepare(
download_link, download_link,
download_name, download_name,
packages, packages,
repositories,
replace_repositories,
keyrings,
identifier, identifier,
scripts, scripts,
package_manager, package_manager,
extra_files,
) )
case "debootstrap": case "debootstrap":
debian_rootfs_prepare( debootstrap_rootfs_prepare(
download_link, download_link,
download_name, download_name,
packages, packages,
repositories,
replace_repositories,
keyrings,
identifier, identifier,
scripts, scripts,
package_manager, package_manager,
extra_files,
) )
close_chroot() close_chroot()