| 1 |
# dh-virtualenv postinst autoscript |
| 2 |
set -e |
| 3 |
#ARGS# |
| 4 |
|
| 5 |
# set to empty to enable verbose output |
| 6 |
test "${DH_VERBOSE:-0}" = "1" && DH_VENV_DEBUG="" || DH_VENV_DEBUG=: |
| 7 |
$DH_VENV_DEBUG set -x |
| 8 |
|
| 9 |
|
| 10 |
dh_venv_safe_interpreter_update() { |
| 11 |
# get Python version used |
| 12 |
local pythonX_Y=$(cd "$dh_venv_install_dir/lib" && ls -1d python[2-9].*[0-9] | tail -n1) |
| 13 |
|
| 14 |
local i |
| 15 |
for i in python ${pythonX_Y%.*} ${pythonX_Y}; do |
| 16 |
local interpreter_path="$dh_venv_install_dir/bin/$i" |
| 17 |
|
| 18 |
# skip any symlinks, and make sure we have an existing target |
| 19 |
test ! -L "$interpreter_path" || continue |
| 20 |
test -x "$interpreter_path" || continue |
| 21 |
|
| 22 |
# skip if already identical |
| 23 |
if cmp "/usr/bin/$pythonX_Y" "$interpreter_path" >/dev/null 2>&1; then |
| 24 |
continue |
| 25 |
fi |
| 26 |
|
| 27 |
# hardlink or copy new interpreter |
| 28 |
cp -fpl "/usr/bin/$pythonX_Y" "$interpreter_path,new" \ |
| 29 |
|| cp -fp "/usr/bin/$pythonX_Y" "$interpreter_path,new" \ |
| 30 |
|| rm -f "$interpreter_path,new" \ |
| 31 |
|| true |
| 32 |
|
| 33 |
# make a backup (once) |
| 34 |
test -f "$interpreter_path,orig" || ln "$interpreter_path" "$interpreter_path,orig" |
| 35 |
|
| 36 |
# atomic move |
| 37 |
if test -x "$interpreter_path,new" && mv "$interpreter_path,new" "$interpreter_path"; then |
| 38 |
echo "Successfully updated $interpreter_path" |
| 39 |
else |
| 40 |
echo >&2 "WARNING: Some error occured while updating $interpreter_path" |
| 41 |
fi |
| 42 |
done |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
case "$1" in |
| 47 |
configure|reconfigure) |
| 48 |
$DH_VENV_DEBUG echo "$0 $1 called with $# args:" "$@" |
| 49 |
dh_venv_safe_interpreter_update |
| 50 |
;; |
| 51 |
|
| 52 |
triggered) |
| 53 |
$DH_VENV_DEBUG echo "$0 $1 called with $# args:" "$@" |
| 54 |
for trigger in $2; do |
| 55 |
case "$trigger" in |
| 56 |
/usr/bin/python?.*) |
| 57 |
# this trigger might be for the "wrong" interpreter (other version), |
| 58 |
# but the "cmp" in "dh_venv_safe_interpreter_update" and the fact we only |
| 59 |
# ever look at our own Python version catches that |
| 60 |
dh_venv_safe_interpreter_update |
| 61 |
;; |
| 62 |
dh-virtualenv-interpreter-update) |
| 63 |
dh_venv_safe_interpreter_update |
| 64 |
;; |
| 65 |
*) |
| 66 |
#echo >&2 "ERROR:" $(basename "$0") "called with unknown trigger '$2'" |
| 67 |
#exit 1 |
| 68 |
;; |
| 69 |
esac |
| 70 |
done |
| 71 |
;; |
| 72 |
|
| 73 |
abort-upgrade|abort-remove|abort-deconfigure) |
| 74 |
;; |
| 75 |
|
| 76 |
*) |
| 77 |
#echo >&2 "ERROR:" $(basename "$0") "called with unknown argument '$1'" |
| 78 |
#exit 1 |
| 79 |
;; |
| 80 |
esac |
| 81 |
|
| 82 |
$DH_VENV_DEBUG set +x |
| 83 |
# END dh-virtualenv postinst autoscript |