#!/bin/bash

if [ -z "$PYTHON" ]; then
    echo "Error: no PYTHON in env" >&2
    exit 1
fi

./build.sh bundle

rm -rf snapshot/share

ln -snf ../ctl.py snapshot/
ln -snf ../share snapshot/
ln -snf ../install.sh snapshot/
ln -snf ../share/config_${VARIANT}.yaml snapshot/etc/config.yaml

for mod in $(ls src/); do
    if [ "$mod" = "${VARIANT/-/_}_api_proxy.py" ]; then
        tgt=snapshot/lib/${VARIANT/-/_}_api_proxy.py
        rm -rf "$tgt" "${tgt}c"  # coz we want to drop .pyc file as well
        ln -snf ../../src/$mod $tgt
    else
        tgt=snapshot/lib/${VARIANT/-/_}/$mod
        rm -rf $tgt
        ln -snf ../../../src/$mod $tgt
    fi
done
