diff --git a/build-all.sh b/build-all.sh index 839c579..799ea01 100755 --- a/build-all.sh +++ b/build-all.sh @@ -4,8 +4,8 @@ set -e SOURCE_DIR=$(realpath $(dirname "${0}")) # Install build scripts -cp ${SOURCE_DIR}/zz-extra/lxc-build /usr/bin/lxc-build -cp ${SOURCE_DIR}/zz-extra/fix-apk /usr/bin/fix-apk +ln -s ${SOURCE_DIR}/zz-extra/lxc-build /usr/bin/lxc-build +ln -s ${SOURCE_DIR}/zz-extra/fix-apk /usr/bin/fix-apk # Build basic Alpine LXC image mkdir -p /var/lib/lxc/shared/alpine diff --git a/zz-extra/fix-apk b/zz-extra/fix-apk new file mode 100644 index 0000000..1092e7b --- /dev/null +++ b/zz-extra/fix-apk @@ -0,0 +1,34 @@ +#!/usr/bin/python3 + +import os +import sys + +def fix_installed(layers): + installed = [] + for layer in layers[:-1]: + with open(os.path.join(layer, 'lib/apk/db/installed'), 'r') as fd: + buffer = [] + for line in df: + if line.startswith('C:'): + buffer = ''.join(buffer) + if buffer not in installed: + installed.append(buffer) + buffer = [] + buffer.append(line) + os.makedirs(os.path.join(layers[-1], 'lib/apk/db', 0o755, True)) + with open(os.path.join(layers[-1], 'lib/apk/db/installed'), 'w') as fd: + fd.writelines(world_items) + +def fix_world(layers): + world = [] + for layer in layers[:-1]: + with open(os.path.join(layer, 'etc/apk/world'), 'r') as fd: + for line in fd: + if line in world: + world.append(world) + os.makedirs(os.path.join(layers[-1], 'etc/apk', 0o755, True)) + with open(os.path.join(layers[-1], 'etc/apk/world'), 'w') as fd: + fd.writelines(world_items) + +fix_installed(sys.argv) +fix_world(sys.argv) diff --git a/zz-extra/lxc-build b/zz-extra/lxc-build index 882b28e..2bc71a5 100755 --- a/zz-extra/lxc-build +++ b/zz-extra/lxc-build @@ -73,11 +73,12 @@ class LXCImage: script_eof = None for line in lxcfile: - if script_eof and line == script_eof: - script_eof = None - self.run_script(script) - elif in_script: - script.append(line) + if script_eof: + if line == script_eof: + script_eof = None + self.run_script(script) + elif in_script: + script.append(line) elif line.startswith('RUN'): script = [] script_eof = line.split()[1]