#!/bin/bash
# now using uv, unbelieveably simpler.
# Run this in a terminal in the troggle directory: 'bash venv-trog.sh'
echo '-- Run this in a terminal in the directory above the troggle directory: "bash troggle/venv-trog.sh"'

# Expects an Ubuntu 22.04 with all the gubbins already installed
# If you have not already installed these on your clean Ubuntu install DO THIS FIRST
# use the script os-trog24.04.sh runniing it in /home/username/
python --version

echo "-- EXPO    folder [current directory]:    `pwd`"
TROGDIR=$(cd $(dirname $0) && pwd)
echo "-- Troggle folder [this script location]: ${TROGDIR}"

cp troggle/pyproject.toml .

uv self update
uv sync


exit 1
# this next is a bit wordy
# uv python list --only-installed

# we are in  /home/$USER/expo/
# ln -s ${TROGDIR} troggle
# ln -s ${TROGDIR}/../expoweb expoweb
# ln -s ${TROGDIR}/../loser loser
# ln -s ${TROGDIR}/../drawings drawings
#ln -s ${TROGDIR}/../expofiles expofiles

# fudge for philip's laptop prior to M2 SSD upgrade
if [ ! -d /mnt/d/EXPO ]; then
  sudo mkdir /mnt/d
  sudo mount -t drvfs D: /mnt/d
fi
  
if [  -d ${TROGDIR}/../expofiles ]; then
  ln -s ${TROGDIR}/../expofiles expofiles
else
  ln -s /mnt/d/EXPO/expofiles expofiles
fi

read -p "Press any key to resume ..."
PIP="uv pip"


REQUIRE="requirements.txt"
$PIP freeze > $REQUIRE  
$PIP list 

echo "Django version:`uv run django-admin --version`"

echo "### Now do 
  '[sudo service mysql start]'
  '[sudo service mariadb restart]'
  '[sudo mysql_secure_installation]'
  'cd troggle'
  'uv run django-admin'
  'uv run manage.py check'
## this tests if you have set up ssh correcting. Refer to documentation https://expo.survex.com/handbook/computing/keyexchange.html
## you need to follow the Linux instructions.
  'ssh expo@expo.survex.com'

## the next tests will fail unless ~/expofiles is set correctly to a folder on your machine

   'uv run  manage.py test -v 2'
   './pre-run.sh' (runs the tests again)
   
   'uv run  databaseReset.py reset INIT'
   'uv run  manage.py runserver 0.0.0.0:8000 (and allow access when the firewall window pops up)'
   "
# if [ ! -d /mnt/d/expofiles ]; then
  # echo '### No valid expofiles directory on /mnt/d . Fix this before any tests will work.'
# fi