Files

36 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# Install reversible boot hooks. Run as root after copying the files to the device.
set -eu
base=/data/opt/alice-backend
init=/etc/init.d
case "${1:-}" in
install)
[ -x "$base/alice-station" ] && [ -x "$base/station-supervisor.sh" ] && [ -r "$base/device-token" ] && [ -s "$base/alisa.tflite" ] && [ -x "$base/wake-helper.sh" ] && [ -x "$base/alice-wake-helper" ] || { echo 'Missing station binary, supervisor, token or keyword model' >&2; exit 1; }
chmod 600 "$base/device-token"
if [ ! -e "$base/S99quasar.original" ]; then cp -p "$init/S99quasar" "$base/S99quasar.original"; fi
cp "$base/S99alice" "$init/S99alice"
chmod 755 "$init/S99alice"
if [ -x "$base/S98alice-music" ]; then
cp "$base/S98alice-music" "$init/S98alice-music"
chmod 755 "$init/S98alice-music"
fi
cat > "$init/S99quasar.alice-new" <<'WRAPPER'
#!/bin/sh
if [ -f /data/opt/alice-backend/stock-disabled ]; then exit 0; fi
exec /data/opt/alice-backend/S99quasar.original "$@"
WRAPPER
chmod 755 "$init/S99quasar.alice-new"
mv "$init/S99quasar.alice-new" "$init/S99quasar"
touch "$base/stock-disabled"
;;
restore)
if [ -x "$init/S99alice" ]; then "$init/S99alice" stop; fi
if [ -x "$init/S98alice-music" ]; then "$init/S98alice-music" stop; fi
rm -f "$init/S98alice-music"
rm -f "$base/stock-disabled"
if [ -f "$base/S99quasar.original" ]; then cp -p "$base/S99quasar.original" "$init/S99quasar"; fi
rm -f "$init/S99alice"
;;
*) echo "Usage: $0 {install|restore}" >&2; exit 2;;
esac