diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c58c9d..fd6ab4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # GameVault Backend Server Changelog +## 11.0.2 + +Recommended Gamevault App Version: `v1.8.2.0` or `v1.9.0.0` + +### Changes + +- Moved folder-checks to entrypoint to avoid permissions issues. + ## 11.0.1 Recommended Gamevault App Version: `v1.8.2.0` or `v1.9.0.0` diff --git a/entrypoint.sh b/entrypoint.sh index 69c2ecc..cfc21d5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,11 +1,38 @@ #!/bin/sh set -e -# If running as root, it means the --user directive for Docker CLI/Compose was not used -# Use then the PUID env +# Function to create a directory if it does not exist and set the proper ownership +createDirectoryIfNotExist() { + if [ ! -d "$1" ]; then + echo "Directory \"$1\" does not exist. Trying to create a new one..." + sudo mkdir -p "$1" + sudo chown "$PUID":"$PGID" "$1" + fi +} + +# Check and create necessary folders if they do not exist +check_folders() { + if [ "$MOCK_FILES" = "true" ]; then + echo "Not checking or creating any folders because MOCK_FILES is set to true" + return + fi + + createDirectoryIfNotExist "$FILES_VOLUME" + createDirectoryIfNotExist "$IMAGES_VOLUME" + createDirectoryIfNotExist "$LOGS_VOLUME" + createDirectoryIfNotExist "$SQLITEDB_VOLUME" +} + +# Perform directory checks +check_folders + +# Existing logic for user permissions and running the node process if [ "$(id -u)" = '0' ]; then groupmod -o -g "$PGID" node usermod -o -u "$PUID" node + # Ensure that all specified directories are owned by the node user + sudo chown -R "$PUID":"$PGID" "$FILES_VOLUME" "$IMAGES_VOLUME" "$LOGS_VOLUME" "$SQLITEDB_VOLUME" + # Execute the command as the node user sudo -u "#$PUID" -g "#$PGID" -E node "${@}" else # if using the user directive, run normally exec node "${@}" diff --git a/package.json b/package.json index 1543b30..de75d70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gamevault-backend", - "version": "11.0.1", + "version": "11.0.2", "description": "the self-hosted gaming platform for drm-free games", "author": "Alkan Alper, Schäfer Philip GbR / Phalcode", "private": true, diff --git a/src/modules/files/files.service.ts b/src/modules/files/files.service.ts index f3bb2f8..d5db3d9 100644 --- a/src/modules/files/files.service.ts +++ b/src/modules/files/files.service.ts @@ -27,7 +27,7 @@ import { watch } from "chokidar"; import { debounce } from "lodash"; import { Readable } from "stream"; import { Throttle } from "stream-throttle"; -import { mkdir, readdir, stat } from "fs/promises"; +import { readdir, stat } from "fs/promises"; import { Cron } from "@nestjs/schedule"; @Injectable() @@ -41,7 +41,6 @@ export class FilesService implements OnApplicationBootstrap { ) {} onApplicationBootstrap() { - this.checkFolders(); this.index("Initial indexing on application start").catch((error) => { this.logger.error(error, "Error in initial file indexing"); }); @@ -550,52 +549,4 @@ export class FilesService implements OnApplicationBootstrap { type, }); } - - /** Checks and creates necessary folders if they do not exist. */ - private checkFolders() { - if (configuration.TESTING.MOCK_FILES) { - this.logger.warn( - "Not checking or creating any folders because TESTING_MOCK_FILES is set to true", - ); - return; - } - - this.createDirectoryIfNotExist( - configuration.VOLUMES.FILES, - `Directory "${configuration.VOLUMES.FILES}" does not exist. Trying to create a new one...`, - ); - - this.createDirectoryIfNotExist( - configuration.VOLUMES.IMAGES, - `Directory "${configuration.VOLUMES.IMAGES}" does not exist. Trying to create a new one...`, - ); - - if (configuration.SERVER.LOG_FILES_ENABLED) { - this.createDirectoryIfNotExist( - configuration.VOLUMES.LOGS, - `Directory "${configuration.VOLUMES.LOGS}" does not exist. Trying to create a new one...`, - ); - } - - if ( - configuration.DB.SYSTEM === "SQLITE" && - !configuration.TESTING.IN_MEMORY_DB - ) { - this.createDirectoryIfNotExist( - configuration.VOLUMES.SQLITEDB, - `Directory "${configuration.VOLUMES.SQLITEDB}" does not exist. Trying to create a new one...`, - ); - } - } - - /** Creates a directory if it does not exist. */ - private async createDirectoryIfNotExist( - path: string, - errorMessage: string, - ): Promise { - if (!existsSync(path)) { - this.logger.error(errorMessage); - await mkdir(path); - } - } }