distribution/packages/jelos/sources/scripts/automount

92 lines
2.4 KiB
Text
Raw Normal View History

#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2020 Fewtarius (https://github.com/fewtarius)
. /etc/profile
. /etc/os-release
UPDATE_ROOT="/storage/.update"
MOUNT_GAMES=$(get_setting system.automount)
GAMES_DEVICE=$(get_setting system.gamesdevice)
2022-09-25 22:22:32 +00:00
if [[ ! "${MOUNT_GAMES}" =~ [0-9] ]]
then
set_setting system.automount 1
elif [[ "${MOUNT_GAMES}" == "0" ]]
then
exit 0
fi
load_modules() {
for MODULE in exfat vfat
do
lsmod | grep ${MODULE} 2>/dev/null
if [ ! $? = 0 ]
then
modprobe ${MODULE} 2>/dev/null
fi
done
}
mount_games() {
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" ]
then
### Udevil shouldn't mount it this early, but just in-case.
umount /var/media/*
log $0 "FSCK ${1}"
fsck -Mly ${1}
log $0 "Mounting ${1} on /storage/roms"
/usr/bin/busybox mount ${1} /storage/roms >/dev/null 2>&1
/usr/bin/systemd-tmpfiles --create /usr/lib/tmpfiles.d/JELOS-system-dirs.conf >/dev/null 2>&1
fi
}
find_games() {
if /usr/bin/busybox mountpoint -q /storage ; then
if [ ! -d "/storage/roms" ]
then
/usr/bin/busybox mkdir -p /storage/roms >/dev/null 2>&1
fi
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)
do
ROOTDEV=$(echo ${DEV} | sed -e "s#^/.*/##g" -e "s#p[0-9].*\$##g")
SIZE=$(awk '/'${ROOTDEV}'$/ {print $3}' /proc/partitions)
if (( ${SIZE} <= 8388608 ))
then
log $0 "Device ${ROOTDEV} is too small, ignoring."
# We don't want to mount partitions smaller than ~8GB.
continue
fi
if [ -L "/sys/class/block/${ROOTDEV}boot0" ]
then
log $0 "Device ${ROOTDEV} might be Android, ignoring."
# 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" ]
then
GAMES_DEVICE=${DEV}
mount_games "${DEV}"
break
fi
done
fi
}
load_modules
if [ -e "${GAMES_DEVICE}" ]
then
mount_games ${GAMES_DEVICE}
else
find_games
fi