Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt new layout for files/, env/, hooks/ #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Installed via ${GRML_FAI_CONFIG}/files/etc/apt/apt.conf.d/15grml-live/GRMLBASE
// Installed via ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/apt/apt.conf.d/15grml-live

// Recommends just pull in way tooooo much packages, so disable it:
APT::Install-Recommends false; // added by grml-live
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###################################################################
# Installed via grml-live's
# ${GRML_FAI_CONFIG}/files/etc/apt/sources.list/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/apt/sources.list
###################################################################

##### IMPORTANT NOTE ##############################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/51-cloud-init script, using
# ${GRML_FAI_CONFIG}/files/etc/cloud/cloud.cfg.d/42_grml.cfg/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/cloud/cloud.cfg.d/42_grml.cfg

system_info:
# This will affect which distro class gets used
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/26-console-setup script, using
# ${GRML_FAI_CONFIG}/files/etc/default/console-setup/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/default/console-setup

# CONFIGURATION FILE FOR SETUPCON
# Consult the console-setup(5) manual page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/30-fstab script, using
# ${GRML_FAI_CONFIG}/files/etc/fstab/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/fstab
#
# <filesystem> <mountpoint> <type> <options> <dump> <pass>
/dev/fd0 /media/floppy auto user,noauto,exec 0 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/34-hosts script, using
# ${GRML_FAI_CONFIG}/files/etc/hosts/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/hosts

127.0.0.1 $HOSTNAME localhost

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/25-locales script, using
# ${GRML_FAI_CONFIG}/files/etc/locale.conf/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/locale.conf
################################################################################
# This file lists the locales configuration as used by e.g. systemd-firstboot
LANG=C.UTF-8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/25-locales script, using
# ${GRML_FAI_CONFIG}/files/etc/locale.gen/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/locale.gen
################################################################################
# This file lists locales that you wish to have built. You can find a list
# of valid supported locales at /usr/share/i18n/SUPPORTED. Other
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/39-modprobe script, using
# ${GRML_FAI_CONFIG}/files/etc/modprobe.d/loop-part.conf/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/modprobe.d/loop-part.conf
#
# Filename: /etc/modprobe.d/loop-part.conf
# Purpose: Enable partitions for loop devices per default in Grml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/41-modules script, using
# ${GRML_FAI_CONFIG}/files/etc/modules-load.d/grml.conf/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/modules-load.d/grml.conf
################################################################################
# This file should contain the names of kernel modules that are
# to be loaded at boot time, one per line. Comments begin with
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/35-network script, using
# ${GRML_FAI_CONFIG}/files/etc/network/interfaces/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/20-sudo script, using
# ${GRML_FAI_CONFIG}/files/etc/sudoers.d/user-nopasswd/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/sudoers.d/user-nopasswd

# WARNING: This allows the unprivileged $USERNAME user to start commands as root
# WARNING: This is totally insecure and (almost) makes $USERNAME a second root account.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/85-systemd script, using
# ${GRML_FAI_CONFIG}/files/etc/tmpfiles.d/man-db.conf/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/tmpfiles.d/man-db.conf

# Override default (age set to 1w) to avoid disappearing mandb caches
d /var/cache/man 0755 man man -
zeha marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/42-branding script, using
# ${GRML_FAI_CONFIG}/files/usr/share/initramfs-tools/scripts/init-top/grml/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/usr/share/initramfs-tools/scripts/init-top/grml
#
# Filename: /usr/share/initramfs-tools/scripts/init-top/grml
# Purpose: Early boot progress handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/scripts/GRMLBASE/25-locales script, using
# ${GRML_FAI_CONFIG}/files/etc/locale.gen/GRMLBASE
# ${GRML_FAI_CONFIG}/files/GRMLBASE/etc/locale.gen
################################################################################
# This file lists locales that you wish to have built. You can find a list
# of valid supported locales at /usr/share/i18n/SUPPORTED. Other
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions docs/grml-live.txt
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ Can I use my own (local) Debian mirror?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Yes. Set up an according sources.list configuration as class file in
${GRML_FAI_CONFIG}/files/etc/apt/sources.list.d/ and adjust the variable
${GRML_FAI_CONFIG}/files/${CLASS}/etc/apt/sources.list.d/ and adjust the variable
FAI_DEBOOTSTRAP in /etc/grml/grml-live.conf[.local]. If you're setting up
your own class file make sure to include the class name in the class list
(grml-live -c ...).
Expand Down Expand Up @@ -700,7 +700,7 @@ Serving via bind mount / MIRROR_DIRECTORY
Make sure to create an according sources.list configuration file, e.g. using
your own class name `CUSTOM`:

# cat > $GRML_FAI_CONFIG/files/etc/apt/sources.list.d/local-packages.list/CUSTOM << EOF
# cat > $GRML_FAI_CONFIG/files/CUSTOM/etc/apt/sources.list.d/local-packages.list << EOF
deb file:///home/foobar/local-packages ./
EOF

Expand All @@ -722,7 +722,7 @@ Serving a repository via HTTP
Make sure to create an according sources.list configuration file, e.g. using
your own class name `CUSTOM`:

# cat > $GRML_FAI_CONFIG/files/etc/apt/sources.list.d/local-packages.list/CUSTOM << EOF
# cat > $GRML_FAI_CONFIG/files/CUSTOM/etc/apt/sources.list.d/local-packages.list << EOF
deb http://127.0.0.1:8000/ ./
EOF

Expand Down
4 changes: 2 additions & 2 deletions etc/grml/grml-live.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
# Do you want to use a local mirror (like NFS)?
# If so specify the directory where debian/ is available:
# MIRROR_DIRECTORY="/media/mirror"
# ... and then set up an according class file in
# ${GRML_FAI_CONFIG}/files/etc/apt/sources.list.d/
# ... and then set up an according file in
# ${GRML_FAI_CONFIG}/files/${CLASS}/etc/apt/sources.list.d/custom.list
# containing something like:
# deb file:///media/mirror/debian sid main contrib non-free-firmware non-free

Expand Down
81 changes: 52 additions & 29 deletions usr/lib/grml-live/minifai
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's just me, but I find the fcopy logic hard to follow without comments. The function and variable names aren't really intuitive for me.

Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def install_packages_for_classes(
for class_name in classes:
chrooted_debconf_set_selections(chroot_dir, conf_dir / "debconf" / class_name)

run_script(chroot_dir, conf_dir / "hooks" / f"instsoft.{class_name}", helper_tools_path, hook_env)
run_script(chroot_dir, conf_dir / "hooks" / class_name / "instsoft", helper_tools_path, hook_env)

package_list = parse_class_packages(conf_dir, class_name)
full_package_list.merge(package_list)
Expand All @@ -246,26 +246,56 @@ def show_env(log_text: str, env):
print()


def do_fcopy_path(source_dir: Path, dest_path: Path, classes: list[str], mode) -> bool:
def do_fcopy_file(to_copy: Path, chroot_dir: Path, path: str, mode):
dest_path = chroot_dir / path

print(f"I: fcopy: Installing {to_copy} as {dest_path}.")
if dest_path.exists():
print(f"W: fcopy: Destination {dest_path} already exists.")

# this is probably fine, as we expect to run as root and do not support
# different file/directory ownership.
dest_path.parent.mkdir(exist_ok=True, parents=True)

shutil.copyfile(to_copy, dest_path, follow_symlinks=False)
dest_path.chmod(mode)
os.chown(dest_path, 0, 0, follow_symlinks=False)

return True


def do_fcopy_path(files_dir: Path, chroot_dir: Path, classes: list[str], path: str, mode: int) -> bool:
to_copy = None
for class_name in classes:
if (source_dir / class_name).exists():
to_copy = source_dir / class_name
class_path = files_dir / class_name / path
if class_path.exists():
to_copy = class_path

if to_copy:
do_fcopy_file(to_copy, chroot_dir, path, mode)
return True
else:
return False


def do_fcopy_recursive(files_dir: Path, chroot_dir: Path, classes: list[str], path_root: str, mode: int):
tree = {}

if to_copy is not None:
print(f"I: fcopy: Installing {to_copy} as {dest_path}.")
if dest_path.exists():
print(f"W: fcopy: Destination {dest_path} already exists.")
for class_name in classes:
class_files_dir = files_dir / class_name
if not class_files_dir.exists():
continue

# this is probably fine, as we expect to run as root and do not support
# different file/directory ownership.
dest_path.parent.mkdir(exist_ok=True, parents=True)
class_path_root = class_files_dir / path_root
if not class_path_root.exists():
continue

shutil.copyfile(to_copy, dest_path, follow_symlinks=False)
dest_path.chmod(mode)
os.chown(dest_path, 0, 0, follow_symlinks=False)
files = [p.relative_to(class_files_dir) for p in class_path_root.glob("**/*") if not p.is_dir()]
for file in files:
tree[file] = class_name

return True
for path, class_name in tree.items():
do_fcopy_file(files_dir / class_name/ path, chroot_dir, path, mode)


def parse_fcopy_args(fcopy_args: list[str]) -> tuple[str, str, int, bool, bool, list[str]]:
Expand Down Expand Up @@ -334,18 +364,11 @@ def do_fcopy(conf_dir: Path, chroot_dir: Path, classes: list[str], fcopy_args: l

if recursive:
for path in paths:
path_dir = files_dir / path
dirs = [p for p in path_dir.glob("**/*") if p.is_dir()]
for dir in dirs:
dir = dir.relative_to(files_dir)
do_fcopy_path(files_dir / dir, chroot_dir / dir, classes, mode)
do_fcopy_recursive(files_dir, chroot_dir, classes, path, mode)

else:
for path in paths:
path_dir = files_dir / path
found = False
if path_dir.exists():
found = do_fcopy_path(path_dir, chroot_dir / path, classes, mode)
found = do_fcopy_path(files_dir, chroot_dir, classes, path, mode)
if not found and not ignore_missing:
print(f"E: Source {path=} is missing for fcopy")
rc = 1
Expand Down Expand Up @@ -550,12 +573,12 @@ def parse_varfile(varfile: Path) -> dict:
return env


def read_vars_for_classes(conf_dir: Path, classes: list[str]) -> dict:
"""Parse FAI .var files"""
def read_envvars_for_classes(conf_dir: Path, classes: list[str]) -> dict:
"""Read environment variable files"""
env = {}

for class_name in classes:
varfile = conf_dir / "class" / f"{class_name}.var"
varfile = conf_dir / "env" / class_name
if varfile.exists():
env.update(parse_varfile(varfile))

Expand Down Expand Up @@ -617,13 +640,13 @@ def _run_tasks(conf_dir: Path, chroot_dir: Path, classes: list[str], grml_live_c
env = {
"GRML_LIVE_CONFIG": str(grml_live_config),
"LOGDIR": str(logdir),
} | read_vars_for_classes(conf_dir, classes)
} | read_envvars_for_classes(conf_dir, classes)
show_env("Merged class variables", env)

with helper_tools(conf_dir, chroot_dir, classes, dynamic_state) as helper_tools_path:
hook_env = env | {"FAI_ACTION": fai_action}
for class_name in classes:
run_script(chroot_dir, conf_dir / "hooks" / f"updatebase.{class_name}", helper_tools_path, hook_env)
run_script(chroot_dir, conf_dir / "hooks" / class_name / "updatebase", helper_tools_path, hook_env)

with policy_rcd(chroot_dir):
task_updatebase(chroot_dir, dynamic_state)
Expand Down