From d47fef080660f45428bfb49de83818075b5a4463 Mon Sep 17 00:00:00 2001 From: jo Date: Thu, 24 Nov 2022 21:14:59 +0100 Subject: [PATCH] chore: fix shell scripts lint errors --- api/compose/django/dev-entrypoint.sh | 2 + api/compose/django/entrypoint.sh | 5 +- api/compose/django/server.sh | 17 +++-- api/install_os_dependencies.sh | 82 ++++++++++------------ changes/changelog.d/lint-shell-script.misc | 1 + demo/setup.sh | 64 ++++++++++------- deploy/FreeBSD/funkwhale_beat | 22 +++--- deploy/FreeBSD/funkwhale_server | 20 ++++-- deploy/FreeBSD/funkwhale_worker | 21 +++--- deploy/Gentoo/funkwhale_beat | 50 ++++++++----- deploy/Gentoo/funkwhale_server | 48 ++++++++----- deploy/Gentoo/funkwhale_worker | 49 ++++++++----- docker/nginx/entrypoint.sh | 13 ++-- docs/build_docs.sh | 33 +++++---- docs/build_swagger.sh | 16 +++-- docs/i18n_generate.sh | 13 ++-- front/scripts/fix-fomantic-css.sh | 22 ++++-- front/scripts/i18n-compile.sh | 11 +-- front/scripts/i18n-extract.sh | 55 +++++++++------ front/scripts/i18n-weblate-to-origin.sh | 10 ++- front/scripts/utils.sh | 12 +++- scripts/check-api-deps.sh | 3 +- scripts/set-api-build-metadata.sh | 16 +++-- 23 files changed, 358 insertions(+), 227 deletions(-) create mode 100644 changes/changelog.d/lint-shell-script.misc diff --git a/api/compose/django/dev-entrypoint.sh b/api/compose/django/dev-entrypoint.sh index 4ba161148..18b36f947 100755 --- a/api/compose/django/dev-entrypoint.sh +++ b/api/compose/django/dev-entrypoint.sh @@ -1,3 +1,5 @@ #!/bin/sh + set -e + exec "$@" diff --git a/api/compose/django/entrypoint.sh b/api/compose/django/entrypoint.sh index df6f83374..21137fcbf 100755 --- a/api/compose/django/entrypoint.sh +++ b/api/compose/django/entrypoint.sh @@ -1,5 +1,7 @@ #!/bin/sh + set -e + # This entrypoint is used to play nicely with the current cookiecutter configuration. # Since docker-compose relies heavily on environment variables itself for configuration, we'd have to define multiple # environment variables just to support cookiecutter out of the box. That makes no sense, so this little entrypoint @@ -9,6 +11,7 @@ if [ -z "$DATABASE_URL" ]; then if [ -z "$POSTGRES_ENV_POSTGRES_USER" ]; then export POSTGRES_ENV_POSTGRES_USER=postgres fi - export DATABASE_URL=postgres://$POSTGRES_ENV_POSTGRES_USER:$POSTGRES_ENV_POSTGRES_PASSWORD@postgres:5432/$POSTGRES_ENV_POSTGRES_USER + export DATABASE_URL="postgres://$POSTGRES_ENV_POSTGRES_USER:$POSTGRES_ENV_POSTGRES_PASSWORD@postgres:5432/$POSTGRES_ENV_POSTGRES_USER" fi + exec "$@" diff --git a/api/compose/django/server.sh b/api/compose/django/server.sh index 7729bd326..8343a58b0 100755 --- a/api/compose/django/server.sh +++ b/api/compose/django/server.sh @@ -1,4 +1,13 @@ -#!/bin/bash -eux -python /app/manage.py collectstatic --noinput -python /app/manage.py migrate -gunicorn config.asgi:application -w ${FUNKWHALE_WEB_WORKERS-1} -k uvicorn.workers.UvicornWorker -b 0.0.0.0:5000 ${GUNICORN_ARGS-} +#!/bin/sh + +set -eux + +python3 /app/manage.py collectstatic --noinput +python3 /app/manage.py migrate + +# shellcheck disable=SC2086 +gunicorn config.asgi:application \ + --workers "${FUNKWHALE_WEB_WORKERS-1}" \ + --worker-class uvicorn.workers.UvicornWorker \ + --bind 0.0.0.0:5000 \ + ${GUNICORN_ARGS-} diff --git a/api/install_os_dependencies.sh b/api/install_os_dependencies.sh index fb0363de4..b9eed4725 100755 --- a/api/install_os_dependencies.sh +++ b/api/install_os_dependencies.sh @@ -1,19 +1,19 @@ -#!/bin/bash -ex +#!/usr/bin/env bash -script_path=$(dirname "$(realpath $0)") +set -ex + +script_path=$(dirname "$(realpath "$0")") OS_REQUIREMENTS_FILENAME="$script_path/requirements.apt" # Handle call with wrong command -function wrong_command() -{ +function wrong_command() { echo "${0##*/} - unknown command: '${1}'" usage_message } # Print help / script usage -function usage_message() -{ +function usage_message() { echo "usage: ./${0##*/} " echo "available commands are:" echo -e "\tlist\t\tPrint a list of all packages defined on ${OS_REQUIREMENTS_FILENAME} file" @@ -25,59 +25,53 @@ function usage_message() } # Read the requirements.apt file, and remove comments and blank lines -function list_packages(){ - grep -v "#" ${OS_REQUIREMENTS_FILENAME} | grep -v "^$"; +function list_packages() { + grep -v "#" "${OS_REQUIREMENTS_FILENAME}" | grep -v "^$" } -function install() -{ - list_packages | xargs apt-get --no-upgrade install -y; +function install() { + list_packages | xargs apt-get --no-upgrade install -y } -function upgrade() -{ - list_packages | xargs apt-get install -y; +function upgrade() { + list_packages | xargs apt-get install -y } +function install_or_upgrade() { + P=${1} + PARAN=${P:-"install"} -function install_or_upgrade() -{ - P=${1} - PARAN=${P:-"install"} + if [[ $EUID -ne 0 ]]; then + echo -e "\nYou must run this with root privilege" 2>&1 + echo -e "Please do:\n" 2>&1 + echo "sudo ./${0##*/} $PARAN" 2>&1 + echo -e "\n" 2>&1 - if [[ $EUID -ne 0 ]]; then - echo -e "\nYou must run this with root privilege" 2>&1 - echo -e "Please do:\n" 2>&1 - echo "sudo ./${0##*/} $PARAN" 2>&1 - echo -e "\n" 2>&1 + exit 1 + else - exit 1 + apt-get update + + # Install the basic compilation dependencies and other required libraries of this project + if [ "$PARAN" == "install" ]; then + install else - - apt-get update - - # Install the basic compilation dependencies and other required libraries of this project - if [ "$PARAN" == "install" ]; then - install; - else - upgrade; - fi - - # cleaning downloaded packages from apt-get cache - apt-get clean - - exit 0 + upgrade fi + # cleaning downloaded packages from apt-get cache + apt-get clean + + exit 0 + fi } - # Handle command argument case "$1" in - install) install_or_upgrade;; - upgrade) install_or_upgrade "upgrade";; - list) list_packages;; - help) usage_message;; - *) wrong_command $1;; + install) install_or_upgrade ;; + upgrade) install_or_upgrade "upgrade" ;; + list) list_packages ;; + help) usage_message ;; + *) wrong_command "$1" ;; esac diff --git a/changes/changelog.d/lint-shell-script.misc b/changes/changelog.d/lint-shell-script.misc new file mode 100644 index 000000000..37a34a1bc --- /dev/null +++ b/changes/changelog.d/lint-shell-script.misc @@ -0,0 +1 @@ +Fix shell scripts lint errors diff --git a/demo/setup.sh b/demo/setup.sh index 13db1b2cb..8818ee555 100755 --- a/demo/setup.sh +++ b/demo/setup.sh @@ -1,38 +1,52 @@ -#!/bin/bash -eux -version=${VERSION:-develop} -music_path=${MUSIC_PATH:-/usr/share/music} -demo_path=${DEMO_PATH:-/srv/funkwhale-demo/demo} -env_file=${ENV_FILE} +#!/usr/bin/env bash + +set -eux + +error() { + echo >&2 "$*" + exit 1 +} + +# $ENV_FILE is required +[[ -f "${ENV_FILE}" ]] || error "env file $ENV_FILE is not a file!" + +VERSION="${VERSION:-develop}" +MUSIC_PATH="${MUSIC_PATH:-/usr/share/music}" +DEMO_PATH="${DEMO_PATH:-/srv/funkwhale-demo/demo}" + echo 'Cleaning everything...' -mkdir -p $demo_path -cd $demo_path +mkdir -p "$DEMO_PATH" +cd "$DEMO_PATH" /usr/local/bin/docker-compose down -v || echo 'Nothing to stop' -sudo rm -rf $demo_path/* -mkdir -p $demo_path +sudo rm -rf "$DEMO_PATH/*" +mkdir -p "$DEMO_PATH" + echo 'Downloading demo files...' -curl -L -o docker-compose.yml "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$version/deploy/docker-compose.yml" -curl -L -o .env "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$version/deploy/env.prod.sample" +curl -L -o docker-compose.yml "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$VERSION/deploy/docker-compose.yml" +curl -L -o .env "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$VERSION/deploy/env.prod.sample" mkdir nginx -curl -L -o nginx/funkwhale.template "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$version/deploy/docker.nginx.template" -curl -L -o nginx/funkwhale_proxy.conf "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$version/deploy/funkwhale_proxy.conf" +curl -L -o nginx/funkwhale.template "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$VERSION/deploy/docker.nginx.template" +curl -L -o nginx/funkwhale_proxy.conf "https://dev.funkwhale.audio/funkwhale/funkwhale/raw/$VERSION/deploy/funkwhale_proxy.conf" mkdir data/ -curl -L -o front.zip "https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/artifacts/$version/download?job=build_front" +curl -L -o front.zip "https://dev.funkwhale.audio/funkwhale/funkwhale/-/jobs/artifacts/$VERSION/download?job=build_front" unzip front.zip -cat $env_file >> .env -echo "FUNKWHALE_VERSION=$version" >> .env -echo "MUSIC_DIRECTORY_SERVE_PATH=$music_path" >> .env -echo "MUSIC_DIRECTORY_PATH=$music_path" >> .env -echo "MEDIA_ROOT=$demo_path/data/media/" >> .env -echo "STATIC_ROOT=$demo_path/data/static/" >> .env -echo "FUNKWHALE_FRONTEND_PATH=$demo_path/front/dist/" >> .env +{ + cat "$ENV_FILE" + echo "FUNKWHALE_VERSION=$VERSION" + echo "MUSIC_DIRECTORY_SERVE_PATH=$MUSIC_PATH" + echo "MUSIC_DIRECTORY_PATH=$MUSIC_PATH" + echo "MEDIA_ROOT=$DEMO_PATH/data/media/" + echo "STATIC_ROOT=$DEMO_PATH/data/static/" + echo "FUNKWHALE_FRONTEND_PATH=$DEMO_PATH/front/dist/" +} >> .env # /usr/local/bin/docker-compose pull /usr/local/bin/docker-compose up -d postgres redis sleep 5 cat .env -cat <> /var/log/funkwhale/${name##funkwhale_}.log 2>&1 &" run_rc_command "$1" diff --git a/deploy/FreeBSD/funkwhale_server b/deploy/FreeBSD/funkwhale_server index 4c7394ab0..cc915422e 100755 --- a/deploy/FreeBSD/funkwhale_server +++ b/deploy/FreeBSD/funkwhale_server @@ -1,4 +1,5 @@ #!/bin/sh +# shellcheck disable=SC2034 # PROVIDE: funkwhale_server # REQUIRE: LOGIN postgresql nginx redis @@ -10,23 +11,28 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin +# shellcheck disable=SC1091 . /etc/rc.subr desc="Funkwhale server" -name=funkwhale_server -rcvar=funkwhale_server_enable +name="funkwhale_server" +rcvar="funkwhale_server_enable" -load_rc_config $name +load_rc_config "$name" -: ${funkwhale_server_enable:=NO} +: "${funkwhale_server_enable:=NO}" funkwhale_server_chdir="/usr/local/www/funkwhale/api" -funkwhale_server_user=funkwhale -funkwhale_server_env=$(cat /usr/local/www/funkwhale/config/.env | grep -v ^# | xargs) +funkwhale_server_user="funkwhale" +funkwhale_server_env="$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs)" command_interpreter="/usr/local/www/funkwhale/virtualenv/bin/python3" command="/usr/local/www/funkwhale/virtualenv/bin/gunicorn" -command_args="config.asgi:application -w 4 -k uvicorn.workers.UvicornWorker -b 127.0.0.1:5000 \ +command_args="\ +config.asgi:application \ +--workers 4 \ +--worker-class uvicorn.workers.UvicornWorker \ +--bind 127.0.0.1:5000 \ >> /var/log/funkwhale/${name##funkwhale_}.log 2>&1 &" run_rc_command "$1" diff --git a/deploy/FreeBSD/funkwhale_worker b/deploy/FreeBSD/funkwhale_worker index e9aab90fd..4fa6adbea 100755 --- a/deploy/FreeBSD/funkwhale_worker +++ b/deploy/FreeBSD/funkwhale_worker @@ -1,4 +1,5 @@ #!/bin/sh +# shellcheck disable=SC2034 # PROVIDE: funkwhale_worker # REQUIRE: LOGIN postgresql nginx redis @@ -10,25 +11,29 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin +# shellcheck disable=SC1091 . /etc/rc.subr desc="Funkwhale worker" -name=funkwhale_worker -rcvar=funkwhale_worker_enable +name="funkwhale_worker" +rcvar="funkwhale_worker_enable" -load_rc_config $name +load_rc_config "$name" -: ${funkwhale_worker_enable:=NO} +: "${funkwhale_worker_enable:=NO}" funkwhale_worker_chdir="/usr/local/www/funkwhale/api" -funkwhale_worker_user=funkwhale -funkwhale_worker_env=$(cat /usr/local/www/funkwhale/config/.env | grep -v ^# | xargs) +funkwhale_worker_user="funkwhale" +funkwhale_worker_env=$(grep -v '^#' /usr/local/www/funkwhale/config/.env | xargs) pidfile="/var/run/funkwhale/${name##funkwhale_}.pid" command_interpreter="/usr/local/www/funkwhale/virtualenv/bin/python3" command="/usr/local/www/funkwhale/virtualenv/bin/celery" -command_args="-A funkwhale_api.taskapp worker -l INFO \ ---pidfile=${pidfile} \ +command_args="\ +--app funkwhale_api.taskapp \ +worker \ +--loglevel INFO \ +--pidfile $pidfile \ >> /var/log/funkwhale/${name##funkwhale_}.log 2>&1 &" run_rc_command "$1" diff --git a/deploy/Gentoo/funkwhale_beat b/deploy/Gentoo/funkwhale_beat index 5e4fdd95a..970b02908 100755 --- a/deploy/Gentoo/funkwhale_beat +++ b/deploy/Gentoo/funkwhale_beat @@ -1,27 +1,41 @@ #!/sbin/openrc-run -NAME=funkwhalebeat -PIDFILE=/var/run/$NAME.pid -USER=funkwhale -WORKDIR=/srv/funkwhale/api -Celery=/srv/funkwhale/virtualenv/bin/celery -BEAT_ARGS="-A funkwhale_api.taskapp beat -l INFO" +# shellcheck shell=bash + +NAME="funkwhalebeat" +PIDFILE="/var/run/$NAME.pid" +USER="funkwhale" +WORKDIR="/srv/funkwhale/api" +Celery="/srv/funkwhale/virtualenv/bin/celery" +BEAT_ARGS="--app funkwhale_api.taskapp beat --loglevel INFO" + depend() { - need net + need net } start() { - ebegin "Starting Funkwhale Beat" - cd /srv/funkwhale/api - set -a && source /srv/funkwhale/config/.env && set +a - echo ' start beat' - start-stop-daemon --start --user $USER --make-pidfile --pidfile $PIDFILE -d $WORKDIR --exec $Celery -- $BEAT_ARGS >> /var/log/funk/worker.log 2>&1& - echo 'Started Beat' - echo - eend $? + ebegin "Starting Funkwhale Beat" + cd /srv/funkwhale/api || exit 1 + + # shellcheck disable=SC1091 + set -a && source /srv/funkwhale/config/.env && set +a + + echo "Starting Funkwhale Beat" + # shellcheck disable=SC2086 + start-stop-daemon --start \ + --user "$USER" \ + --make-pidfile \ + --pidfile "$PIDFILE" \ + --chdir "$WORKDIR" \ + --exec "$Celery" \ + -- $BEAT_ARGS \ + >> /var/log/funk/worker.log 2>&1 & + echo "Funkwhale Beat started" + echo + eend $? } stop() { - ebegin "Stopping Funkwhale Beat" - start-stop-daemon --stop --pidfile $PIDFILE - eend $? + ebegin "Stopping Funkwhale Beat" + start-stop-daemon --stop --pidfile "$PIDFILE" + eend $? } diff --git a/deploy/Gentoo/funkwhale_server b/deploy/Gentoo/funkwhale_server index c6771f6d7..e89167430 100755 --- a/deploy/Gentoo/funkwhale_server +++ b/deploy/Gentoo/funkwhale_server @@ -1,29 +1,41 @@ #!/sbin/openrc-run +# shellcheck shell=bash -NAME=funkwhaleserver -PIDFILE=/var/run/$NAME.pid -USER=funkwhale -DAEMON_ARGS="config.asgi:application -w 4 -k uvicorn.workers.UvicornWorker -b 127.0.0.1:5000 " -Gunicorn=/srv/funkwhale/virtualenv/bin/gunicorn -WORKDIR=/srv/funkwhale/api +NAME="funkwhaleserver" +PIDFILE="/var/run/$NAME.pid" +USER="funkwhale" +DAEMON_ARGS="config.asgi:application --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:5000" +Gunicorn="/srv/funkwhale/virtualenv/bin/gunicorn" +WORKDIR="/srv/funkwhale/api" depend() { - need net redis postgresql nginx funkwhale_beat funkwhale_worker + need net redis postgresql nginx funkwhale_beat funkwhale_worker } start() { - ebegin "Starting Funkwhale Server" - cd /srv/funkwhale/api - set -a && source /srv/funkwhale/config/.env && set +a - echo 'Starting Funkwhale Server' - start-stop-daemon --start --user $USER --make-pidfile --pidfile $PIDFILE -d $WORKDIR --exec $Gunicorn -- $DAEMON_ARGS >> /var/log/funk/server.log 2>&1& - echo 'Funkwhale Server started' - echo - eend $? + ebegin "Starting Funkwhale Server" + cd /srv/funkwhale/api || exit 1 + + # shellcheck disable=SC1091 + set -a && source /srv/funkwhale/config/.env && set +a + + echo "Starting Funkwhale Server" + # shellcheck disable=SC2086 + start-stop-daemon --start \ + --user "$USER" \ + --make-pidfile \ + --pidfile "$PIDFILE" \ + --chdir "$WORKDIR" \ + --exec "$Gunicorn" \ + -- $DAEMON_ARGS \ + >> /var/log/funk/server.log 2>&1 & + echo "Funkwhale Server started" + echo + eend $? } stop() { - ebegin "Stopping Funkwhale" - start-stop-daemon --stop --pidfile $PIDFILE - eend $? + ebegin "Stopping Funkwhale" + start-stop-daemon --stop --pidfile "$PIDFILE" + eend $? } diff --git a/deploy/Gentoo/funkwhale_worker b/deploy/Gentoo/funkwhale_worker index daca4d94d..1df362b10 100755 --- a/deploy/Gentoo/funkwhale_worker +++ b/deploy/Gentoo/funkwhale_worker @@ -1,28 +1,41 @@ #!/sbin/openrc-run -NAME=funkwhaleworker -PIDFILE=/var/run/$NAME.pid -USER=funkwhale -WORKDIR=/srv/funkwhale/api -Celery=/srv/funkwhale/virtualenv/bin/celery -WORKER_ARGS=" -A funkwhale_api.taskapp worker -l INFO" +# shellcheck shell=bash + +NAME="funkwhaleworker" +PIDFILE="/var/run/$NAME.pid" +USER="funkwhale" +WORKDIR="/srv/funkwhale/api" +Celery="/srv/funkwhale/virtualenv/bin/celery" +WORKER_ARGS="--app funkwhale_api.taskapp worker --loglevel INFO" depend() { - need net + need net } start() { - ebegin "Starting Funkwhale Worker" - cd /srv/funkwhale/api - set -a && source /srv/funkwhale/config/.env && set +a - echo ' start beat' - start-stop-daemon --start --user $USER --make-pidfile --pidfile $PIDFILE -d $WORKDIR --exec $Celery -- $WORKER_ARGS >> /var/log/funk/worker.log 2>&1& - echo 'Started Worker' - echo - eend $? + ebegin "Starting Funkwhale Worker" + cd /srv/funkwhale/api || exit 1 + + # shellcheck disable=SC1091 + set -a && source /srv/funkwhale/config/.env && set +a + + echo "Starting Funkwhale Worker" + # shellcheck disable=SC2086 + start-stop-daemon --start \ + --user "$USER" \ + --make-pidfile \ + --pidfile "$PIDFILE" \ + --chdir "$WORKDIR" \ + --exec "$Celery" \ + -- $WORKER_ARGS \ + >> /var/log/funk/worker.log 2>&1 & + echo "Funkwhale Worker started" + echo + eend $? } stop() { - ebegin "Stopping Funkwhale Worker" - start-stop-daemon --stop --pidfile $PIDFILE - eend $? + ebegin "Stopping Funkwhale Worker" + start-stop-daemon --stop --pidfile "$PIDFILE" + eend $? } diff --git a/docker/nginx/entrypoint.sh b/docker/nginx/entrypoint.sh index 7c36bcd2f..1839759c2 100755 --- a/docker/nginx/entrypoint.sh +++ b/docker/nginx/entrypoint.sh @@ -1,8 +1,11 @@ -#!/bin/bash -eux +#!/bin/sh +set -eux -envsubst "`env | awk -F = '{printf \" $$%s\", $$1}'`" \ +envsubst "$(env | awk -F = '{printf \" $$%s\", $$1}')" \ < /etc/nginx/nginx.conf.template \ - > /etc/nginx/nginx.conf \ - && cat /etc/nginx/nginx.conf \ - && nginx-debug -g 'daemon off;' + > /etc/nginx/nginx.conf + +cat /etc/nginx/nginx.conf + +nginx-debug -g 'daemon off;' diff --git a/docs/build_docs.sh b/docs/build_docs.sh index 7128e6da0..56f09ff56 100755 --- a/docs/build_docs.sh +++ b/docs/build_docs.sh @@ -1,24 +1,29 @@ -#!/bin/bash -eux +#!/usr/bin/env bash + +set -eux + # We clean up translations, only fully translated components are kept IFS=$'\n' for i in $(poetry run sphinx-intl stat); do - echo "$i" - if [[ "$i" != *" 0 untranslated." ]]; then - file=$(echo $i | cut -d: -f1) - echo "delete $file" - rm $file - fi + echo "$i" + if [[ "$i" != *" 0 untranslated." ]]; then + file=$(echo "$i" | cut -d: -f1) + echo "delete $file" + rm "$file" + fi done + # Build sphinx -poetry run sphinx-multiversion . $BUILD_PATH -for d in $(ls locales); do - if [[ $d != "gettext" ]]; then - poetry run sphinx-multiversion -D language="$d" . $BUILD_PATH/$d - fi +poetry run sphinx-multiversion . "$BUILD_PATH" +for path in locales/*; do + lang="$(basename "$path")" + if [[ "$lang" != "gettext" ]]; then + poetry run sphinx-multiversion -D language="$lang" . "$BUILD_PATH/$lang" + fi done # Build swagger TARGET_PATH="$BUILD_PATH/swagger" ./build_swagger.sh -python ./get-releases-json.py > $BUILD_PATH/releases.json -python ./get-releases-json.py --latest > $BUILD_PATH/latest.txt +python3 ./get-releases-json.py > "$BUILD_PATH/releases.json" +python3 ./get-releases-json.py --latest > "$BUILD_PATH/latest.txt" diff --git a/docs/build_swagger.sh b/docs/build_swagger.sh index 95e9e0781..6902a4549 100755 --- a/docs/build_swagger.sh +++ b/docs/build_swagger.sh @@ -1,10 +1,14 @@ -#!/bin/bash -eux +#!/usr/bin/env bash + +set -eux SWAGGER_VERSION="4.1.3" TARGET_PATH=${TARGET_PATH-"swagger"} -rm -rf $TARGET_PATH /tmp/swagger-ui + +rm -rf "$TARGET_PATH" /tmp/swagger-ui git clone --branch="v$SWAGGER_VERSION" --depth=1 "https://github.com/swagger-api/swagger-ui.git" /tmp/swagger-ui -mv /tmp/swagger-ui/dist $TARGET_PATH -cp schema.yml $TARGET_PATH -cp -r api $TARGET_PATH/api -sed -i "s,https://petstore.swagger.io/v2/swagger.json,schema.yml,g" $TARGET_PATH/index.html + +mv /tmp/swagger-ui/dist "$TARGET_PATH" +cp schema.yml "$TARGET_PATH" +cp -r api "$TARGET_PATH/api" +sed -i "s,https://petstore.swagger.io/v2/swagger.json,schema.yml,g" "$TARGET_PATH/index.html" diff --git a/docs/i18n_generate.sh b/docs/i18n_generate.sh index 5164b5309..e80f64fe9 100755 --- a/docs/i18n_generate.sh +++ b/docs/i18n_generate.sh @@ -1,5 +1,10 @@ -#!/bin/sh +#!/usr/bin/env bash + poetry run make -e BUILDDIR=locales gettext -for f in $(ls locales | grep -v gettext); do - poetry run sphinx-intl update -p locales/gettext -l $f -done; + +for path in locales/*; do + lang="$(basename "$path")" + if [[ "$lang" != "gettext" ]]; then + poetry run sphinx-intl update -p locales/gettext -l "$lang" + fi +done diff --git a/front/scripts/fix-fomantic-css.sh b/front/scripts/fix-fomantic-css.sh index 76ec60971..734f2abfe 100755 --- a/front/scripts/fix-fomantic-css.sh +++ b/front/scripts/fix-fomantic-css.sh @@ -1,12 +1,20 @@ -#!/usr/bin/env -S bash -eux +#!/usr/bin/env bash -cd "$(dirname $0)/.." # change into base directory +set -eux + +cd "$(dirname "$0")/.." # change into base directory + +FOMANTIC_SRC_PATH="node_modules/fomantic-ui-css" + +find "$FOMANTIC_SRC_PATH/components" -name "*.min.css" -delete +mkdir -p "$FOMANTIC_SRC_PATH/tweaked" -find node_modules/fomantic-ui-css/components -name "*.min.css" -delete -mkdir -p node_modules/fomantic-ui-css/tweaked echo 'Removing google font…' -sed -i '/@import url(/d' node_modules/fomantic-ui-css/components/site.css +sed -i '/@import url(/d' "$FOMANTIC_SRC_PATH/components/site.css" + echo "Replacing hardcoded values by CSS vars…" -scripts/fix-fomantic-css.py node_modules/fomantic-ui-css node_modules/fomantic-ui-css/tweaked +scripts/fix-fomantic-css.py "$FOMANTIC_SRC_PATH" "$FOMANTIC_SRC_PATH/tweaked" + echo 'Fixing jQuery import…' -sed -i '1s/^/import jQuery from "jquery"\n/' `find node_modules/fomantic-ui-css/ -name '*.js'` +# shellcheck disable=SC2046 +sed -i '1s/^/import jQuery from "jquery"\n/' $(find "$FOMANTIC_SRC_PATH" -name '*.js') diff --git a/front/scripts/i18n-compile.sh b/front/scripts/i18n-compile.sh index c144c34c6..3142c749a 100755 --- a/front/scripts/i18n-compile.sh +++ b/front/scripts/i18n-compile.sh @@ -1,13 +1,16 @@ -#!/usr/bin/env -S bash -eux +#!/usr/bin/env bash -cd "$(dirname $0)/.." # change into base directory +set -eux + +cd "$(dirname "$0")/.." # change into base directory +# shellcheck disable=SC1091 source scripts/utils.sh locales=$(jq -r '.[].code' src/locales.json | grep -v 'en_US') mkdir -p src/translations for locale in $locales; do - $(npm_binaries)/gettext-compile locales/$locale/LC_MESSAGES/app.po --output src/translations/$locale.json + "$(npm_binaries)/gettext-compile" "locales/$locale/LC_MESSAGES/app.po" --output "src/translations/$locale.json" done -# find locales -name '*.po' | xargs $(npm_binaries)/.bin/gettext-compile --output src/translations.json +# find locales -name '*.po' | xargs "$(npm_binaries)/.bin/gettext-compile" --output src/translations.json diff --git a/front/scripts/i18n-extract.sh b/front/scripts/i18n-extract.sh index 209731d63..473f05e77 100755 --- a/front/scripts/i18n-extract.sh +++ b/front/scripts/i18n-extract.sh @@ -1,35 +1,48 @@ -#!/usr/bin/env -S bash -eux +#!/usr/bin/env bash -cd "$(dirname $0)/.." # change into base directory +set -eux + +cd "$(dirname "$0")/.." # change into base directory +# shellcheck disable=SC1091 source scripts/utils.sh locales=$(jq -r '.[].code' src/locales.json) locales_dir="locales" sources=$(find src -name '*.vue' -o -name '*.html' 2> /dev/null) js_sources=$(find src -name '*.vue' -o -name '*.js') -touch $locales_dir/app.pot -GENERATE=${GENERATE-true} +touch "$locales_dir/app.pot" +GENERATE="${GENERATE-true}" + # Create a main .pot template, then generate .po files for each available language. # Extract gettext strings from templates files and create a POT dictionary template. -$(npm_binaries)/gettext-extract --attribute v-translate --quiet --output $locales_dir/app.pot $sources +# shellcheck disable=SC2086 +"$(npm_binaries)/gettext-extract" --attribute v-translate --quiet --output "$locales_dir/app.pot" $sources + +# shellcheck disable=SC2086 xgettext --language=JavaScript --keyword=npgettext:1c,2,3 \ - --from-code=utf-8 --join-existing --no-wrap \ - --package-name=$(node -e "console.log(require('./package.json').name);") \ - --package-version=$(node -e "console.log(require('./package.json').version);") \ - --output $locales_dir/app.pot $js_sources \ - --no-wrap + --from-code=utf-8 --join-existing --no-wrap \ + --package-name="$(jq -r '.name' package.json)" \ + --package-version="$(jq -r '.version' package.json)" \ + --output "$locales_dir/app.pot" $js_sources \ + --no-wrap # Fix broken files path/lines in pot -sed -e 's|#: src/|#: front/src/|' -i $locales_dir/app.pot +sed -e 's|#: src/|#: front/src/|' -i "$locales_dir/app.pot" -if [ $GENERATE = 'true' ]; then - # Generate .po files for each available language. - echo $locales - for lang in $locales; do \ - po_file=$locales_dir/$lang/LC_MESSAGES/app.po; \ - echo "msgmerge --update $po_file "; \ - mkdir -p $(dirname $po_file); \ - [ -f $po_file ] && msgmerge --lang=$lang --update $po_file $locales_dir/app.pot --no-wrap || msginit --no-wrap --no-translator --locale=$lang --input=$locales_dir/app.pot --output-file=$po_file; \ - msgattrib --no-wrap --no-obsolete -o $po_file $po_file; \ - done; +if [ "$GENERATE" = 'true' ]; then + # Generate .po files for each available language. + echo "$locales" + for lang in $locales; do + po_file="$locales_dir/$lang/LC_MESSAGES/app.po" + echo "msgmerge --update $po_file" + mkdir -p "$(dirname "$po_file")" + + if [[ -f "$po_file" ]]; then + msgmerge --lang="$lang" --update "$po_file" "$locales_dir/app.pot" --no-wrap + else + msginit --no-wrap --no-translator --locale="$lang" --input="$locales_dir/app.pot" --output-file="$po_file" + fi + + msgattrib --no-wrap --no-obsolete -o "$po_file" "$po_file" + done fi diff --git a/front/scripts/i18n-weblate-to-origin.sh b/front/scripts/i18n-weblate-to-origin.sh index e7d98f48b..25bd13040 100755 --- a/front/scripts/i18n-weblate-to-origin.sh +++ b/front/scripts/i18n-weblate-to-origin.sh @@ -1,12 +1,16 @@ -#!/usr/bin/env -S bash -eux +#!/usr/bin/env bash + +set -eux + integration_branch="translations-integration" + git remote add weblate https://translate.funkwhale.audio/git/funkwhale/front/ || echo "remote already exists" git fetch weblate git checkout weblate/develop git reset --hard weblate/develop -git checkout -b $integration_branch || git checkout $integration_branch +git checkout -b "$integration_branch" || git checkout "$integration_branch" git reset --hard weblate/develop -git push -f origin $integration_branch +git push -f origin "$integration_branch" echo "Branch created on pushed on origin/$integration_branch" echo "Open a merge request by visiting https://dev.funkwhale.audio/funkwhale/funkwhale/merge_requests/new?merge_request%5Bsource_branch%5D=$integration_branch" diff --git a/front/scripts/utils.sh b/front/scripts/utils.sh index 727318948..6470ae07a 100755 --- a/front/scripts/utils.sh +++ b/front/scripts/utils.sh @@ -1,5 +1,11 @@ -#!/usr/bin/env -S bash -eux +#!/usr/bin/env bash -npm_binaries () { - command -v yarn > /dev/null && yarn bin || npm bin +set -eux + +npm_binaries() { + if command -v yarn > /dev/null; then + yarn bin + else + npm bin + fi } diff --git a/scripts/check-api-deps.sh b/scripts/check-api-deps.sh index e0a93df9e..582d0f447 100755 --- a/scripts/check-api-deps.sh +++ b/scripts/check-api-deps.sh @@ -2,5 +2,4 @@ outdated=$(pip list -o) echo -n "$outdated" -return_code=$(echo -n "$outdated" | wc -l) -exit $return_code +exit "$(echo -n "$outdated" | wc -l)" diff --git a/scripts/set-api-build-metadata.sh b/scripts/set-api-build-metadata.sh index 08bcf5ea6..0ecbce59a 100755 --- a/scripts/set-api-build-metadata.sh +++ b/scripts/set-api-build-metadata.sh @@ -1,9 +1,13 @@ -#!/bin/sh -eu +#!/usr/bin/env bash + +set -eux + # given a commit hash, will append this to the version number stored # in api/funkwhale_api/__init__.py -commit=$1 -suffix="+git.$commit" -replace="__version__ = \"\1${suffix}\"" -file="api/funkwhale_api/__init__.py" -sed -i -E 's@__version__ = \"(.*)\"@'"$replace"'@' $file +COMMIT=$1 +FILE="api/funkwhale_api/__init__.py" + +SUFFIX="\1+git.$COMMIT" +EXPR=$(printf 's@__version__ = "(.*)"@__version__ = "%s"@' "$SUFFIX") +sed -i -E "$EXPR" "$FILE"