#!/usr/bin/env bash
################################################################################

PYMODULE=OpenSSL
PIPMODULE=pyOpenSSL
PACKAGE=python-openssl
# 170104 want 16.2.0
# centos6 pyOpenSSL.x86_64 0:0.13.1-2.el6
# centos7 pyOpenSSL.x86_64 0:0.13.1-3.el7
# debian7 wheezy python-openssl_0.13-2+deb7u1_amd64.deb
# debian8 jessie python-openssl_0.14-1_all.deb
# ubuntu12 precise python-openssl_0.12-1ubuntu2.1_amd64.deb
# ubuntu14 trusty python-openssl_0.13-2ubuntu6_amd64.deb
# ubuntu16 xenial python-openssl_0.15.1-2build1_all.deb


################################################################################

if [ $EUID -ne 0 ]; then
	echo "This script requires root or sudo privileges."
	exit 1
fi

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

python <<EOF
try:
	import ${PYMODULE}
	import sys
	sys.exit(0)
except Exception as e:
	import sys
	sys.exit(1)
EOF
has_pymodule=$?

if [ $has_pymodule -eq 0 ]; then
	exit 0
fi

if [ -f /etc/os-release ]; then
	. /etc/os-release
fi

distro_id=${ID,,}
distro_version=${VERSION_ID}

case "$distro_id:$distro_version" in
	* )
		echo Installing ${PACKAGE}
		apt-get install -y ${PACKAGE}
		;;
esac
