2022-09-16 21:13:51 +00:00
|
|
|
#!/bin/bash
|
2023-10-23 22:44:47 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2023-10-24 16:00:57 +00:00
|
|
|
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
2022-09-16 21:13:51 +00:00
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
. /etc/os-release
|
|
|
|
|
|
|
|
UPDATE_ROOT="/storage/.update"
|
2022-09-23 10:41:45 +00:00
|
|
|
MOUNT_GAMES=$(get_setting system.automount)
|
2022-09-16 21:13:51 +00:00
|
|
|
GAMES_DEVICE=$(get_setting system.gamesdevice)
|
2023-11-27 22:41:15 +00:00
|
|
|
MOUNT_PATH="/storage/games-external"
|
2023-11-28 02:29:06 +00:00
|
|
|
OVERLAY_PATH="/storage/roms"
|
2022-09-16 21:13:51 +00:00
|
|
|
|
2022-09-25 22:22:32 +00:00
|
|
|
if [[ ! "${MOUNT_GAMES}" =~ [0-9] ]]
|
2022-09-23 10:41:45 +00:00
|
|
|
then
|
|
|
|
set_setting system.automount 1
|
|
|
|
elif [[ "${MOUNT_GAMES}" == "0" ]]
|
|
|
|
then
|
2023-11-28 02:55:11 +00:00
|
|
|
systemctl enable storage-roms.mount >/dev/null 2>&1
|
|
|
|
systemctl start storage-roms.mount >/dev/null 2>&1
|
2022-09-23 10:41:45 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-05-02 10:55:33 +00:00
|
|
|
load_modules() {
|
2023-07-05 18:47:07 +00:00
|
|
|
for MODULE in exfat vfat
|
2023-05-02 10:55:33 +00:00
|
|
|
do
|
|
|
|
lsmod | grep ${MODULE} 2>/dev/null
|
|
|
|
if [ ! $? = 0 ]
|
|
|
|
then
|
|
|
|
modprobe ${MODULE} 2>/dev/null
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-09-16 21:13:51 +00:00
|
|
|
mount_games() {
|
2023-11-28 02:29:06 +00:00
|
|
|
FSTYPE=$(blkid -o export ${1} | awk 'BEGIN {FS="="} /TYPE/ {print $2}')
|
|
|
|
case ${FSTYPE} in
|
|
|
|
ext4)
|
|
|
|
ENABLE_OVERLAY=true
|
|
|
|
if [ -e "/storage/.overlay_unsupported" ]
|
|
|
|
then
|
|
|
|
rm -f /storage/.overlay_unsupported
|
|
|
|
fi
|
|
|
|
touch /storage/.overlay_supported
|
|
|
|
set_setting system.merged.storage 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
systemctl stop storage-roms.mount >/dev/null 2>&1
|
|
|
|
systemctl disable storage-roms.mount >/dev/null 2>&1
|
|
|
|
MOUNT_PATH=${OVERLAY_PATH}
|
|
|
|
if [ -e "/storage/.overlay_supported" ]
|
|
|
|
then
|
|
|
|
rm -f /storage/.overlay_supported
|
|
|
|
fi
|
|
|
|
touch /storage/.overlay_unsupported
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ ! -d "${MOUNT_PATH}" ]
|
|
|
|
then
|
|
|
|
/usr/bin/busybox mkdir -p ${MOUNT_PATH} >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
2022-09-26 11:47:48 +00:00
|
|
|
NULL=$(cat /proc/mounts | grep -v -e "/var/media" 2>/dev/null | grep ${1})
|
|
|
|
if [ ! "$?" = "0" ] && \
|
|
|
|
[ -e "${1}" ] && \
|
2022-09-26 11:49:27 +00:00
|
|
|
[ ! -e "/storage/.please_resize_me" ]
|
2022-09-16 21:13:51 +00:00
|
|
|
then
|
2023-09-06 23:49:20 +00:00
|
|
|
### Udevil shouldn't mount it this early, but just in-case.
|
2023-11-28 02:29:06 +00:00
|
|
|
umount /var/media/* 2>/dev/null
|
2023-09-06 23:49:20 +00:00
|
|
|
log $0 "FSCK ${1}"
|
|
|
|
fsck -Mly ${1}
|
2023-11-27 22:41:15 +00:00
|
|
|
log $0 "Mounting ${1} on ${MOUNT_PATH}"
|
|
|
|
/usr/bin/busybox mount ${1} ${MOUNT_PATH} >/dev/null 2>&1
|
2023-11-28 02:29:06 +00:00
|
|
|
if [ "${ENABLE_OVERLAY}" = true ]
|
|
|
|
then
|
|
|
|
systemctl enable storage-roms.mount >/dev/null 2>&1
|
2023-11-28 02:55:11 +00:00
|
|
|
systemctl restart storage-roms.mount >/dev/null 2>&1
|
2023-11-28 02:29:06 +00:00
|
|
|
fi
|
2022-09-16 21:13:51 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
find_games() {
|
|
|
|
if /usr/bin/busybox mountpoint -q /storage ; then
|
|
|
|
|
2023-07-05 18:47:07 +00:00
|
|
|
for DEV in $(for dev in mmcblk[0-9] sd[a-z] nvme[0-9]; do blkid | grep ${dev} | awk 'BEGIN {FS=":"}; /ext4/ || /fat/ {print $1}' | sort -r; done)
|
2022-09-16 21:13:51 +00:00
|
|
|
do
|
|
|
|
ROOTDEV=$(echo ${DEV} | sed -e "s#^/.*/##g" -e "s#p[0-9].*\$##g")
|
2022-10-14 20:51:45 +00:00
|
|
|
SIZE=$(awk '/'${ROOTDEV}'$/ {print $3}' /proc/partitions)
|
|
|
|
if (( ${SIZE} <= 8388608 ))
|
2022-09-16 21:13:51 +00:00
|
|
|
then
|
2023-01-20 02:30:33 +00:00
|
|
|
log $0 "Device ${ROOTDEV} is too small, ignoring."
|
2022-09-16 21:13:51 +00:00
|
|
|
# We don't want to mount partitions smaller than ~8GB.
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ -L "/sys/class/block/${ROOTDEV}boot0" ]
|
|
|
|
then
|
2023-01-20 02:30:33 +00:00
|
|
|
log $0 "Device ${ROOTDEV} might be Android, ignoring."
|
2022-09-16 21:13:51 +00:00
|
|
|
# Assume this is an android boot device and ignore it.
|
|
|
|
continue
|
|
|
|
fi
|
2022-09-25 22:22:32 +00:00
|
|
|
# Udevil might mount it, and we shouldn't care if it does.
|
2022-09-26 11:47:48 +00:00
|
|
|
NULL=$(cat /proc/mounts | grep -v -e "/var/media" 2>/dev/null | grep ${DEV})
|
|
|
|
if [ ! "$?" = "0" ] && \
|
|
|
|
[ -e "${DEV}" ] && \
|
2022-09-26 11:49:27 +00:00
|
|
|
[ ! -e "/storage/.please_resize_me" ]
|
2022-09-16 21:13:51 +00:00
|
|
|
then
|
|
|
|
GAMES_DEVICE=${DEV}
|
|
|
|
mount_games "${DEV}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-02 10:55:33 +00:00
|
|
|
load_modules
|
|
|
|
|
2022-09-16 21:13:51 +00:00
|
|
|
if [ -e "${GAMES_DEVICE}" ]
|
|
|
|
then
|
|
|
|
mount_games ${GAMES_DEVICE}
|
|
|
|
else
|
|
|
|
find_games
|
|
|
|
fi
|