LP 1900005: Improve root user detection and directory writability
authorJason Boyer <JBoyer@EquinoxInitiative.org>
Mon, 12 Jul 2021 20:49:04 +0000 (16:49 -0400)
committerJason Boyer <JBoyer@EquinoxInitiative.org>
Tue, 13 Jul 2021 11:56:09 +0000 (07:56 -0400)
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 <JBoyer@EquinoxInitiative.org>
Open-ILS/examples/oils_ctl.sh
Open-ILS/src/extras/autogen.sh

index 92ecd9b..459b08f 100755 (executable)
@@ -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 {
index 0af609a..fd8ab6b 100755 (executable)
@@ -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"