public inbox for [email protected]  
help / color / mirror / Atom feed
From: Dave Page <[email protected]>
To: pgadmin-hackers <[email protected]>
Cc: Syed Fahar Abbas <[email protected]>
Subject: RM6228 - setup-web.sh platform detection
Date: Fri, 26 Feb 2021 14:59:47 +0000
Message-ID: <CA+OCxoxcuWHr8bGJR=SR5K89XhZ=2sBBFYm3B8vN-nzaz_pHGg@mail.gmail.com> (raw)

The attached patch attempts to make the platform detection in setup-web.sh
more capable of detecting Debian/Ubuntu variants, and simplifies a couple
of other parts of the code. It also allows the platform type to be
overridden in the PGADMIN_PLATFORM_TYPE environment variable with either
'redhat' or 'debian', for any cases where auto-detection fails.

Fahar; I've also attached a copy of the modified script. Before this is
committed, please test it on all our Redhat/Fedora/Debian/Ubuntu platforms.
You can install the v5.0 packages as normal, but then use this version of
the script (from any directory) to configure web mode instead of the one
that ships in the -web package.

Thanks.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EDB: http://www.enterprisedb.com


Attachments:

  [application/octet-stream] RM6228.diff (3.3K, 3-RM6228.diff)
  download | inline diff:
Index: pkg/linux/setup-web.sh
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pkg/linux/setup-web.sh	(revision e8114b5dc67b245d34ff94bae058900fb14b6eb8)
+++ pkg/linux/setup-web.sh	(date 1614351104525)
@@ -14,11 +14,44 @@
     exit 1
 fi
 
-# Get the distro
 IS_REDHAT=0
 IS_DEBIAN=0
 UNAME=$(uname -a)
 
+# Get the distro from the environment
+if [ "x${PGADMIN_PLATFORM_TYPE}" == "x" ]; then
+    if [ -f /etc/redhat-release ]; then
+        PLATFORM_TYPE=redhat
+    elif [[ ${UNAME} =~ "Ubuntu" ]] || [[ ${UNAME} =~ "Debian" ]] || [ -f /etc/apt/sources.list ]; then
+        PLATFORM_TYPE=debian
+    else
+        echo "Failed to detect the platform. This may mean you're running on a Linux distribution that isn't supported by pgAdmin."
+        echo "Please set the PGADMIN_PLATFORM_TYPE environment variable to one of 'redhat' or 'debian' and try again."
+        exit 1
+    fi
+else
+    PLATFORM_TYPE=${PGADMIN_PLATFORM_TYPE}
+fi
+
+case ${PLATFORM_TYPE} in
+    redhat)
+        echo "Setting up pgAdmin 4 in web mode on a Redhat platform..."
+        IS_REDHAT=1
+        APACHE=httpd
+        ;;
+
+    debian)
+        echo "Setting up pgAdmin 4 in web mode on a Debian platform..."
+        IS_DEBIAN=1
+        APACHE=apache2
+        ;;
+
+    *)
+        echo "Invalid value for the PGADMIN_PLATFORM_TYPE environment variable. Please set it to one of 'redhat' or 'debian' and try again."
+        exit 1
+        ;;
+esac
+
 # Is this an automated install?
 AUTOMATED=0
 if [ "$#" -eq 1 ]; then
@@ -26,16 +59,6 @@
     echo "Running in non-interactive mode..."
 fi
 
-if [ -f /etc/redhat-release ]; then
-    IS_REDHAT=1
-    APACHE=httpd
-    echo "Setting up pgAdmin 4 in web mode on a Redhat platform..."
-elif [[ ${UNAME} =~ "Ubuntu" ]] || [[ ${UNAME} =~ "Debian" ]]; then
-    IS_DEBIAN=1
-    APACHE=apache2
-    echo "Setting up pgAdmin 4 in web mode on a Debian platform..."
-fi
-
 # Run setup script first:
 echo "Creating configuration database..."
 /usr/pgadmin4/venv/bin/python3 /usr/pgadmin4/web/setup.py 
@@ -70,22 +93,16 @@
 # Setup Apache on Debian/Ubuntu
 if [ ${IS_DEBIAN} == 1 ]; then
     if [ ${AUTOMATED} == 1 ]; then
-	RESPONSE=Y
+	      RESPONSE=Y
     else
         read -p "We can now configure the Apache Web server for you. This involves enabling the wsgi module and configuring the pgAdmin 4 application to mount at /pgadmin4. Do you wish to continue (y/n)? " RESPONSE
     fi
 
     case ${RESPONSE} in
         y|Y )
-          # Debian uses a different path to Ubuntu
-          if [[ ${UNAME} =~ "Debian" ]]; then
-            /sbin/a2enmod wsgi 1> /dev/null
-            /sbin/a2enconf pgadmin4 1> /dev/null
-          else
-            /usr/sbin/a2enmod wsgi 1> /dev/null
-            /usr/sbin/a2enconf pgadmin4 1> /dev/null
-          fi
-          ;;
+            a2enmod wsgi 1> /dev/null
+            a2enconf pgadmin4 1> /dev/null
+            ;;
         * )
             exit 1;;
     esac
@@ -101,7 +118,7 @@
 
     case ${RESPONSE} in
         y|Y )
-	    systemctl restart ${APACHE}
+	          systemctl restart ${APACHE}
             if [ $? != 0 ]; then
                 echo "Error restarting ${APACHE}. Please check the systemd logs"
             else


  [text/x-sh] setup-web.sh (4.5K, 4-setup-web.sh)
  download | inline:
#!/bin/bash

#
# Setup pgadmin4 in server mode
#

if [ "$EUID" -ne 0 ]
  then echo "This script must be run as root"
  exit 1
fi

if [[ "$#" -ne 0 ]] && ([[ "$#" -eq 1 ]] && [[ "$1" != "--yes" ]]); then
    echo "Usage: $0 [--yes]"
    exit 1
fi

IS_REDHAT=0
IS_DEBIAN=0
UNAME=$(uname -a)

# Get the distro from the environment
if [ "x${PGADMIN_PLATFORM_TYPE}" == "x" ]; then
    if [ -f /etc/redhat-release ]; then
        PLATFORM_TYPE=redhat
    elif [[ ${UNAME} =~ "Ubuntu" ]] || [[ ${UNAME} =~ "Debian" ]] || [ -f /etc/apt/sources.list ]; then
        PLATFORM_TYPE=debian
    else
        echo "Failed to detect the platform. This may mean you're running on a Linux distribution that isn't supported by pgAdmin."
        echo "Please set the PGADMIN_PLATFORM_TYPE environment variable to one of 'redhat' or 'debian' and try again."
        exit 1
    fi
else
    PLATFORM_TYPE=${PGADMIN_PLATFORM_TYPE}
fi

case ${PLATFORM_TYPE} in
    redhat)
        echo "Setting up pgAdmin 4 in web mode on a Redhat platform..."
        IS_REDHAT=1
        APACHE=httpd
        ;;

    debian)
        echo "Setting up pgAdmin 4 in web mode on a Debian platform..."
        IS_DEBIAN=1
        APACHE=apache2
        ;;

    *)
        echo "Invalid value for the PGADMIN_PLATFORM_TYPE environment variable. Please set it to one of 'redhat' or 'debian' and try again."
        exit 1
        ;;
esac

# Is this an automated install?
AUTOMATED=0
if [ "$#" -eq 1 ]; then
    AUTOMATED=1
    echo "Running in non-interactive mode..."
fi

# Run setup script first:
echo "Creating configuration database..."
/usr/pgadmin4/venv/bin/python3 /usr/pgadmin4/web/setup.py 

if [ $? != 0 ]
then
	echo "Error setting up server mode. Please examine the output above."
	exit 1
fi

# Create and own directories:
echo "Creating storage and log directories..."
mkdir -p /var/log/pgadmin /var/lib/pgadmin

if [ ${IS_REDHAT} == 1 ]; then
    chown apache: /var/log/pgadmin /var/lib/pgadmin -R
else
    chown www-data: /var/log/pgadmin /var/lib/pgadmin -R
fi

# Set SELinux up:
if [ ${IS_REDHAT} == 1 ]; then
    echo "Configuring SELinux..."
    setsebool -P httpd_can_network_connect 1 1> /dev/null
    setsebool -P httpd_can_network_connect_db 1 1> /dev/null
    semanage fcontext -a -t httpd_var_lib_t '/var/lib/pgadmin(/.*)?' 1> /dev/null
    restorecon -R -v /var/lib/pgadmin 1> /dev/null
    semanage fcontext -a -t httpd_log_t '/var/log/pgadmin(/.*)?' 1> /dev/null
    restorecon -R -v /var/log/pgadmin 1> /dev/null
fi

# Setup Apache on Debian/Ubuntu
if [ ${IS_DEBIAN} == 1 ]; then
    if [ ${AUTOMATED} == 1 ]; then
	      RESPONSE=Y
    else
        read -p "We can now configure the Apache Web server for you. This involves enabling the wsgi module and configuring the pgAdmin 4 application to mount at /pgadmin4. Do you wish to continue (y/n)? " RESPONSE
    fi

    case ${RESPONSE} in
        y|Y )
            a2enmod wsgi 1> /dev/null
            a2enconf pgadmin4 1> /dev/null
            ;;
        * )
            exit 1;;
    esac
fi

APACHE_STATUS=`ps cax | grep ${APACHE}`
if [ $? -eq 0 ]; then
    if [ ${AUTOMATED} == 1 ]; then
        RESPONSE=Y
    else
        read -p "The Apache web server is running and must be restarted for the pgAdmin 4 installation to complete. Continue (y/n)? " RESPONSE
    fi

    case ${RESPONSE} in
        y|Y )
	          systemctl restart ${APACHE}
            if [ $? != 0 ]; then
                echo "Error restarting ${APACHE}. Please check the systemd logs"
            else
                echo "Apache successfully restarted. You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4"
            fi;;
        * ) 
            exit 1;;
    esac
else
    if [ ${AUTOMATED} == 1 ]; then
        RESPONSE=Y
    else
        read -p "The Apache web server is not running. We can enable and start the web server for you to finish pgAdmin 4 installation. Continue (y/n)? " RESPONSE
    fi

    case ${RESPONSE} in
        y|Y )
            systemctl enable ${APACHE}
            if [ $? != 0 ]; then
                echo "Error enabling ${APACHE}. Please check the systemd logs"
            else
                echo "Apache successfully enabled."
            fi

            systemctl start ${APACHE}
            if [ $? != 0 ]; then
                echo "Error starting ${APACHE}. Please check the systemd logs"
            else
                echo "Apache successfully started."
                echo "You can now start using pgAdmin 4 in web mode at http://127.0.0.1/pgadmin4"
            fi;;
        * ) 
            exit 1;;
    esac
fi

exit 0

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: RM6228 - setup-web.sh platform detection
  In-Reply-To: <CA+OCxoxcuWHr8bGJR=SR5K89XhZ=2sBBFYm3B8vN-nzaz_pHGg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox