#!/bin/ash

# Enable and start the services
echo "Starting and enabling services..."
service mount-fix enable
service mount-fix-final enable

if grep -qs '/usrdata' /proc/mounts; then
    echo "/usrdata is mounted. Enabling at /usrdata..."
    cp -P /etc/rc.d/S03mount-fix /usrdata/etc/rc.d/S03mount-fix
	rm /usrdata/overlay-work/etc-upper/rc.d/S03mount-fix
	cp -P /etc/rc.d/S03mount-fix /usrdata/overlay-work/etc-upper/rc.d/S03mount-fix
    cp -P /etc/rc.d/S04mount-fix-final /usrdata/etc/rc.d/S04mount-fix-final
	rm /usrdata/overlay-work/etc-upper/rc.d/S04mount-fix-final
	cp -P /etc/rc.d/S04mount-fix-final /usrdata/overlay-work/etc-upper/rc.d/S04mount-fix-final
fi

service mount-fix start
service mount-fix enable
service mount-fix-final enable

echo -e "\e[32m sdxpinn-mount-fix installed! Here is the new file structure! \e[0m"
echo -e "\e[32m ============================================================ \e[0m"
mount && df -h
echo -e "\e[32m ============================================================ \e[0m"
echo -e "\e[32m sdxpinn-mount-fix installed! New file structure above! \e[0m"

exit 0

