Skip to content

Instantly share code, notes, and snippets.

@melizeche
Last active June 1, 2020 17:45
Show Gist options
  • Save melizeche/b780f01509c48563f8d4ed5af60adc56 to your computer and use it in GitHub Desktop.
Save melizeche/b780f01509c48563f8d4ed5af60adc56 to your computer and use it in GitHub Desktop.
Easy pgAdmin4 2.0 Installer with python3 for Ubuntu
#!/bin/bash
SP_PATH=$(python3 -m site --user-site)
URL="https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v2.0/pip/pgadmin4-2.0-py2.py3-none-any.whl"
ICON="https://www.postgresql.org/message-id/attachment/1139/pgAdmin.svg"
FILE=$(echo $URL | sed 's/.*\///')
#Install pip3
echo "Installing python3-pip if not installed..."
sudo apt install -y python3-pip
#Get pgAdmin4 Python Wheel
echo "Downloading pgAdmin4..."
wget -c $URL -O /tmp/$FILE
#Install pgAdmin4 package
pip3 install /tmp/$FILE
#Create necessary directories
sudo mkdir -p /var/log/pgadmin
sudo mkdir -p /var/lib/pgadmin/sessions
sudo mkdir -p /var/lib/pgadmin/storage
sudo chmod 777 -R /var/log/pgadmin/ /var/lib/pgadmin/
#Create basic configuration file
echo "SERVER_MODE = False">$SP_PATH/pgadmin4/config_local.py
#Create launcher
printf "#!/bin/bash\npython3 $SP_PATH/pgadmin4/pgAdmin4.py & sleep 7 && xdg-open http://localhost:5050\n">${HOME}/pgadmin4.sh
# Create desktop launcher
printf "#!/usr/bin/env xdg-open\n[Desktop Entry]\nName=pgAdmin 4\nExec=${HOME}/pgadmin4.sh\nIcon=${HOME}/.local/share/icons/pgadmin.svg\nType=Application\nCategories=Database;\nTerminal=false\n">~/.local/share/applications/pgAdmin4.desktop
chmod +x ${HOME}/pgadmin4.sh ${HOME}/.local/share/applications/pgAdmin4.desktop
#Get the icon
wget -q $ICON -O ~/.local/share/icons/pgadmin.svg
#Create desktop shorcut
ln -s ${HOME}/.local/share/applications/pgAdmin4.desktop $(xdg-user-dir DESKTOP)/pgAdmin.desktop
echo "Done! A shorcut for pgAdmin4 should be in your Desktop"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment