diff --git a/configs/ubuntu/noble_gnome.json b/configs/ubuntu/noble_gnome.json index 1ba765a..cdfeb3d 100644 --- a/configs/ubuntu/noble_gnome.json +++ b/configs/ubuntu/noble_gnome.json @@ -4,6 +4,7 @@ "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz", "repositories": [], + "replace_repositories": "False", "packages": "grub-pc linux-image-generic ubuntu-desktop", "scripts": [ "configs/scripts/install.sh", diff --git a/configs/ubuntu/noble_kde.json b/configs/ubuntu/noble_kde.json index 7bed4b8..bb355aa 100644 --- a/configs/ubuntu/noble_kde.json +++ b/configs/ubuntu/noble_kde.json @@ -4,6 +4,7 @@ "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz", "repositories": [], + "replace_repositories": "False", "packages": "grub-pc linux-image-generic kubuntu-desktop", "scripts": [ "configs/scripts/install.sh", diff --git a/configs/ubuntu/noble_lxqt.json b/configs/ubuntu/noble_lxqt.json index f5f1325..649ae12 100644 --- a/configs/ubuntu/noble_lxqt.json +++ b/configs/ubuntu/noble_lxqt.json @@ -4,6 +4,7 @@ "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz", "repositories": [], + "replace_repositories": "False", "packages": "grub-pc linux-image-generic lubuntu-desktop", "scripts": [ "configs/scripts/install.sh", diff --git a/configs/ubuntu/noble_mate.json b/configs/ubuntu/noble_mate.json index bfdfdb6..32d5b69 100644 --- a/configs/ubuntu/noble_mate.json +++ b/configs/ubuntu/noble_mate.json @@ -4,6 +4,7 @@ "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz", "repositories": [], + "replace_repositories": "False", "packages": "grub-pc linux-image-generic ubuntu-mate-desktop", "scripts": [ "configs/scripts/install.sh", diff --git a/configs/ubuntu/noble_server.json b/configs/ubuntu/noble_server.json index 915a921..eb85d68 100644 --- a/configs/ubuntu/noble_server.json +++ b/configs/ubuntu/noble_server.json @@ -4,6 +4,7 @@ "download_link": "https://cdimage.ubuntu.com/ubuntu-base/noble/daily/current/noble-base-amd64.tar.gz", "download_name": "noble-base-amd64.tar.gz", "repositories": [], + "replace_repositories": "False", "packages": "nginx grub-pc linux-image-generic", "scripts": [ "configs/scripts/install.sh", diff --git a/main.py b/main.py index 5d3ef45..3b7ceed 100755 --- a/main.py +++ b/main.py @@ -58,7 +58,7 @@ def rootfs_creator(filename): # packaging rootfs -def rootfs_package(identifier, scripts): +def rootfs_package(identifier, scripts, extra_files): infile = f"{identifier}.tar.gz" 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/.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/.bashrc'") command(f"echo 'reboot' | sudo tee -a '{chroot}/root/.profile'") @@ -109,31 +112,83 @@ def rootfs_package(identifier, scripts): # distro specific -def ubuntu_rootfs_prepare( - download_link, download_name, packages, identifier, scripts, package_manager +def download_rootfs_prepare( + download_link, + download_name, + packages, + repositories, + replace_repositories, + keyrings, + identifier, + scripts, + package_manager, + extra_files, ): 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( - download_link, download_name, packages, identifier, scripts, package_manager +def debootstrap_rootfs_prepare( + 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}") - 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() + + 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 full-upgrade -y") - do_chroot_command( - f"DEBIAN_FRONTEND=noninteractive {package_manager} install -y {packages}" - ) + do_chroot_command(f"DEBIAN_FRONTEND=noninteractive apt install -y {packages}") do_chroot_command("echo 'localmachine' > /etc/hostname") close_chroot() rootfs_creator(f"{identifier}.tar.gz") - rootfs_package(f"{output}{identifier}", scripts) + rootfs_package(f"{output}{identifier}", scripts, extra_files) # main @@ -182,28 +237,40 @@ def main(): download_link = data["download_link"] download_name = data["download_name"] packages = data["packages"] + repositories = data["repositories"] + replace_repositories = bool(data["replace_repositories"]) + keyrings = data["keyrings"] identifier = data["identifier"] scripts = data["scripts"] package_manager = data["package_manager"] + extra_files = data["extra_files"] match rootfs_type: case "download": - ubuntu_rootfs_prepare( + download_rootfs_prepare( download_link, download_name, packages, + repositories, + replace_repositories, + keyrings, identifier, scripts, package_manager, + extra_files, ) case "debootstrap": - debian_rootfs_prepare( + debootstrap_rootfs_prepare( download_link, download_name, packages, + repositories, + replace_repositories, + keyrings, identifier, scripts, package_manager, + extra_files, ) close_chroot()