Reply
Thread Tools
Posts: 219 | Thanked: 282 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#1
Probably quite a few of us have created shell scripts for our N9's to help with different tasks and to increase usability of our devices. Idea of this thread is to share what you have in your ~/bin and maybe some people will find these scripts useful and/or can improve on them.
 

The Following 3 Users Say Thank You to ladoga For This Useful Post:
Posts: 219 | Thanked: 282 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#2
I'll start with a script called "httpshare" which I made to ease sharing files on my N9. It's basically just a helper script for Python's SimpleHTTPServer, but I've found it very useful when I need to quickly access contents of my N9 from another device.

See/Get it here.

Screenshots for impatient:



Installation:
It depends on python so you need to:
Code:
# apt-get install python
Copy the script to your ~/bin (or elsewhere inside your user's $PATH) and give it executable permissions:
Code:
$ chmod 755 ~/bin/httpshare
Usage examples:
Code:
$ httpshare .
$ httpshare ~/MyDocs/Movies
$ httpshare /etc
On the client side, open a web browser and navigate to N9's IP address.

If you want to access the server from WAN (internet) remember to set your router's port forwarding accordingly.

On a mobile "broadband" (2G/3G) it's possible that your ISP uses NAT for IP addresses (your device doesn't have a public IP address) or the port 80 (http) for incoming traffic is blocked. In latter case you might be able to get through using some other port. (set the value of port variable in the script accordingly).

Known issues:
-Python SimpleHTTPServer will spit out some garbage on keyboard interrupt (Ctrl+c). This is harmless other than aesthetically. I didn't find a good way to remove the garbage as it seems to lump almost all of it's output into stderr and thus sending 2 > /dev/null will also get rid of useful output, such as info on incoming connections. If you nonetheless want to make it quiet you can redirect all it's output to /dev/null by replacing the line:
Code:
develsh -c "python -m SimpleHTTPServer $port > /dev/null"
with:
Code:
develsh -c "python -m SimpleHTTPServer $port > /dev/null 2>&1"
-On Harmattan you need to exit using Ctrl+c. Simply closing the parent terminal won't kill the server. This is probably caused by having develsh inside the script to enable access to port 80 for user. (I didn't notice the same behaviour when running the script sans develsh on a linux desktop.)

PS. Code tags on TMO don't work (wrapping of lines), otherwise I would have posted the script into message itself.

Last edited by ladoga; 01-01-2013 at 03:32 PM.
 

The Following 8 Users Say Thank You to ladoga For This Useful Post:
Schturman's Avatar
Posts: 4,660 | Thanked: 3,140 times | Joined on Jan 2010 @ Israel
#3
Nice script and can be useful. Thanks.
__________________
Lausanne & Lyon de descente...
----------------
Schturman's home page
Schturman's repo on openrepos
N9 QuickTweak - If you like my work, you can donate here. Thanks!
Facebook chat fix for N9/50 (thanks to mbanck) - FB fixed itself (no need this anymore) .
DEB packages creator for N9/50 (create your packages on the phone).
IMAGE Converter for N9/50 (convert/resize your images on the phone).
 

The Following User Says Thank You to Schturman For This Useful Post:
Schturman's Avatar
Posts: 4,660 | Thanked: 3,140 times | Joined on Jan 2010 @ Israel
#4
I have a question.. Instead exiting with Pressing "Ctrl" + c how I can exit with command ?
__________________
Lausanne & Lyon de descente...
----------------
Schturman's home page
Schturman's repo on openrepos
N9 QuickTweak - If you like my work, you can donate here. Thanks!
Facebook chat fix for N9/50 (thanks to mbanck) - FB fixed itself (no need this anymore) .
DEB packages creator for N9/50 (create your packages on the phone).
IMAGE Converter for N9/50 (convert/resize your images on the phone).
 
Posts: 219 | Thanked: 282 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#5
Originally Posted by Schturman View Post
I have a question.. Instead exiting with Pressing "Ctrl" + c how I can exit with command ?
Check the PID of the process with:
Code:
$ ps -Af | grep HTTP
and then kill it with:
Code:
$ kill [PID]
Or if you want to kill it with a oneliner:
Code:
$ pid=`pgrep -f HTTP`; kill $pid

Last edited by ladoga; 01-01-2013 at 03:00 PM.
 

The Following User Says Thank You to ladoga For This Useful Post:
Schturman's Avatar
Posts: 4,660 | Thanked: 3,140 times | Joined on Jan 2010 @ Israel
#6
Tell me please if this ok to add this into N9QT ?
Thanks
__________________
Lausanne & Lyon de descente...
----------------
Schturman's home page
Schturman's repo on openrepos
N9 QuickTweak - If you like my work, you can donate here. Thanks!
Facebook chat fix for N9/50 (thanks to mbanck) - FB fixed itself (no need this anymore) .
DEB packages creator for N9/50 (create your packages on the phone).
IMAGE Converter for N9/50 (convert/resize your images on the phone).
 

The Following User Says Thank You to Schturman For This Useful Post:
Posts: 219 | Thanked: 282 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#7
Sure, you can use it as you wish.
 

The Following User Says Thank You to ladoga For This Useful Post:
Win7Mac's Avatar
Posts: 427 | Thanked: 509 times | Joined on Apr 2012 @ Hamburg
#8
I would like to present my new years' gift from thedead 1440 - a desktop toggle for LPM/standby sreen.

Basically its just 2 icons, 1 sh file and 1 .desktop file, but he even made a .deb for it!
All files are here so feel free to modify if requried.
The regarding thread is here, better icons can be found here or here.
Enjoy.
__________________
Nokia 5110 > 3310 > 6230 > N70 > N9 BLACK 64GB
Hildon Foundation Board member term 2013/2014

Last edited by Win7Mac; 01-02-2013 at 09:22 PM. Reason: new icons
 

The Following 2 Users Say Thank You to Win7Mac For This Useful Post:
Schturman's Avatar
Posts: 4,660 | Thanked: 3,140 times | Joined on Jan 2010 @ Israel
#9
ladoga, can you help me to create a simple script that can check if SimpleHTTPServer runs or not and if it is running -> command to close, if not running -> start this "httpshare ~/MyDocs/Movies"
I want to create desktop icon for this:
1. one click = check if SimpleHTTPServer run or not and if it is runing -> command to close.
2. second click = check if SimpleHTTPServer run or not and if it is NOT run -> start this "httpshare ~/MyDocs/Movies"

Thanks
__________________
Lausanne & Lyon de descente...
----------------
Schturman's home page
Schturman's repo on openrepos
N9 QuickTweak - If you like my work, you can donate here. Thanks!
Facebook chat fix for N9/50 (thanks to mbanck) - FB fixed itself (no need this anymore) .
DEB packages creator for N9/50 (create your packages on the phone).
IMAGE Converter for N9/50 (convert/resize your images on the phone).

Last edited by Schturman; 01-01-2013 at 07:38 PM.
 
Posts: 219 | Thanked: 282 times | Joined on Oct 2009 @ Helsinki, Suomi (Finland)
#10
@Schturman
In above post there was all you needed to know.

Code:
#!/bin/sh
pid=`pgrep -f SimpleHTTPServer`
dir="/home/user/MyDocs/Movies"

if [ -z $pid ]
then
        cd $dir
        develsh -c "python -m SimpleHTTPServer 80"
else
        kill $pid
fi
Basically you just check if the process does not exist ($pid lenght is zero), if true run python SimpleHTTPServer, else kill the process. There's no need to use httpshare script as you're not using any of it's functionality.

Last edited by ladoga; 01-01-2013 at 08:13 PM.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT -4. The time now is 02:40 AM.