# 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 "";
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"