#!/bin/bash

# doxygen produces html files with "~" in the name. while this is OK offline, it
# doesn't play well with many webservers. this script replaces all
# "...~.html" with "...-.html"

# navigate to rstt main folder
cd ../..
RSTT_HOME=$PWD

# GeoTessCPP
cd GeoTessCPP/doc/html  # navigate to folder
echo "cd --> GeoTessCPP/doc/html"
echo "Changing *~.html to ~-.html..."
for file in $(ls *~.html 2>/dev/null); do mv -v $file ${file/\~/-}; done  # rename ~.html to -.html
grep -l '~.html' *.* | xargs sed -i.tmp 's/~.html/-.html/g'  # replace all mentions of ~.html with -.html
rm -v *.tmp 2>/dev/null  # remove .tmp files from sed
echo ""
cd $RSTT_HOME

# SLBM
cd SLBM/doc/html  # navigate to folder
echo "cd --> SLBM/doc/html"
echo "Changing *~.html to ~-.html..."
for file in $(ls *~.html 2>/dev/null); do mv -v $file ${file/\~/-}; done  # rename ~.html to -.html
grep -l '~.html' *.* | xargs sed -i.tmp 's/~.html/-.html/g'  # replace all mentions of ~.html with -.html
rm -v *.tmp 2>/dev/null  # remove .tmp files from sed
echo ""
cd $RSTT_HOME
