summaryrefslogtreecommitdiff
path: root/update.sh
blob: 677aa03e551de6b0109cf3117ce9f4f2735363f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# Use this script to download or update all dependencies to their last
# developpement version.
# The dependencies will be located in a virtualenv, so you do not
# need to install them on your system at all.

# Use launch.sh to start poezio directly from here

cd "$(dirname "$0")"
if [ -z "$POEZIO_VENV" ]
then
    POEZIO_VENV="poezio-venv"
fi

if [ -z "$POEZIO_PYTHON" ]
then
    POEZIO_PYTHON=python3
fi

command -v "$POEZIO_PYTHON" > /dev/null 2>&1 || {
    echo "Python executable '$POEZIO_PYTHON' not found."
    exit 1
}

$POEZIO_PYTHON -c 'import venv' &> /dev/null || {
    echo "'$POEZIO_PYTHON' venv module not found. Check that you have python (>= 3.7) installed,"
    exit 1
}

# XXX: Migration from master branch to main
branch=$(git rev-parse --abbrev-ref HEAD)
changes=$(git status --porcelain | grep -v "^??")
if [ "$branch" == "master" ]; then
  echo "! WARNING !"
  echo "We are changing our default branch to 'main' and we have detected"
  echo "you are still using 'master'."
  echo

  if [ -n "$changes" ]; then
    echo "! Manual action required !"
    echo "There are uncommited changes in your staging area. Please sort this"
    echo "out and then manually checkout the 'main' branch using 'git checkout main'."
    exit 1
  fi

  git checkout main
  echo "Automatically switched to 'main' branch."
fi

echo 'Updating poezio'
git pull --ff-only origin master || {
    echo "The script failed to update poezio."
    exit 1
}

if [ -e "$POEZIO_VENV" ]
then
    # In case of a python version upgrade
    echo 'Trying to upgrade the virtualenv'
    $POEZIO_PYTHON -m venv --upgrade "$POEZIO_VENV"
    $POEZIO_PYTHON -m venv --system-site-packages "$POEZIO_VENV"

    . "$POEZIO_VENV/bin/activate"
    echo 'Updating the in-venv pip'
    pip install --upgrade pip
    python3 -c 'import sys;(print("Python 3.7 or newer is required") and exit(1)) if sys.version_info < (3, 7) else exit(0)' || exit 1
    echo 'Updating the poezio dependencies'
    pip install -r requirements.txt --upgrade
    echo 'Updating the poezio plugin dependencies'
    pip install -r requirements-plugins.txt --upgrade
else
    echo "Creating the $POEZIO_VENV virtualenv"
    $POEZIO_PYTHON -m venv "$POEZIO_VENV"
    $POEZIO_PYTHON -m venv --system-site-packages "$POEZIO_VENV"

    . "$POEZIO_VENV/bin/activate"
    cd "$POEZIO_VENV" # needed to download slixmpp inside the venv
    python3 -c 'import sys;(print("Python 3.7 or newer is required") and exit(1)) if sys.version_info < (3, 7) else exit(0)' || exit 1

    echo 'Installing the poezio dependencies using pip'
    pip install -r "../requirements.txt"
    echo 'Installing the poezio plugin dependencies using pip'
    pip install -r "../requirements-plugins.txt"
    cd ..
fi

make