#!/bin/bash

usage()
{
  echo "Usage: $0 [-p PATH]"
  exit 2
}

set_perm() {
  echo "$PROGNAME: Setting perm for \"$PATH_NAME\" ..."
  chmod -R 777 "$PATH_NAME"
  chown -r nobody:users "$PATH_NAME"
  exit 0
}

set_variable()
{
  local varname=$1
  shift
  if [ -z "${!varname}" ]; then
  eval "$varname=\"$@\""
  else
  echo "Error: $varname already set"
  usage
  fi
}

####################################################################
# Main script starts here

while getopts 'p:?h' c
do
  case $c in
  p) set_variable PATH_NAME "$OPTARG" ;;
  h|?) usage ;; esac
done

set_variable PROGNAME "$(basename "$0")"
# set_variable CHECK_FILE "/tmp/DOCK_PREV_STATE"

set_perm
