diff --git a/README.md b/README.md index 8e1aa4f..5055fbe 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ cd steam-gift-manager ```bash git clone https://git.nocci.it/nocci/GameKeyManager +cd steam-gift-manager ``` ### 2. **Setup Docker** diff --git a/setup.sh b/setup.sh index 4741e96..362cdb9 100644 --- a/setup.sh +++ b/setup.sh @@ -1,13 +1,13 @@ #!/bin/bash set -e -# Colors +# Color definitions RED='\033[1;31m' GREEN='\033[1;32m' YELLOW='\033[1;33m' NC='\033[0m' -# 1. Docker check (incl. Arch Linux) +# 1. Docker check (including Arch Linux) if ! command -v docker &>/dev/null; then echo -e "${RED}❗ Docker is not installed.${NC}" read -p "Would you like to install Docker automatically now? [y/N]: " install_docker @@ -23,7 +23,7 @@ if ! command -v docker &>/dev/null; then rm get-docker.sh fi - # Docker group membership prüfen + # Check Docker group membership if ! groups | grep -q '\bdocker\b'; then echo -e "${YELLOW}⚠️ Your user is not in the docker group. Adding now...${NC}" sudo usermod -aG docker $USER @@ -37,7 +37,7 @@ if ! command -v docker &>/dev/null; then fi fi -# 2. Check Docker compose (V1 und V2 Plugin, incl. Arch Support) +# 2. Docker Compose check (V1 and V2 plugin, with Arch support) DOCKER_COMPOSE_CMD="" if command -v docker-compose &>/dev/null; then DOCKER_COMPOSE_CMD="docker-compose" @@ -74,12 +74,13 @@ else fi fi + # Configuration PROJECT_DIR="steam-gift-manager" -TRANSLATIONS_DIR="$PWD/translations" -DATA_DIR="$PWD/data" +TRANSLATIONS_DIR="../translations" +DATA_DIR="../data" -# 1. Create folders +# 1. Create project folder & translations folder mkdir -p "$PROJECT_DIR"/{templates,static} mkdir -p "$TRANSLATIONS_DIR"/de/LC_MESSAGES mkdir -p "$TRANSLATIONS_DIR"/en/LC_MESSAGES @@ -110,7 +111,7 @@ pillow gunicorn EOL -# 3. .env Datei in Parent-VFolder +# 3. Create .env file in parent directory cd .. SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_hex(24))') REDEEM_SECRET=$(python3 -c 'import secrets; print(secrets.token_hex(16))') @@ -153,11 +154,13 @@ MATRIX_ACCESS_TOKEN="" MATRIX_ROOM_ID="" EOL +# Back to project directory cd $PROJECT_DIR # 4. app.py (the main app) cat <<'PYTHON_END' > app.py import os +import logging import warnings from sqlalchemy.exc import LegacyAPIWarning warnings.simplefilter("ignore", category=LegacyAPIWarning) @@ -199,11 +202,8 @@ from reportlab.lib.utils import ImageReader from reportlab.lib.units import cm, inch, mm from io import BytesIO import reportlab.lib -import logging -logging.basicConfig() -logging.getLogger('babel').setLevel(logging.DEBUG) -app = Flask(__name__) +app = Flask(__name__) csrf = CSRFProtect(app) convention = { @@ -223,19 +223,14 @@ load_dotenv(override=True) # App-Configuration app.config.update( SECRET_KEY=os.getenv('SECRET_KEY'), - SQLALCHEMY_DATABASE_URI='sqlite:////app/data/games.db', + SQLALCHEMY_DATABASE_URI=('sqlite:////app/data/games.db'), SQLALCHEMY_TRACK_MODIFICATIONS=False, - BABEL_DEFAULT_LOCALE=os.getenv('BABEL_DEFAULT_LOCALE', 'en'), - BABEL_SUPPORTED_LOCALES=os.getenv('BABEL_SUPPORTED_LOCALES', 'de,en').split(','), - BABEL_TRANSLATION_DIRECTORIES=os.path.join(app.root_path, 'translations'), - SESSION_COOKIE_SECURE=os.getenv('SESSION_COOKIE_SECURE', 'False') == 'True', - SESSION_COOKIE_SAMESITE='Lax', - PERMANENT_SESSION_LIFETIME=timedelta(days=30), - SESSION_REFRESH_EACH_REQUEST=False, - WTF_CSRF_ENABLED=os.getenv('CSRF_ENABLED', 'True') == 'True', - REGISTRATION_ENABLED=os.getenv('REGISTRATION_ENABLED', 'True').lower() == 'true', - SEND_FILE_MAX_AGE_DEFAULT=int(os.getenv('SEND_FILE_MAX_AGE_DEFAULT', 0)), - TEMPLATES_AUTO_RELOAD=os.getenv('TEMPLATES_AUTO_RELOAD', 'True') == 'True' + BABEL_DEFAULT_LOCALE=os.getenv('BABEL_DEFAULT_LOCALE'), + BABEL_SUPPORTED_LOCALES=os.getenv('BABEL_SUPPORTED_LOCALES').split(','), + BABEL_TRANSLATION_DIRECTORIES=os.getenv('BABEL_TRANSLATION_DIRECTORIES'), + SESSION_COOKIE_SECURE=os.getenv('SESSION_COOKIE_SECURE') == 'True', + WTF_CSRF_ENABLED=os.getenv('CSRF_ENABLED') == 'True', + REGISTRATION_ENABLED=os.getenv('REGISTRATION_ENABLED', 'True').lower() == 'true' ) interval_hours = int(os.getenv('CHECK_EXPIRING_KEYS_INTERVAL_HOURS', 12)) @@ -257,11 +252,6 @@ def get_locale(): return session['lang'] return request.accept_languages.best_match(app.config['BABEL_SUPPORTED_LOCALES']) -@app.before_request -def reload_translations(): - if app.config['DEBUG']: - babel.reload() - @app.context_processor def inject_template_vars(): return dict( @@ -728,13 +718,6 @@ def redeem_page(token): redeem_token=redeem_token, platform_link='https://store.steampowered.com/account/registerkey?key=' if game.steam_appid else 'https://www.gog.com/redeem') -@app.route('/debug-session') -def debug_session(): - return jsonify({ - 'session_lang': session.get('lang'), - 'config_locales': app.config['BABEL_SUPPORTED_LOCALES'] - }) - # Benachrichtigungsfunktionen def send_pushover_notification(user, game): """Sendet Pushover-Benachrichtigung für ablaufenden Key""" @@ -914,44 +897,46 @@ services: - TZ=${TZ} volumes: - ../data:/app/data - - ../translations:/app/translations:rw + - ../translations:/app/translations - ../.env:/app/.env - user: "${UID}:${GID}" + user: "1000:1000" restart: unless-stopped - COMPOSE_END # 7. Directories and permissions mkdir -p ../data ../translations chmod -R a+rwX ../data ../translations -find ../data ../translations -type d -exec chmod 775 {} \; -find ../data ../translations -type f -exec chmod 664 {} \; # 8. Translation and upgrade scripts cat <<'SCRIPT_END' > ../translate.sh #!/bin/bash set -e -# 0.1 Change to the project directory (where docker-compose.yml is located) cd "$(dirname "$0")/steam-gift-manager" -declare -a locales=("de" "en") +declare -A locales=( + ["de"]="de" + ["en"]="en" +) -# 1. POT-Datei aktualisieren -docker-compose run --rm steam-manager pybabel extract -F babel.cfg -o translations/messages.pot . +# create POT-file +docker-compose exec steam-manager pybabel extract -F babel.cfg -o translations/messages.pot . -# 2. PO files for each language -for lang in "${locales[@]}"; do - docker-compose run --rm steam-manager pybabel update \ - -i translations/messages.pot \ - -d translations \ - -l $lang --previous +# Check for each language and initialize if necessary +for lang in "${!locales[@]}"; do + if [ ! -f "translations/${locales[$lang]}/LC_MESSAGES/messages.po" ]; then + docker-compose exec steam-manager pybabel init \ + -i translations/messages.pot \ + -d translations \ + -l "${locales[$lang]}" + fi done -# 3. Compile MO files (without fuzzy entries) -docker-compose run --rm steam-manager pybabel compile -d translations +# Update and compile translations +docker-compose exec steam-manager pybabel update -i translations/messages.pot -d translations +docker-compose exec steam-manager pybabel compile -d translations -echo "✅ Translations successfully updated!" +echo "✅ Translations updated!" SCRIPT_END chmod +x ../translate.sh @@ -1020,8 +1005,6 @@ cat < templates/base.html