Last active
October 5, 2018 17:12
-
-
Save ulcuber/0c245b30eacfb6a4a671737385e7e60d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# run with sudo -H | |
HELP="Missing params\nsudo -H bash pgAdmin.sh <user> <host>" | |
APACHE_SITES="/etc/apache2/sites-available" | |
USER=${1} | |
if [[ -z ${USER} ]]; then | |
echo -e ${HELP} | |
exit 1 | |
fi | |
HOST=${2} | |
if [[ -z ${HOST} ]]; then | |
echo -e ${HELP} | |
exit 1 | |
fi | |
# Dependencies | |
add-apt-repository ppa:deadsnakes/ppa | |
apt-get update | |
apt-get install python3.5 python3.5-venv python3-pip python3.5-dev libpq-dev libapache2-mod-wsgi-py3 libffi-dev | |
# VENV | |
python3.5 -m venv pgAdmin4 | |
cd pgAdmin4 | |
VENV_PATH=${PWD} | |
VENV_PATH_FOR_SED=$(echo ${PWD} | sed -e 's/[\/&]/\\&/g') | |
. ${VENV_PATH}/bin/activate | |
echo 'Insise virtual env' | |
pip install https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v3.4/pip/pgadmin4-3.4-py2.py3-none-any.whl | |
python ./lib/python3.5/site-packages/pgadmin4/setup.py | |
deactivate | |
echo 'Outside virtual env' | |
EXEC_DIR="${VENV_PATH}/lib/python3.5/site-packages/pgadmin4/pgAdmin4.py" | |
echo -e "#!/usr/bin/env python\n$(cat ${EXEC_DIR})" > ${EXEC_DIR} | |
chmod +x ${EXEC_DIR} | |
chown -R ${USER}:${USER} ./ | |
chown -R ${USER}:${USER} '/var/log/pgadmin/' | |
chown -R ${USER}:${USER} '/var/lib/pgadmin/' | |
EXEC_DIR_FOR_SED=$(echo ${EXEC_DIR} | sed -e 's/[\/&]/\\&/g') | |
wget -qO- https://gist.githubusercontent.com/ulcuber/f9aa901cadd68bc6481fbe142e46b28e/raw/f0057c8575886ec532ae54d673d53057780815b9/pgadmin4.service |\ | |
sed "s/__EXEC_DIR__/${EXEC_DIR_FOR_SED}/" |\ | |
sed "s/__VENV_PATH__/${VENV_PATH_FOR_SED}/" \ | |
> /etc/systemd/system/pgadmin4.service | |
systemctl daemon-reload | |
systemctl enable pgadmin4 | |
systemctl start pgadmin4 | |
# Apache conf | |
a2enmod wsgi | |
# Apache vhost | |
wget -qO- https://gist.githubusercontent.com/ulcuber/8c3574e3f2627937d7f235165959fb19/raw/4bed49ef3df009e5bc18ce244d43d07e2fd35565/pgadmin.conf |\ | |
sed "s/ServerName.*/ServerName ${HOST}/" |\ | |
sed "s/__VENV_PATH__/${VENV_PATH_FOR_SED}/" \ | |
> ${APACHE_SITES}/${HOST}.conf | |
a2ensite ${HOST} | |
service apache2 restart > /dev/null | |
echo 'Apache restarted' | |
echo 'OK' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment