diff --git a/.gitlab-ci/shellcheck.sh b/.gitlab-ci/shellcheck.sh index a6a7a8512..0f925d9f0 100755 --- a/.gitlab-ci/shellcheck.sh +++ b/.gitlab-ci/shellcheck.sh @@ -17,11 +17,8 @@ fi sh_files=" ./main/mdss-fb-init-hack/mdss-fb-init-hack.sh ./main/postmarketos-base/rootfs-usr-lib-firmwareload.sh - ./main/postmarketos-mkinitfs/init.sh.in + ./main/postmarketos-mkinitfs/init.sh ./main/postmarketos-mkinitfs/init_functions.sh - ./main/postmarketos-mkinitfs/mkinitfs.sh - ./main/postmarketos-mkinitfs/mkinitfs_functions.sh - ./main/postmarketos-mkinitfs/mkinitfs_test.sh ./main/postmarketos-mkinitfs-hook-debug-shell/20-debug-shell.sh ./main/postmarketos-update-kernel/update-kernel.sh ./main/swclock-offset/swclock-offset-boot.sh diff --git a/main/postmarketos-mkinitfs/APKBUILD b/main/postmarketos-mkinitfs/APKBUILD index 6debf857f..a06bb5c37 100644 --- a/main/postmarketos-mkinitfs/APKBUILD +++ b/main/postmarketos-mkinitfs/APKBUILD @@ -1,10 +1,12 @@ # Maintainer: Oliver Smith +# Co-Maintainer: Clayton Craft pkgname=postmarketos-mkinitfs -pkgver=0.32 +pkgver=1.0.1 pkgrel=0 pkgdesc="Tool to generate initramfs images for postmarketOS" url="https://postmarketos.org" depends=" + boot-deploy busybox-extras bzip2 cryptsetup @@ -12,50 +14,60 @@ depends=" e2fsprogs e2fsprogs-extra f2fs-tools - kmod - lddtree lz4 multipath-tools parted postmarketos-fde-unlocker xz " +makedepends="go" replaces="mkinitfs" triggers="$pkgname.trigger=/etc/postmarketos-mkinitfs/hooks:/usr/share/kernel/*:/usr/share/postmarketos-mkinitfs-triggers" -source="00-default.modules - init.sh.in +source=" + https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/archive/$pkgver/postmarketos-mkinitfs-$pkgver.tar.gz + 00-default.modules + init.sh init_functions.sh - mkinitfs.sh - mkinitfs_functions.sh - mkinitfs_test.sh " -arch="noarch" +install="$pkgname.post-upgrade" +arch="all" license="GPL-2.0-or-later" provides="mkinitfs=0.0.1" +export GOPATH="$srcdir" +export CGO_ENABLED=0 + +build() { + # "-s -w" build a stripped binary + go build -v -ldflags="-s -w" +} + package() { - for file in init.sh.in init_functions.sh mkinitfs_functions.sh; do - install -Dm644 "$srcdir/$file" \ - "$pkgdir/usr/share/postmarketos-mkinitfs/$file" - done + install -Dm644 "$srcdir/init_functions.sh" \ + "$pkgdir/usr/share/postmarketos-mkinitfs/init_functions.sh" + + install -Dm755 "$srcdir/init.sh" \ + "$pkgdir/usr/share/postmarketos-mkinitfs/init.sh" install -Dm644 "$srcdir/00-default.modules" \ "$pkgdir/etc/postmarketos-mkinitfs/modules/00-default.modules" - install -Dm755 "$srcdir/mkinitfs.sh" \ + install -Dm755 postmarketos-mkinitfs \ + "$pkgdir/sbin/postmarketos-mkinitfs" + + ln -s /sbin/postmarketos-mkinitfs \ "$pkgdir/sbin/mkinitfs" mkdir -p "$pkgdir/etc/postmarketos-mkinitfs/hooks/" } check() { - /bin/busybox sh ./mkinitfs_test.sh + go test ./... } + sha512sums=" +bd37db8aec3ec5a8f8e71f1c3529e3c497450c6871bad6f28fb078fea5e704e97238de675fcd568b2db7c09e8833ee6fe6295ec607353b680e87347dc2f519a3 postmarketos-mkinitfs-1.0.1.tar.gz 4717bf24bd13fd4d90f3ab000ab43f7d61529515de224ebc86458ae709ebe0b5065655457e34f5952126bac6ab45143a91cddb09a8ad2d0a55c5cecd564a0135 00-default.modules -4d718fca3b6a8c2d362003e7d57f9fa29510c05c27b372d21b8278fe76b2096ae098aa9f9a266a029f82956d165fd764e406ddaf36cec2e4f3bd30c6022d07a7 init.sh.in +40033b421e79999c85bd72e1353fe6745a87fcbf9f6a5b8180e832c7f340da7d4e33d056f557ae95a9924f5d186a6e728f3ed53c0922cdac4c39513fdc3e3a82 init.sh 563dfbd8e1ff1d3f42cd8f9615144fde83d0e1107fa1d6751eb7e049628cded12c0f1762d4ce498f741802b5f8449ef7cf1959fec22ea975fefeaa8050c171ec init_functions.sh -5590087d67cf8cae0e4f2b9a0d3f055a01282ace53abe586a0117a9701287cf60a88230ba5817e77886b9496098139c025c6221c4b7404e36faac7df63adc1ee mkinitfs.sh -879223b6b608f3b26993c3536b4e6b37728f774d6e4da891ae87ef26e38603a15b09918b69963c4f65aa4551b721815fd3578a1ec598b7b9d418aa677520d55f mkinitfs_functions.sh -c7a3c33daeb12b33ac72207191941c4d634f15c22958273b52af381a70ebaba1d3a9299483f0c447d9e66c560151fe7b9588bb4bbef2c8914f83185984ee4622 mkinitfs_test.sh " diff --git a/main/postmarketos-mkinitfs/init.sh.in b/main/postmarketos-mkinitfs/init.sh similarity index 97% rename from main/postmarketos-mkinitfs/init.sh.in rename to main/postmarketos-mkinitfs/init.sh index 385f29d1c..bc90216c1 100644 --- a/main/postmarketos-mkinitfs/init.sh.in +++ b/main/postmarketos-mkinitfs/init.sh @@ -36,7 +36,7 @@ start_udhcpd mount_boot_partition /boot show_splash_loading -extract_initramfs_extra @INITRAMFS_EXTRA@ +extract_initramfs_extra /boot/initramfs-extra # charging-sdl does not work properly at the moment, so skip it. # See also https://gitlab.com/postmarketOS/pmaports/-/issues/1064 # start_charging_mode diff --git a/main/postmarketos-mkinitfs/mkinitfs.sh b/main/postmarketos-mkinitfs/mkinitfs.sh deleted file mode 100644 index 6eebaafb0..000000000 --- a/main/postmarketos-mkinitfs/mkinitfs.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -outfile="" -outfile_extra="" -# shellcheck disable=SC1091 -. /usr/share/postmarketos-mkinitfs/mkinitfs_functions.sh - -# initialize -source_deviceinfo -parse_commandline "$1" "$2" "$3" -check_hook_files - -echo "==> initramfs: creating $outfile" -tmpdir=$(mktemp -d /tmp/mkinitfs.XXXXXX) - -# set up initfs in temp folder -create_folders -copy_files "$(get_modules)" "$tmpdir" -copy_files "$(get_binaries)" "$tmpdir" -copy_files "/etc/deviceinfo" "$tmpdir" -copy_files "/etc/postmarketos-mkinitfs/hooks/*.sh" "$tmpdir" -cp /usr/share/postmarketos-splashes/*.ppm.gz "$tmpdir" -ln -s "/bin/busybox" "$tmpdir/bin/sh" -install -Dm755 "/usr/share/postmarketos-mkinitfs/init.sh.in" \ - "$tmpdir/init" -install -Dm755 "/usr/share/postmarketos-mkinitfs/init_functions.sh" \ - "$tmpdir/init_functions.sh" - -# finish up -replace_init_variables -create_cpio_image "$tmpdir" "$outfile" -append_or_copy_dtb -add_mtk_header -create_uboot_files -create_bootimg -flash_updated_boot_parts - -rm -rf "$tmpdir" - -generate_initramfs_extra "$outfile_extra" - -sync -exit 0 diff --git a/main/postmarketos-mkinitfs/mkinitfs_functions.sh b/main/postmarketos-mkinitfs/mkinitfs_functions.sh deleted file mode 100644 index ca7582c1c..000000000 --- a/main/postmarketos-mkinitfs/mkinitfs_functions.sh +++ /dev/null @@ -1,530 +0,0 @@ -#!/bin/sh - -# Declare used deviceinfo variables to pass shellcheck (order alphabetically) -deviceinfo_append_dtb="" -deviceinfo_arch="" -deviceinfo_bootimg_append_seandroidenforce="" -deviceinfo_bootimg_blobpack="" -deviceinfo_bootimg_dtb_second="" -deviceinfo_bootimg_mtk_mkimage="" -deviceinfo_bootimg_pxa="" -deviceinfo_bootimg_qcdt="" -deviceinfo_dtb="" -deviceinfo_flash_offset_base="" -deviceinfo_flash_offset_kernel="" -deviceinfo_flash_offset_ramdisk="" -deviceinfo_flash_offset_second="" -deviceinfo_flash_offset_tags="" -deviceinfo_flash_pagesize="" -deviceinfo_generate_bootimg="" -deviceinfo_generate_legacy_uboot_initfs="" -deviceinfo_mesa_driver="" -deviceinfo_mkinitfs_postprocess="" -deviceinfo_initfs_compression="" -deviceinfo_kernel_cmdline="" -deviceinfo_legacy_uboot_load_address="" -deviceinfo_modules_initfs="" -deviceinfo_flash_kernel_on_update="" - -# Overwritten by mkinitfs.sh -tmpdir="" - -source_deviceinfo() -{ - if [ ! -e "/etc/deviceinfo" ]; then - echo "NOTE: deviceinfo (from device package) not installed yet," \ - "not building the initramfs now (it should get built later" \ - "automatically.)" - exit 0 - fi - # shellcheck disable=SC1091 - . /etc/deviceinfo -} - -parse_commandline() -{ - if [ "$1" != "-o" ]; then - echo "postmarketos-mkinitfs" - echo "usage: $(basename "$0") -o OUTFILE KERNELVERSION" - exit 1 - fi - - outfile=$2 - outfile_extra=$2-extra - kernel=$3 -} - -# Verify that each file required by the installed hooks exists and exit with an -# error if they don't. -check_hook_files() -{ - for file in "/etc/postmarketos-mkinitfs/files"/*.files; do - [ -f "$file" ] || continue - while IFS= read -r line; do - if ! [ -f "$line" ]; then - echo "ERROR: File ${line} specified in ${file} does not exist!" - exit 1 - fi - done < "$file" - done -} - -create_folders() -{ - for dir in /bin /sbin /usr/bin /usr/sbin /proc /sys /dev /tmp /lib \ - /boot /sysroot /etc; do - mkdir -p "$tmpdir$dir" - done -} - -get_modules_by_globs() -{ - globs=" - # base.modules - kernel/drivers/block/loop.ko - kernel/fs/overlayfs - - # cryptsetup.modules - kernel/crypto/* - kernel/arch/*/crypto/* - kernel/drivers/md/dm-crypt.ko - - # required for modprobe - modules.* - " - - for glob in $globs; do - for file in /lib/modules/$kernel/$glob; do - if [ -d "$file" ]; then - find "$file" -type f - elif [ -e "$file" ]; then - echo "$file" - fi - done - done -} - -# Read a modules-load.d style file into a single line. The file is expected to -# have empty lines, lines starting with "#" that are comments or one word in -# the line. The resulting parsed line is printed to stdout. -# $1: file to parse -parse_file_as_line() -{ - _first="true" - while IFS= read -r line; do - case "$line" in - ""|"#"*) - # Comment or empty line, ignore - ;; - *) - if [ "$_first" = "true" ]; then - _first="false" - else - printf " " - fi - printf "%s" "$line" - ;; - esac - done < "$1" -} - -# Parse modules by name from deviceinfo and from these files: -# /etc/postmarketos-mkinitfs/modules/*.modules. The postmarketos-mkinitfs -# package installs a 00-default.modules there. -# Resolved kernel module paths get printed to stdout, informative logging to -# stderr. -# NOTE: This does not work with busybox' modprobe. That's why -# postmarketos-mkinitfs depends on kmod. -get_modules_by_name() -{ - { - echo "Scanning kernel module dependencies..." - echo "NOTE: ** modprobe warnings below can be ignored ** if your device does not run the" - echo "mainline kernel yet (most devices!) or if the related kernel options are enabled" - echo "with 'y' instead of 'm' (module)." - } >&2 - - MODULES="$deviceinfo_modules_initfs" - echo " - deviceinfo: $deviceinfo_modules_initfs" >&2 - - for file in "/etc/postmarketos-mkinitfs/modules/"*.modules; do - [ -f "$file" ] || continue - _modules_file="$(parse_file_as_line "$file")" - echo " - $(basename "$file"): $_modules_file" >&2 - MODULES="$MODULES $_modules_file" - done - - # shellcheck disable=SC2086 - modprobe \ - -a \ - --dry-run \ - --show-depends \ - --set-version="$kernel" \ - $MODULES \ - | sort -u \ - | cut -d ' ' -f 2 -} - -get_modules() -{ - get_modules_by_globs - get_modules_by_name -} - -# Get the paths to all binaries and their dependencies -get_binaries() -{ - BINARIES=" - /bin/busybox - /bin/busybox-extras - /usr/sbin/telnetd - /sbin/kpartx - " - - for file in "/etc/postmarketos-mkinitfs/files"/*.files; do - [ -f "$file" ] || continue - while IFS= read -r line; do - BINARIES="${BINARIES} ${line}" - done < "$file" - done - # shellcheck disable=SC2086 - sudo -u nobody lddtree -l $BINARIES | sort -u -} - -# Collect non-binary files for osk-sdl and its dependencies -# This gets called as $(get_osk_config), so the exit code can be checked/handled. -get_osk_config() -{ - fontpath=$(awk '/^keyboard-font = /{print $3}' /etc/osk.conf) - if [ ! -f "$fontpath" ]; then - echo "ERROR: failed to parse 'keyboard-font' from osk-sdl config!" - exit 1 - fi - ret=" - /etc/osk.conf - /etc/ts.conf - /etc/pointercal - /etc/fb.modes - /etc/directfbrc - $fontpath - " - echo "${ret}" -} - -get_binaries_extra() -{ - BINARIES_EXTRA=" - /lib/libz.so.1 - /sbin/dmsetup - /sbin/e2fsck - /usr/sbin/parted - /usr/sbin/resize2fs - /usr/sbin/resize.f2fs - " - - if [ -x /usr/bin/osk-sdl ]; then - BINARIES_EXTRA=" - $BINARIES_EXTRA - $(find /usr/lib/directfb-* -name '*.so') - /usr/bin/osk-sdl - /sbin/cryptsetup - /usr/lib/libGL.so.1 - /usr/lib/libts* - /usr/lib/ts/* - " - if [ -n "$deviceinfo_mesa_driver" ]; then - BINARIES_EXTRA=" - $BINARIES_EXTRA - /usr/lib/libEGL.so.1 - /usr/lib/libGLESv2.so.2 - /usr/lib/libgbm.so.1 - /usr/lib/libudev.so.1 - /usr/lib/xorg/modules/dri/${deviceinfo_mesa_driver}_dri.so - " - fi - fi - - tmp1=$(mktemp /tmp/mkinitfs.XXXXXX) - get_binaries > "$tmp1" - tmp2=$(mktemp /tmp/mkinitfs.XXXXXX) - - # shellcheck disable=SC2086 - sudo -u nobody lddtree -l $BINARIES_EXTRA | sort -u > "$tmp2" - ret=$(comm -13 "$tmp1" "$tmp2") - rm "$tmp1" "$tmp2" - echo "${ret}" -} - -# Copy files to the destination specified -# $1: files -# $2: destination -copy_files() -{ - for file in $1; do - [ -e "$file" ] || continue - cp -a --parents "$file" "$2" - done -} - -replace_init_variables() -{ - sed -i "s:@INITRAMFS_EXTRA@:${outfile_extra}:g" "$tmpdir/init" -} - -# Create a cpio image of the specified folder -# $1: folder -# $2: outfile -create_cpio_image() -{ - if ! cd "$1"; then - echo "ERROR: failed to cd to '$1'" - exit 1 - fi - [ -z "$deviceinfo_initfs_compression" ] && deviceinfo_initfs_compression='gzip -1' - find . -print0 \ - | cpio --quiet -o -0 -H newc \ - | $deviceinfo_initfs_compression > "$2" -} - -# Required command check with useful error message -# $1: command (e.g. "mkimage") -# $2: package (e.g. "u-boot-tools") -# $3: related deviceinfo variable (e.g. "generate_bootimg") -require_package() -{ - [ "$(command -v "$1")" = "" ] || return - echo "ERROR: 'deviceinfo_$3' is set, but the package '$2' was not" - echo "installed! Please add '$2' to the depends= line of your device's" - echo "APKBUILD. See also: " - exit 1 -} - -# Legacy u-boot images -create_uboot_files() -{ - arch="arm" - if [ "${deviceinfo_arch}" = "aarch64" ]; then - arch="arm64" - fi - - [ "${deviceinfo_generate_legacy_uboot_initfs}" = "true" ] || return - require_package "mkimage" "u-boot-tools" "generate_legacy_uboot_initfs" - - echo "==> initramfs: creating uInitrd" - # shellcheck disable=SC3060 - mkimage -A $arch -T ramdisk -C none -n uInitrd -d "$outfile" \ - "${outfile/initramfs-/uInitrd-}" || exit 1 - - echo "==> kernel: creating uImage" - # shellcheck disable=SC3060 - kernelfile="${outfile/initramfs-/vmlinuz-}" - if [ "${deviceinfo_append_dtb}" = "true" ]; then - kernelfile="${kernelfile}-dtb" - fi - - if [ -z "$deviceinfo_legacy_uboot_load_address" ]; then - deviceinfo_legacy_uboot_load_address="80008000" - fi - - # shellcheck disable=SC3060 - mkimage -A $arch -O linux -T kernel -C none -a "$deviceinfo_legacy_uboot_load_address" \ - -e "$deviceinfo_legacy_uboot_load_address" \ - -n postmarketos -d "$kernelfile" "${outfile/initramfs-/uImage-}" || exit 1 -} - -# Android devices -create_bootimg() -{ - [ "${deviceinfo_generate_bootimg}" = "true" ] || return - # shellcheck disable=SC3060 - bootimg="${outfile/initramfs-/boot.img-}" - - if [ "${deviceinfo_bootimg_pxa}" = "true" ]; then - require_package "pxa-mkbootimg" "pxa-mkbootimg" "bootimg_pxa" - MKBOOTIMG=pxa-mkbootimg - else - require_package "mkbootimg-osm0sis" "mkbootimg" "generate_bootimg" - MKBOOTIMG=mkbootimg-osm0sis - fi - - echo "==> initramfs: creating boot.img" - _base="${deviceinfo_flash_offset_base}" - [ -z "$_base" ] && _base="0x10000000" - - # shellcheck disable=SC3060 - kernelfile="${outfile/initramfs-/vmlinuz-}" - if [ "${deviceinfo_append_dtb}" = "true" ]; then - kernelfile="${kernelfile}-dtb" - fi - - if [ "${deviceinfo_bootimg_mtk_mkimage}" = "true" ]; then - kernelfile="${kernelfile}-mtk" - fi - - _second="" - if [ "${deviceinfo_bootimg_dtb_second}" = "true" ]; then - if [ -z "${deviceinfo_dtb}" ]; then - echo "ERROR: deviceinfo_bootimg_dtb_second is set, but" - echo "'deviceinfo_dtb' is missing. Set 'deviceinfo_dtb'" - echo "to the device tree blob for your device." - echo "See also: " - exit 1 - fi - dtb="/usr/share/dtb/${deviceinfo_dtb}.dtb" - _second="--second $dtb" - if ! [ -e "$dtb" ]; then - echo "ERROR: File not found: $dtb. Please set 'deviceinfo_dtb'" - echo "to the relative path to the device tree blob for your" - echo "device (without .dtb)." - echo "See also: " - exit 1 - fi - fi - _dt="" - if [ "${deviceinfo_bootimg_qcdt}" = "true" ]; then - _dt="--dt /boot/dt.img" - if ! [ -e "/boot/dt.img" ]; then - echo "ERROR: File not found: /boot/dt.img, but" - echo "'deviceinfo_bootimg_qcdt' is set. Please verify that your" - echo "device is a QCDT device by analyzing the boot.img file" - echo "(e.g. 'pmbootstrap bootimg_analyze path/to/twrp.img')" - echo "and based on that, set the deviceinfo variable to false or" - echo "adjust your linux APKBUILD to properly generate the dt.img" - echo "file. See also: " - exit 1 - fi - fi - # shellcheck disable=SC2039 disable=SC2086 - "${MKBOOTIMG}" \ - --kernel "${kernelfile}" \ - --ramdisk "$outfile" \ - --base "${_base}" \ - --second_offset "${deviceinfo_flash_offset_second}" \ - --cmdline "${deviceinfo_kernel_cmdline}" \ - --kernel_offset "${deviceinfo_flash_offset_kernel}" \ - --ramdisk_offset "${deviceinfo_flash_offset_ramdisk}" \ - --tags_offset "${deviceinfo_flash_offset_tags}" \ - --pagesize "${deviceinfo_flash_pagesize}" \ - ${_second} \ - ${_dt} \ - -o "$bootimg" || exit 1 - if [ "${deviceinfo_mkinitfs_postprocess}" != "" ]; then - sh "${deviceinfo_mkinitfs_postprocess}" "$outfile" - fi - if [ "${deviceinfo_bootimg_blobpack}" = "true" ] || [ "${deviceinfo_bootimg_blobpack}" = "sign" ]; then - echo "==> initramfs: creating blob" - _flags="" - if [ "${deviceinfo_bootimg_blobpack}" = "sign" ]; then - _flags="-s" - fi - # shellcheck disable=SC3060 - blobpack $_flags "${outfile/initramfs-/blob-}" \ - LNX "$bootimg" || exit 1 - # shellcheck disable=SC3060 - mv "${outfile/initramfs-/blob-}" "$bootimg" - fi - if [ "${deviceinfo_bootimg_append_seandroidenforce}" = "true" ]; then - echo "==> initramfs: appending 'SEANDROIDENFORCE' to boot.img" - # shellcheck disable=SC3037 - echo -n "SEANDROIDENFORCE" >> "$bootimg" - fi -} - -flash_updated_boot_parts() -{ - [ "${deviceinfo_flash_kernel_on_update}" = "true" ] || return - # If postmarketos-update-kernel is not installed then nop - [ -f /sbin/pmos-update-kernel ] || return - if [ -f "/in-pmbootstrap" ]; then - echo "==> Not flashing boot in chroot" - return - fi - - # We assume here that the device only has a single kernel - # package installed and that it is also the one being upgraded. - FLAVOR="$(basename "$(find /usr/share/kernel/* -type d -print -quit)")" - - if [ -z "$FLAVOR" ]; then - echo "==> Couldn't determine flavor, are you running the stock kernel?" - return - fi - - echo "==> Flashing boot image flavor: $FLAVOR" - - pmos-update-kernel "$FLAVOR" -} - -# Append the correct device tree to the linux image file or copy the dtb to the boot partition -append_or_copy_dtb() -{ - [ -n "${deviceinfo_dtb}" ] || return - echo "==> kernel: device-tree blob operations" - dtb="" - for filename in $deviceinfo_dtb; do - if ! [ -e "/usr/share/dtb/$filename.dtb" ]; then - echo "ERROR: File not found: /usr/share/dtb/$filename.dtb" - exit 1 - fi - dtb="$dtb /usr/share/dtb/$filename.dtb" - done - # shellcheck disable=SC3060 - kernel="${outfile/initramfs-/vmlinuz-}" - if [ "${deviceinfo_append_dtb}" = "true" ]; then - echo "==> kernel: appending device-tree ${deviceinfo_dtb}" - # shellcheck disable=SC2086 - cat "$kernel" $dtb > "${kernel}-dtb" - else - echo "==> kernel: copying dtb ${deviceinfo_dtb} to boot partition" - # shellcheck disable=SC2086 - cp $dtb "$(dirname "${outfile}")" - fi -} - -# Add Mediatek header to kernel & initramfs -add_mtk_header() -{ - [ "${deviceinfo_bootimg_mtk_mkimage}" = "true" ] || return - require_package "mtk-mkimage" "mtk-mkimage" "bootimg_mtk_mkimage" - - echo "==> initramfs: adding Mediatek header" - mv "$outfile" "$outfile-orig" - mtk-mkimage ROOTFS "$outfile-orig" "$outfile" - rm "$outfile-orig" - - echo "==> kernel: adding Mediatek header" - # shellcheck disable=SC3060 - kernel="${outfile/initramfs-/vmlinuz-}" - rm -f "${kernel}-mtk" - mtk-mkimage KERNEL "$kernel" "${kernel}-mtk" -} - -# Create the initramfs-extra archive -# $1: outfile -generate_initramfs_extra() -{ - echo "==> initramfs: creating $1" - - osk_conf="" - if [ -x /usr/bin/osk-sdl ]; then - osk_conf="$(get_osk_config)" - if [ $? -eq 1 ]; then - echo "ERROR: Font specified in /etc/osk.conf does not exist!" - exit 1 - fi - fi - - # Set up initramfs-extra in temp folder - tmpdir_extra=$(mktemp -d /tmp/mkinitfs.XXXXXX) - tmpdir_extra_cpio=$(mktemp -d /tmp/mkinitfs-cpio.XXXXXX) - tmpdir_extra_cpio_img="$tmpdir_extra_cpio/extra.img" - mkdir -p "$tmpdir_extra" - copy_files "$(get_binaries_extra)" "$tmpdir_extra" - [ -n "$osk_conf" ] && copy_files "$osk_conf" "$tmpdir_extra" - create_cpio_image "$tmpdir_extra" "$tmpdir_extra_cpio_img" - rm -rf "$tmpdir_extra" - - # Replace old initramfs-extra *after* we are done to make sure - # it does not become corrupted if something goes wrong. - cp "$tmpdir_extra_cpio_img" "$1" - rm -rf "$tmpdir_extra_cpio" -} diff --git a/main/postmarketos-mkinitfs/mkinitfs_test.sh b/main/postmarketos-mkinitfs/mkinitfs_test.sh deleted file mode 100644 index 9866f8b92..000000000 --- a/main/postmarketos-mkinitfs/mkinitfs_test.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -e -# Test single functions of mkinitfs_functions.sh. Add -x for verbosity. - -. ./mkinitfs_functions.sh - -echo ":: testing parse_file_as_line()" -cat << EOF > _test -# comment -module1 - -module2 -# comment2 -module3 -EOF - -if [ "$(parse_file_as_line _test)" != "module1 module2 module3" ]; then - echo "ERROR in line $LINENO" - exit 1 -fi - - -echo ":: all tests passed" diff --git a/main/postmarketos-mkinitfs/postmarketos-mkinitfs.post-upgrade b/main/postmarketos-mkinitfs/postmarketos-mkinitfs.post-upgrade new file mode 100644 index 000000000..926747374 --- /dev/null +++ b/main/postmarketos-mkinitfs/postmarketos-mkinitfs.post-upgrade @@ -0,0 +1,12 @@ +#!/bin/sh + +# This attempts to clean up files in /boot left over from when mkinitfs +# appended kernel 'flavors'. Without doing this cleanup, /boot might be more +# full than it needs to be, and things like copying files atomically in the new +# mkinitfs may not have enough space to do the atomic copy +echo "Cleaning up old boot files..." +for f in /boot/boot.img-* /boot/vmlinuz-* /boot/initramfs-*-extra* /boot/initramfs-*[!-extra]; do + [ -f "$f" ] && rm "$f" +done + +exit 0 diff --git a/main/postmarketos-mkinitfs/postmarketos-mkinitfs.trigger b/main/postmarketos-mkinitfs/postmarketos-mkinitfs.trigger index 948f8cea4..ce168616c 100644 --- a/main/postmarketos-mkinitfs/postmarketos-mkinitfs.trigger +++ b/main/postmarketos-mkinitfs/postmarketos-mkinitfs.trigger @@ -1,60 +1,5 @@ #!/bin/sh -e -# $1: kernel flavor -rebuild_initfs_flavor() -{ - abi_release=$(cat /usr/share/kernel/"$1"/kernel.release) - mkinitfs -o /boot/initramfs-"$1" "$abi_release" -} - -# Each argument to this shell script is a path, that caused the trigger to -# execute. When a hook was changed, rebuild all flavors. When only one flavor -# was changed, find out if it has been installed or uninstalled, and rebuild -# it or delete the left-overs. -rebuild_all="false" -for i in "$@"; do - case "$i" in - # Hook change - /etc/postmarketos-mkinitfs/hooks*) - rebuild_all="true" - break ;; - - # osk-sdl change - /usr/share/postmarketos-mkinitfs-triggers) - rebuild_all="true" - break ;; - - # Kernel flavor change - /usr/share/kernel/*) - flavor=${i##*/} - if [ -f "$i"/kernel.release ]; then - # installed - [ "$rebuild_all" = "true" ] || rebuild_initfs_flavor "$flavor" - else - # uninstalled - rm -f "$( readlink -f /boot/initramfs-"$flavor" )" \ - /boot/initramfs-"$flavor" /boot/vmlinuz-"$flavor" \ - /boot/"$flavor" /boot/"$flavor".gz /"$flavor" /"$flavor".gz - fi - - break ;; - esac -done - -# Rebuild all flavors, if necessary -if [ "$rebuild_all" = "true" ]; then - for i in /usr/share/kernel/*; do - [ -d "$i" ] && rebuild_initfs_flavor "${i##*/}" - done -fi - -# Cleanup unused initramfs -for i in /boot/initramfs-[0-9]*; do - [ -f "$i" ] || continue - if ! [ -f /boot/vmlinuz-"${i#/boot/initramfs-}" ]; then - rm "$i" - fi -done - +/sbin/postmarketos-mkinitfs sync exit 0