#!/bin/bash

# -------------------------------------------------------
# RPC Project :
# Run RPC_chmod_tree  set mode to all files in the tree
# P. Robert, ScientiDev, Dec 2020
# -------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=0

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : set mode to all files in the tree, from current directory"
   echo "$appli   require $Narg argument(s)"
   echo " "
   echo "example:"
   echo "$appli"
   echo ""
   echo "all dir  : chmod go-w & chmod ugo+rx"
   echo "all .exe : chmod ugo+rx"
   echo "all .bash: chmod ugo+rx"
   echo "all .sh  : chmod ugo+rx"
   echo "all RPC  : chmod ugo+rx RPC*"
   if test $hh = 1 ; then exit 0 ; fi
   echo " $appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

datim1=`date +%F'  '%H':'%M':'%S `
julsec1=`date +%s`


echo " ------------------------------------------------------------------"
echo " $appli :"

echo "  -> all files    : chmod go-w " 
echo "  -> all dir      : chmod go-w & chmod ugo+rx"
find . -type f -exec chmod go-w {} \;
find . -type d -exec chmod go-w {} \;
find . -type d -exec chmod ugo+rx {} \;

echo "  -> all RPC      : chmod ugo+rx RPC*"
chmod ugo+rx $RPC_DIR/bash/RPC*

echo "  -> all .exe     : chmod ugo+rx"
find . -type f -name "*.exe"  -exec chmod ugo+rx {} \; 

echo "  -> all .sh      : chmod ugo+rx"
find . -type f -name "*.sh"   -exec chmod ugo+rx {} \; 

echo "  -> all .bash    : chmod ugo+rx"
find . -type f -name "*.bash" -exec chmod ugo+rx {} \; 

echo "  -> all .desktop : chmod ugo+rx"
find . -type f -name "*.desktop" -exec chmod ugo+rx {} \; 


echo
echo "Done !"

# end of command
# --------------

datim2=`date +%F'  '%H':'%M':'%S `
julsec2=`date +%s`
diff=`expr $julsec2 - $julsec1`

echo ""
echo " Starting time $appli : $datim1"
echo " Ending   time $appli : $datim2"
echo " Duration      $appli : $diff sec."
echo    
echo " $appli36 : NORMAL TERMINATION - time exe= $diff s." >&2 

echo " ==================================================================="
