36 lines
1.5 KiB
Bash
Executable File
36 lines
1.5 KiB
Bash
Executable File
#!/bin/busybox sh
|
|
|
|
# SPDX-FileCopyrightText: Copyright 2022-2023, macmpi
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
# scrip meant to be run on Alpine (busybox) or on Ubuntu
|
|
command -v doas > /dev/null || alias doas="/usr/bin/sudo"
|
|
|
|
build_path="$(mktemp -d)"
|
|
if [ -n "$build_path" ]; then
|
|
cp -a overlay "$build_path"/.
|
|
# busybox config on Alpine & Ubuntu has FEATURE_TAR_GNU_EXTENSIONS
|
|
# so will preserve user/group/modes & mtime
|
|
find "$build_path"/overlay/ -exec sh -c 'TZ=UTC touch -chm -t $( TZ=UTC date +%Y%m%d0000.00 ) $0' {} \;
|
|
# setting modes and owner/groups for runtime (won't affect mtime)
|
|
find "$build_path"/overlay/etc -type d -exec chmod 755 {} \;
|
|
chmod 755 "$build_path"/overlay/etc/init.d/*
|
|
chmod 755 "$build_path"/overlay/etc/runlevels/default/*
|
|
chmod 777 "$build_path"/overlay/tmp
|
|
chmod 700 "$build_path"/overlay/tmp/.trash
|
|
chmod -R 600 "$build_path"/overlay/tmp/.trash/ssh_host_*_key
|
|
find "$build_path"/overlay/usr -type d -exec chmod 755 {} \;
|
|
chmod 755 "$build_path"/overlay/usr/local/bin/*
|
|
# busybox config on Ubuntu does not enable use of user and group names in tar
|
|
# (FEATURE_TAR_UNAME_GNAME not set)
|
|
doas chown -Rh 0:0 "$build_path"/overlay/*
|
|
|
|
# shellcheck disable=SC2046 # we want word splitting as result of find
|
|
doas tar cv -C "$build_path"/overlay --no-recursion \
|
|
$(doas find "$build_path"/overlay/ | sed "s|$build_path/overlay/||" | sort | xargs ) | \
|
|
gzip -c9n > headless.apkovl.tar.gz
|
|
TZ=UTC touch -cm -t "$( TZ=UTC date +%Y%m%d0000.00 )" headless.apkovl.tar.gz
|
|
doas rm -rf "$build_path"
|
|
fi
|
|
|