2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-12-19 15:02:17 +00:00
troggle/_deploy/wsl/venv-trog-d5.sh

184 lines
5.6 KiB
Bash
Raw Normal View History

2022-03-02 23:18:39 +00:00
#!/bin/bash
2022-11-15 23:56:17 +00:00
# footled lots to make this work with python 3.10 & 3.11 and WSL1 and WSL2 on Ubuntu 22.04
2022-03-02 23:18:39 +00:00
# Run this in a terminal in the troggle directory: 'bash venv-trog.sh'
2022-11-15 23:56:17 +00:00
echo '-- Run this in a terminal in the real troggle directory: "bash venv-trog.sh"'
2022-03-02 23:18:39 +00:00
2023-05-02 12:27:55 +01:00
# Expects an Ubuntu 22.04 (or 20.04) relatively clean install.
2022-03-02 23:18:39 +00:00
# If you have not already installed these on your clean Ubuntu install DO THIS FIRST
2022-06-25 17:28:01 +01:00
# use the script os-trog.sh
2022-11-15 23:56:17 +00:00
# If you are using Debian, then stick with the default version of python
2022-11-23 21:59:42 +00:00
# If you are using Ubuntu, then it is easy to use a later version of python, e.g. 3.11
2022-11-15 23:56:17 +00:00
2022-10-27 16:29:11 +01:00
# NOW we set up troggle
2023-02-11 23:03:12 +00:00
PYTHON=python3.11
2023-09-26 13:20:59 +01:00
VENAME=p11d5 # python3.x and django 4.2
2022-10-27 17:23:41 +01:00
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`/$VENAME/"
2022-10-27 16:29:11 +01:00
TROGDIR=$(cd $(dirname $0) && pwd)
2022-10-27 17:23:41 +01:00
echo "-- Troggle folder (this script location): ${TROGDIR}"
2022-03-02 23:18:39 +00:00
2023-09-26 13:20:59 +01:00
REQUIRE=requirements-$VENAME.txt
if [ -d $REQUIRE ]; then
echo "-- No ${REQUIRE} found. You should be in the /troggle/ folder. Copy it from your most recent installation."
2022-03-02 23:18:39 +00:00
exit 1
fi
2023-09-26 13:20:59 +01:00
echo ## Using $REQUIRE :
cat $REQUIRE
2022-11-15 23:56:17 +00:00
echo ##
2022-03-02 23:18:39 +00:00
2023-05-02 21:26:53 +01:00
2022-11-15 23:56:17 +00:00
$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
2022-10-27 16:29:11 +01:00
# 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 ~
2022-03-02 23:18:39 +00:00
if [ ! -d $VENAME ]; then
2022-11-15 23:56:17 +00:00
echo "## Creating venv $VENAME. (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 $VENAME
2022-03-02 23:18:39 +00:00
else
2022-10-27 16:29:11 +01:00
echo "## /$VENAME/ already exists ! Delete it first."
2022-03-02 23:18:39 +00:00
exit 1
fi
# Activate the virtual env and see what the default packages are
echo "### Activating $VENAME"
2022-10-27 16:29:11 +01:00
2022-03-02 23:18:39 +00:00
cd $VENAME
2022-10-27 16:29:11 +01:00
echo "-- now in: ${PWD}"
2023-09-26 13:20:59 +01:00
ls -tlarg
2022-03-02 23:18:39 +00:00
source bin/activate
2023-09-26 13:20:59 +01:00
echo $VIRTUAL_ENV
if [ -d ~/$VENAME/bin ]; then
echo "### Activating."
else
echo "## ~/$VENAME/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
2022-10-27 16:29:11 +01:00
2022-10-27 17:23:41 +01:00
# update local version of setuptools, more recent than OS version, needed for packages without wheels
2022-10-27 16:29:11 +01:00
2022-06-25 19:34:42 +01:00
echo "### installing later version of pip inside $VENAME"
2022-11-15 23:56:17 +00:00
$PYTHON -m pip install --upgrade pip
$PYTHON -m pip install --upgrade setuptools
PIP=pip
2022-03-02 23:18:39 +00:00
$PIP list > original-pip.list
$PIP freeze >original.txt
2022-10-27 17:23:41 +01:00
# we are in /home/$USER/$VENAME/
2022-10-27 16:29:11 +01:00
ln -s ${TROGDIR} troggle
ln -s ${TROGDIR}/../expoweb expoweb
ln -s ${TROGDIR}/../loser loser
ln -s ${TROGDIR}/../drawings drawings
2023-05-02 13:28:28 +01:00
#ln -s ${TROGDIR}/../expofiles expofiles
2022-10-27 16:29:11 +01:00
2022-11-15 23:56:17 +00:00
# fudge for philip's machine
2023-05-02 13:28:28 +01:00
if [ ! -d /mnt/d/EXPO ]; then
sudo mkdir /mnt/d
sudo mount -t drvfs D: /mnt/d
fi
2022-11-15 23:56:17 +00:00
if [ -d ${TROGDIR}/../expofiles ]; then
ln -s ${TROGDIR}/../expofiles expofiles
else
2023-05-02 13:28:28 +01:00
ln -s /mnt/d/EXPO/expofiles expofiles
2022-11-15 23:56:17 +00:00
fi
2022-11-23 21:59:42 +00:00
echo "### Setting file permissions.. may take a while.."
git config --global --add safe.directory '*'
2023-05-02 12:27:55 +01:00
sudo chmod -R 777 *
2022-11-15 23:56:17 +00:00
echo "### links to expoweb, troggle etc. complete:"
ls -tla
2022-10-27 17:23:41 +01:00
echo "###"
2023-09-26 13:20:59 +01:00
echo "### now installing ${TROGDIR}/${REQUIRE}"
2022-10-27 17:23:41 +01:00
echo "###"
2023-09-26 13:20:59 +01:00
cat ${TROGDIR}/${REQUIRE}
2023-02-11 23:03:12 +00:00
# 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
2023-09-26 13:20:59 +01:00
read -p "Press any key to resume ..."
$PIP install -r ${TROGDIR}/${REQUIRE}
echo "### install from ${TROGDIR}/${REQUIRE} completed."
2022-03-02 23:18:39 +00:00
echo '### '
2023-09-26 13:20:59 +01:00
$PIP install --pre django
$PIP freeze > $REQUIRE
2022-03-02 23:18:39 +00:00
# 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
2022-10-27 17:23:41 +01:00
# Now find out what we actually installed by subtracting the stuff venv installed anyway
2022-03-02 23:18:39 +00:00
sort original.txt > 1
2023-09-26 13:20:59 +01:00
sort $REQUIRE >2
comm -3 1 2 --check-order | awk '{ print $1}'>fresh-$REQUIRE
2022-03-02 23:18:39 +00:00
rm 1
rm 2
2023-09-26 13:20:59 +01:00
# cp $REQUIRE requirements-$VENAME.txt
cp $REQUIRE troggle/$REQUIRE
2022-03-02 23:18:39 +00:00
$PIP list > installed-pip.list
$PIP list -o > installed-pip-o.list
REQ=installation-record
mkdir $REQ
2023-09-26 13:20:59 +01:00
2022-03-02 23:18:39 +00:00
mv original.txt $REQ
2023-09-26 13:20:59 +01:00
mv $REQUIRE $REQ
2022-03-02 23:18:39 +00:00
mv original-pip.list $REQ
mv installed-pip.list $REQ
mv installed-pip-o.list $REQ
2023-09-26 13:20:59 +01:00
cp fresh-$REQUIRE ../$REQUIRE
mv fresh-$REQUIRE $REQ
2022-03-02 23:18:39 +00:00
cp troggle/`basename "$0"` $REQ
2022-10-27 16:29:11 +01:00
2022-11-15 23:56:17 +00:00
$PYTHON --version
2022-03-02 23:18:39 +00:00
python --version
2022-10-27 16:29:11 +01:00
echo "Django version:`django-admin --version`"
2022-03-02 23:18:39 +00:00
echo "### Now do
2022-10-27 17:23:41 +01:00
'[sudo service mysql start]'
'[sudo service mariadb restart]'
'[sudo mysql_secure_installation]'
2022-10-27 16:29:11 +01:00
'cd ~/$VENAME'
2022-03-02 23:18:39 +00:00
'source bin/activate'
'cd troggle'
2022-11-15 23:56:17 +00:00
'django-admin'
2022-06-25 19:34:42 +01:00
'python manage.py check'
2022-11-23 21:59:42 +00:00
## 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
2023-05-02 12:27:55 +01:00
2022-11-23 21:59:42 +00:00
## So you will need to run
$sudo chown -Rhv philip:philip ~/$VENAME (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.
2022-10-27 17:23:41 +01:00
'python manage.py test -v 2'
2022-11-23 21:59:42 +00:00
'./pre-run.sh' (runs the tests again)
2022-10-27 17:23:41 +01:00
'python databaseReset.py reset $VENAME'
'python manage.py runserver 0.0.0.0:8000 (and allow access when the firewall window pops up)'
"
2023-09-26 13:20:59 +01:00
# if [ ! -d /mnt/d/expofiles ]; then
# echo '### No valid expofiles directory on /mnt/d . Fix this before any tests will work.'
# fi