#!/bin/sh # Build the `ltk/` tree an Android package carries under `assets/`: the # themes, the font files their theme.json names by absolute path, the # on-screen keyboard's layouts, and the MANIFEST that src/platform/android/assets.rs unpacks from, whose first # line is a hash of the contents so a changed tree is unpacked again. # web-assets.sh builds the same tree for a page through this script. # # Usage: scripts/android-assets.sh OUT_DIR [THEMES_DIR [THEME_ID...]] # THEMES_DIR defaults to /usr/share/ltk/themes, THEME_ID to `default`. # EXTRA_FONTS, space-separated paths, adds fonts the app itself reads from # `ltk::resource_dir()/fonts`, such as a terminal's monospace face. # KEYBOARDS_DIR defaults to the `keyboards/` next to this script's directory. # MIME_DIR, shared-mime-info's directory, whose globs2, which # `ltk::files::mime_type` reads from `mime/`, and subclasses are copied there, # defaults to /usr/share/mime. set -eu keyboards=${KEYBOARDS_DIR:-$( cd "$( dirname "$0" )/.." && pwd )/keyboards} if [ $# -lt 1 ] then echo "usage: $0 OUT_DIR [THEMES_DIR [THEME_ID...]]" >&2 exit 2 fi out=$1 shift themes=/usr/share/ltk/themes if [ $# -gt 0 ] then themes=$1 shift fi [ $# -gt 0 ] || set -- default root=$out/ltk rm -rf "$root" mkdir -p "$root/themes" "$root/fonts" "$root/keyboards" cp "$keyboards"/*.json "$root/keyboards/" for id in "$@" do cp -r "$themes/$id" "$root/themes/$id" # ltk draws no cursor of its own on Android. rm -rf "$root/themes/$id/cursors" "$root/themes/$id/cursor.theme" grep -o '"path"[[:space:]]*:[[:space:]]*"/[^"]*"' "$themes/$id/theme.json" \ | sed 's/.*"\(\/[^"]*\)"$/\1/' \ | while read -r font do if [ -f "$font" ] then cp "$font" "$root/fonts/" else echo "android-assets: $font not found, skipped" >&2 fi done done for font in ${EXTRA_FONTS:-} do cp "$font" "$root/fonts/" done mime=${MIME_DIR:-/usr/share/mime} for table in globs2 subclasses do if [ -f "$mime/$table" ] then mkdir -p "$root/mime" cp "$mime/$table" "$root/mime/$table" else echo "android-assets: $mime/$table not found, skipped" >&2 fi done cd "$root" hash=$( find . -type f ! -name MANIFEST -print0 | LC_ALL=C sort -z | xargs -0 sha256sum | sha256sum | cut -d' ' -f1 ) { printf '# %s\n' "$hash" find . -type f ! -name MANIFEST | sed 's|^\./||' | LC_ALL=C sort } > MANIFEST