From dab3332f96033dc7d2be83d396302202d0a9681b Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 22 Sep 2015 14:55:23 +0100 Subject: [PATCH] Ensure python2 is installed before hook execution --- hooks/install | 21 ++++++++++++++++++++- hooks/install.real | 1 + hooks/rabbitmq_server_relations.py | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) mode change 120000 => 100755 hooks/install create mode 120000 hooks/install.real diff --git a/hooks/install b/hooks/install deleted file mode 120000 index eecaaa74..00000000 --- a/hooks/install +++ /dev/null @@ -1 +0,0 @@ -rabbitmq_server_relations.py \ No newline at end of file diff --git a/hooks/install b/hooks/install new file mode 100755 index 00000000..83a9d3ce --- /dev/null +++ b/hooks/install @@ -0,0 +1,20 @@ +#!/bin/bash +# Wrapper to deal with newer Ubuntu versions that don't have py2 installed +# by default. + +declare -a DEPS=('apt' 'netaddr' 'netifaces' 'pip' 'yaml') + +check_and_install() { + pkg="${1}-${2}" + if ! dpkg -s ${pkg} 2>&1 > /dev/null; then + apt-get -y install ${pkg} + fi +} + +PYTHON="python" + +for dep in ${DEPS[@]}; do + check_and_install ${PYTHON} ${dep} +done + +exec ./hooks/install.real diff --git a/hooks/install.real b/hooks/install.real new file mode 120000 index 00000000..eecaaa74 --- /dev/null +++ b/hooks/install.real @@ -0,0 +1 @@ +rabbitmq_server_relations.py \ No newline at end of file diff --git a/hooks/rabbitmq_server_relations.py b/hooks/rabbitmq_server_relations.py index 9e5a8c59..02e66862 100755 --- a/hooks/rabbitmq_server_relations.py +++ b/hooks/rabbitmq_server_relations.py @@ -101,7 +101,7 @@ STATS_DATAFILE = os.path.join(RABBIT_DIR, 'data', ''.format(socket.gethostname())) -@hooks.hook('install') +@hooks.hook('install.real') def install(): pre_install_hooks() # NOTE(jamespage) install actually happens in config_changed hook