#!/bin/bash
# -*- Mode:Shell; indent-tabs-mode:nil; tab-width -*-
#
# Copyright 2022 Kenneth Loafman <kenneth@loafman.com>
#
# This file is part of duplicity.
#
# Duplicity is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Duplicity is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with duplicity; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

set -e

if [ "`uname`" != "Linux" ]; then
    echo "$0 does not run on `uname`"
    exit 2
fi

if [ "$#" -ne 0 ]; then
    echo "usage: $0"
    exit 2
fi

VERS="3.8 3.9 3.10 3.11 3.12 3.13"

# install python build environ
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev \
                 libbz2-dev libreadline-dev libsqlite3-dev curl \
                 libncursesw5-dev xz-utils tk-dev libxml2-dev \
                 libxmlsec1-dev libffi-dev liblzma-dev

# install duplicity build environ
sudo apt install -y python3-dev librsync-dev gnupg

# install all versions of python and do initial setup
for V in ${VERS}; do
    pyenv global $V
    # here we install pip and friends with versions equal to Ubuntu repo that year
    if [[ `hostname` =~ "-20-" ]]; then
        curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
        python$V get-pip.py "pip==20.0.2" "setuptools==45.2.0" "wheel==0.34.2"
        python$V -m pip install distutils==3.8.10 packaging==20.3
    elif [[ `hostname` =~ "-22-" ]]; then
        curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
        python$V get-pip.py "pip==22.0.2" "setuptools==59.6.0" "wheel==0.37.1"
        python$V -m pip install build==0.7.0 distutils==3.10.8 packaging==21.3
    elif [[ `hostname` =~ "-24-" ]]; then
        curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
        python$V get-pip.py "pip==24.0" "setuptools==68.1.2" "wheel==0.42.0"
        python$V -m pip install build==1.0.3 packaging==24.0
    fi
    # install requirements.txt
    python$V -m pip install -U -r requirements.txt
done

pyenv global system
