From 73b7b358e83704fa8c394d58b3389ca401adfe3f Mon Sep 17 00:00:00 2001 From: fewtarius Date: Mon, 27 Nov 2023 22:41:15 +0000 Subject: [PATCH] Feature: Use overlayfs to merge internal and external storage into /storage/roms. * Creates a new directory structure for games: * Internal Storage (or tf1): /storage/games-internal * External MicroSD: /storage/games-external * Combined Path: /storage/roms * Games copied to /storage/roms will be saved to /storage/games-internal. * Samba has been updated to present both volumes for network access. * EmulationStation now has an eject option under System Settings -> Hardware /Storage. * When a compatible microsd is inserted, JELOS will automatically add it to the overlay, making the content available to ES after a gamelist update or an ES restart. * Udevil will no longer mount microsd cards to /run/media, however it will still handle mounting all other external storage. * After the update, JELOS will automatically migrate your current roms directory once. * Additionally the hotkey management feature has moved from System Settings to Controller and Bluetooth Settings. * The rom split tool is now deprecated as it is no longer needed. --- .../devices/Anbernic RG351M/001-device_config | 2 +- .../001-device_config | 1 + .../ODROID-GO Advance/001-device_config | 2 +- .../devices/ODROID-GO Super/001-device_config | 1 + packages/hardware/quirks/profile.d/999-export | 1 + packages/jelos/sources/post-update | 20 +++++ packages/jelos/sources/scripts/automount | 9 ++- .../jelos/sources/scripts/rom_system_split | 76 ------------------- packages/network/samba/config/smb.conf | 10 ++- packages/sysutils/udevil/config/udevil.conf | 2 +- .../udevil/udev.d/95-udevil-mount.rules | 8 +- packages/ui/emulationstation/package.mk | 2 +- packages/virtual/emulators/package.mk | 4 + .../emulators/system.d/storage-roms.mount | 14 ++++ .../emulators/tmpfiles.d/jelos-dirs.conf | 3 + .../emulators/udev.d/99-automount.rules | 21 +++++ 16 files changed, 86 insertions(+), 90 deletions(-) delete mode 100755 packages/jelos/sources/scripts/rom_system_split create mode 100644 packages/virtual/emulators/system.d/storage-roms.mount create mode 100644 packages/virtual/emulators/udev.d/99-automount.rules diff --git a/packages/hardware/quirks/devices/Anbernic RG351M/001-device_config b/packages/hardware/quirks/devices/Anbernic RG351M/001-device_config index b47379e97..161fa2c34 100644 --- a/packages/hardware/quirks/devices/Anbernic RG351M/001-device_config +++ b/packages/hardware/quirks/devices/Anbernic RG351M/001-device_config @@ -13,5 +13,5 @@ DEVICE_VOLUME="100" DEVICE_BATTERY_LED_STATUS="true" DEVICE_PWR_LED_GPIO="77" DEVICE_TEMP_SENSOR="/sys/devices/virtual/thermal/thermal_zone0/temp" - +DEVICE_MMC_EJECT="false" EOF diff --git a/packages/hardware/quirks/devices/ODROID-GO Advance Black Edition/001-device_config b/packages/hardware/quirks/devices/ODROID-GO Advance Black Edition/001-device_config index 7621a4d00..ca36d07df 100644 --- a/packages/hardware/quirks/devices/ODROID-GO Advance Black Edition/001-device_config +++ b/packages/hardware/quirks/devices/ODROID-GO Advance Black Edition/001-device_config @@ -10,4 +10,5 @@ DEVICE_SW_HP_SWITCH="true" DEVICE_PLAYBACK_PATH_SPK="SPK" DEVICE_PLAYBACK_PATH_HP="HP" DEVICE_BRIGHTNESS="128" +DEVICE_MMC_EJECT="false" EOF diff --git a/packages/hardware/quirks/devices/ODROID-GO Advance/001-device_config b/packages/hardware/quirks/devices/ODROID-GO Advance/001-device_config index 9bd46c657..b0a30ac3c 100644 --- a/packages/hardware/quirks/devices/ODROID-GO Advance/001-device_config +++ b/packages/hardware/quirks/devices/ODROID-GO Advance/001-device_config @@ -14,5 +14,5 @@ DEVICE_VOLUME="100" DEVICE_BATTERY_LED_STATUS="true" DEVICE_PWR_LED_GPIO="77" DEVICE_TEMP_SENSOR="/sys/devices/virtual/thermal/thermal_zone0/temp" - +DEVICE_MMC_EJECT="false" EOF diff --git a/packages/hardware/quirks/devices/ODROID-GO Super/001-device_config b/packages/hardware/quirks/devices/ODROID-GO Super/001-device_config index 5f3794c28..cdf836298 100644 --- a/packages/hardware/quirks/devices/ODROID-GO Super/001-device_config +++ b/packages/hardware/quirks/devices/ODROID-GO Super/001-device_config @@ -9,4 +9,5 @@ DEVICE_POWER_LED="false" DEVICE_PLAYBACK_PATH_SPK="SPK" DEVICE_PLAYBACK_PATH_HP="HP" DEVICE_BRIGHTNESS="128" +DEVICE_MMC_EJECT="false" EOF diff --git a/packages/hardware/quirks/profile.d/999-export b/packages/hardware/quirks/profile.d/999-export index 7cc4fc629..95433c38e 100755 --- a/packages/hardware/quirks/profile.d/999-export +++ b/packages/hardware/quirks/profile.d/999-export @@ -26,6 +26,7 @@ export SLOW_CORES \ DEVICE_KEY_VOLUMEUP \ DEVICE_LED_BRIGHTNESS \ DEVICE_LED_CONTROL \ + DEVICE_MMC_EJECT \ DEVICE_PIPEWIRE_PROFILE \ DEVICE_PWR_LED_CONTROL \ DEVICE_PWR_LED_GPIO \ diff --git a/packages/jelos/sources/post-update b/packages/jelos/sources/post-update index 9cccee80f..6295e920f 100644 --- a/packages/jelos/sources/post-update +++ b/packages/jelos/sources/post-update @@ -73,6 +73,26 @@ sed -i 's~"pulse"~"alsathread"~g' /storage/.config/retroarch/retroarch.cfg ### 20231114 - Update hosts.conf grep "127.0.0.1" /storage/.config/hosts.conf >/dev/null 2>&1 || cp /usr/config/hosts.conf /storage/.config/ +### 20231127 - Migrate games to overlayfs +systemctl stop storage-roms.mount +GAMECOUNT=$(find /storage/roms -type f | wc -l) +if [ "${GAMECOUNT}" -gt 20 ] && \ + [ ! -e "/storage/.migrated_games" ] +then + echo "Migrating games to overlayfs" >>${LOG} + if [ -d "/storage/games-internal" ] + then + echo "Backing up games-internal" >>${LOG} + mv /storage/games-internal /storage/games-internal.backup + fi + mv /storage/roms /storage/games-internal + mkdir /storage/roms + touch /storage/.migrated_games +else + echo "Game weight too low (${GAMECOUNT}) or content already migrated." >>${LOG} +fi +systemctl start storage-roms.mount + ### Items below this line should not be removed. tocon "Update complete, rebooting..." reboot diff --git a/packages/jelos/sources/scripts/automount b/packages/jelos/sources/scripts/automount index ed9a646ee..b1479ed27 100755 --- a/packages/jelos/sources/scripts/automount +++ b/packages/jelos/sources/scripts/automount @@ -8,6 +8,7 @@ UPDATE_ROOT="/storage/.update" MOUNT_GAMES=$(get_setting system.automount) GAMES_DEVICE=$(get_setting system.gamesdevice) +MOUNT_PATH="/storage/games-external" if [[ ! "${MOUNT_GAMES}" =~ [0-9] ]] then @@ -38,17 +39,17 @@ mount_games() { 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 + log $0 "Mounting ${1} on ${MOUNT_PATH}" + /usr/bin/busybox mount ${1} ${MOUNT_PATH} >/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" ] + if [ ! -d "${MOUNT_PATH}" ] then - /usr/bin/busybox mkdir -p /storage/roms >/dev/null 2>&1 + /usr/bin/busybox mkdir -p ${MOUNT_PATH} >/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) diff --git a/packages/jelos/sources/scripts/rom_system_split b/packages/jelos/sources/scripts/rom_system_split deleted file mode 100755 index a52869337..000000000 --- a/packages/jelos/sources/scripts/rom_system_split +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -# rom_system_split: split your roms across your local and external storage - -# prerequesites: -# - local roms must be stored in "/storage/roms_local" -# - external roms must be stored in "/storage/roms" -# - you cannot spread the same system files across multiple locations -# NOTE: if duplicate systems are found, local folders will take preference - -LOCAL_FOLDER_NAME="roms_local" -EXT_FOLDER_NAME="roms" - -LOCAL_ROM_FOLDERS=$( - ls -d ${LOCAL_FOLDER_NAME}/*/ | - sed -e "s/${LOCAL_FOLDER_NAME}//g" -) -EXT_ROM_FOLDERS=$( - ls -d ${EXT_FOLDER_NAME}/*/ | - sed -e "s/${EXT_FOLDER_NAME}//g" -) - -ES_SYSTEMS="/storage/.emulationstation/es_systems.cfg" - -ES_LIST=$( - cat ${ES_SYSTEMS} | - grep "" | - sed -e "s///g" -e "s/<\/path>//g" -e "s/\/storage\///g" -) - - -echo "LOCAL_FOLDER_NAME: ${LOCAL_FOLDER_NAME}" -echo "EXT_FOLDER_NAME: ${EXT_FOLDER_NAME}" -echo "EXT_STORAGE: ${EXT_STORAGE}" -echo "EXTERNAL: ${EXTERNAL}" -echo "LOCAL_ROM_FOLDERS: $LOCAL_ROM_FOLDERS{}" -echo "EXT_ROM_FOLDERS: ${EXT_ROM_FOLDERS}" -echo "ES_SYSTEMS: ${ES_SYSTEMS}" -echo "ES_LIST: ${ES_LIST}" - - -# required paramaters: local/external, rom folder list, es folder list -update_es_folders() { - folder_name=${LOCAL_FOLDER_NAME} - orig_folder_name=${EXT_FOLDER_NAME} - if [[ $1 == "external" ]] - then - folder_name=${EXT_FOLDER_NAME} - orig_folder_name=${LOCAL_FOLDER_NAME} - fi - folder_array=( $2 ) - for folder in ${folder_array[@]} - do - system=${folder%?} - # check that the system exists in ES - if [[ $3 == *"${system}"* ]] - then - # skip if there are no files in the folder - if [ -z "$(ls -A /storage/${folder_name}${system})" ] - then - continue - fi - # if the folder doesn't exist in ES, update the original - if [[ $3 != *"${folder_name}${system}"* ]] - then - sed -i -e "s|/storage/${orig_folder_name}${system}|/storage/${folder_name}${system}|g" ${ES_SYSTEMS} - fi - fi - done -} - -# check the external folders first -update_es_folders "external" "${EXT_ROM_FOLDERS}" "${ES_LIST}" -# next check the local folders -# if there are duplicate folders in EXTERNAL, LOCAL ones will take preference -update_es_folders "local" "${LOCAL_ROM_FOLDERS}" "${ES_LIST}" diff --git a/packages/network/samba/config/smb.conf b/packages/network/samba/config/smb.conf index b85887629..f8c85aa61 100644 --- a/packages/network/samba/config/smb.conf +++ b/packages/network/samba/config/smb.conf @@ -55,8 +55,14 @@ browseable = yes writeable = yes -[roms] - path = /storage/roms +[games-internal] + path = /storage/games-internal + available = yes + browseable = yes + writeable = yes + +[games-external] + path = /storage/games-external available = yes browseable = yes writeable = yes diff --git a/packages/sysutils/udevil/config/udevil.conf b/packages/sysutils/udevil/config/udevil.conf index a36411687..99d6e29fe 100644 --- a/packages/sysutils/udevil/config/udevil.conf +++ b/packages/sysutils/udevil/config/udevil.conf @@ -119,7 +119,7 @@ allowed_media_dirs = /var/media, /media, /run/media/$USER # allowed_devices = /dev/* # WARNING: ALLOWING USERS TO MOUNT DEVICES OUTSIDE OF /dev CAN CAUSE SERIOUS # SECURITY PROBLEMS. DO NOT ALLOW DEVICES IN /dev/shm -allowed_devices = /dev/* +allowed_devices = /dev/sd* /dev/nvme* # allowed_internal_devices causes udevil to treat any listed block devices as diff --git a/packages/sysutils/udevil/udev.d/95-udevil-mount.rules b/packages/sysutils/udevil/udev.d/95-udevil-mount.rules index 64065d04b..ddf15659b 100644 --- a/packages/sysutils/udevil/udev.d/95-udevil-mount.rules +++ b/packages/sysutils/udevil/udev.d/95-udevil-mount.rules @@ -2,15 +2,15 @@ IMPORT{cmdline}="installer" ENV{installer}=="1", GOTO="exit" -# check for blockdevices, /dev/sd*, /dev/sr* and /dev/mmc* -SUBSYSTEM!="block", KERNEL!="sd*|sr*|mmc*", GOTO="exit" +# check for blockdevices, /dev/sd*, /dev/sr* +SUBSYSTEM!="block", KERNEL!="sd*|sr*", GOTO="exit" # check for special partitions we dont want mount IMPORT{builtin}="blkid" ENV{ID_FS_LABEL}=="EFI|BOOT|Recovery|RECOVERY|SETTINGS|boot|root0|share0", GOTO="exit" -# /dev/sd* and /dev/mmc* ith partitions/disk and filesystems only and /dev/sr* disks only -KERNEL=="sd*|mmc*", ENV{DEVTYPE}=="partition|disk", ENV{ID_FS_USAGE}=="filesystem", GOTO="harddisk" +# /dev/sd* with partitions/disk and filesystems only and /dev/sr* disks only +KERNEL=="sd*", ENV{DEVTYPE}=="partition|disk", ENV{ID_FS_USAGE}=="filesystem", GOTO="harddisk" KERNEL=="sr*", ENV{DEVTYPE}=="disk", GOTO="optical" GOTO="exit" diff --git a/packages/ui/emulationstation/package.mk b/packages/ui/emulationstation/package.mk index 5c1933428..23252fbe5 100644 --- a/packages/ui/emulationstation/package.mk +++ b/packages/ui/emulationstation/package.mk @@ -3,7 +3,7 @@ # Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS) PKG_NAME="emulationstation" -PKG_VERSION="6c712ff" +PKG_VERSION="0dffaea" PKG_GIT_CLONE_BRANCH="main" PKG_REV="1" PKG_ARCH="any" diff --git a/packages/virtual/emulators/package.mk b/packages/virtual/emulators/package.mk index 2bd004480..64b31f902 100644 --- a/packages/virtual/emulators/package.mk +++ b/packages/virtual/emulators/package.mk @@ -1235,3 +1235,7 @@ makeinstall_target() { cp ${PKG_DIR}/autostart/* ${INSTALL}/usr/lib/autostart/common chmod 0755 ${INSTALL}/usr/lib/autostart/common/* } + +post_install() { + enable_service storage-roms.mount +} diff --git a/packages/virtual/emulators/system.d/storage-roms.mount b/packages/virtual/emulators/system.d/storage-roms.mount new file mode 100644 index 000000000..948511251 --- /dev/null +++ b/packages/virtual/emulators/system.d/storage-roms.mount @@ -0,0 +1,14 @@ +[Unit] +Description=Overlays directory +After=systemd-tmpfiles-setup.service +Before=jelos-automount.service +DefaultDependencies=no + +[Mount] +What=none +Where=/storage/roms +Type=overlay +Options=lowerdir=/storage/games-external,upperdir=/storage/games-internal,workdir=/storage/.tmp/games-workdir + +[Install] +WantedBy=jelos.target diff --git a/packages/virtual/emulators/tmpfiles.d/jelos-dirs.conf b/packages/virtual/emulators/tmpfiles.d/jelos-dirs.conf index 81f731a36..80cb02100 100644 --- a/packages/virtual/emulators/tmpfiles.d/jelos-dirs.conf +++ b/packages/virtual/emulators/tmpfiles.d/jelos-dirs.conf @@ -2,5 +2,8 @@ # Copyright (C) 2021-present 351ELEC (https://github.com/351ELEC) # Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS) +d /storage/.tmp/games-workdir 0777 root root - - +d /storage/games-internal 0777 root root - - +d /storage/games-external 0777 root root - - d /storage/roms 0777 root root - - d /tmp/cache 0777 root root - - diff --git a/packages/virtual/emulators/udev.d/99-automount.rules b/packages/virtual/emulators/udev.d/99-automount.rules new file mode 100644 index 000000000..f35013ded --- /dev/null +++ b/packages/virtual/emulators/udev.d/99-automount.rules @@ -0,0 +1,21 @@ +# dont run in "installer" mode +IMPORT{cmdline}="installer" +ENV{installer}=="1", GOTO="exit" + +SUBSYSTEM!="block", KERNEL!="mmc*", GOTO="exit" + +# check for special partitions we dont want mount +IMPORT{builtin}="blkid" +ENV{ID_FS_LABEL}=="EFI|BOOT|Recovery|RECOVERY|SETTINGS|boot|root0|share0", GOTO="exit" + +# /dev/mmc* partitions/disk and filesystems only +KERNEL=="mmc*", ENV{DEVTYPE}=="partition|disk", ENV{ID_FS_USAGE}=="filesystem", GOTO="harddisk" +GOTO="exit" + +# mount or umount for hdds +LABEL="harddisk" +ACTION=="add", PROGRAM="/usr/bin/sh -c '/usr/bin/grep -E ^/dev/%k\ /proc/mounts || true'", RESULT=="", RUN+="/usr/bin/systemctl stop storage-roms.mount", RUN+="/usr/bin/systemctl restart jelos-automount.service", RUN+="/usr/bin/systemctl start storage-roms.mount" +GOTO="exit" + +# Exit +LABEL="exit"