protege:smbcc

smbcc

smbcc
#!/usr/bin/env bash
 
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
 
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
 
usage() {
  cat << EOF # remove the space between << and EOF, this is due to web plugin issue
Usage: $(basename "${BASH_SOURCE[0]}") [-h] <unc> <user/passwd> <-e|-v> <keyfile>
 
Script description here.
 
Available options:
 
-h, --help      Print this help and exit
-e, --encrypt   ription
-d, --decrypt   Some flag description
unc             NC path (ex: 192.168.1.100/public)
user/passwd     username/password (ex: paul/mypw)
 
 
EOF
  exit
}
 
cleanup() {
  trap - SIGINT SIGTERM ERR EXIT
  # script cleanup here
}
 
msg() {
  echo >&2 -e "${1-}"
}
 
die() {
  local msg=$1
  local code=${2-1} # default exit status 1
  msg "$msg"
  exit "$code"
}
 
parse_params() {
  # default values of variables set from params
  flag=0
  param=''
 
  while :; do
    case "${1-}" in
    -h | --help) usage ;;
    -v | --verbose) set -x ;;
    -e | --encrypt) encrypt=1 ;; # example flag
    -d | --decrypt) decrypt=1 ;; # example flag
      param="${2-}"
      shift
      ;;
    -?*) die "Unknown option: $1" ;;
    *) break ;;
    esac
    shift
  done
 
  args=("$@")
 
  # check required params and arguments
  [[ -z "${param-}" ]] && die "Missing required parameter: param"
  [[ ${#args[@]} -eq 0 ]] && die "Missing script arguments"
 
  return 0
}
 
parse_params "$@"
 
# script logic here
if [[ $# != 4 ]] ; then
  usage
fi
unc=$1
userpw=$2
user=$(echo $userpw|cut -f1 -d/)
password=$(echo $userpw|cut -f2 -d/)
mode=$3
passwdfile=$4
passwd=$(cat ${passwdfile})
msg "${RED}Read parameters:${NOFORMAT}"
msg "- flag: ${flag}"
msg "- param: ${param}"
msg "- arguments: ${args[*]-}"
cmd="mount.cifs -o \"username=${user},password=${password}\" //${unc} /tmp/share" 
eval "${cmd)"
if [[ $? == 0 ]] ; then
   ....
else
   ...
fi
umount /tmp/share
exit 0
  • protege/smbcc.txt
  • Dernière modification : 2023/11/09 00:44
  • de ps