diff --git a/ipk-source/sdxpinn-mount-fix/CONTROL/control b/ipk-source/sdxpinn-mount-fix/CONTROL/control old mode 100644 new mode 100755 index 0d8fddd..ff60012 --- a/ipk-source/sdxpinn-mount-fix/CONTROL/control +++ b/ipk-source/sdxpinn-mount-fix/CONTROL/control @@ -1,5 +1,5 @@ Package: sdxpinn-mount-fix -Version: 1.2.0-NOT-READY +Version: 1.2.0 Architecture: aarch64_cortex-a53 Maintainer: Cameron Thompson iamromulan@github.com Description: Creates a usable mount space and overlay for SDXPINN modems. Dependencies bundled: libinotifytools and inotifywait diff --git a/ipk-source/sdxpinn-mount-fix/CONTROL/postinst b/ipk-source/sdxpinn-mount-fix/CONTROL/postinst old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/CONTROL/prerm b/ipk-source/sdxpinn-mount-fix/CONTROL/prerm old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/build-ipk b/ipk-source/sdxpinn-mount-fix/build-ipk old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/etc/init.d/add_opkg_status_bundled b/ipk-source/sdxpinn-mount-fix/root/etc/init.d/add_opkg_status_bundled old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/etc/init.d/init-overlay-watchdog b/ipk-source/sdxpinn-mount-fix/root/etc/init.d/init-overlay-watchdog old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/etc/init.d/mount-fix b/ipk-source/sdxpinn-mount-fix/root/etc/init.d/mount-fix old mode 100644 new mode 100755 index d2f8327..32af3b6 --- a/ipk-source/sdxpinn-mount-fix/root/etc/init.d/mount-fix +++ b/ipk-source/sdxpinn-mount-fix/root/etc/init.d/mount-fix @@ -98,27 +98,8 @@ handle_old_firmware() { /bin/mount --move /real_rootfs/cache /cache /bin/mount --move /real_rootfs/data /data - # Synchronize /etc/rc.d/ and /real_rootfs/etc/rc.d/ - /bin/echo "Synchronizing /etc/rc.d/ and /real_rootfs/etc/rc.d/" - for link in /etc/rc.d/*; do - if [ -L "$link" ]; then - link_name=$(basename "$link") - if [ ! -e "/real_rootfs/etc/rc.d/$link_name" ]; then - /bin/echo "Copying $link_name to /real_rootfs/etc/rc.d/" - cp -a "$link" "/real_rootfs/etc/rc.d/$link_name" - fi - fi - done - - for link in /real_rootfs/etc/rc.d/*; do - if [ -L "$link" ]; then - link_name=$(basename "$link") - if [ ! -e "/etc/rc.d/$link_name" ]; then - /bin/echo "Removing $link_name from /real_rootfs/etc/rc.d/" - rm "/real_rootfs/etc/rc.d/$link_name" - fi - fi - done + # Synchronize between /etc/rc.d and /real_rootfs/etc/rc.d + synchronize_rc_d "/etc/rc.d" "/real_rootfs/etc/rc.d" # Final logs and remount the original root as read-only /bin/echo "...and we're back! The original root now lives at /real_rootfs" @@ -142,7 +123,7 @@ handle_new_firmware() { /bin/mount -o remount,rw / # Begin layer merge checks - # Layer 1 + # Layer 1 to 2 # Check if /overlay/etc-upper/merged.done exists /bin/echo "First time this is ran the stuff you have been putting in the old overlay and /usrdata/etc needs merged." /bin/echo "Looking for evidence that this has already happened..." @@ -153,7 +134,7 @@ handle_new_firmware() { else /bin/echo "/usrdata/overlay-work/etc-upper/merged.done found, skipping merge" fi - # Layer 2 + # Layer 2 to 3 # Check if /usrdata/etc/merged.done exists /bin/echo "First time this is ran the stuff you have been putting in /usrdata/etc and /etc needs merged." /bin/echo "Looking for evidence that this has already happened..." @@ -174,27 +155,21 @@ handle_new_firmware() { else /bin/echo "'option overlay_root /overlay' not found in /etc/opkg.conf, no changes made" fi -# # -# # -# Continue Working from here.... # -# # -# # -# # -# + # Ensure necessary directories exist for overlay and pivot_root /bin/echo "Creating new overlay system" - if [ ! -d /data/rootfs ]; then - mkdir -p /data/rootfs + if [ ! -d /usrdata/rootfs ]; then + mkdir -p /usrata/rootfs fi - if [ ! -d /data/rootfs-workdir ]; then - mkdir -p /data/rootfs-workdir + if [ ! -d /usrdata/rootfs-workdir ]; then + mkdir -p /usrdata/rootfs-workdir fi if [ ! -d /rootfs ]; then mkdir -p /rootfs fi # Mount the new overlay filesystem - /bin/mount -t overlay overlay -o lowerdir=/,upperdir=/data/rootfs,workdir=/data/rootfs-workdir /rootfs + /bin/mount -t overlay overlay -o lowerdir=/,upperdir=/usrdata/rootfs,workdir=/usrdata/rootfs-workdir /rootfs # Create the real_rootfs directory in the new root if [ ! -d /rootfs/real_rootfs ]; then @@ -211,31 +186,18 @@ handle_new_firmware() { /bin/mount --move /real_rootfs/tmp /tmp /bin/mount --move /real_rootfs/dev /dev /bin/mount --move /real_rootfs/firmware /firmware - /bin/mount --move /real_rootfs/persist /persist - /bin/mount --move /real_rootfs/cache /cache + /bin/mount --move /real_rootfs/usrdata /usrdata /bin/mount --move /real_rootfs/data /data + /bin/mount --move /real_rootfs/cache /cache + /bin/mount --move /real_rootfs/systemrw /systemrw + /bin/mount --move /real_rootfs/persist /persist - # Synchronize /etc/rc.d/ and /real_rootfs/etc/rc.d/ - /bin/echo "Synchronizing /etc/rc.d/ and /real_rootfs/etc/rc.d/" - for link in /etc/rc.d/*; do - if [ -L "$link" ]; then - link_name=$(basename "$link") - if [ ! -e "/real_rootfs/etc/rc.d/$link_name" ]; then - /bin/echo "Copying $link_name to /real_rootfs/etc/rc.d/" - cp -a "$link" "/real_rootfs/etc/rc.d/$link_name" - fi - fi - done - for link in /real_rootfs/etc/rc.d/*; do - if [ -L "$link" ]; then - link_name=$(basename "$link") - if [ ! -e "/etc/rc.d/$link_name" ]; then - /bin/echo "Removing $link_name from /real_rootfs/etc/rc.d/" - rm "/real_rootfs/etc/rc.d/$link_name" - fi - fi - done + # Synchronize between /etc/rc.d and /real_rootfs/etc/rc.d + synchronize_rc_d "/etc/rc.d" "/real_rootfs/etc/rc.d" + + # Synchronize between /etc/rc.d and /usrdata/etc/rc.d + synchronize_rc_d "/etc/rc.d" "/usrdata/etc/rc.d" # Final logs and remount the original root as read-only /bin/echo "...and we're back! The original root now lives at /real_rootfs" @@ -246,12 +208,56 @@ handle_new_firmware() { } -stop() { - # Redirect all output (stdout and stderr) to the log file - exec >>"$LOG_FILE" 2>&1 +synchronize_rc_d() { + local source_dir="$1" + local target_dir="$2" + + /bin/echo "Synchronizing $source_dir with $target_dir" + for link in "$source_dir"/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "$target_dir/$link_name" ]; then + /bin/echo "Copying $link_name to $target_dir" + cp -a "$link" "$target_dir/$link_name" + fi + fi + done + + for link in "$target_dir"/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "$source_dir/$link_name" ]; then + /bin/echo "Removing $link_name from $target_dir" + rm "$target_dir/$link_name" + fi + fi + done } -stop_handle_old_firmware() { +stop() { + # Initialize log + rm -f "$LOG_FILE" >/dev/null 2>&1 + touch "$LOG_FILE" + # Redirect all output (stdout and stderr) to the log file + exec >>"$LOG_FILE" 2>&1 + + # Check if /real_rootfs exists + if [ ! -d "/real_rootfs" ]; then + echo "Error: /real_rootfs does not exist. Cannot proceed with stop." >> "$LOG_FILE" + return 1 + fi + + # Determine firmware version based on mounts + if [ -d "/usrdata" ] && [ -d "/systemrw" ]; then + echo "New firmware scenario detected (with /usrdata and /systemrw)." >> "$LOG_FILE" + stop_handle_new_firmware + else + echo "Old firmware scenario detected (without /usrdata and /systemrw)." >> "$LOG_FILE" + stop_handle_old_firmware + fi +} + +stop_handle_new_firmware() { # Redirect all output (stdout and stderr) to the log file exec >>"$LOG_FILE" 2>&1 /bin/echo "Stopping and reverting overlay and pivot_root" @@ -265,15 +271,52 @@ stop_handle_old_firmware() { /bin/mount --move /tmp /real_rootfs/tmp /bin/mount --move /dev /real_rootfs/dev /bin/mount --move /firmware /real_rootfs/firmware - /bin/mount --move /persist /real_rootfs/persist - /bin/mount --move /cache /real_rootfs/cache + /bin/mount --move /usrdata /real_rootfs/usrdata /bin/mount --move /data /real_rootfs/data + /bin/mount --move /cache /real_rootfs/cache + /bin/mount --move /systemrw /real_rootfs/systemrw + /bin/mount --move /persist /real_rootfs/persist # Pivot root back to the original root /sbin/pivot_root /real_rootfs /real_rootfs/rootfs /bin/echo "Reverted pivot_root" - /bin/echo "Previous root overlay available at /rootfs" + + # Unmount /rootfs overlay + /bin/umount -lf /rootfs >/dev/null 2>&1 + + # Mount layer 2 /etc back + /bin/mount -t ubifs -o rw,relatime,bulk_read,assert=read-only,ubi=2,vol=0 /dev/ubi2_0 /etc + + # Mount layer 3 /etc back + /bin/mount -t overlay overlay -o lowerdir=/etc,upperdir=/usrdata/overlay-work/etc-upper,workdir=/usrdata/overlay-work/.etc-work /etc + df -h + echo -e "\e[31m / is read-write right now. Be careful\e[0m" + echo -e "\e[31m Reboot or run mount -o remount,ro / \e[0m" +} + +stop_handle_old_firmware() { + # Redirect all output (stdout and stderr) to the log file + exec >>"$LOG_FILE" 2>&1 + /bin/echo "Stopping and reverting overlay and pivot_root" + + # Remount the original root filesystem as read-write + /bin/mount -o remount,rw /real_rootfs + + # Move the mounted filesystems back to the original locations + /bin/mount --move /sys /real_rootfs/sys + /bin/mount --move /proc /real_rootfs/proc + /bin/mount --move /tmp /real_rootfs/tmp + /bin/mount --move /dev /real_rootfs/dev + /bin/mount --move /firmware /real_rootfs/firmware + /bin/mount --move /persist /real_rootfs/persist + /bin/mount --move /cache /real_rootfs/cache + /bin/mount --move /data /real_rootfs/data + + # Pivot root back to the original root + /sbin/pivot_root /real_rootfs /real_rootfs/rootfs + + /bin/echo "Reverted pivot_root" # Unmount /rootfs overlay /bin/umount -lf /rootfs >/dev/null 2>&1 @@ -282,15 +325,11 @@ stop_handle_old_firmware() { mount -t ubifs /dev/ubi0_3 /overlay # Mount the old overlay filesystem back for etc - /bin/mount -t overlay overlay -o lowerdir=/etc,upperdir=/overlay/etc-upper,workdir=/overlay/.etc-work /etc + /bin/mount -t overlay overlay -o lowerdir=/etc,upperdir=/overlay/etc-upper,workdir=/overlay/.etc-work /etc echo -e "\e[31m / is read-write right now. Be careful\e[0m" echo -e "\e[31m Reboot or run mount -o remount,ro / \e[0m" } - -stop_handle_new_firmware() { - # Redirect all output (stdout and stderr) to the log file - exec >>"$LOG_FILE" 2>&1 } restart() { diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/bin/inotifywait b/ipk-source/sdxpinn-mount-fix/root/usr/bin/inotifywait old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/inotifywait.postinst b/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/inotifywait.postinst old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/inotifywait.prerm b/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/inotifywait.prerm old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.control b/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.control old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.list b/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.list old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.postinst b/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.postinst old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.prerm b/ipk-source/sdxpinn-mount-fix/root/usr/lib/opkg/info/libinotifytools.prerm old mode 100644 new mode 100755 diff --git a/ipk-source/sdxpinn-mount-fix/root/usr/sbin/init-overlay-watchdog.sh b/ipk-source/sdxpinn-mount-fix/root/usr/sbin/init-overlay-watchdog.sh old mode 100644 new mode 100755 index 92a8d02..ca79d39 --- a/ipk-source/sdxpinn-mount-fix/root/usr/sbin/init-overlay-watchdog.sh +++ b/ipk-source/sdxpinn-mount-fix/root/usr/sbin/init-overlay-watchdog.sh @@ -2,30 +2,57 @@ # Paths to monitor and synchronize WATCH_DIR="/etc/rc.d" -TARGET_DIR="/real_rootfs/etc/rc.d" +TARGET_DIR1="/real_rootfs/etc/rc.d" +TARGET_DIR2="/usrdata/etc/rc.d" # Function to synchronize init scripts synchronize_init_scripts() { + # Ensure /real_rootfs is writable for updates mount -o remount,rw /real_rootfs - # Copy new or updated symlinks from WATCH_DIR to TARGET_DIR + + # Synchronize with TARGET_DIR1 + echo "Synchronizing $WATCH_DIR with $TARGET_DIR1..." for link in "$WATCH_DIR"/*; do if [ -L "$link" ]; then link_name=$(basename "$link") - if [ ! -e "$TARGET_DIR/$link_name" ] || [ "$link" -nt "$TARGET_DIR/$link_name" ]; then - cp -af "$link" "$TARGET_DIR/$link_name" + if [ ! -e "$TARGET_DIR1/$link_name" ] || [ "$link" -nt "$TARGET_DIR1/$link_name" ]; then + cp -af "$link" "$TARGET_DIR1/$link_name" fi fi done - # Remove symlinks in TARGET_DIR that no longer exist in WATCH_DIR - for link in "$TARGET_DIR"/*; do + for link in "$TARGET_DIR1"/*; do if [ -L "$link" ]; then link_name=$(basename "$link") if [ ! -e "$WATCH_DIR/$link_name" ]; then - rm -f "$TARGET_DIR/$link_name" + rm -f "$TARGET_DIR1/$link_name" fi fi done + + # Synchronize with TARGET_DIR2 if /usrdata exists + if [ -d "/usrdata" ]; then + echo "Synchronizing $WATCH_DIR with $TARGET_DIR2..." + for link in "$WATCH_DIR"/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "$TARGET_DIR2/$link_name" ] || [ "$link" -nt "$TARGET_DIR2/$link_name" ]; then + cp -af "$link" "$TARGET_DIR2/$link_name" + fi + fi + done + + for link in "$TARGET_DIR2"/*; do + if [ -L "$link" ]; then + link_name=$(basename "$link") + if [ ! -e "$WATCH_DIR/$link_name" ]; then + rm -f "$TARGET_DIR2/$link_name" + fi + fi + done + fi + + # Restore /real_rootfs to read-only mount -o remount,ro /real_rootfs } @@ -37,3 +64,4 @@ while true; do inotifywait -e create,delete,modify,move "$WATCH_DIR" synchronize_init_scripts done + diff --git a/ipk-source/sdxpinn-mount-fix/sdxpinn-mount-fix_1.2.0_aarch64_cortex-a53.ipk b/ipk-source/sdxpinn-mount-fix/sdxpinn-mount-fix_1.2.0_aarch64_cortex-a53.ipk new file mode 100644 index 0000000..3ca710e Binary files /dev/null and b/ipk-source/sdxpinn-mount-fix/sdxpinn-mount-fix_1.2.0_aarch64_cortex-a53.ipk differ