diff --git a/smart-iscsi.sh b/Smart-iSCSI/smart-iscsi.sh similarity index 65% rename from smart-iscsi.sh rename to Smart-iSCSI/smart-iscsi.sh index dbfd735..e2cb2d9 100755 --- a/smart-iscsi.sh +++ b/Smart-iSCSI/smart-iscsi.sh @@ -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) diff --git a/Smart-iSCSI/vms.conf b/Smart-iSCSI/vms.conf new file mode 100644 index 0000000..aedb701 --- /dev/null +++ b/Smart-iSCSI/vms.conf @@ -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 \ No newline at end of file