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

Live system nochange #419

Merged
merged 24 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9632f6a
Update coreutils to 9.4
fosslinux Dec 29, 2023
46268e2
Update builder-hex0 for USB boot support
Googulator Jan 22, 2024
67aa2a4
Fix the default build script used by "build <package name>"
Googulator Jan 22, 2024
679f73b
Create disk images without root
eduardosm Dec 28, 2023
2883225
Only copy no-network distfiles to "init" when `--external-source` is …
eduardosm Dec 28, 2023
f995a74
Fix detection of device type (partition/full disk) in move_disk.sh
eduardosm Dec 28, 2023
8cc26fa
Remove old relic of "maint"
fosslinux Jan 12, 2024
bbe121f
Add uninstall directive to manifest
fosslinux Jan 12, 2024
5b84cdd
Don't touch live filesystem in bash-5.2.15
fosslinux Jan 12, 2024
3669db9
Use merged usr throughout the entire bootstrap
fosslinux Jan 12, 2024
c0485bc
Remove unneccessary touching of live filesystem in coreutils-5.0 pass2
fosslinux Jan 12, 2024
6901877
Remove unnecessary touching of live filesystem in flex-2.5.11
fosslinux Jan 12, 2024
718bccc
Remove yacc using uninstall rather than in src_install of flex-2.6.4
fosslinux Jan 12, 2024
0a98747
Remove files unnecessarily kept around
fosslinux Jan 12, 2024
fb35fca
Uninstall previous perl files using uninstall rather than src_install
fosslinux Jan 12, 2024
62ce1b0
Remove old python versions
fosslinux Jan 12, 2024
8d99817
Dont remove /usr/include
fosslinux Jan 12, 2024
7f967fe
Cleanup the filesystem at end of bootstrap
fosslinux Jan 24, 2024
b1e3da4
Move where DESTDIR is made
fosslinux Jan 24, 2024
76217c6
Ensure sources are always cleaned the same
fosslinux Jan 24, 2024
1665723
Respect DESTDIR for lib-dynload directory in py 2.0.1
fosslinux Jan 24, 2024
67acb60
Never create pyc files on filesystem
fosslinux Jan 24, 2024
2182076
Use a constant umask
fosslinux Jan 24, 2024
438e018
Update checksums
fosslinux Jan 25, 2024
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
2 changes: 1 addition & 1 deletion builder-hex0
40 changes: 19 additions & 21 deletions lib/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, arch, external_sources, early_preseed, repo_path):
self.external_sources = external_sources
self.repo_path = repo_path
self.source_manifest = self.get_source_manifest(not self.external_sources)
self.early_source_manifest = self.get_source_manifest(True)
self.target_dir = None
self.external_dir = None

Expand Down Expand Up @@ -59,26 +60,16 @@ def prepare(self, target, using_kernel=False, kernel_bootstrap=False, target_siz
# argument matrix ... or we could just use ext3 instead which
# is effectively universally the same
if kernel_bootstrap:
init_path = os.path.join(self.target_dir, 'init')
self.target_dir = os.path.join(self.target_dir, 'init')
os.mkdir(self.target_dir)

os.mkdir(init_path)
self.target_dir = init_path

if self.repo_path or self.external_sources:
target.add_disk("external", filesystem="ext3")
target.mount_disk("external", "external")
else:
if not self.repo_path and not self.external_sources:
self.external_dir = os.path.join(self.target_dir, 'external')
elif using_kernel:
self.target_dir = os.path.join(self.target_dir, 'disk')
target.add_disk("disk",
filesystem="ext3",
size=(str(target_size) + "M") if target_size else "16G",
bootable=True)
target.mount_disk("disk", "disk")
self.external_dir = os.path.join(self.target_dir, 'external')

os.makedirs(self.external_dir, exist_ok=True)
os.makedirs(self.external_dir)

if self.early_preseed:
# Extract tar containing preseed
Expand All @@ -103,10 +94,16 @@ def prepare(self, target, using_kernel=False, kernel_bootstrap=False, target_siz
if kernel_bootstrap:
self.create_builder_hex0_disk_image(self.target_dir + '.img', target_size)

if kernel_bootstrap and (self.external_sources or self.repo_path):
target.umount_disk('external')
if self.repo_path or self.external_sources:
mkfs_args = ['-d', os.path.join(target.path, 'external')]
target.add_disk("external", filesystem="ext3", mkfs_args=mkfs_args)
elif using_kernel:
target.umount_disk('disk')
mkfs_args = ['-d', os.path.join(target.path, 'disk')]
target.add_disk("disk",
filesystem="ext3",
size=(str(target_size) + "M") if target_size else "16G",
bootable=True,
mkfs_args=mkfs_args)

def steps(self):
"""Copy in steps."""
Expand Down Expand Up @@ -163,9 +160,10 @@ def create_fiwix_file_list(self):

def distfiles(self):
"""Copy in distfiles"""
def copy_no_network_distfiles(out):
def copy_no_network_distfiles(out, early):
# Note that "no disk" implies "no network" for kernel bootstrap mode
for file in self.source_manifest:
manifest = self.early_source_manifest if early else self.source_manifest
for file in manifest:
file = file[3].strip()
shutil.copy2(os.path.join(self.distfiles_dir, file),
os.path.join(out, file))
Expand All @@ -175,13 +173,13 @@ def copy_no_network_distfiles(out):

if early_distfile_dir != main_distfile_dir:
os.makedirs(early_distfile_dir, exist_ok=True)
copy_no_network_distfiles(early_distfile_dir)
copy_no_network_distfiles(early_distfile_dir, True)

if self.external_sources:
shutil.copytree(self.distfiles_dir, main_distfile_dir, dirs_exist_ok=True)
else:
os.mkdir(main_distfile_dir)
copy_no_network_distfiles(main_distfile_dir)
copy_no_network_distfiles(main_distfile_dir, False)

@staticmethod
def output_dir(srcfs_file, dirpath):
Expand Down
46 changes: 8 additions & 38 deletions lib/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
"""

import enum
import getpass
import os

from lib.utils import mount, umount, create_disk, run_as_root
from lib.utils import mount, create_disk

class TargetType(enum.Enum):
"""Different types of target dirs we can have"""
Expand All @@ -24,7 +23,6 @@ class Target:
"""

_disks = {}
_disk_filesystems = {}
_mountpoints = {}

def __init__(self, path="target"):
Expand All @@ -34,15 +32,6 @@ def __init__(self, path="target"):
if not os.path.exists(self.path):
os.mkdir(self.path)

def __del__(self):
for path in self._mountpoints:
print(f"Unmounting {path}")
umount(path)

for disk in self._disks.values():
print(f"Detaching {disk}")
run_as_root("losetup", "-d", disk)

def tmpfs(self, size="8G"):
"""Mount a tmpfs"""
print(f"Mounting tmpfs on {self.path}")
Expand All @@ -59,32 +48,13 @@ def add_disk(self,
mkfs_args=None):
"""Add a disk"""
disk_path = os.path.join(self.path, f"{name}.img")
self._disks[name] = create_disk(disk_path,
tabletype,
filesystem,
size,
bootable,
mkfs_args)
self._disk_filesystems[name] = filesystem
# Allow executing user to access it
run_as_root("chown", getpass.getuser(), self._disks[name])

def mount_disk(self, name, mountpoint=None):
"""Mount the disk"""
if mountpoint is None:
mountpoint = f"{name}_mnt"
mountpoint = os.path.join(self.path, mountpoint)
os.mkdir(mountpoint)
mount(self._disks[name] + "p1", mountpoint, self._disk_filesystems[name])
# Allow executing user to access it
run_as_root("chown", getpass.getuser(), mountpoint)
self._mountpoints[name] = mountpoint
return mountpoint

def umount_disk(self, name):
"""Unmount a disk"""
umount(self._mountpoints[name])
del self._mountpoints[name]
create_disk(disk_path,
tabletype,
filesystem,
size,
bootable,
mkfs_args)
self._disks[name] = disk_path

def get_disk(self, name):
"""Get the path to a device of a disk"""
Expand Down
13 changes: 5 additions & 8 deletions lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ def create_disk(image, disk_type, fs_type, size, bootable=False, mkfs_args=None)
if mkfs_args is None:
mkfs_args = []
run('truncate', '-s', size, image)
# First find the device we will use, then actually use it
loop_dev = run_as_root('losetup', '-f', capture_output=True).stdout.decode().strip()
run_as_root('losetup', '-P', loop_dev, image)
# Create the partition
if disk_type != "none":
run_as_root('parted', '--script', image, 'mklabel', disk_type, 'mkpart',
'primary', fs_type, '1GiB' if bootable else '1MiB', '100%')
run_as_root('partprobe', loop_dev)
run_as_root('mkfs.' + fs_type, loop_dev + "p1", *mkfs_args)
return loop_dev
# 1 GiB if bootable, 1 MiB otherwise
offset = str(1024 * 1024 * (1024 if bootable else 1))
run('parted', '--script', image, 'mklabel', disk_type, 'mkpart',
'primary', fs_type, offset + 'B', '100%')
run('mkfs.' + fs_type, image, '-E', 'offset=' + offset, *mkfs_args)

def mount(source, target, fs_type, options='', **kwargs):
"""Mount filesystem"""
Expand Down
3 changes: 3 additions & 0 deletions rootfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ def check_types():
else:
args.swap = 0

# Set constant umask
os.umask(0o022)

# bootstrap.cfg
try:
os.remove(os.path.join('steps', 'bootstrap.cfg'))
Expand Down
58 changes: 36 additions & 22 deletions seed/script-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#define MAX_TOKEN 64
#define MAX_STRING 2048

#include <bootstrappable.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <bootstrappable.h>

struct Token {
char *val;
Expand All @@ -22,7 +22,7 @@ typedef struct Token Token;
#define TYPE_IMPROVE 2
#define TYPE_DEFINE 3
#define TYPE_JUMP 4
#define TYPE_MAINT 5
#define TYPE_UNINSTALL 5

struct Directive {
Token *tok;
Expand Down Expand Up @@ -212,12 +212,12 @@ Token *fill(Token *tok, Directive *directive, int type) {

Token *logic(Token *tok, char **val) {
/* logic = "("
* (name |
* (name "==" value) |
* (name "!=" value) |
* (logic "||" logic) |
* (logic "&&" logic))
* ")"
* (name |
* (name "==" value) |
* (name "!=" value) |
* (logic "||" logic) |
* (logic "&&" logic))
* ")"
*/

char *lhs = tok->val;
Expand All @@ -237,15 +237,15 @@ Token *logic(Token *tok, char **val) {
lhs = "False";
}
} else if (strcmp(tok->val, "!=") == 0) {
/* Case for inequality. */
rhs = tok->next->val;
tok = tok->next->next;
if (strcmp(get_var(lhs), rhs) == 0) {
lhs = "False";
} else {
lhs = "True";
}
} else {
/* Case for inequality. */
rhs = tok->next->val;
tok = tok->next->next;
if (strcmp(get_var(lhs), rhs) == 0) {
lhs = "False";
} else {
lhs = "True";
}
} else {
fputs("Expected == or != after ", stderr);
fputs(lhs, stderr);
fputs(" in logic\n", stderr);
Expand Down Expand Up @@ -360,19 +360,31 @@ Token *define(Token *tok, Directive *directive) {
}

int interpret(Directive *directive) {
/* directive = (build | improve | define | jump | maint) predicate? */
/* directive = (build | improve | define | jump | uninstall) predicate? */
Token *tok = directive->tok;
if (strcmp(tok->val, "build:") == 0) {
tok = fill(tok->next, directive, TYPE_BUILD);
} else if (strcmp(tok->val, "improve:") == 0) {
tok = fill(tok->next, directive, TYPE_IMPROVE);
} else if (strcmp(tok->val, "jump:") == 0) {
tok = fill(tok->next, directive, TYPE_JUMP);
} else if (strcmp(tok->val, "maint:") == 0) {
tok = fill(tok->next, directive, TYPE_MAINT);
} else if (strcmp(tok->val, "define:") == 0) {
tok = define(tok->next, directive);
return 1; /* There is no codegen for a define. */
} else if (strcmp(tok->val, "uninstall:") == 0) {
tok = fill(tok->next, directive, TYPE_UNINSTALL);
while (tok != NULL) {
if (strcmp(tok->val, "(") == 0) {
break;
}
if (strlen(directive->arg) + strlen(tok->val) + 1 > MAX_STRING) {
fputs("somehow you have managed to have too many uninstall arguments.\n", stderr);
exit(1);
}
directive->arg = strcat(directive->arg, " ");
directive->arg = strcat(directive->arg, tok->val);
tok = tok->next;
}
}

if (tok != NULL) {
Expand Down Expand Up @@ -620,8 +632,10 @@ void generate(Directive *directives) {
fclose(out);
out = start_script(counter, bash_build);
counter += 1;
} else if (directive->type == TYPE_MAINT) {
output_call_script(out, "maint", directive->arg, bash_build, 1);
} else if (directive->type == TYPE_UNINSTALL) {
fputs("uninstall ", out);
fputs(directive->arg, out);
fputs("\n", out);
}
}
fclose(out);
Expand Down
20 changes: 10 additions & 10 deletions steps/SHA256SUMS.pkgs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ca7403a7503e8f3bb55e6c5bd54571b8c061b11c96e50ee89e006df6011d1518 bzip2-1.0.8_0.
543214998317d764595d3dd247a1fb2e0803ad77978b8474bd24d64c161b9530 ca-certificates-3.95_0.tar.bz2
7450bb38caaa633f8c11269fed44eb680c6ba03bb0e19c18fce3b2450f80e358 coreutils-5.0_0.tar.bz2
c95fd8c51c3bfbd4d08a4a50d0033ee85394e6efe4ff82703c050e4dbc4347bf coreutils-6.10_0.tar.bz2
f49900486ae7f0c8107d729b71ede155ee44544cdf8d562b50fbea4095bd05b2 coreutils-8.32_0.tar.bz2
9fa31a4aeaa5132205efb796c8f546c94c1cfef6b5c27e64f6ebe06ca0360e67 coreutils-9.4_0.tar.bz2
6a10f5258650ae75e92eb7aa1a5e6107b72c8b6419a4f64272262a1545c43161 curl-8.5.0_0.tar.bz2
f9efd6600ceb91918078078ff44a33f2a4fb4a59edb804866aebd288c2cfb24e curl-8.5.0_1.tar.bz2
1d4dec2d1885a6b5499a0f0d55e9c2c65dab532c4c593d848b6a542f67789627 dhcpcd-10.0.1_0.tar.bz2
Expand Down Expand Up @@ -87,20 +87,20 @@ c490016e49bbf77e7f63071f7aa60e8290a0c67f017846def1c3f65bd10d5712 openssl-1.1.1l
71864d042cdc564b65eab21360902c714e9b43f80a19689c5600589529b267e7 patch-2.7.6_0.tar.bz2
5ae7fe43d62d1064c123d9813017015e5e8d5107d0e70f0199576141416ff81d perl-5.000_0.tar.bz2
4994c55e3832649600f190079bd4779c463478a092b167098b1d00eff3358fbe perl-5.003_0.tar.bz2
74d64a8af080022432fa94dba449090419d25b103d247710dc0b6102a4ad86a6 perl-5.10.1_0.tar.bz2
fdccd3ba27a44d2149f159040414a04b39bfc72673ba36f50051b61199cc425c perl-5.32.1_0.tar.bz2
101a791b6843b997ec10d5ce6dc32af2637f687772674eb6f1cdc1c8ff836a03 perl-5.6.2_0.tar.bz2
ae6c84e55c2d9bcd7b80bf780ae6921fe890608123c9ba904e1b7d90759ade3d perl5.004-05_0.tar.bz2
8cedd2240bbbd5bca65a1362998ed73884756aa7ff5208226d3fa22c68868052 perl5.005-03_0.tar.bz2
74d64a8af080022432fa94dba449090419d25b103d247710dc0b6102a4ad86a6 perl-5.10.1_0.tar.bz2
71ad3cadba5801cb19d4520825d4b3606713807b1eaa5eb3c49b3149bc2675ad perl-5.32.1_0.tar.bz2
101a791b6843b997ec10d5ce6dc32af2637f687772674eb6f1cdc1c8ff836a03 perl-5.6.2_0.tar.bz2
1b9d4260edf7b2241d10e4c4ad17d0f90047bd4bf42f2487a7133902529e9dfe pkg-config-0.29.2_0.tar.bz2
1e882c3206f9d1de2a9be8b5c6ae4cc65e80a4de607bd521058577bf4169c0e9 python-2.0.1_0.tar.bz2
aba9710341db75b78c7bc1eb4ef45b9496e23f7a356128af6c2b116ee0f3f31a python-2.0.1_1.tar.bz2
d497c9b614194b941620bb5c5111fc72eca8cafd7d4f476eacb24fb7f909b614 python-2.3.7_0.tar.bz2
8a977205933431c2a4207f647cb683b570dfdb0146e21abf5fab3f8426e1356b python-2.3.7_1.tar.bz2
34e5083ed3e72da5aa5950acebf9e95464089d693e3d6a047a2b69b6103f5ca9 python-2.5.6_0.tar.bz2
2f7198009e4d021d52ee4ce86241b4936fb88349c20cc8b6c286261368878c3c python-2.0.1_0.tar.bz2
b5d86ddc98cfbc684b03f1c84c786caaad810d5e4c7be38089f324eb3c276ad9 python-2.0.1_1.tar.bz2
396577cdd0cc61d76420a1771c64156e49e8f9d00430c82feb88ad933b341632 python-2.3.7_0.tar.bz2
2499cb7f10f292c3506fbf1b6a876195179ec98edfe7b8c357140137a1449492 python-2.3.7_1.tar.bz2
2dd06364e281da421a16251fa2258df201efd180461718f5a000012c4b2bdfe5 python-2.5.6_0.tar.bz2
52ffb1ea6f2b893a6fd26f930c8ff63f78ddcc31ac3ec9c2ddade555205aa1ef python-3.11.1_0.tar.bz2
3508248f299b73c50e3607c4c294d40face05170476a5026b0821aed69025863 python-3.1.5_0.tar.bz2
12b1ffc7ec98ba8f807160b93ba69a694d5395567c3bcac1e49e8f8d1d50de43 python-3.1.5_1.tar.bz2
52ffb1ea6f2b893a6fd26f930c8ff63f78ddcc31ac3ec9c2ddade555205aa1ef python-3.11.1_0.tar.bz2
60b93253a2078f849f81e7e1ed6233e30702f03b1893640eee95671d814f5514 python-3.3.7_0.tar.bz2
da7c8ec579dd225c0d8bee63d95aeeb27ac2d5a60d4eefe298508cbf86bf506c python-3.4.10_0.tar.bz2
0be505f63205b4bc1b1421896c610468ad1a2194bbc4c9abf58f61685c2023d1 python-3.8.16_0.tar.bz2
Expand Down
5 changes: 1 addition & 4 deletions steps/bash-2.05b/pass1.kaem
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ make

# Install
install bash ${PREFIX}/bin/
mkdir /bin/
ln -s ${PREFIX}/bin/bash /bin/bash
ln -s ${PREFIX}/bin/bash /bin/sh
ln -s ${PREFIX}/bin/bash ${PREFIX}/bin/sh
install bash ${PREFIX}/bin/sh

cd ../..

Expand Down
4 changes: 0 additions & 4 deletions steps/bash-5.2.15/pass1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,5 @@ src_compile() {

src_install() {
install -D bash "${DESTDIR}${PREFIX}/bin/bash"
# Work around weird symlink bug
install bash "${DESTDIR}${PREFIX}/bin/sh"

# Needs special handling b/c is currently running - tar doesn't like this
rm -f "${PREFIX}/bin/bash" "${PREFIX}/bin/sh"
}
7 changes: 0 additions & 7 deletions steps/coreutils-5.0/pass2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,3 @@ src_prepare() {

cp "${mk_dir}/pass2.mk" Makefile
}

src_install() {
default

# perl later requires /bin/pwd
ln -s "${PREFIX}/bin/pwd" /bin/pwd
}
Loading
Loading