#!/bin/sh set -eu JAR="/app/app.jar" if [ ! -f "$JAR" ]; then echo "[ERROR] JAR file not found at /app/app.jar" exit 1 fi echo "[INFO] ========================================" echo "[INFO] \$uicide Music Bot (JMusicBot) Containerized" echo "[INFO] ========================================" echo "[INFO] Selected jar: $JAR" echo "[INFO] Working directory: $(pwd)" echo "[INFO] Running as: uid=$(id -u) gid=$(id -g)" # The bot keeps config.txt, serversettings.json, Playlists/ and its instance # lock in the working directory. If that is not writable the bot's own error is # a misleading "Another instance of JMusicBot is already running", so check # first and say what is actually wrong. if ! touch .write-test 2>/dev/null; then echo "[ERROR] $(pwd) is not writable by uid $(id -u)." echo "[ERROR] Make the mounted data directory writable by that user, e.g." echo "[ERROR] chown -R $(id -u):$(id -g) " echo "[ERROR] or run the container with --user : matching the directory's owner." exit 1 fi rm -f .write-test # First run: write the default config.txt (the bot's own generate-config # command) and stop, so there is something to edit. Headless, the bot would # otherwise prompt for a token on a console that does not exist and exit # without writing anything. if [ ! -f "config.txt" ]; then echo "[INFO] config.txt: Not found - generating the default one" java -Dnogui=true --enable-native-access=ALL-UNNAMED -jar "$JAR" generate-config echo "[INFO] ========================================" echo "[INFO] Wrote $(pwd)/config.txt" echo "[INFO] Edit it and set, at minimum:" echo "[INFO] discord.token - your Discord bot token" echo "[INFO] discord.owner - your Discord user ID" echo "[INFO] then start the container again." echo "[INFO] ========================================" exit 0 fi echo "[INFO] config.txt: Found" echo "[INFO] ========================================" # Default JVM options for optimal audio performance (ZGC with sub-ms pauses) # Set JAVA_OPTS to override; add -Xms/-Xmx for heap limits if desired : "${JAVA_OPTS:=-XX:+UseZGC -XX:+AlwaysPreTouch}" # Build argv set -- java -Dnogui=true --enable-native-access=ALL-UNNAMED # Append JAVA_OPTS (either default or user-provided) if [ -n "${JAVA_OPTS:-}" ]; then # shellcheck disable=SC2086 set -- "$@" $JAVA_OPTS fi set -- "$@" -jar "$JAR" exec "$@"