From 0f110339896d227da9ff3621b851d55bdd0cda66 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Wed, 10 Aug 2022 15:54:51 +0100 Subject: [PATCH] More Sonarqube fixes for Linux --- pkg/linux/build-functions.sh | 7 ++++--- pkg/linux/setup-web.sh | 21 ++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/pkg/linux/build-functions.sh b/pkg/linux/build-functions.sh index cc37351e5..ae2c9752d 100644 --- a/pkg/linux/build-functions.sh +++ b/pkg/linux/build-functions.sh @@ -15,7 +15,7 @@ _setup_env() { APP_NAME=$(grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //' | sed 's/ //g' | tr '[:upper:]' '[:lower:]') APP_LONG_VERSION=${APP_RELEASE}.${APP_REVISION} APP_SUFFIX=$(grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g") - if [ ! -z ${APP_SUFFIX} ]; then + if [ -n "${APP_SUFFIX}" ]; then APP_LONG_VERSION=${APP_LONG_VERSION}-${APP_SUFFIX} fi } @@ -114,7 +114,7 @@ _create_python_virtualenv() { # Link the python directory to python so that the private environment path is found by the application. if test -d "${DIR_PYMODULES_PATH}"; then - ln -s $(basename "${DIR_PYMODULES_PATH}") "${DIR_PYMODULES_PATH}/../python" + ln -s "$(basename "${DIR_PYMODULES_PATH}")" "${DIR_PYMODULES_PATH}/../python" fi } @@ -193,7 +193,8 @@ _build_docs() { cd "${SOURCEDIR}/docs/en_US" || exit python3 build_code_snippet.py SYS_PYTHONPATH=$(/usr/bin/python3 -c "import sys; print(':'.join([p for p in sys.path if p]))") - if [ $1 == "redhat" ] && [ "${OS_VERSION}" == "7" ]; then + # shellcheck disable=SC2154 + if [ "$1" == "redhat" ] && [ "${OS_VERSION}" == "7" ]; then PYTHONPATH=$PYTHONPATH:${SYS_PYTHONPATH} python3 /usr/local/bin/sphinx-build . "${SERVERROOT}/usr/${APP_NAME}/share/docs/en_US/html" else PYTHONPATH=$PYTHONPATH:${SYS_PYTHONPATH} python3 -msphinx . "${SERVERROOT}/usr/${APP_NAME}/share/docs/en_US/html" diff --git a/pkg/linux/setup-web.sh b/pkg/linux/setup-web.sh index f54600d39..1b16bffa6 100755 --- a/pkg/linux/setup-web.sh +++ b/pkg/linux/setup-web.sh @@ -20,7 +20,7 @@ IS_SUSE=0 UNAME=$(uname -a) # Get the distro from the environment -if [ "x${PGADMIN_PLATFORM_TYPE}" == "x" ]; then +if [ "${PGADMIN_PLATFORM_TYPE}" == "" ]; then if [ -f /etc/redhat-release ]; then PLATFORM_TYPE=redhat elif [[ ${UNAME} =~ "Ubuntu" ]] || [[ ${UNAME} =~ "Debian" ]] || [ -f /etc/apt/sources.list ]; then @@ -72,9 +72,7 @@ fi # Run setup script first: echo "Creating configuration database..." -/usr/pgadmin4/venv/bin/python3 /usr/pgadmin4/web/setup.py - -if [ $? != 0 ] +if ! /usr/pgadmin4/venv/bin/python3 /usr/pgadmin4/web/setup.py; then echo "Error setting up server mode. Please examine the output above." exit 1 @@ -108,7 +106,7 @@ 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 + read -r -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 @@ -121,12 +119,11 @@ if [ ${IS_DEBIAN} == 1 ]; then esac fi -ps cax | grep ${APACHE} > /dev/null -if [ $? -eq 0 ]; then +if pgrep ${APACHE} > /dev/null; 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 + read -r -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 @@ -144,20 +141,18 @@ 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 + read -r -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 + if ! systemctl enable ${APACHE}; then echo "Error enabling ${APACHE}. Please check the systemd logs" else echo "Apache successfully enabled." fi - systemctl start ${APACHE} - if [ $? != 0 ]; then + if ! systemctl start ${APACHE}; then echo "Error starting ${APACHE}. Please check the systemd logs" else echo "Apache successfully started."