PassThePeas
12/8/2014 - 1:44 PM

Bash Shell Header with Helper section

Bash Shell Header with Helper section

#!/opt/bin/bash

BASEDIR=$(dirname $0)
. ${BASEDIR}/conf/Syno.cnf

##
############# HELPER SECTION #############
##
PARAMETERS_STRING="[directory] [-h]"
PARAMETERS_MIN_NUM=0
PARAMETERS_MAX_NUM=1
HELPER_MESSAGE="Positionne les droits et le proprietaire des fichiers jpg, mkv, nfo, srt et tbn"
read -d '' USAGE_PARAMETERS_MESSAGE <<"EOF"
Parametres:
  directory : répertoire racine a traiter
  REM : Si directory n'est pas fourni, realise l'operation sur les repertoires definis dans le script
  -h : Affiche cette aide
EOF

helper() {
	echo $HELPER_MESSAGE
	echo ""
}

usage() {
	SCRIPT_NAME=`basename $0`
	echo "Usage: $SCRIPT_NAME $*"
	echo "$USAGE_PARAMETERS_MESSAGE"
}

while getopts ":h" opt; do
  	case $opt in
    	h)
			helper
      		usage $PARAMETERS_STRING
      		exit 0
      		;;
	esac
done

if [ $# -lt $PARAMETERS_MIN_NUM ] || [ $# -gt $PARAMETERS_MAX_NUM ]
then
	echo "Too many or too few arguments passed"
	usage $PARAMETERS_STRING
	exit 1
fi
##
############# END OF HELPER SECTION #############
##