August 04, 2008, 11:04:15 am
News:
  Pages: [1]
Author Topic: HOWTO: 3 easy hacks in one: automount, VNC, and no UPNP  (Read 1981 times)
pEEf
Newbie

Posts: 26


« on: February 05, 2008, 02:24:21 pm »

Thanks to Greyback for his excellent hack  on auto-mounting your network shares on bootup, and Bagster  for porting a VNC server.  Awesome job!

The main problem so far with implementing hacks that involve the rc.user script, is that it is called twice.  This is what's causing a lot of funky behavior!

The "sleep" command is needed in an attempt to fix the auto-mount script, but knowing about the double-run makes the sleep unnecessary.

Here is what I did.  I will post the code for those that already know how, followed by detailed instructions for beginners.

Here is my rc.user file:

Code:
#!/bin/sh
/mnt/OSD/phils.sh &

I called my custom init file "phils.sh", but you can call it anything you like as long as it's consistent.

Here is my phils.sh file:

Code:
#!/bin/sh

if [ -e /var/tmp/philran ]; then
  date >> /var/tmp/philran
else
  touch /var/tmp/philran
  exit 
fi 

/usr/bin/killall djmount

/bin/mkdir /media/Movies
/sbin/mount.cifs //10.0.0.1/movies /media/Movies -o user=root,pass=,r,nolock

/bin/mkdir /media/Music
/sbin/mount.cifs //10.0.0.1/music /media/Music -o user=root,pass=,r,nolock

/bin/mkdir /media/Recordings
/sbin/mount.cifs //10.0.0.1/neuros /media/Recordings -o user=root,pass=,rw,nolock

if [ -x /media/Recordings/x11vnc ]; then
date >> /var/tmp/vnclog
/media/Recordings/x11vnc -rawfb fb0 -pipeinput /media/Recordings/send_ir.sh -forever >> /var/tmp/vnclog &
else
/bin/rmdir /media/Movies
/bin/rmdir /media/Music
/bin/rmdir /media/Recordings
fi

What it does:  First, since it is going to run twice, once early before any networking is inited, and once after everything is up, I check to see which instance it's being called.  I do this by looking for the file "philran" in RAM.  (it gets erased during reboot)  If it's not there, I create it with touch, then, since it's the first calling, I exit the script.  On the second call, the file exists, so I stuff the date/time in RAM just as a log of when it ran, and allow the rest of the script to continue.  The next thing I do is kill "djmount" which is what shows up in the Play-Browse menu as upnp.  I don't use upnp on my network, and don't particularly care for it, so I kill it.  If you use it, simply omit this line.  Next I create 3 mount points for the 3 Samba shares on my Linux server used by the OSD.  One for Movies (read only), one for Music (also RO) and one that's Read-Write for recording things and storage of favorites, playlists, etc.  Once complete, I look for Bagster's x11vnc implementation.  It's large, so I leave it on the linux server instead of filling all my flash on the OSD.  Also, if I take my OSD over to a friend's house, I don't need it running or the shares mounted, so I check to see if it's there.  If it's not, I don't run it, and in addition I remove all the share mount points, as they will have failed to mount anyway.  I originally tried to check the return status of the mount.cifs command, but it doesn't return failure if the mount operation fails, so this is a good alternative.  Now, When I grab my OSD and run over to a friend's house with a large CF full of movies, It boots without any of the empty shares to get in the way!

If you use any NFS mounts, be sure to include them as well.  My passwords are all null as the Samba server is configured without them.  If you have passwords on your shares, be sure to set them.

For those that would like to implement this but have little experience, Look down for the second post which has simple instructions.  Prepare to meet "vi"!!!  =)
Logged
pEEf
Newbie

Posts: 26


« Reply #1 on: February 05, 2008, 03:21:05 pm »

If you don't have much Linux experience, here are more details:

First you will need a "server" to hold your media.  This can be Wind0ze, Mac, or Linux.  I have a slackware server that has 1.6TB of disk space, it runs Samba so all the wind0ze boxen on our network can access it easily.  It has 3 shares; Movies, Music, and Recordings.  The Movies and Music are read-only, so my housemates don't accidentally hose anything, and the Recordings is where you can put stuff.  Only the OSD has access to the Recordings share because it's restricted by IP.  There is a symbolic link from recordings to Movies, so people can watch the OSD recordings but cannot delete them.

So at the very least, we need one share.  Depending on your operating system, creating this will differ in procedure, but information on how to do this can be easily found on the net.  I DO NOT recommend you set a password on it, at least not yet.  Once you have your share ready, download Bagster's VNC package and put the files into your new shared directory.  Here is where to get them:
https://svn.neurostechnology.com/hackers/bagster/x11vnc/

The 2 files you need are "send_ir.sh" and "x11vnc".  You don't need the readme.

Now, You will need to determine the IP address of your OSD.  Once you know this, open your shell, command prompt, or terminal window depending on what OS you run.  On windows this would be "Command Prompt".  Almost all OS's have Telnet.  So now type this:

Code:
telnet  0.0.0.0

Replace 0.0.0.0 with the actual IP address of your OSD.  What I did on mine was assign it a fixed address via DHCP.  This way it never changes.  Your router or DHCP server usually has a way to do this, but it's not needed.  You can also set it as static IP in the OSD setup.

Once connected the OSD will display a "login:" prompt.  Type "root" and hit enter.  It will then ask for the password.  It should be "pablod", but if that fails, try just hitting enter.  You can change this if you like, but I don't recommend it.

Once logged in you will see (should see!) something similar this:

Code:
Connected to neuros.
Escape character is '^]'.

neuros login: root
Password:


BusyBox v1.6.1 (2008-01-08 12:18:59 CST) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

~ $

The "~$" is your command prompt.  Type "cd  /mnt/OSD" and hit enter.  (don't type the quotes!)  The prompt will change  reflecting your current directory.  The "cd" command means "change directory".

Now type "ls" and hit enter.  This will list stuff (files and subdirectories) in your current directory.  It should show a few files and return to a waiting command prompt.  Beware that case matters in linux for everything, and pay attention to where I put the spaces.

Now, lets test your share.  Type "mkdir   /media/test" and hit enter.  This will create an empty directory which we will use as a mount point.  This is where the OSD "looks" for media when you browse.  If you go to the "Play - Browse" menu on your OSD now, you will see a new entry called "test".  There will be nothing in it, yet.  Also note that this is not persistent.  As soon as you reboot the OSD it will go away.

Now let's put something in it!  Type "mount.cifs   //0.0.0.0/sharename   /media/test" where 0.0.0.0 is replaced with the IP address of the machine with the share, and "sharename" with the name of your share.  On mine, it's called "neuros", so I did this:  "mount.cifs //10.0.0.1/neuros   /media/test".  Note the spaces.  I have exaggerated them so they are  clear.  It usually doesn't hurt to have extra spaces where one is required, but having at least one is absolutely needed!

I use the IP address for my server's name, but you could also use the machines name.  Like "//mypc/myshare".  It should work, but is not guaranteed like an IP address is.   Beware, that the IP address could change in the future if it is not set static!!!

Once you hit enter on the mount.cifs command, it should come back and ask you for a password.  If you have set a password on your share,  (against my advice) enter it now.  You should get a "could not update mount table" if all went well.  Ignore this error, it is a quirk because the mount table on the OSD is set in ROM.  If you get something like:

Code:
retrying with upper case share name
mount error 6 = No such device or address
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

You probably didn't get the IP address right, or your share doesn't actually exist.  If it worked, you should be able to Browse into test on the OSD and see your x11vnc files!  Did it work?  If it didn't, you need to troubleshoot your share.  Can you access it from another machine on your network?   Can you "ping" the IP address from yoour OSD?  (type "ping   0.0.0.0" with the IP address of your server, it should come back with "64 bytes from 0.0.0.0: seq=1 ttl=52 time=4.2 ms".  The seq will increment and the time will vary.  To stop ping, hit CTRL-C.)

Once you get the shares working, then we are ready to make the script to automount them.

type "vi /mnt/OSD/rc.user" and hit enter.  "vi" is a old-school UNIX text editor.  It scares many, and hurts few.  There are many tutorials online on how to use it fully, but I'm going to only give you the basics.

Hit the "i" key which means "insert".  Type the following:

Code:
#!/bin/sh
/mnt/OSD/phils.sh &

Then hit the ESC key to take you out of insert.  Hit the colon key ":" then "w" then enter.  This means write.  Then hit ":" then "q" then Enter.  This Quits.   Voila!  Your first encounter with vi and you lived to tell about it!  =)

Now lets create the phils.sh file:

Type "vi   /mnt/OSD/phils.sh" and hit enter.  You know the drill now,  hit "i" then begin typing:  (or you can copy/paste into your telnet)

Code:
#!/bin/sh

if [ -e /var/tmp/philran ]; then
  date >> /var/tmp/philran
else
  touch /var/tmp/philran
  exit 
fi 

/bin/mkdir /media/Recordings
/sbin/mount.cifs //0.0.0.0/myshare /media/Recordings -o user=root,pass=,rw,nolock

if [ -x /media/Recordings/x11vnc ]; then
date >> /var/tmp/vnclog
/media/Recordings/x11vnc -rawfb fb0 -pipeinput /media/Recordings/send_ir.sh -forever >> /var/tmp/vnclog &
else
/bin/rmdir /media/Recordings
fi

Note that you need to replace the IP address and share name with yours!!!

If you want to add more shares, or the UPNP killer, do it later.  For now, lets see if it works!   Carefully verify your script is correct, then Hit ESC, then ":w" enter, then ":q" enter.

You can check your file by typing "cat   /mnt/OSD/phils.sh" and hitting enter.  It will spit it all out.

We now need to make them executable.  type "chmod   755  /mnt/OSD/rc.user" and hit enter, then do the same for phils.sh: "chmod  755  /mnt/OSD/phils.sh" and hit enter.  We also need to do this for the 2 vnc files.  If you sucessfully mounted them in test, you do that with "chmod   755  /media/test/x11vnc" and "chmod  755  /media/test/send_ir.sh".  If you get a "chmod: /media/Movies/.htaccess: Input/output error" that means your share is not writeable.  Fix this!!!

If all is well, you should be able to type "reboot".  The OSD will kick you out of telnet and reboot.  Once it's up, you should be able to VNC into it if all went well!

I recommend UltraVNC:
http://prdownloads.sourceforge.net/ultravnc/UltraVNC-102-Setup.exe?download

Run the VNC Viewer and put in the IP address of your OSD.  Voila!

If it didn't work, check to make sure your "Recordings" share is in Play - Browse.  If it is not, something's wrong!  Telnet in and try to see what happened.  You can look at the "logs" in the form of /var/tmp/philran  and /var/tmp/vnclog to see what happened.

Enjoy!


Code:
cd /mnt/OSD
Logged
pEEf
Newbie

Posts: 26


« Reply #2 on: February 05, 2008, 03:24:32 pm »

Hey pEEf, nice work! Keep the tips coming!!

Thanks!   I'm having fun!  =)

so it is being called twice, in /etc/init.d/mainsetup and in /etc/rcS.d/S10_mainsetup. That's for Bugzilla!
-G

Well, the cool thing about calling it twice is we can do things early or late.  Besides, if they fix this it will break my new script!  :-P

Logged
greyback
Moderator
Hero Member

Posts: 925


« Reply #3 on: February 05, 2008, 03:35:01 pm »

Hey pEEf, nice work! Keep the tips coming!!

The main problem so far with implementing hacks that involve the rc.user script, is that it is called twice.  This is what's causing a lot of funky behavior!

Yeah I noticed this only yesterday (I'd loads of if/else in my scripts so nothing broke) but thought my fiddling with scripts was to blame. Apparently not. A quick grep gave me:
Code:
/etc $ grep -r rc.user *
init.d/mainsetup:# This checks if there is a rc.user script on the JFFS2 mount and,
init.d/mainsetup:#if [ -r /tmp/media/OSD/rc.user ]; then
init.d/mainsetup:#       . /tmp/media/OSD/rc.user
init.d/rc:# If there is a rc.user on /mnt/OSD then run it.
init.d/rc:if [ -r /mnt/OSD/rc.user ]; then
init.d/rc:       . /mnt/OSD/rc.user
grep: lighttpd: No such file or directory
rcS.d/S10_mainsetup:# This checks if there is a rc.user script on the JFFS2 mount and,
rcS.d/S10_mainsetup:#if [ -r /tmp/media/OSD/rc.user ]; then
rcS.d/S10_mainsetup:#       . /tmp/media/OSD/rc.user
so it is being called twice, in /etc/init.d/mainsetup and in /etc/rcS.d/S10_mainsetup. That's for Bugzilla!
-G
Logged
greyback
Moderator
Hero Member

Posts: 925


« Reply #4 on: February 05, 2008, 03:40:49 pm »

Heh, I messed that bit of moderation up

I deleted my post so you had a nice clean run of posts - which is easier to read than with my crap in between. Then I saw you'd replied so had to repost it again!

Whoops!!

I logged that bug here and did ask that the first one is removed, so there should be no need for the 'sleep' command bodge.

Great post! Thank you on behalf of those just starting off with their OSD.
-G
« Last Edit: February 05, 2008, 03:48:10 pm by greyback » Logged
kdan
Newbie

Posts: 19


« Reply #5 on: February 13, 2008, 04:10:20 pm »

pEEf,

Thank you for this tip it. Now I have removed all my sleep commands my OSD boots within half the time it used to and everything loads fine.

However the command  '/usr/bin/killall djmount' fails with the following in my boot log (The last line is from an if statement).
Code:
killall: cannot kill pid 964: No such process
killall: cannot kill pid 966: No such process
killall: cannot kill pid 967: No such process
UPnP: Failed to stop
Any ideas what might be causing this?  Huh

Now on a different note, I realised something interesting... The folders in /media/ (excluding network and upnpBrowser) are symlinks from folders in /mnt/tmpsf.  Now if your not aware everything that appears in the media folder appears in the Play / Browse menu on the OSD.  I don't use the SD or CF cards for media storage so I have an 'rm' command for each in my boot script to remove them from the media folder. I also remove the USB symlink and create my own for Movies, TV Shows and Records.
Here is that part of my boot script
Code:
#!/bin/sh

# Remove the Sym-Links for CF/SD cards & USB drive
rm /media/CF-card
rm /media/SD-card
rm /media/USB

# Add Symlinks for Movies
ln -s /mnt/tmpfs/mount_USB/Movies /media/Movies

# Add Symlinks for TV Shows
ln -s "/mnt/tmpfs/mount_USB/TV Shows" "/media/TV Shows"
                               
# Add Symlink for Recordings
ln -s /mnt/tmpfs/mount_USB/Recordings /media/Recordings
This is a stripped down version of my boot script, I have removed all if statements and echo commands that are saved to my boot log file for easy debugging.

Now I only have the things I use in the Play / Browse menu, or atleast I will when I manged to remove uPnP Wink

KDan
« Last Edit: February 13, 2008, 04:19:05 pm by kdan » Logged
greyback
Moderator
Hero Member

Posts: 925


« Reply #6 on: February 13, 2008, 05:11:42 pm »

However the command  '/usr/bin/killall djmount' fails...
[\quote]

A slightly more polite way of doing this is
Code:
/etc/init.d/djmount stop
-G
Logged
nexus6
Newbie

Posts: 20


« Reply #7 on: July 03, 2008, 05:59:31 am »

check out http://forums.neurostechnology.com/index.php?topic=7918.msg41941#msg41941
I had to put a sleep comand before creating and mounting
sleep 30
Logged
j_a_muller
Newbie

Posts: 4


« Reply #8 on: July 14, 2008, 05:27:03 am »

I used to have the VNC and FTP working fine on OSD. Everything needs to be reconfigured now that I have upgraded to Arizona.

Since I ave both running from SD-cards that came with cameras and are permanently in th OSD, can I just put the *.RC scripts on the new user directories, or is it more complex than that?

Has anybody else put FTP and/or VNC on Arizona based OSD's?

Thanks,
Joost
Logged
greyback
Moderator
Hero Member

Posts: 925


« Reply #9 on: July 17, 2008, 12:43:09 pm »

Hey,
you need to place the rc.user file in /mnt/OSD. But that script can point to all your apps on your SD-cards, CF cards, etc.

I believe many have got FTP and VLC running on Arizona. I can testify that VNC works for Arizona quite well, but UI control is a bit dodgy.
-G
Logged
j_a_muller
Newbie

Posts: 4


« Reply #10 on: July 21, 2008, 02:25:46 pm »

Thanks.

I got  both working in Arizona. I ould ctually move the software onto the CF card, so it is easier.

Now all that is left is to be able to rconnect shares.

Logged
  Pages: [1]
Jump to: