MX-760HD AddingACustomInitialisationScript
From MvixCommunity
Contents |
A script hook has been added to the modified images
A hook has been added into the modified images to look for custom initialisation scripts at boot time. It is called /usr/local/bin/check_for_scripts and contains the following:
#!/bin/sh
#----------------------------------
# A simple check_for_scripts script
#----------------------------------
/usr/local/bin/sleep 10
SCRIPT="mvix_init_script"
SCRIPT_FOUND=0
for PARTITION in /tmp/ide/*/* /tmp/usb/*/*/* ; do
if [ -e "${PARTITION}/${SCRIPT}" ] ; then
SCRIPT_FOUND=1
break
fi
done
[ ${SCRIPT_FOUND} -eq 0 ] && exit
/bin/sh ${PARTITION}/${SCRIPT} ${PARTITION}
You will see that its quite simple. It is called at boot time and first waits a while for the MVIX to settle down. It then searches the known locations of USB and IDE drives for the existence of a file called "mvix_init_script". If found, it runs the script. It runs the only the first one found.
Note: I wrote this on a 760HD which only has an IDE drive. I'm not sure what to add for the SATA device on newer models. Somebody might like to modify this???
Adding A Custom Initialisation Script
You can use the script to do things like automatically mount external shares.
When mvix_init_script is called, it is passed a single parameter corresponding to the full path to the root of the device where the script has been found. The script should be located in the root of a USB key or USB hard drive, or at the root of the internal hard drive. If the device is formatted using ext2/3, the script must be executable.
An example shell script to mount remote NFS directories
Because the mvix devices use a cut down version of the shell, not all shell scripting commands and features are available. With a little ingenuity however, you can work around most of these limitations.
Here is an example of a script to auto-mount remote NFS directories. As written, it shows how you can test for the presence of the remote server first (using ping) before trying to mount the partitions. You can use this approach to search for several different servers, and connect to the first one found, or all of them. By testing for the presence of a server first, you can avoid the otherwise long time-out if you try to mount a non-existent partition.
#!/bin/sh
#------------------------------------------
# mvix_init_script
# Put this file in root of USB stick or IDE drive
# It is called with one command line param (the path to the partition)
#
# Prepare your USB stick by creating 'mount points' in the root... for example
# /ACTION
# /ADVENTURE
# /SCI-FI
# and so on
#
# Then create the SAME directories on your NFS server.
# 172.16.1.1:/path/to/movies/ACTION
# 172.16.1.1:/path/to/movies/ADVENTURE
# 172.16.1.1:/path/to/movies/SCI-FI
#
# Then copy your AVI files into these directories.
#
# Finally, plug the USB stick into the MVIX and reboot it.
#
# Note: only works with olav's modified firmware
#------------------------------------------
# Firstly, test the parameter that was passed to the script on the command line.
# Exit if blank or if it doesn't point to a real directory on the MVIX
# (normally, param is the path to the USB stick)
[ -z "${1}" ] && exit
[ ! -d "${1}" ] && exit
#------------------------------------------
# Create a temporary mount point in the RAM disc
MOUNT_POINT="/tmp/NFS_dir"
[ ! -d "${MOUNT_POINT}" ] && mkdir "${MOUNT_POINT}"
#------------------------------------------
MOUNT_OPTIONS="ro,nolock,rsize=4096,wsize=4096"
#**** Edit following to point to the IP address of your server
IP_ADDRESS="172.16.1.1"
#**** Edit following to point to the NFS path where the matching movie directories are located
MOVIE_DIR="/path/to/movies"
# Try three times to ping then give up
for i in 1 2 3 ; do
ping ${IP_ADDRESS}
[ $? -eq 0 ] && break
done
# Did we hit a real / alive NFS server?
if [ $? -eq 0 ] ; then
# We CAN reach ${IP_ADDRESS}
mount -t nfs "${IP_ADDRESS}:${MOVIE_DIR}" "${MOUNT_POINT}" -o "${MOUNT_OPTIONS}"
# Change to the root of the device which contains this script
cd "${1}"
# Find all directories on this device.... these will become mount points if the same
# directory exists on the NFS server we've just found
for j in * ; do
[ ! -d "${j}" ] && continue
[ "${j}" = "lost+found" ] && continue
[ ! -d "${MOUNT_POINT}/${j}" ] && continue
mount -t nfs "${IP_ADDRESS}:${MOVIE_DIR}/${j}" "${1}/${j}" -o "${MOUNT_OPTIONS}"
done
# Finally, unmount the temporary device, it is no longer required now we have the other mounts
umount "${MOUNT_POINT}"
fi
Final note: why did I want to mount NFS rather than windows / samba??? Basically, I found I could transfer data using NFS at about twice the rate I could transfer using windows / samba. This was quite important to me - my MVIX cannot keep up with high definition video using windows / samba and was always stalling and generally polluting my viewing experience. I tried NFS and it worked much better. I then wrote these scripts to automate the process of mounting NFS directories on my 760HD to save the trouble of manually doing it every time I turn the 760HD on.
Network mounted directories have the advantage that they're available to ALL your media players, at the same time, all the time. A stand alone file server can also spin-down your drives when they're not in use, which the 760HD cannot do itself (ie the internal drive is always spinning, consuming power and generating heat).
A trick to emulate the shell echo statement
Sometimes, especially when you're debugging scripts like the one above, you need to print variables or echo status. The busybox doesn't include an echo function, but this can be emulated using cat.
#!/bin/sh
VARIABLE="This is an example"
# Use the following cat trick to emulate echo
cat << EOF
This is an example echo of a variable. You'll see it on the following line.
${VARIABLE}
EOF

