Initial Git commit - package version 1.4.2
This commit is contained in:
commit
31dedd5b05
|
@ -0,0 +1,8 @@
|
|||
Package: network-shares-automount
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Version: 1.4-2
|
||||
Architecture: mipsel
|
||||
Maintainer: drutt
|
||||
Description: Automatic mounting of remote nfs or smb directories, with configuration on the box, using special "settings" directorys to add and configure shares. Remote host(s) are "pinged" regularly, and shares are mounting / unmounting automatically with host availability. Wake on Lan also supported.
|
||||
Depends: busybox,cifs,portmap,python
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ -d "/media/My Video" ]; then # HD - add link to settings here as it can't get to /mod
|
||||
if [ ! -d "/media/My Video/[ModSettings]" ]; then
|
||||
mkdir "/media/My Video/[ModSettings]"
|
||||
fi
|
||||
fi
|
||||
if [ -d "/media/drive1" ]; then # HD
|
||||
if [ ! -d "/media/drive1/[ModSettings]" ]; then
|
||||
mkdir "/media/drive1/[ModSettings]"
|
||||
fi
|
||||
fi
|
||||
/mod/etc/init.d/S90netshares start
|
||||
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
/mod/etc/init.d/S90netshares stop
|
||||
|
||||
exit 0
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
case "$1" in
|
||||
|
||||
start)
|
||||
/mod/sbin/scanmounts &
|
||||
|
||||
;;
|
||||
|
||||
stop)
|
||||
killall scanmounts || exit 1
|
||||
;;
|
||||
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
|
@ -0,0 +1,174 @@
|
|||
#!/bin/sh
|
||||
|
||||
TryMount()
|
||||
{
|
||||
type="$1"
|
||||
name="$2"
|
||||
|
||||
doShareFolder=$(ls -1 "$name" | grep "shareFolder=on")
|
||||
if [ "$doShareFolder" ]; then
|
||||
if [ -d "/media/My Video" ]; then
|
||||
sharesFolder="/media/My Video/[Shares] Do not delete!"
|
||||
else
|
||||
sharesFolder="/media/drive1/Video/[Shares] Do not delete!" # don't really need on HD as we can asccess the root
|
||||
fi
|
||||
fi
|
||||
|
||||
host=$(ls -1 "$name" | grep -e "^host" | cut -d'=' -f2 | sed -e 's/_/./g') #convert "_"s to "."s in host
|
||||
folder=$(ls -1 "$name" | grep -e "^folder" | cut -d'=' -f2 | sed -e 's/_/\//g') #convert "_"s to "/"s in folder name
|
||||
|
||||
# should we wake up constantly?
|
||||
wakeConstantly=$(ls -1 "$name" | grep "wakeConstantly")
|
||||
|
||||
# should we wake up now?
|
||||
wake=$(ls -1 "$name" | grep "wakeNow")
|
||||
if [ "$wake" = "wakeNow" ] || [ "$wakeConstantly" = "wakeConstantly" ]; then
|
||||
mac=$(ls -1 "$name" | grep -e "^mac" | cut -d'=' -f2)
|
||||
/mod/sbin/wakecmd "$mac" "$host"
|
||||
|
||||
if [ "$wake" = "wakeNow" ]; then
|
||||
/mod/bin/busybox/rmdir "$name/wakeNow"
|
||||
fi
|
||||
fi
|
||||
if [ ! -d "$name/wakeNow?" ]; then
|
||||
mkdir "$name/wakeNow?"
|
||||
fi
|
||||
if [ ! -d "$name/wakeConstantly?" ] && [ ! -d "$name/wakeConstantly" ]; then
|
||||
mkdir "$name/wakeConstantly?"
|
||||
fi
|
||||
|
||||
ping -c 2 -w 3 $host > /dev/null # try ping again
|
||||
pingresult=$?
|
||||
|
||||
if [ $pingresult != 0 ]; then # mount or unmount?
|
||||
#echo "$host not responding.."
|
||||
mounted=$(mount | grep "/media/$name")
|
||||
if [ "$mounted" ]; then
|
||||
echo "$host not found - unmounting.."
|
||||
# unmount if mounted
|
||||
echo "umount "/media/$name""
|
||||
umount "/media/$name" -l
|
||||
/mod/bin/busybox/rmdir "/media/$name"
|
||||
if [ "$sharesFolder" ]; then
|
||||
umount "$sharesFolder/$name" -l
|
||||
/mod/bin/busybox/rmdir "$sharesFolder/$name"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [ ! -d "/media/$name" ]; then
|
||||
echo "$host is on-line - attempting to mount $name"
|
||||
mkdir "/media/$name" # and in My Videos?
|
||||
|
||||
if [ $type = "smb" ]; then
|
||||
user=$(ls -1 "$name" | grep -e "^user") # keep the [user|password etc]=... for these as they go into mount int that format
|
||||
password=$(ls -1 "$name" | grep -e "^password")
|
||||
domain=$(ls -1 "$name" | grep -e "^domain")
|
||||
unc="unc=\\\\$host\\`echo $folder | sed 's^/^\\\\^g'`"
|
||||
echo "mount -t cifs "//$host/$folder" "/media/$name" -o $user,$password,$domain,$unc"
|
||||
mount -t cifs "//$host/$folder" "/media/$name" -o "$user,$password,$domain,$unc"
|
||||
elif [ $type = "nfs" ]; then
|
||||
echo "mount -o soft "$host:/$folder" "/media/$name""
|
||||
mount -o soft "$host:/$folder" "/media/$name"
|
||||
fi
|
||||
|
||||
if [ $? != 0 ]; then # failed
|
||||
echo "Mount failed..."
|
||||
umount "/media/$name" -l
|
||||
/mod/bin/busybox/rmdir "/media/$name"
|
||||
elif [ "$sharesFolder" ]; then
|
||||
mkdir -p "$sharesFolder/$name" # and in My Videos?
|
||||
mount "/media/$name" "$sharesFolder/$name"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
CreateExample()
|
||||
{
|
||||
type="$1"
|
||||
name="$2"
|
||||
mkdir "$name/host=10_0_1_XX"
|
||||
mkdir "$name/shareFolder=off"
|
||||
mkdir "$name/mac=ABABABABABAB (only needed for wakeUp)"
|
||||
mkdir "$name/wakeNow?"
|
||||
mkdir "$name/wakeConstantly?"
|
||||
if [ $type = "smb" ]; then
|
||||
mkdir "$name/folder=ShareFolder"
|
||||
mkdir "$name/user=User"
|
||||
mkdir "$name/password=Password"
|
||||
mkdir "$name/domain=Domain or Workgroup"
|
||||
else
|
||||
mkdir "$name/folder=ShareFolder (use _ for slash)"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
exec >/tmp/scanmounts.log 2>&1
|
||||
|
||||
if [ ! -d /mod/settings ]; then
|
||||
mkdir /mod/settings
|
||||
fi
|
||||
|
||||
cd /mod/settings
|
||||
# create some help 1st time
|
||||
if [ ! -d smb ]; then
|
||||
mkdir -p "smb/*Create folder with mount name (opt+)"
|
||||
mkdir -p "smb/*Then edit options in folder"
|
||||
fi
|
||||
if [ ! -d nfs ]; then
|
||||
mkdir -p "nfs/*Create folder with mount name (opt+)"
|
||||
mkdir -p "nfs/*Then edit options in folder"
|
||||
fi
|
||||
|
||||
# set up links to where we can get at the settings folder (a bit messy due to HDR / HD differences)
|
||||
mounted=$(mount | grep "\[ModSettings\]")
|
||||
if [ ! "$mounted" ]; then
|
||||
if [ -d "/media/My Video/[ModSettings]" ]; then # HDR - add link to settings here as it can't get to /mod
|
||||
mount /mod/settings "/media/My Video/[ModSettings]"
|
||||
elif [ -d "/media/drive1/[ModSettings]" ]; then # HD put [Modsettings] on root and add link to settings
|
||||
mount /mod/settings "/media/drive1/[ModSettings]"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# reset wake constantly flags on restart and remove old settings
|
||||
for type in smb nfs; do
|
||||
if [ -d $type ]; then
|
||||
cd $type
|
||||
for mountname in [!*]*; do
|
||||
if [ -d "$mountname/wakeConstantly" ]; then
|
||||
mv "$mountname/wakeConstantly" "$mountname/wakeConstantly?"
|
||||
fi
|
||||
if [ -d "$name/wakeNow" ]; then
|
||||
/mod/bin/busybox/rmdir "$name/wakeNow"
|
||||
fi
|
||||
if [ -d "$mountname/wakeUp=off" ]; then
|
||||
/mod/bin/busybox/rmdir "$mountname/wakeUp=off"
|
||||
fi
|
||||
done
|
||||
cd .. # back up to settings
|
||||
fi
|
||||
done
|
||||
|
||||
# now loop forever checking the mounts
|
||||
while [ 1 ]
|
||||
do
|
||||
for type in smb nfs; do
|
||||
if [ -d $type ]; then
|
||||
cd $type
|
||||
for mountname in [!*]*; do #ignore "comments" starting with *
|
||||
if [ -d "$mountname" ]; then
|
||||
#echo "Checking $mountname"
|
||||
if [ "$(ls -A "$mountname")" != "" ]; then
|
||||
TryMount $type "$mountname"
|
||||
else
|
||||
CreateExample $type "$mountname" #Empty dir - create examples
|
||||
fi
|
||||
fi
|
||||
done
|
||||
cd .. # back up to settings
|
||||
fi
|
||||
done
|
||||
sleep 1
|
||||
done
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
mac="$1"
|
||||
host="$2"
|
||||
|
||||
# create colon separated mac address for ether-wake
|
||||
macSep=${mac:0:2}:${mac:2:2}:${mac:4:2}:${mac:6:2}:${mac:8:2}:${mac:10:2}
|
||||
echo "Attempting to wake $host ($mac)"
|
||||
#send 5 wake up packets using 2 methods to be sure!
|
||||
for i in 1 2 3 4 5; do
|
||||
/mod/sbin/wakeonlan "$mac" "$host"
|
||||
/mod/bin/busybox/ether-wake $macSep
|
||||
sleep 1
|
||||
done
|
|
@ -0,0 +1,38 @@
|
|||
#!/mod/bin/python
|
||||
# wol.py
|
||||
|
||||
import socket
|
||||
import struct
|
||||
import sys
|
||||
|
||||
def wake_on_lan(macaddress, ip):
|
||||
""" Switches on remote computers using WOL. """
|
||||
|
||||
# Check macaddress format and try to compensate.
|
||||
if len(macaddress) == 12:
|
||||
pass
|
||||
elif len(macaddress) == 12 + 5:
|
||||
sep = macaddress[2]
|
||||
macaddress = macaddress.replace(sep, '')
|
||||
else:
|
||||
raise ValueError('Incorrect MAC address format')
|
||||
|
||||
# Pad the synchronization stream.
|
||||
data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
|
||||
send_data = ''
|
||||
|
||||
# Split up the hex values and pack.
|
||||
for i in range(0, len(data), 2):
|
||||
send_data = ''.join([send_data,
|
||||
struct.pack('B', int(data[i: i + 2], 16))])
|
||||
|
||||
# Broadcast it to the LAN.
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
sock.sendto(send_data, (ip, 7))
|
||||
print "Sent WOL to "+sys.argv[1]+" @ "+sys.argv[2]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Use macaddresses with any seperators.
|
||||
wake_on_lan(sys.argv[1], sys.argv[2])
|
Loading…
Reference in New Issue