fhnw-tools/fhnw-ad-mount

62 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env sh
set -o errexit
export SUDO_PROMPT="sudo password: "
mount_dir="/mnt/fhnw-share"
pass_path="accounts/fhnw/students.fhnw.ch"
display_help() {
echo "Usage: $0 [option...] " >&2
echo
echo " -m, ad mount directory [default: $mount_dir]"
echo " -p, path for pass to get user and password information [default: $pass_path]"
echo " -h, display this help and exit"
echo
}
parse_args() {
while getopts ":hm:p:" opt; do
case $opt in
h)
display_help
exit 0
;;
m)
mount_dir=$OPTARG
;;
p)
pass_path=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
display_help
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
display_help
exit 1
;;
esac
done
}
get_account_info() {
echo "getting account info from pass..."
acc_info="$(pass "$pass_path")"
acc_pw="$(echo "$acc_info" | head -n 1)"
acc_user="$(echo "$acc_info" | awk -F ': ' '/^login-shortcut:/ {print $2}')"
}
mount_ad() {
echo "mounting ad..."
sudo mkdir -p "$mount_dir"
sudo mount -t cifs //fs.edu.ds.fhnw.ch/data "$mount_dir" \
-o vers=3.0,username="$acc_user",password="$acc_pw",workgroup=EDU,iocharset=utf8,uid="$USER",gid="$USER"
}
parse_args "$@"
get_account_info
mount_ad