From ed565488b2c398e788bfa9408b932ae5dc49dcca Mon Sep 17 00:00:00 2001 From: Yukari Chiba Date: Wed, 17 Jul 2024 17:18:17 +0800 Subject: [PATCH] cleanup code, move tmp dirs into ./tmpdir --- .gitignore | 3 +-- utils/cleanup.sh | 3 +-- utils/collect.sh | 30 ++++++++++++------------------ utils/function_def.sh | 15 ++++++++++++--- utils/hooks.sh | 17 +++++++---------- utils/install.sh | 6 +++--- 6 files changed, 36 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index f2280f1..b3c03d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -isofs/ -rootfs/ +tmpdir/ *.img *.iso *.tar.xz diff --git a/utils/cleanup.sh b/utils/cleanup.sh index f21c902..09a7e3c 100755 --- a/utils/cleanup.sh +++ b/utils/cleanup.sh @@ -2,6 +2,5 @@ _logtxt "#### cleaning up env" -$RUNAS rm -r rootfs || true -$RUNAS rm -r isofs || true +$RUNAS rm -r tmpdir || true diff --git a/utils/collect.sh b/utils/collect.sh index ed47707..423b4f0 100755 --- a/utils/collect.sh +++ b/utils/collect.sh @@ -5,10 +5,10 @@ _logtxt "#### collecting result" mkdir -p results if [[ $PROFILE == liveimage* ]]; then - mkdir -p ./isofs/live/sfs/ - $RUNAS mksquashfs ./rootfs ./isofs/live/sfs/root.sfs - echo "root" | $RUNAS tee ./isofs/live/live.list - if [ -f ./isofs/limine-bios-cd.bin ]; then + mkdir -p ./tmpdir/isofs/live/sfs/ + $RUNAS mksquashfs ./tmpdir/rootfs ./tmpdir/isofs/live/sfs/root.sfs + echo "root" | $RUNAS tee ./tmpdir/isofs/live/live.list + if [ -f ./tmpdir/isofs/limine-bios-cd.bin ]; then BIOS_ARG="-b limine-bios-cd.bin" fi $RUNAS xorriso -as mkisofs \ @@ -19,30 +19,24 @@ if [[ $PROFILE == liveimage* ]]; then -efi-boot-part --efi-boot-image --protective-msdos-label \ -V "EWE_ISO" \ -A "eweOS Live ISO" \ - isofs + tmpdir/isofs if [ ! -z "$BIOS_ARG" ]; then _logtxt "#### Install BIOS boot for ISO" # limine install bios - $RUNAS mkdir -p ./rootfs/results - $RUNAS mount --bind results ./rootfs/results - $RUNAS arch-chroot rootfs bash -c "limine bios-install /results/eweos-$TARGET_ARCH-$PROFILE.iso" - _logtxt "#### wait 3 sec to release mountpoint" - sleep 3 - $RUNAS umount ./rootfs/proc || true - $RUNAS umount ./rootfs/results + $RUNAS mkdir -p ./tmpdir/rootfs/results + $RUNAS mount --bind ./results ./tmpdir/rootfs/results + $RUNAS arch-chroot ./tmpdir/rootfs bash -c "limine bios-install /results/eweos-$TARGET_ARCH-$PROFILE.iso" + $RUNAS umount ./tmpdir/rootfs/results + umount_chroot ./tmpdir/rootfs fi sha256sum results/eweos-$TARGET_ARCH-$PROFILE.iso > results/eweos-$TARGET_ARCH-$PROFILE.iso.sha256 fi if [[ $PROFILE == tarball* ]]; then - # wait for arch-chroot to release mountpoint - sleep 5 - # failsafe - $RUNAS umount ./rootfs/sys/firmware/efi/efivars || true - $RUNAS umount ./rootfs/sys || true - $RUNAS tar cJf results/eweos-$TARGET_ARCH-$PROFILE.tar.xz -C ./rootfs . + umount_chroot ./tmpdir/rootfs + $RUNAS tar cJf results/eweos-$TARGET_ARCH-$PROFILE.tar.xz -C ./tmpdir/rootfs . pushd results sha256sum eweos-$TARGET_ARCH-$PROFILE.tar.xz > eweos-$TARGET_ARCH-$PROFILE.tar.xz.sha256 popd diff --git a/utils/function_def.sh b/utils/function_def.sh index 48148b8..c42fbc0 100755 --- a/utils/function_def.sh +++ b/utils/function_def.sh @@ -5,7 +5,16 @@ function _logtxt() { } function crsh(){ - cp $1 ./rootfs/config.sh && chmod +x ./rootfs/config.sh - $RUNAS arch-chroot rootfs bash -c "/config.sh" - $RUNAS rm ./rootfs/config.sh + cp $1 ./tmpdir/rootfs/config.sh && chmod +x ./tmpdir/rootfs/config.sh + $RUNAS arch-chroot tmpdir/rootfs bash -c "/config.sh" + $RUNAS rm ./tmpdir/rootfs/config.sh +} + +function umount_chroot(){ + _logtxt "#### wait 3 sec to release mountpoint on $1" + sleep 3 + $RUNAS umount $1/proc || true + $RUNAS umount $1/boot || true + $RUNAS umount $1/sys/firmware/efi/efivars || true + $RUNAS umount $1/sys || true } diff --git a/utils/hooks.sh b/utils/hooks.sh index 073c0fd..ab78fef 100755 --- a/utils/hooks.sh +++ b/utils/hooks.sh @@ -2,14 +2,14 @@ if [[ $PROFILE == liveimage* ]]; then _logtxt "#### creating boot partition" - mkdir -p isofs - $RUNAS mkdir -p ./rootfs/boot - $RUNAS mount --bind ./isofs ./rootfs/boot + mkdir -p tmpdir/isofs + $RUNAS mkdir -p ./tmpdir/rootfs/boot + $RUNAS mount --bind ./tmpdir/isofs ./tmpdir/rootfs/boot fi if [ -d profiles/$PROFILE/files ]; then _logtxt "#### copying files" - $RUNAS cp -r profiles/$PROFILE/files ./rootfs/.files + $RUNAS cp -r profiles/$PROFILE/files ./tmpdir/rootfs/.files fi function concat_config() { @@ -35,12 +35,9 @@ if [ -f "./profiles/$PROFILE/config.sh" ]; then fi crsh $chrconf -if [ -d ./rootfs/.files ]; then +if [ -d ./tmpdir/rootfs/.files ]; then _logtxt "#### remove unused files" - $RUNAS rm -r ./rootfs/.files + $RUNAS rm -r ./tmpdir/rootfs/.files fi -_logtxt "#### wait 3 sec to release mountpoint" -sleep 3 -$RUNAS umount ./rootfs/boot || true -$RUNAS umount ./rootfs/proc || true +umount_chroot ./tmpdir/rootfs diff --git a/utils/install.sh b/utils/install.sh index fbb944b..a51a5c1 100755 --- a/utils/install.sh +++ b/utils/install.sh @@ -1,12 +1,12 @@ #!/bin/env sh -mkdir -p rootfs +mkdir -p tmpdir/rootfs _logtxt "#### bootstrapping system" -$RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./rootfs `cat profiles/$PROFILE/packages.txt | xargs` +$RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./tmpdir/rootfs `cat profiles/$PROFILE/packages.txt | xargs` if [ -f profiles/$PROFILE/packages.$TARGET_ARCH.txt ]; then - $RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./rootfs `cat profiles/$PROFILE/packages.$TARGET_ARCH.txt | xargs` + $RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./tmpdir/rootfs `cat profiles/$PROFILE/packages.$TARGET_ARCH.txt | xargs` fi