2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00
troggle/venv-trog.sh

170 lines
5.1 KiB
Bash
Raw Normal View History

2022-03-02 23:18:39 +00:00
#!/bin/bash
2022-10-27 16:29:11 +01:00
# footled lots to make this work with python 3.10 and WSL1 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-10-27 16:29:11 +01:00
echo '-- Run this in a terminal in the troggle directory: "bash venv-trog.sh"'
2022-03-02 23:18:39 +00:00
2022-06-25 17:28:01 +01:00
# Expects an Ubuntu 22.04 relatively clean install.
# Running using SQLite version 3.37.2 2022-01-06 13:25:41
# Many permissions conflicts under WSL2 mean more sudo needed
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-10-27 16:29:11 +01:00
# which does the following:
2022-06-25 17:28:01 +01:00
# python --version : ensure python is an alias for python3 not python2.7
2022-03-02 23:18:39 +00:00
# sudo apt install sqlite3
# sudo apt install python3-pip # this installs a shed-load of other stuff: binutils etc.
2022-06-25 17:28:01 +01:00
# sudo apt install python3.10
# sudo apt install python3.10-venv
# sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
# on WSL there is an oddity that creating a venv trips over a PowerShell permissions issue
# and of course:
# sudo apt update
# sudo apt dist-upgrade
2022-03-02 23:18:39 +00:00
# On a clean debian 11 (bullseye) installation with Xfce & ssh,
# as debian does not install everything that ubuntu does, you need:
# sudo usermod -a -G sudo expo # to put expo in sudoers group, re-login required
# sudo apt install python3.10
# sudo apt install python3.10-pip
# sudo apt install python3.10-venv
# sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1
#
2022-10-27 16:29:11 +01:00
# NOW we set up troggle
2022-03-02 23:18:39 +00:00
# copy this file and requirements.txt into the directory above where you want to install the VENV
2022-10-27 16:29:11 +01:00
VENAME=zp310d3 # python3.10 and django 3.2
echo "-- Script executed from: ${PWD}"
TROGDIR=$(cd $(dirname $0) && pwd)
sudo echo "-- Troggle folder (this script location): ${TROGDIR}"
2022-03-02 23:18:39 +00:00
if [ -d requirements.txt ]; then
2022-10-27 16:29:11 +01:00
echo "-- No requirements.txt found. Copy it from your most recent installation."
2022-03-02 23:18:39 +00:00
exit 1
fi
python --version
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 ~
# cd ..
# mkdir expo
# cd expo
# ln -s ${TROGDIR}../$VENAME $VENAME
if [ -d troggle ]; then
echo "-- No /troggle/ found. Creating links."
ln -s ${TROGDIR} troggle
ln -s ${TROGDIR}/../expoweb expoweb
ln -s ${TROGDIR}/../loser loser
ln -s ${TROGDIR}/../drawings drawings
ln -s ${TROGDIR}/../expofiles expofiles
fi
# LOOK HERE: we go up a level so that /$VENAME is parallel to /troggle
2022-10-27 16:29:11 +01:00
#cd ..
2022-03-02 23:18:39 +00:00
if [ ! -d $VENAME ]; then
2022-10-27 16:29:11 +01:00
echo "## Creating venv $VENAME. (If this fails with a pip error, you need to 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
2022-10-27 16:29:11 +01:00
# seems to create infinite loop for tests
# echo "-- Make link from EXPO folder to venv $VENAME"
# sudo ln -s $VENAME ${TROGDIR}/../$VENAME
2022-03-02 23:18:39 +00:00
# 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}"
2022-03-02 23:18:39 +00:00
source bin/activate
echo "### Activated."
# 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
#This fails when using python3.10 (which has installed pip 22.0.2) and is attempting to upgrade to 22.3
# WARNING: No metadata found in ./lib/python3.10/site-packages
# and then the rollback fails to roll back successfully.
2022-06-25 19:34:42 +01:00
echo "### installing later version of pip inside $VENAME"
python -m pip install --upgrade pip
2022-10-27 16:29:11 +01:00
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 16:29:11 +01:00
ln -s ${TROGDIR} troggle
ln -s ${TROGDIR}/../expoweb expoweb
ln -s ${TROGDIR}/../loser loser
ln -s ${TROGDIR}/../drawings drawings
ln -s ${TROGDIR}/../expofiles expofiles
2022-03-02 23:18:39 +00:00
# Package Version
# ------------- ----------
echo '### links to expoweb, troggle etc. complete'
echo '###'
2022-10-27 16:29:11 +01:00
echo '### now installing ${TROGDIR}/requirements.txt'
2022-03-02 23:18:39 +00:00
echo '###'
2022-10-27 16:29:11 +01:00
$PIP install -r ${TROGDIR}/requirements.txt
2022-03-02 23:18:39 +00:00
echo '### install from requirements.txt completed.'
echo '### '
$PIP freeze > requirements.txt
# 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 virtualenv installed anyway
sort original.txt > 1
sort requirements.txt >2
comm -3 1 2 --check-order | awk '{ print $1}'>fresh-requirements.txt
rm 1
rm 2
cp requirements.txt requirements-$VENAME.txt
cp requirements-$VENAME.txt troggle/requirements-$VENAME.txt
$PIP list > installed-pip.list
$PIP list -o > installed-pip-o.list
REQ=installation-record
mkdir $REQ
mv requirements-$VENAME.txt $REQ
mv original.txt $REQ
2022-10-27 16:29:11 +01:00
mv requirements.txt $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
cp fresh-requirements.txt ../requirements.txt
mv fresh-requirements.txt $REQ
cp troggle/`basename "$0"` $REQ
2022-10-27 16:29:11 +01:00
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-06-25 19:34:42 +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-06-25 19:34:42 +01:00
'python manage.py check'
2022-10-27 16:29:11 +01:00
'./pre-run.sh'
2022-03-02 23:18:39 +00:00
'python manage.py test -v 3' "