#!/bin/sh
base="$PWD"
src="/n/s/dev/src"
dst="$base/osmo_fsm_graphs"
dot="$dst/dot"
png="$dst/png"
err="$dst/errors.txt"
tgz="$dst/osmo_fsm_graphs.tgz"
remote="po"
remote_dst="public_html/osmo_fsm_graphs"
scripts="$dst/scripts"

set -x

rm -rf "$dst"

mkdir -p "$dot"
cd "$dot"
set +x
echo "$src"/libosmocore/contrib/fsm-to-dot.py "[...]"
"$src"/libosmocore/contrib/fsm-to-dot.py $(find "$src" -name "*.c") > "$err" 2>&1
set -x

mkdir -p "$png"
cd "$png"
for f in "$dot"/*.dot ; do dot -Tpng "$f" > "$(basename "$f").png"; done

cd "$dst"
"$base"/to_html.py

mkdir "$scripts"
cp "$base/"*.sh "$base/"*.py "$scripts"/

cd "$dst"/..
tar czf new.tgz "$(basename "$dst")"
mv new.tgz "$tgz"


echo "hit enter to publish"
read enter_to_publish
ssh "$remote" rm -rf "$remote_dst"
scp -r "$dst" "$remote":"$remote_dst"
