Create rc_sync

- Added a executable that can be called upon manually to ensure rc.d stays in sync with the orginal.
This commit is contained in:
Cameron Thompson
2025-01-20 15:37:56 -05:00
parent 8fcbbbb6b2
commit 429d34d48a

View File

@@ -0,0 +1,62 @@
#!/bin/ash
# Paths to monitor and synchronize
WATCH_DIR="/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
# 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_DIR1/$link_name" ] || [ "$link" -nt "$TARGET_DIR1/$link_name" ]; then
cp -af "$link" "$TARGET_DIR1/$link_name"
fi
fi
done
for link in "$TARGET_DIR1"/*; do
if [ -L "$link" ]; then
link_name=$(basename "$link")
if [ ! -e "$WATCH_DIR/$link_name" ]; then
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
}
# Synchronization
synchronize_init_scripts
exit 0