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:
2020-05-21 19:50:55 +01:00
parent 6f6bb50444
commit 4b1dc8c5fc
+18 -10
View File
@@ -9,9 +9,14 @@ MONITOR_PROC_CNT=7
# Do not modify # Do not modify
_MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l) _MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l)
_ISCSI_CON_CNT=$(iscsiadm -m session | wc -l) _ISCSI_CON=""
_FLAG_FORCE=0 _FLAG_FORCE=0
# The use of iscsiadm requires admin privilages
read_iscsi_con (){
_ISCSI_CON=$(iscsiadm -m session)
}
show_usage (){ show_usage (){
echo "[Usage]" echo "[Usage]"
echo "Please use either '-m (--mount)' to mount or '-u (--umount)' to unmount this volume." echo "Please use either '-m (--mount)' to mount or '-u (--umount)' to unmount this volume."
@@ -35,8 +40,8 @@ check_dir (){
fi fi
echo "" echo ""
echo "The below iSCSI connection(s) is/are open:" echo "There is/are currently '$(${_ISCSI_CON} 2>&1 | wc -l)' iSCSI connection(s) open:"
echo "$(iscsiadm -m session)" echo "${_ISCSI_CON}"
} }
check_proc_status (){ check_proc_status (){
@@ -52,9 +57,9 @@ check_proc_status (){
mount_func (){ mount_func (){
echo "[Attempting to mount iSCSI volume]" 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 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." echo "Use the -f (--force) flag to bypass this warning."
exit 2; exit 2;
fi fi
@@ -72,9 +77,9 @@ umount_func (){
check_proc_status check_proc_status
fi fi
if [[ ${_ISCSI_CON_CNT} -eq 0 ]] && [[ $_FLAG_FORCE -eq 0 ]] if [[ ${_ISCSI_CON} != *${IQN}* ]] && [[ $_FLAG_FORCE -eq 0 ]]
then 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." echo "Use the -f (--force) flag to bypass this warning."
exit 2; exit 2;
fi fi
@@ -88,7 +93,7 @@ umount_func (){
check_admin (){ check_admin (){
if [[ $EUID -ne 0 ]] if [[ $EUID -ne 0 ]]
then 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; exit 1;
fi fi
} }
@@ -98,24 +103,27 @@ while (( "$#" )); do
case "$2" in case "$2" in
-f|--force) -f|--force)
_FLAG_FORCE=1 _FLAG_FORCE=1
#echo "FLAG: ${_FLAG_FORCE}"
;; ;;
esac esac
case "$1" in case "$1" in
-m|--mount) -m|--mount)
check_admin check_admin
read_iscsi_con
mount_func mount_func
;; ;;
-u|--umount) -u|--umount)
check_admin check_admin
read_iscsi_con
umount_func umount_func
;; ;;
-s|--status) -s|--status)
echo "[Showing status of mount-point]" echo "[Showing status of mount-point]"
check_admin
read_iscsi_con
check_dir check_dir
;; ;;
-r|--release) -r|--release)
echo "Smart iSCSI Mounter v0.96" echo "Smart iSCSI Mounter v0.97"
;; ;;
-*) -*)
show_usage show_usage