Files
corescope-voices/install.sh
T
richandClaude Opus 5.5 6dc4592ed2 Initial voice pack: seven live-map voices for CoreScope
Voices taken from CoreScope feat/audio-voices (ac257569), plus a compat
shim for stock audio.js, an idempotent install/uninstall script, a
derived-image Dockerfile, and tests that run against a real public/ dir.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 14:39:51 -04:00

68 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
# Install (or remove) the extra live-map voices into a CoreScope public/ dir.
#
# ./install.sh <path/to/corescope/public> install or update
# ./install.sh --uninstall <path/to/corescope/public> remove
#
# Copies voices/*.js into the directory and adds their <script> tags to
# index.html right after audio-v1-constellation.js (so constellation stays
# the default voice). Safe to re-run: the tag block is replaced, not repeated.
# POSIX sh + awk only, so it also runs inside the Alpine CoreScope image.
set -eu
BEGIN_MARK='<!-- corescope-voices:begin -->'
END_MARK='<!-- corescope-voices:end -->'
ANCHOR='audio-v1-constellation.js'
# Load order matters: compat shim, synth kit, metal (guitar rig), then the rest.
FILES='audio-voices-compat.js audio-synthkit.js audio-v2-metal.js audio-v3-synthmetal.js audio-v4-technoir.js audio-v5-ambient.js audio-v6-dub.js audio-v7-acid.js audio-v8-lofi.js'
die() { echo "install.sh: $*" >&2; exit 1; }
UNINSTALL=0
if [ "${1:-}" = "--uninstall" ]; then UNINSTALL=1; shift; fi
[ $# -eq 1 ] || die "usage: $0 [--uninstall] <corescope public dir>"
PUBLIC=$1
HERE=$(cd "$(dirname "$0")" && pwd)
INDEX=$PUBLIC/index.html
[ -f "$INDEX" ] || die "$INDEX not found (point me at CoreScope's public/ directory)"
TMP=$INDEX.voices.tmp
# Strip any block from a previous install.
awk -v b="$BEGIN_MARK" -v e="$END_MARK" \
'index($0, b) { skip = 1 } !skip { print } index($0, e) { skip = 0 }' "$INDEX" > "$TMP"
if [ $UNINSTALL -eq 1 ]; then
mv "$TMP" "$INDEX"
for f in $FILES; do rm -f "$PUBLIC/$f"; done
echo "Removed corescope-voices from $PUBLIC"
exit 0
fi
# If CoreScope already ships the voices, installing would load them twice.
if grep -q 'audio-synthkit.js' "$TMP"; then
rm -f "$TMP"
echo "This CoreScope already includes the extra voices; nothing to install."
exit 0
fi
grep -q "$ANCHOR" "$TMP" || { rm -f "$TMP"; die "no <script> tag for $ANCHOR in $INDEX; cannot place the voices"; }
for f in $FILES; do
[ -f "$HERE/voices/$f" ] || { rm -f "$TMP"; die "missing $HERE/voices/$f"; }
cp "$HERE/voices/$f" "$PUBLIC/$f"
done
export TAGS
TAGS=$(for f in $FILES; do
printf ' <script src="%s?v=__BUST__" onerror="console.error('"'"'Failed to load:'"'"', this.src)"></script>\n' "$f"
done)
awk -v a="$ANCHOR" -v b="$BEGIN_MARK" -v e="$END_MARK" '
{ print }
!done && index($0, a) { print " " b; print ENVIRON["TAGS"]; print " " e; done = 1 }
' "$TMP" > "$INDEX"
rm -f "$TMP"
echo "Installed corescope-voices into $PUBLIC. Restart CoreScope so it re-reads index.html."