#!/bin/bash

set -eu -o pipefail

# This script downloads new translation data from weblate at https://translate.cloudron.io

OUT="/home/yellowtent/box/dashboard/dist/translation"

# We require root
if [[ ${EUID} -ne 0 ]]; then
    echo "This script should be run as root. Run with sudo"
    exit 1
fi

echo "=> Downloading new translation files..."
curl https://translate.cloudron.io/download/cloudron/dashboard/?format=zip -o /tmp/lang.zip

echo "=> Unpacking..."
unzip -jo /tmp/lang.zip -d $OUT
chown -R yellowtent:yellowtent $OUT
# unzip put very restrictive permissions
chmod ua+r $OUT/*

echo "=> Cleanup..."
rm /tmp/lang.zip

echo "=> Done"

echo ""
echo "Reload the dashboard to see the new translations"
echo ""
