#!/bin/bash
# Usage: bash reproduce.sh extracted-deb-root new-output-directory driver-file
set -eu
package=$(realpath "$1")
out=$(realpath -m "$2")
driver=$(realpath "$3")
mkdir -p "$out"/{home,config,data,runtime}
chmod 700 "$out/runtime"
HOME="$out/home" XDG_CONFIG_HOME="$out/config" XDG_DATA_HOME="$out/data" XDG_RUNTIME_DIR="$out/runtime" T3CODE_HOME="$out/t3" T3CODE_DEV_SEED=0 headless-desktop python3 "$driver" "$package" "$out"
# Exclude the private environment label; keep the complete dash menu and icon.
for label in running-menu pinned-quit pinned-relaunch; do
  if [ -f "$out/$label.png" ]; then
    convert "$out/$label.png" -crop 330x400+600+520 +repage "$out/$label-public.png"
  fi
done
ffmpeg -y -i "$out/interaction.mp4" -vf crop=330:400:600:520 -c:v libx264 -crf 18 -pix_fmt yuv420p -an -movflags +faststart "$out/interaction-public.mp4"
