diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2024-12-12 00:38:28 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2024-12-12 00:38:28 +0000 |
commit | f3235f8b762a2a404859c4c46d58ac7089c772bb (patch) | |
tree | 0e72ca7d1558016733c4044fe9f42ab846d2ca12 /_deploy | |
parent | 8b6a8be2c8930ecd0bab67cba37b7b8525f2443a (diff) | |
download | troggle-f3235f8b762a2a404859c4c46d58ac7089c772bb.tar.gz troggle-f3235f8b762a2a404859c4c46d58ac7089c772bb.tar.bz2 troggle-f3235f8b762a2a404859c4c46d58ac7089c772bb.zip |
using uv not pip
Diffstat (limited to '_deploy')
-rw-r--r-- | _deploy/wsl/venv-trog.sh | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/_deploy/wsl/venv-trog.sh b/_deploy/wsl/venv-trog.sh new file mode 100644 index 0000000..b96b422 --- /dev/null +++ b/_deploy/wsl/venv-trog.sh @@ -0,0 +1,184 @@ +#!/bin/bash +# footled lots to make this work with python 3.10 & 3.11 and WSL1 and WSL2 on Ubuntu 22.04 +# Run this in a terminal in the troggle directory: 'bash venv-trog.sh' +echo '-- Run this in a terminal in the real troggle directory: "bash 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 + +# NOW we set up troggle +PYTHONSVR=python3.11 +PYTHONDEV=python3.13 + +VSVR=svr # python3.11 and django 3.2 +VDEV=dev # python3.13 and django 5 +echo "** You are logged in as `id -u -n`" +#echo "The 50MB pip cache will be in /home/`id -u -n`/.cache/" +echo "The 150MB venv will created in /home/`id -u -n`/$VSVR/ and /home/`id -u -n`/$VDEV/ +TROGDIR=$(cd $(dirname $0) && pwd) +echo "-- Troggle folder (this script location): ${TROGDIR}" +exit +REQUIRE=requirements-$VSVR.txt + +if [ -d $REQUIRE ]; then + echo "-- No ${REQUIRE} found. You should be in the /troggle/ folder. Copy it from your most recent installation." + exit 1 +fi +echo ## Using $REQUIRE : +cat $REQUIRE +echo ## + + +$PYTHON --version + +# NOTE that when using a later or earlier verison of python, you MUST also +# use the allowed version of Pillow, see https://pillow.readthedocs.io/en/latest/installation.html + +# NOW set up link from expo user folder +# needed for WSL2 +echo Creating links from Linux filesystem user +# These links only need making once, for many venv +cd ~ + +if [ ! -d $VSVR ]; then + echo "## Creating venv $VSVR. (If this fails with a pip error, you need to ensure you have python3.11-venv installed and/or use a Ubuntu window)" + $PYTHON -m venv $VSVR +else + echo "## /$VSVR/ already exists ! Delete it first." + exit 1 +fi + + # Activate the virtual env and see what the default packages are +echo "### Activating $VSVR" + +cd $VSVR +echo "-- now in: ${PWD}" +ls -tlarg +source bin/activate +echo $VIRTUAL_ENV +if [ -d ~/$VSVR/bin ]; then + echo "### Activating." +else + echo "## ~/$VSVR/bin does not exist. FAILed to create venv properly." + exit 1 +fi + # update local version of pip, more recent than OS version + # debian bullseye installs pip 20.3.4 which barfs, we want >22.0.3 + + # update local version of setuptools, more recent than OS version, needed for packages without wheels + +echo "### installing later version of pip inside $VSVR" +$PYTHON -m pip install --upgrade pip +$PYTHON -m pip install --upgrade setuptools + +PIP=pip + +$PIP list > original-pip.list +$PIP freeze >original.txt + +# we are in /home/$USER/$VSVR/ +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 machine +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 + +echo "### Setting file permissions.. may take a while.." +git config --global --add safe.directory '*' +sudo chmod -R 777 * + +echo "### links to expoweb, troggle etc. complete:" +ls -tla +echo "###" +echo "### now installing ${TROGDIR}/${REQUIRE}" +echo "###" +cat ${TROGDIR}/${REQUIRE} + +# NOW THERE IS A PERMISSIONS FAILURE THAT DIDN'T HAPPEN BEFORE +# seen on wsl2 as well as wsl1 +# which ALSO ruins EXISTING permissions ! +# Guessing it is to do with pip not liking non-standard py 3.11 installation on Ubuntu 22.04 + +read -p "Press any key to resume ..." +$PIP install -r ${TROGDIR}/${REQUIRE} +echo "### install from ${TROGDIR}/${REQUIRE} completed." +echo '### ' + +$PIP install --pre django + +$PIP freeze > $REQUIRE +# so that we can track requirements more easily with git +# because we do not install these with pip, but they are listed by the freeze command +# Now find out what we actually installed by subtracting the stuff venv installed anyway +sort original.txt > 1 +sort $REQUIRE >2 +comm -3 1 2 --check-order | awk '{ print $1}'>fresh-$REQUIRE +rm 1 +rm 2 + +# cp $REQUIRE requirements-$VSVR.txt +cp $REQUIRE troggle/$REQUIRE + +$PIP list > installed-pip.list +$PIP list -o > installed-pip-o.list + +REQ=installation-record +mkdir $REQ + +mv original.txt $REQ +mv $REQUIRE $REQ +mv original-pip.list $REQ +mv installed-pip.list $REQ +mv installed-pip-o.list $REQ +cp fresh-$REQUIRE ../$REQUIRE +mv fresh-$REQUIRE $REQ +cp troggle/`basename "$0"` $REQ + + +$PYTHON --version +python --version +echo "Django version:`django-admin --version`" + +echo "### Now do + '[sudo service mysql start]' + '[sudo service mariadb restart]' + '[sudo mysql_secure_installation]' + 'cd ~/$VSVR' + 'source bin/activate' + 'cd troggle' + 'django-admin' + 'python 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 +## the tests may ALSO fail because of ssh and permissions errors + +## So you will need to run +$sudo chown -Rhv philip:philip ~/$VSVR (if your username is philip) +# and then REBOOT (or at least, exit WSL and terminate and restart WSL) +# because this chmod only takes effect then. + + 'python manage.py test -v 2' + './pre-run.sh' (runs the tests again) + + 'python databaseReset.py reset $VSVR' + 'python 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
\ No newline at end of file |