From 4a5955df5db8049bffdbe641b720eca29fbe4d5d Mon Sep 17 00:00:00 2001 From: rzrbld Date: Sat, 12 Nov 2022 01:17:58 +0300 Subject: [PATCH] change iso.img creation --- .../userpatches/customize-image.sh | 2 ++ gadget_cdrom_auto_img.service | 5 ++--- init_iso_img.sh | 18 +++++++++++------- mode.sh | 3 +-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/armbian/banapi_m2_zero/userpatches/customize-image.sh b/armbian/banapi_m2_zero/userpatches/customize-image.sh index 5cd585a..e327997 100644 --- a/armbian/banapi_m2_zero/userpatches/customize-image.sh +++ b/armbian/banapi_m2_zero/userpatches/customize-image.sh @@ -93,7 +93,9 @@ InstallCDROMGadget(){ # add cdrom_gadget to systemd ln -s /opt/gadget_cdrom/gadget_cdrom.service /etc/systemd/system/gadget_cdrom.service && \ + ln -s /opt/gadget_cdrom/gadget_cdrom_auto_img.service /etc/systemd/system/gadget_cdrom_auto_img.service && \ systemctl enable gadget_cdrom.service + systemctl enable gadget_cdrom_auto_img.service } diff --git a/gadget_cdrom_auto_img.service b/gadget_cdrom_auto_img.service index f737079..0d32eaf 100644 --- a/gadget_cdrom_auto_img.service +++ b/gadget_cdrom_auto_img.service @@ -1,5 +1,5 @@ [Unit] -Description=gadget_cdrom +Description=gadget_cdrom_image_creation Before=basic.target After=local-fs.target sysinit.target DefaultDependencies=no @@ -8,8 +8,7 @@ DefaultDependencies=no Type=simple User=root WorkingDirectory=/opt/gadget_cdrom -ExecStartPre=/opt/gadget_cdrom/create_image.sh auto -ExecStart=/opt/gadget_cdrom/gadget_cdrom.py +ExecStart=/opt/gadget_cdrom/init_iso_img.sh Restart=on-failure [Install] diff --git a/init_iso_img.sh b/init_iso_img.sh index 0967601..3f8e5c4 100755 --- a/init_iso_img.sh +++ b/init_iso_img.sh @@ -1,16 +1,17 @@ -#!/bin/bash +#!/bin/bash -ue FILE="/iso.img" if [ -f "$FILE" ]; then + echo "$FILE already exists" 1>&2 exit 0 fi resize2fs_status="$(systemctl is-enabled armbian-resize-filesystem)" if [[ $resize2fs_status == "enabled" ]]; then - sleep 5 - ./$0 - exit 0 + sleep 30 + echo "armbian-resize-filesystem in progress" 2>&1 + exit 1 fi free="$(df -k / | tail -n1 | awk '{print $4}')" @@ -21,7 +22,7 @@ fi size="${size}k" part_type="ntfs" -echo "Creating $size image..." +echo "Creating $size image..." 1>&2 fallocate -l "$size" "$FILE" dev="$(losetup -fL --show "$FILE")" @@ -35,5 +36,8 @@ sync mkdir -p /iso -echo "Done!" -reboot +echo "img.iso creation is done!" 1>&2 + +systemctl disable gadget_cdrom_auto_img.service && \ +systemctl restart gadget_cdrom.service && \ +systemctl stop gadget_cdrom_auto_img.service diff --git a/mode.sh b/mode.sh index 43fca16..fa7aa37 100755 --- a/mode.sh +++ b/mode.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /bin/bash -ue IDIR="${BASH_SOURCE%/*}" if [[ ! -d "$IDIR" ]]; then IDIR="$PWD"; fi @@ -16,6 +16,5 @@ elif [ "$MODE" == "usb" ] ; then elif [ "$MODE" == "shutdown" ]; then true elif [ "$MODE" == "init" ]; then - source "/$IDIR/init_iso_img.sh" true fi