maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   MeeGo / Harmattan (https://talk.maemo.org/forumdisplay.php?f=45)
-   -   Share your shell scripts (https://talk.maemo.org/showthread.php?t=88474)

ladoga 2013-01-01 17:51

Share your shell scripts
 
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.

ladoga 2013-01-01 17:58

Re: Share your shell scripts
 
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:
http://www.saunalahti.fi/ladoga/harm...httpshare1.jpg
http://www.saunalahti.fi/ladoga/harm...httpshare2.jpg

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.

Schturman 2013-01-01 18:20

Re: Share your shell scripts
 
Nice script and can be useful. Thanks.

Schturman 2013-01-01 18:32

Re: Share your shell scripts
 
I have a question.. Instead exiting with Pressing "Ctrl" + c how I can exit with command ?

ladoga 2013-01-01 18:44

Re: Share your shell scripts
 
Quote:

Originally Posted by Schturman (Post 1309790)
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

Schturman 2013-01-01 18:58

Re: Share your shell scripts
 
Tell me please if this ok to add this into N9QT ?
Thanks

ladoga 2013-01-01 19:01

Re: Share your shell scripts
 
Sure, you can use it as you wish.

Win7Mac 2013-01-01 21:23

Re: Share your shell scripts
 
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! :cool:
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. :)

Schturman 2013-01-01 22:36

Re: Share your shell scripts
 
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

ladoga 2013-01-01 23:49

Re: Share your shell scripts
 
@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.


All times are GMT. The time now is 18:46.

vBulletin® Version 3.8.8