From 9c9fb293da61078cc555505a506763e7e11cb5f3 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Wed, 10 Aug 2022 16:43:48 +0100 Subject: [PATCH] Yet more Sonarqube fixes. --- pkg/linux/build-functions.sh | 2 +- pkg/linux/setup-web.sh | 5 ++- pkg/pip/build.sh | 52 +++++++++++++++------------- pkg/src/build.sh | 66 +++++++++++++++++++----------------- 4 files changed, 65 insertions(+), 60 deletions(-) diff --git a/pkg/linux/build-functions.sh b/pkg/linux/build-functions.sh index ae2c9752d..5cf36514c 100644 --- a/pkg/linux/build-functions.sh +++ b/pkg/linux/build-functions.sh @@ -193,7 +193,7 @@ _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]))") - # shellcheck disable=SC2154 + # shellcheck disable=SC2153 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 diff --git a/pkg/linux/setup-web.sh b/pkg/linux/setup-web.sh index 1b16bffa6..45e616d98 100755 --- a/pkg/linux/setup-web.sh +++ b/pkg/linux/setup-web.sh @@ -9,7 +9,7 @@ if [ "$EUID" -ne 0 ] exit 1 fi -if [[ "$#" -ne 0 ]] && ([[ "$#" -eq 1 ]] && [[ "$1" != "--yes" ]]); then +if [[ "$#" -gt 1 ]] || { [[ "$#" -eq 1 ]] && [[ "$1" != "--yes" ]]; }; then echo "Usage: $0 [--yes]" exit 1 fi @@ -128,8 +128,7 @@ if pgrep ${APACHE} > /dev/null; then case ${RESPONSE} in y|Y ) - systemctl restart ${APACHE} - if [ $? != 0 ]; then + if ! systemctl restart ${APACHE}; 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" diff --git a/pkg/pip/build.sh b/pkg/pip/build.sh index 963382195..6f4760171 100755 --- a/pkg/pip/build.sh +++ b/pkg/pip/build.sh @@ -10,28 +10,28 @@ ######################################################################### # Runtime checks -if [ ! -d runtime -a ! -d web ]; then +if [ ! -d runtime ] && [ ! -d web ]; then echo This script must be run from the top-level directory of the source tree. exit 1 fi -if [ ! -d .git -a ! -f .git/config ]; then +if [ ! -d .git ] && [ ! -f .git/config ]; then echo This script must be run from a git checkout of the source tree. exit 1 fi # Get the required package info -APP_RELEASE=`grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g'` -APP_REVISION=`grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g'` -APP_NAME=`grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //'` +APP_RELEASE=$(grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g') +APP_REVISION=$(grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g') +APP_NAME=$(grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //') 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 +APP_SUFFIX=$(grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g") +if [ -n "${APP_SUFFIX}" ]; then export APP_LONG_VERSION=${APP_LONG_VERSION}-${APP_SUFFIX} fi # Output basic details to show we're working -echo Building tarballs for ${APP_NAME} version ${APP_LONG_VERSION}... +echo Building tarballs for "${APP_NAME}" version "${APP_LONG_VERSION}"... # Create/clearout the build directory echo Creating/cleaning required directories... @@ -47,36 +47,39 @@ mkdir pip-build/pgadmin4 mkdir pip-build/pgadmin4/docs # Build the clean tree -cd web -for FILE in `git ls-files` +cd web || exit +for FILE in $(git ls-files) do - echo Adding ${FILE} + echo Adding "${FILE}" # We use tar here to preserve the path, as Mac (for example) doesn't support cp --parents - tar cf - ${FILE} | (cd ../pip-build/pgadmin4; tar xf -) + # shellcheck disable=SC2164 + tar cf - "${FILE}" | (cd ../pip-build/pgadmin4; tar xf -) done yarn install yarn run bundle -for FILE in `ls -d pgadmin/static/js/generated/*` +for FILE in pgadmin/static/js/generated/* do - echo Adding ${FILE} - tar cf - ${FILE} | (cd ../pip-build/pgadmin4; tar xf -) + echo Adding "${FILE}" + # shellcheck disable=SC2164 + tar cf - "${FILE}" | (cd ../pip-build/pgadmin4; tar xf -) done -cd ../docs -for FILE in `git ls-files` +cd ../docs || exit +for FILE in $(git ls-files) do - echo Adding ${FILE} + echo Adding "${FILE}" # We use tar here to preserve the path, as Mac (for example) doesn't support cp --parents - tar cf - ${FILE} | (cd ../pip-build/pgadmin4/docs; tar xf -) + # shellcheck disable=SC2164 + tar cf - "${FILE}" | (cd ../pip-build/pgadmin4/docs; tar xf -) done -for DIR in `ls -d ??_??/` +for DIR in ./??_??/ do - if [ -d ${DIR}/_build/html ]; then - mkdir -p ../pip-build/pgadmin4/docs/${DIR}/_build - cp -R ${DIR}/_build/html ../pip-build/pgadmin4/docs/${DIR}/_build + if [ -d "${DIR}"/_build/html ]; then + mkdir -p "../pip-build/pgadmin4/docs/${DIR}/_build" + cp -R "${DIR}/_build/html" "../pip-build/pgadmin4/docs/${DIR}/_build" fi done @@ -85,6 +88,7 @@ for FILE in LICENSE DEPENDENCIES README.md do echo Adding ${FILE} # We use tar here to preserve the path, as Mac (for example) doesn't support cp --parents + # shellcheck disable=SC2164 tar cf - ${FILE} | (cd pip-build/pgadmin4; tar xf -) done @@ -99,7 +103,7 @@ echo recursive-include pgadmin4 \* > pip-build/MANIFEST.in # Run the build echo Building wheel... -cd pip-build +cd pip-build || exit python ../pkg/pip/setup_pip.py bdist_wheel cd ../ diff --git a/pkg/src/build.sh b/pkg/src/build.sh index 2bec42dd1..035efca04 100755 --- a/pkg/src/build.sh +++ b/pkg/src/build.sh @@ -10,30 +10,30 @@ ######################################################################### # Runtime checks -if [ ! -d runtime -a ! -d web ]; then +if [ ! -d runtime ] && [ ! -d web ]; then echo This script must be run from the top-level directory of the source tree. exit 1 fi -if [ ! -d .git -a ! -f .git/config ]; then +if [ ! -d .git ] && [ ! -f .git/config ]; then echo This script must be run from a git checkout of the source tree. exit 1 fi # Get the required package info -APP_RELEASE=`grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g'` -APP_REVISION=`grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g'` -APP_NAME=`grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //'` +APP_RELEASE=$(grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g') +APP_REVISION=$(grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g') +APP_NAME=$(grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //') 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 +APP_SUFFIX=$(grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g") +if [ -n "${APP_SUFFIX}" ]; then export APP_LONG_VERSION=${APP_LONG_VERSION}-${APP_SUFFIX} fi -TARBALL_NAME=`echo ${APP_NAME}-${APP_LONG_VERSION} | sed 's/ //g' | awk '{print tolower($0)}'` -DOC_TARBALL_NAME=`echo ${APP_NAME}-${APP_LONG_VERSION}-docs | sed 's/ //g' | awk '{print tolower($0)}'` +TARBALL_NAME=$(echo "${APP_NAME}-${APP_LONG_VERSION}" | sed 's/ //g' | awk '{print tolower($0)}') +DOC_TARBALL_NAME=$(echo "${APP_NAME}-${APP_LONG_VERSION}-docs" | sed 's/ //g' | awk '{print tolower($0)}') # Output basic details to show we're working -echo Building tarballs for ${APP_NAME} version ${APP_LONG_VERSION}... +echo "Building tarballs for ${APP_NAME} version ${APP_LONG_VERSION}..." # Create/clearout the build directory echo Creating/cleaning required directories... @@ -41,58 +41,60 @@ if [ ! -d src-build ]; then mkdir src-build fi -if [ -d src-build/${TARBALL_NAME} ]; then - rm -rf src-build/${TARBALL_NAME} +if [ -d "src-build/${TARBALL_NAME}" ]; then + rm -rf "src-build/${TARBALL_NAME}" fi -mkdir src-build/${TARBALL_NAME} +mkdir "src-build/${TARBALL_NAME}" # Create the output directory if not present if [ ! -d dist ]; then mkdir dist fi -if [ -f dist/${TARBALL_NAME}.tar.gz ]; then - rm -f dist/${TARBALL_NAME}.tar.gz +if [ -f "dist/${TARBALL_NAME}.tar.gz" ]; then + rm -f "dist/${TARBALL_NAME}.tar.gz" fi -if [ -f dist/${DOC_TARBALL_NAME}.tar.gz ]; then - rm -f dist/${DOC_TARBALL_NAME}.tar.gz +if [ -f "dist/${DOC_TARBALL_NAME}.tar.gz" ]; then + rm -f "dist/${DOC_TARBALL_NAME}.tar.gz" fi # Build the clean tree -for FILE in `git ls-files` +for FILE in $(git ls-files) do - echo Adding ${FILE} + echo Adding "${FILE}" # We use tar here to preserve the path, as Mac (for example) doesn't support cp --parents - tar cf - ${FILE} | (cd src-build/${TARBALL_NAME}; tar xf -) + # shellcheck disable=SC2164 + tar cf - "${FILE}" | (cd src-build/${TARBALL_NAME}; tar xf -) done -pushd web > /dev/null +pushd web > /dev/null || exit yarn install yarn run bundle - for FILE in `ls -d pgadmin/static/js/generated/*` + for FILE in pgadmin/static/js/generated/* do - echo Adding ${FILE} - tar cf - ${FILE} | (cd ../src-build/${TARBALL_NAME}/web; tar xf -) + echo Adding "${FILE}" + # shellcheck disable=SC2164 + tar cf - "${FILE}" | (cd "../src-build/${TARBALL_NAME}/web"; tar xf -) done -popd > /dev/null +popd > /dev/null || exit # Create the tarball echo Creating tarball... -cd src-build -tar zcvf ../dist/${TARBALL_NAME}.tar.gz ${TARBALL_NAME} +cd src-build || exit +tar zcvf "../dist/${TARBALL_NAME}.tar.gz" "${TARBALL_NAME}" cd .. # Create the docs echo Creating docs... -cd src-build/${TARBALL_NAME}/docs/en_US +cd "src-build/${TARBALL_NAME}/docs/en_US" || exit make -f Makefile.sphinx html -cd _build -mv html ${DOC_TARBALL_NAME} -tar zcvf ../../../../../dist/${DOC_TARBALL_NAME}.tar.gz ${DOC_TARBALL_NAME} +cd _build || exit +mv html "${DOC_TARBALL_NAME}" +tar zcvf "../../../../../dist/${DOC_TARBALL_NAME}.tar.gz" "${DOC_TARBALL_NAME}" cd ../../../../../ # Fin! -echo Created tarball dist/${TARBALL_NAME}.tar.gz and dist/${DOC_TARBALL_NAME}.tar.gz +echo "Created tarball dist/${TARBALL_NAME}.tar.gz and dist/${DOC_TARBALL_NAME}.tar.gz"