Smart iSCSI Mounter v0.98.5

- Rearchitected script to handle loading of config files.
- Included personal config file.
This commit is contained in:
2020-05-23 17:56:24 +01:00
parent ba38b506ce
commit d6cd7bbfee
2 changed files with 51 additions and 14 deletions
+45 -14
View File
@@ -1,15 +1,10 @@
#!/bin/bash
DISK_UUID="12E6B87AE6B86021"
IQN="iqn.2000-01.com.synology:SR3.VMs"
PORTAL_IP="192.168.0.3"
MOUNT_DIR="/home/dunestorm/VMs"
MONITOR_PROC="vmware"
MONITOR_PROC_CNT=7
# Do not modify
_MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l)
_ISCSI_CON=""
_RELEASE_VER="0.98.5"
_CONF_FILE=$1
_MONITOR_PROC_CNT=
_ISCSI_CON=
_FLAG_FORCE=0
_FLAG_QUIET=0
@@ -18,11 +13,44 @@ read_iscsi_con (){
_ISCSI_CON=$(iscsiadm -m session 2>&1 /dev/null)
}
load_conf_file (){
_DEFAULT_CONF_FILE=$(echo /etc/smart-iscsi/$_CONF_FILE.conf)
if [ -e $_DEFAULT_CONF_FILE ]
then
source $_DEFAULT_CONF_FILE
else
if [ -e $_CONF_FILE ]
then
source $_CONF_FILE
else
echo "ERROR: Config file not specified!"
exit 2;
fi
fi
# Set variables once valid config file has been loaded
_MONITOR_PROC_CNT=$(pgrep -f $MONITOR_PROC | wc -l)
}
show_help (){
echo "Smart iSCSI Mounter - Help"
echo "Smart iSCSI Mounter v$_RELEASE_VER - Help"
echo ""
echo "[OVERRIDE] [FUNCTION]"
echo "Example: smart-iscsi -q -m"
echo " [EXECUTABLE] [CONFIG FILE] [OVERRIDE] [FUNCTION]"
echo "Example: smart-iscsi config-file -q -m"
echo "Example using fixed path: smart-iscsi ~/config-file.conf -q -m"
echo ""
echo "Config files:"
echo "Place config files inside '/etc/smart-iscsi' and call them without the '.conf' extension."
echo "Configs outside '/etc/smart-iscsi' must be called using their full path."
echo ""
echo "Sample config file (/etc/smart-iscsi/config-file.conf):"
echo "DISK_UUID=\"ABCDEFGHIJK\" # UUID of mounted disk."
echo "IQN=\"iqn.2000-01.com.synology:NAS.MyPool\" # IQN of iSCSI mount."
echo "PORTAL_IP=\"192.168.0.1\" # IP of IQN portal."
echo "MOUNT_DIR=\"/home/username/VMs\" # Mount location."
echo "MONITOR_PROC=\"vmware\" # Process name to block un-mount process, requires below count to be set."
echo "MONITOR_PROC_CNT=7 # Processes above this number will counter un-mount."
echo ""
echo "Overrides:"
echo "'-q (--quiet)'"
@@ -34,7 +62,7 @@ show_help (){
echo "'-s (--status)'"
echo "'-r (--release)'"
echo "'-h (--help)'"
echo ""
}
report_status (){
@@ -136,6 +164,7 @@ for arg in "$@"; do
;;
-m|--mount)
check_admin
load_conf_file
read_iscsi_con
mount_func
report_status
@@ -143,6 +172,7 @@ for arg in "$@"; do
;;
-u|--umount)
check_admin
load_conf_file
read_iscsi_con
umount_func
report_status
@@ -150,12 +180,13 @@ for arg in "$@"; do
;;
-s|--status)
check_admin
load_conf_file
read_iscsi_con
report_status
shift
;;
-r|--release)
echo "Smart iSCSI Mounter v0.98"
echo "Smart iSCSI Mounter v$_RELEASE_VER"
shift
;;
-h|--help)
+6
View File
@@ -0,0 +1,6 @@
DISK_UUID="12E6B87AE6B86021"
IQN="iqn.2000-01.com.synology:SR3.VMs"
PORTAL_IP="192.168.0.3"
MOUNT_DIR="/home/dunestorm/VMs"
MONITOR_PROC="vmware"
MONITOR_PROC_CNT=7