Smart iSCSI Mounter v0.97
- Attempting to read from iscsiadm must now be challenged by root. - Mount operations now take into account the defined iSCSI target rather than simply the number of active connections.
This commit is contained in:
+18
-10
@@ -9,9 +9,14 @@ MONITOR_PROC_CNT=7
|
||||
|
||||
# Do not modify
|
||||
_MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l)
|
||||
_ISCSI_CON_CNT=$(iscsiadm -m session | wc -l)
|
||||
_ISCSI_CON=""
|
||||
_FLAG_FORCE=0
|
||||
|
||||
# The use of iscsiadm requires admin privilages
|
||||
read_iscsi_con (){
|
||||
_ISCSI_CON=$(iscsiadm -m session)
|
||||
}
|
||||
|
||||
show_usage (){
|
||||
echo "[Usage]"
|
||||
echo "Please use either '-m (--mount)' to mount or '-u (--umount)' to unmount this volume."
|
||||
@@ -35,8 +40,8 @@ check_dir (){
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "The below iSCSI connection(s) is/are open:"
|
||||
echo "$(iscsiadm -m session)"
|
||||
echo "There is/are currently '$(${_ISCSI_CON} 2>&1 | wc -l)' iSCSI connection(s) open:"
|
||||
echo "${_ISCSI_CON}"
|
||||
}
|
||||
|
||||
check_proc_status (){
|
||||
@@ -52,9 +57,9 @@ check_proc_status (){
|
||||
mount_func (){
|
||||
echo "[Attempting to mount iSCSI volume]"
|
||||
|
||||
if [[ ${_ISCSI_CON_CNT} -gt 0 ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
||||
if [[ ${_ISCSI_CON} == *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
||||
then
|
||||
echo "WARNING: You're already connected to an iSCSI target."
|
||||
echo "WARNING: You're already connected to the '${IQN}' iSCSI target."
|
||||
echo "Use the -f (--force) flag to bypass this warning."
|
||||
exit 2;
|
||||
fi
|
||||
@@ -72,9 +77,9 @@ umount_func (){
|
||||
check_proc_status
|
||||
fi
|
||||
|
||||
if [[ ${_ISCSI_CON_CNT} -eq 0 ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
||||
if [[ ${_ISCSI_CON} != *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
|
||||
then
|
||||
echo "WARNING: You're not currently connected to an iSCSI target."
|
||||
echo "WARNING: You're not currently connected to the '${IQN}' iSCSI target."
|
||||
echo "Use the -f (--force) flag to bypass this warning."
|
||||
exit 2;
|
||||
fi
|
||||
@@ -88,7 +93,7 @@ umount_func (){
|
||||
check_admin (){
|
||||
if [[ $EUID -ne 0 ]]
|
||||
then
|
||||
echo "You may only mount/un-mount as root, please re-run with appropriate permissions."
|
||||
echo "This command requires root, please re-run with appropriate permissions."
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
@@ -98,24 +103,27 @@ while (( "$#" )); do
|
||||
case "$2" in
|
||||
-f|--force)
|
||||
_FLAG_FORCE=1
|
||||
#echo "FLAG: ${_FLAG_FORCE}"
|
||||
;;
|
||||
esac
|
||||
case "$1" in
|
||||
-m|--mount)
|
||||
check_admin
|
||||
read_iscsi_con
|
||||
mount_func
|
||||
;;
|
||||
-u|--umount)
|
||||
check_admin
|
||||
read_iscsi_con
|
||||
umount_func
|
||||
;;
|
||||
-s|--status)
|
||||
echo "[Showing status of mount-point]"
|
||||
check_admin
|
||||
read_iscsi_con
|
||||
check_dir
|
||||
;;
|
||||
-r|--release)
|
||||
echo "Smart iSCSI Mounter v0.96"
|
||||
echo "Smart iSCSI Mounter v0.97"
|
||||
;;
|
||||
-*)
|
||||
show_usage
|
||||
|
||||
Reference in New Issue
Block a user