#!/bin/bash
# Run this in a terminal in the troggle directory: 'bash os-trog.sh'
# On WSL, do Shift-click in the file explorer on the troggle folder to open a Linux command line
# 'Open Linux shell here'
echo 'Run this in a terminal in the troggle directory: "bash venv-trog.sh"'
cat /etc/os-release
# Expects an Ubuntu 22.04 relatively clean install.

sudo apt install python-is-python3 -y
python --version : ensure python is an alias for python3 not python2.7
sudo apt update -y
sudo apt dist-upgrade -y
sudo apt autoremove -y
sudo apt install sqlite3 -y
sudo apt install python3-pip  -y

# this installs a shed-load of other stuff: binutils etc.sudo apt install survex-aven
sudo apt install git openssh-client -y
# On a clean debian 11 (bullseye) installation with Xfce & ssh, 

    #on ubuntu 20.04:
    #Package sftp is not available, but is referred to by another package.
    #This may mean that the package is missing, has been obsoleted, or
    #is only available from another source
    #E: Package 'sftp' has no installation candidate
    
    
# On Ubuntu 20.04, with python10, the pip install fails.
# So you need to get the pip from source
# sudo curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
# but really you should be using 22.04
# and also, isf using debian, 
# sudo python3.10 -m pip install -U virtualenv

# do not actually use this any more
sudo useradd expo
sudo usermod -a -G sudo expo # to put expo in sudoers group, re-login required

# as debian does not install everything that ubuntu does, you need:
sudo apt install python3-venv -y
sudo apt install python3-dev -y

# default since 22.04 
# sudo apt install python3.10
sudo apt install python3.11-venv -y
sudo apt install python3.11-dev -y
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1

sudo apt install mariadb-server -y 
sudo apt install libmariadb-dev -y

sudo python -m pip install --upgrade pip

sudo apt install sftp -y
echo '###'
echo '### NOW INSTALLING tunnel and therion, go and have a cup of tea. Or a 3-course meal.'
echo '###'
sudo apt install tunnelx therion -y
sudo apt install gedit

# Go to https://expo.survex.com/handbook/troggle/troglaptop.html#dbtools
# sudo service mysql start

echo "### python 3.12"
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.12-full -y
sudo apt install python3.12-distutils -y
sudo apt install python3.12-venv -y

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 7
sudo update-alternatives --config python
sudo rm /usr/bin/python3
sudo ln -s /etc/alternatives/python /usr/bin/python3
sudo apt dist-upgrade


# install VS code - but ONLY on a native ubuntu install, NOT in WSL
sudo apt install software-properties-common apt-transport-https wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt update
sudo apt install code

#this next crashes, why?
#sudo python -m pip install --upgrade pip

sudo apt install gpsprune qgis gedit tig gitg meld rsync

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git config --global pull.rebase true

echo '###'
echo '### Currently set version of python'
python --version

echo '###'
echo '### Now YOU have to configure the git settings for YOURSELF (not "expo")'
echo '### because you can't clone the repos without a key
# cd ~/expo

git clone ssh://expo@expo.survex.com/home/expo/troggle
git clone ssh://expo@expo.survex.com/home/expo/loser
git clone ssh://expo@expo.survex.com/home/expo/expoweb
git clone ssh://expo@expo.survex.com/home/expo/drawings

mkdir expofiles
rsync -azv --delete-after --prune-empty-dirs --exclude="photos" --exclude="video" expo@expo.survex.com:expofiles/ expofiles
rsync  -azv --exclude="*.jpg.xml" --exclude="*.jpeg.xml" --exclude="*.JPG.xml" expo@expo.s^Cvex.com:expofiles/photos/ expofiles/photos

