From 7af7dbaaa9d36d3f9381e78dc93f1b99fe904d3c Mon Sep 17 00:00:00 2001 From: mickael e Date: Wed, 16 Oct 2019 09:24:06 -0400 Subject: [PATCH] Remove Tails 3.x admin virtualenv when upgrading to Tails 4.x Fixes #4910 --- admin/bootstrap.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/admin/bootstrap.py b/admin/bootstrap.py index 766b27c611..a41ee33d1b 100755 --- a/admin/bootstrap.py +++ b/admin/bootstrap.py @@ -20,6 +20,7 @@ import argparse import logging import os +import shutil import subprocess import sys @@ -75,6 +76,32 @@ def is_tails(): return id == 'Tails' +def clean_up_tails3_venv(): + """ + Tails 3.x, based on debian stretch uses libpython3.5, whereas Tails 4.x is + based on Debian Buster and uses libpython3.7. This means that the Tails 3.x + virtualenv will not work under Tails 4.x, and will need to be destroyed and + rebuilt. We can detect if the version of libpython is 3.5 in the + admin/.venv3/ folder, and delete it if that's the case. This will ensure a + smooth upgrade from Tails 3.x to Tails 4.x. + """ + if is_tails(): + try: + dist = subprocess.check_output('lsb_release --codename --short', + shell=True).strip() + except subprocess.CalledProcessError: + dist = None + + # tails4 is based on buster + if dist == 'buster': + python_lib_path = os.path.join(VENV_DIR, "lib/python3.5") + if os.path.exists(os.path.join(python_lib_path)): + sdlog.info("Tails 3 Python 3 virtualenv detected.") + shutil.rmtree(VENV_DIR) + sdlog.info("Tails 3 Python 3 virtualenv deleted. It will be " + "rebuilt to complete migration to Tails 4.x") + + def maybe_torify(): if is_tails(): return ['torify'] @@ -130,6 +157,9 @@ def envsetup(args): Ansible is available to the Admin on subsequent boots without requiring installation of packages again. """ + # clean up tails 3.x venv when migrating to tails 4.x + clean_up_tails3_venv() + # virtualenv doesnt exist? Install dependencies and create if not os.path.exists(VENV_DIR):