Commit 473b9044 authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt

add thekno-chameleon utility script

parent 0eb97ba5
......@@ -11,3 +11,7 @@ insert_final_newline = true
[{Makefile,debian/rules,make.d/*}]
indent_style = tab
indent_size = 4
[*.sh]
indent_style = tab
indent_size = 4
......@@ -10,3 +10,12 @@
# Log files
npm-debug.log*
# debian build files
debian/.debhelper/
debian/debhelper-build-stamp
debian/files
debian/tmp/
debian/*.substvars
debian/thekno/
debian/thekno-chameleon/
......@@ -2,14 +2,30 @@ Source: thekno
Section: web
Priority: optional
Maintainer: Konrad Mohrfeldt <konrad.mohrfeldt@farbdev.org>
Standards-Version: 4.3.0
Standards-Version: 4.4.0
Build-Depends: debhelper (>= 9), dh-exec, nodejs, npm
Homepage: https://git.hack-hro.de/lohro/lohrothek/thekno
Package: thekno
Architecture: all
Depends: ${misc:Depends}
Depends:
${misc:Depends},
Suggests:
${misc:Suggests},
thekno-chameleon,
Description: Vue-based music player app based on the lohrothek-api
Thekno is a frontend and music player for the lohrothek-api backend.
It is designed as a Progressive Web App (PWA) and optimized for
mobile devices and desktops.
Package: thekno-chameleon
Architecture: all
Depends:
${misc:Depends},
jo,
imagemagick,
optipng,
wget,
Description: Helper util for generating branded thekno apps.
thekno-chameleon uses thekno’s environment configuration to produce
a PWA manifest and other assets.
......@@ -3,12 +3,13 @@
#export DH_VERBOSE=1
%:
dh $@ --package=thekno
dh $@ --package thekno
dh $@ --package thekno-chameleon
override_dh_auto_build:
true
override_dh_auto_install:
dh_auto_install --package thekno -- install
dh_auto_install --package thekno --destdir debian/thekno -- install
# vim:ft=make:
#!/usr/bin/dh-exec
scripts/thekno-chameleon.sh => /usr/bin/thekno-chameleon
README.md
docs/environment-configuration.md
#!/bin/dash
set -eu
if [ "$#" -ne 3 ]; then
cat <<-EOF >&2
Usage: $0 ENV_FILE BASE_URL DEST_DIR
ENV_FILE:
The thekno-env JSON file according to the environment configuration
specification. For thekno-chameleon to run take extra care of the
integration property.
BASE_URL:
The domain you’re using for your app. This will be used to prefix
icon URLs as they have to be absolute.
DEST_DIR:
The directory to write the files to. This includes icon/logo files and
the PWA manifest.
EOF
exit 1
fi
ENV_FILE=$1
BASE_URL=$2
DEST_DIR=$(realpath "$3")
THEME_COLOR="#24242e"
LOGO_URL=$(jq -r '.integration.logo' "$ENV_FILE")
LOGO="$DEST_DIR/$(basename "$LOGO_URL")"
NAME=$(jq -r '.name' "$ENV_FILE")
SHORT_NAME=$(jq -r '.integration.shortName' "$ENV_FILE")
BACKGROUND_COLOR=$(jq -r ".integration.splashBackground // \"$THEME_COLOR\"" "$ENV_FILE")
DESCRIPTION=$(jq -r '.description' "$ENV_FILE")
mkdir -p "$DEST_DIR"
wget -q -O "$LOGO" "$LOGO_URL"
render_image() {
local src dest format size
src=$1
dest=$2
format=$3
size=$4
if [ "$format" = webp ]; then
convert -density "$(($size * 3))" -define webp:lossless=true -background none -resize "${size}x" "$src" "$format:$dest"
else
cairosvg --format png --output-width "$size" --output-height "$size" --output "$dest" "$src" 2>/dev/null || \
convert -density "$(($size * 6))" -background none -resize "${size}x" "$src" "$format:$dest"
fi
}
render_logo() {
{
local target_file
# emit the svg logo first
jo src="$BASE_URL/~local/$(basename "$LOGO")" type="image/svg" sizes="512x512"
for size in 32 48 96 144 192 256 512; do
for format in png webp; do
echo "rendering logo to ${size}x${size} as $format" >&2
target_file=$DEST_DIR/$(basename "${LOGO%.svg}")_$size.$format
render_image "$LOGO" "$target_file" "$format" "$size" >/dev/null
[ "$format" = 'png' ] && optipng -o7 -quiet -clobber "$target_file"
jo src="$BASE_URL/~local/$(basename "$target_file")" type="image/$format" sizes="${size}x${size}"
done
done
} | jo -a
}
jo \
name="$NAME" \
short_name="$SHORT_NAME" \
background_color="$BACKGROUND_COLOR" \
theme_color="$THEME_COLOR" \
description="$DESCRIPTION" \
icons="$(render_logo)" \
display=standalone \
start_url=/ \
categories="$(jo -a entertainment music)" \
orientation=portrait-primary >"$DEST_DIR/manifest.json"
cat <<-EOF >&2
Logo files and PWA manifest have been generated in the "$DEST_DIR" directory.
Please add the following section to your NGINX configuration:
EOF
cat <<-EOF
location /~local/ {
alias "$DEST_DIR/";
add_header Cache-Control "public, no-cache";
}
EOF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment