#!/bin/bash

DIR="$(dirname "$(readlink -f "$0")")"

echo "WARNING: This will modify your RVGL installation in:"
echo -e "\t$DIR"
read -r -p "Are you sure? [y/N] " response
echo
if [[ ! "${response,,}" =~ ^(yes|y)$ ]]; then
  exit
fi

cd "$DIR"

echo "Fixing filenames..."
shopt -s globstar
re="^\./[^/]*\.dll$\|^\./lib/.*\.so.*$|^\./licenses/.*$"
for file in **; do
  dest="./${file,,}"
  file="${dest%/*}"/"${file##*/}"
  if [[ "$file" != "$dest" && ! "$file" =~ $re ]]; then
    [ ! -e "$dest" ] && mv -T "$file" "$dest" || echo "$file was not renamed"
  fi
done

echo "Done."
read -r -p "Press any key to continue." -n 1
echo
