From 252f476da6605c74d7269152b372899bfeb6cacb Mon Sep 17 00:00:00 2001 From: Jason Boyer Date: Mon, 12 Jul 2021 16:49:04 -0400 Subject: [PATCH] LP 1900005: Improve root user detection and directory writability Switch to checking userid rather than username, and make sure we can write everywhere needed in autogen.sh. Also remove some never-used variables into autogen.sh leftover from previous changes. Signed-off-by: Jason Boyer --- Open-ILS/examples/oils_ctl.sh | 2 +- Open-ILS/src/extras/autogen.sh | 53 ++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Open-ILS/examples/oils_ctl.sh b/Open-ILS/examples/oils_ctl.sh index 92ecd9b5a8..459b08f263 100755 --- a/Open-ILS/examples/oils_ctl.sh +++ b/Open-ILS/examples/oils_ctl.sh @@ -12,7 +12,7 @@ SIP_DIR="/opt/SIPServer"; # --------------------------------------------------------------------------- # Make sure we're not running as the root user # --------------------------------------------------------------------------- -[ $(whoami) = 'root' ] && echo 'Do not run as user "root"' && exit; +[ `id -u` -eq 0 ] && echo 'Not to be run as root' && exit 1; function usage { diff --git a/Open-ILS/src/extras/autogen.sh b/Open-ILS/src/extras/autogen.sh index 0af609a0db..fd8ab6b97e 100755 --- a/Open-ILS/src/extras/autogen.sh +++ b/Open-ILS/src/extras/autogen.sh @@ -21,22 +21,14 @@ set -e # Throw an error for uninitialized variables set -u -JSDIR="LOCALSTATEDIR/web/opac/common/js/"; -FMDOJODIR="LOCALSTATEDIR/web/js/dojo/fieldmapper/"; -SLIMPACDIR="LOCALSTATEDIR/web/opac/extras/slimpac/"; -SKINDIR='LOCALSTATEDIR/web/opac/skin'; - -COMPRESSOR="" # TODO: set via ./configure -#COMPRESSOR="java -jar /opt/yuicompressor-2.4.2/build/yuicompressor-2.4.2.jar" +JSDIR="LOCALSTATEDIR/web/opac/common/js"; +FMDOJODIR="LOCALSTATEDIR/web/js/dojo/fieldmapper"; +SLIMPACDIR="LOCALSTATEDIR/web/opac/extras/slimpac"; # --------------------------------------------------------------------------- # Make sure we're not root and are able to write to the destination directory # --------------------------------------------------------------------------- -[ $(whoami) = 'root' ] && echo 'Do not run as user "root"' && exit; -if [ ! -d "$JSDIR" ] || [ ! -w "$JSDIR" ]; then - echo "Not able to write to ${JSDIR}!"; - exit; -fi +[ `id -u` -eq 0 ] && echo 'Not to be run as root' && exit 1; function usage { echo ""; @@ -60,6 +52,43 @@ function usage { echo ""; } +function check_dir_writable { + if [ ! -d "$1" ] || [ ! -w "$1" ]; then + echo "Unable to write to ${1}, please check"; + OHNO=1; + fi +} + +function check_files_writable { + # Since we already know the directories are writable there's only + # a problem if the file(s) already exist *and* for some reason isn't writable. + + # This may be passed a single filename or a glob for simplicity. + for F in `ls $1 2>/dev/null` + do + if [ -f "$F" ] && [ ! -w "$F" ]; then + echo "Unable to write to ${F}, please check" + OHNO=1 + fi + done +} + +OHNO=0 + +# Verify we're able to write everywhere we need +for DIR in "$JSDIR" "$FMDOJODIR" "$SLIMPACDIR" +do + check_dir_writable "$DIR" +done + +for FILE in "$JSDIR/fmall.js" "$JSDIR/fmcore.js" "$JSDIR/*/OrgTree.js" "$SLIMPACDIR/*/lib_list.inc" "$SLIMPACDIR/locales.inc" "LOCALSTATEDIR/web/eg_cache_hash" +do + check_files_writable "$FILE" +done + +# Bail on badness +[ $OHNO -eq 0 ] || exit 1 + ( cd "BINDIR" -- 2.11.0