-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhpscans_u.sh
More file actions
134 lines (130 loc) · 3.42 KB
/
hpscans_u.sh
File metadata and controls
134 lines (130 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
me=`basename "$0"`
#C:8/18/2021 M:2/13/2021
#aleczdr
VER="1.14"
VOLUME="hpscans"
NETPATH="user:pw@domain.local/$VOLUME"
WEBPATH="http://readyshare.routerlogin.net/shares/$VOLUME/"
VOLPATH="/Volumes/$VOLUME"
#auto
# line 11 is the setting that disables or enables the mount-at-launch feature. it bypasses the menu. values are #dumb, #notdumb, #auto, and #web
#variables don't work with osascripts
#README
#This script is for mounting the scan volume on the flash drive plugged into
#the router. If the script does not show a menu when run, please chmod +x the
#file and see if it works. If it only shows "Drive Mounted" then please run
#the script with the "menu" argument.
#This script relies on finder running
if pgrep -x Finder; then
findervar="running"
fi
function mountvol
{
if [ "$findervar" == "running" ]; then
open "smb://${NETPATH}"
else
mkdir $VOLPATH
mount -t smbfs $NETPATH $VOLPATH
fi
echo "Drive Mounted"
}
function unmountvol
{
local retryvar=10
local count=0
while true; do
diskutil unmountDisk $VOLPATH
local exitstat=$?
if [ $exitstat == 0 ]; then
echo "Drive Ejected"
break
fi
if [ $count -gt 10 ]; then
echo "Eject Failed"
break
fi
((count++));
sleep 1
done
}
function web
{
open $WEBPATH
}
function toggledumb
{
if [ "$(sed -n '11p' $DIR/$me)" != "#dumb" ]; then
sed -e '11s/.*/#dumb/' -i '' $DIR/$me
echo "Dumb mode on"
echo "To disable, run the script with the \"menu\" argument"
else
sed -e '11s/.*/#notdumb/' -i '' $DIR/$me
echo "Dumb mode off"
fi
}
function toggleauto
{
if [ "$(sed -n '11p' $DIR/$me)" != "#auto" ]; then
sed -e '11s/.*/#auto/' -i '' $DIR/$me
echo "Automatic mode on"
echo "To disable, run the script with the \"menu\" argument"
else
sed -e '11s/.*/#notdumb/' -i '' $DIR/$me
echo "Automatic mode off"
fi
}
function main
{
echo "* * * * * * * * * * * * * * * * * *"
echo "* HP Scans Mounter *"
echo "* smb://rpisecurity.local/hpscans *"
echo "* * * * * * * * * * * * * * * * * *"
#echo "* (Router Flashdrive) *"
#echo "* * * * * * * * * *"
#echo "* * * * * * * * * * * * * *"
#echo "****************************"
echo "1) Mount"
echo "2) Eject"
#echo "3) Web"
echo "4) Toggle Dumb Mode"
echo "5) Toggle Automatic Mode"
echo "q) Quit"
read -p "Choice: " choice
case $choice in
1) mountvol ;;
2) unmountvol ;;
4) toggledumb ;;
3) web;;
5) toggleauto ;;
#*) echo -e "${RED}Error 4...${STD}"
esac
}
##Start Script##
if [ "$1" = 'mount' ]; then mountvol
elif [ "$1" = 'unmount' ]; then unmountvol
elif [ "$1" = 'eject' ]; then unmountvol
elif [ "$1" = 'menu' ]; then main
#elif [ "$1" = 'web' ]; then web
elif [ "$(sed -n '11p' $DIR/$me)" == "#dumb" ]; then mountvol
elif [ "$(sed -n '11p' $DIR/$me)" == "#web" ]; then web
elif [ "$(sed -n '11p' $DIR/$me)" == "#auto" ]; then
NAME=$VOLUME
PART=`diskutil list|grep $NAME|awk '{print $6}'`
if [ -z `ls -1 /Volumes/ | grep $NAME` ] ; then
# check that PART appears to be a disk partition
#if [ `file $VOLPATH | awk '{print $2}'` = "block" ] ; then
mountvol
#else
# echo /dev/$PART does not appear to be a disk partition - exiting
#exit 1
# fi
else
unmountvol
fi
else
main
fi
exit
EOF