Merge branch 'release-2.140.114'
[feisty_meow.git] / scripts / security / cool_permissionator.sh
index 3d0dc8ea4ba37e779d4533003a7e46008b791b30..e4f345c9dc3d2798156004450d7ce56aad651a7e 100644 (file)
@@ -10,6 +10,9 @@ function reapply_cool_permissions()
 {
   local cooluser="$1"; shift
 
+#hmmm: check for non empty name.
+  local homebase="/home/$cooluser"
+
   # first build a list of dirs based on their location in /home/archives.
   local arch_builder="archons basement codebarn games imaginations musix pooling prewar_toaster stuffing toaster walrus"
   local ARCHIVE_TOP=/home/archives
@@ -24,18 +27,18 @@ function reapply_cool_permissions()
   # everything else is only re-permed if it exists.
   if [ ! -d "$DEFAULT_FEISTYMEOW_ORG_DIR" ]; then
     sudo mkdir "$DEFAULT_FEISTYMEOW_ORG_DIR"
-    test_or_die "making directory: $DEFAULT_FEISTYMEOW_ORG_DIR"
+    exit_on_error "making directory: $DEFAULT_FEISTYMEOW_ORG_DIR"
   fi
 
   # fix some permissions for important security considerations.
-  if [ -d $HOME/.ssh ]; then
-    harsh_perm $HOME/.ssh
+  if [ -d $homebase/.ssh ]; then
+    harsh_perm $homebase/.ssh
   fi
 
 #hmmm: consider adding feisty meow apex to the dirname list below.
 
   # iterate across the list of dirs we want cooluser to own and change their ownership.
-  for dirname in $HOME \
+  for dirname in $homebase \
         $DEFAULT_FEISTYMEOW_ORG_DIR \
         /usr/local/${cooluser} \
         /home/games \
@@ -43,33 +46,33 @@ function reapply_cool_permissions()
     if [ -d "$dirname" ]; then
       echo "revising ownership on '$dirname'"
       sudo chown -R ${cooluser}:${cooluser} "$dirname"
-      test_or_die "chowning for ${cooluser}: $dirname"
+      exit_on_error "chowning for ${cooluser}: $dirname"
     fi
   done
 
   # special case for archives directory in stuffing.
   if [ -d /z/stuffing -o -L /z/stuffing ]; then
     sudo chown ${cooluser}:${cooluser} /z/
-    test_or_die "chowning /z for ${cooluser}"
+    exit_on_error "chowning /z for ${cooluser}"
     sudo chmod g+rx,o+rx /z
-    test_or_die "chmodding /z/ for ${cooluser}"
+    exit_on_error "chmodding /z/ for ${cooluser}"
     sudo chown ${cooluser}:${cooluser} /z/stuffing/
-    test_or_die "chowning /z/stuffing for ${cooluser}"
+    exit_on_error "chowning /z/stuffing for ${cooluser}"
     sudo chmod g+rx,o-rwx /z/stuffing
-    test_or_die "chmodding /z/stuffing for ${cooluser}"
+    exit_on_error "chmodding /z/stuffing for ${cooluser}"
     pushd /z/stuffing &>/dev/null
     if [ -d archives -o -L archives ]; then
       sudo chown ${cooluser}:${cooluser} archives/
-      test_or_die "chowning /z/stuffing/archives for ${cooluser}"
+      exit_on_error "chowning /z/stuffing/archives for ${cooluser}"
       sudo chmod -R g+rwx archives
-      test_or_die "chmodding /z/stuffing/archives for ${cooluser}"
+      exit_on_error "chmodding /z/stuffing/archives for ${cooluser}"
     fi
     popd &>/dev/null
   fi
 
   # make the log files readable by normal humans.
   sudo bash $FEISTY_MEOW_SCRIPTS/security/normal_perm.sh /var/log
-  test_or_die "setting normal perms on /var/log"
+  exit_on_error "setting normal perms on /var/log"
 }
 
 # this block should execute when the script is actually run, rather
@@ -77,16 +80,12 @@ function reapply_cool_permissions()
 
 # this runs the cool permission applier on the current user.
 if [[ $0 =~ .*cool_permissionator\.sh.* ]]; then
-echo A
   THISDIR="$( \cd "$(\dirname "$0")" && /bin/pwd )"
-echo B
   export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )"
-echo B.2
   source "$THISDIR/../core/launch_feisty_meow.sh"
-  test_or_die "sourcing the feisty meow launcher"
-echo C
-  reapply_cool_permissions $(logname)
-  test_or_die "reapplying cool permissions on $(logname)"
-echo D
+  exit_on_error "sourcing the feisty meow launcher"
+  coolio="$USER"
+  reapply_cool_permissions "$coolio"
+  exit_on_error "reapplying cool permissions on $coolio"
 fi