Easy Librem 5 App Development: Folders sharing


#1

As @joao.azevedo and @Kyle_Rankin did I just made a quick app for the Librem 5 using bash and yad.

The app ask you to choose a folder and then trough python SimpleHTTPServer it runs a server that shares that folder using your local IP as address, and using libqrencode it creates a QRCode to make it easy to other people to get access to the server.

Off course the can be improved, I’m not programmer this is just a modified version of the one that I use on my Android device.

Dependencies:
yad
libnotify
python3
qrencode
iproute2

We create the app file and give it permissions:

touch /home/purism/bin/share-it.sh
chmod a+x /home/purism/bin/share-it.sh

Main script:

#!/bin/bash

myip=$(hostname -I | cut -f 1 -d " ")
myport=8080

yad --title="Share it" --question \
    --window-icon=emblem-shared \
    --text="\nShare files in your network\n\nDo you wish to continue?\n"

if [ $? -eq 0 ]
then
	sharedf=$(yad --title="Share it" \
    --window-icon=emblem-shared \
    --file-selection --directory)
else
	exit 1
fi


if [ $? -eq 0 ]
then
    sharedf=$(echo $sharedf| sed 's/[^\/]*$//')

    python3 -m http.server --bind $myip --directory $sharedf $myport &

    serverpid=$!

    qrcode=$(qrencode $myip:$myport -o /tmp/qrcode.png -s 10)

    yad --title="Share it" --info --no-wrap \
    --window-icon=emblem-shared \
    --image=/tmp/qrcode.png \
    --text="Shared: $sharedf\n\nOn:\nhttp://$myip:$myport\n\n" \
    --button='Close!gtk-cancel':0
else
	exit 1
fi

kill $serverpid

notify-send -t 1000 "Share it" "Folder sharing stopped"

Desktop icon:

touch /home/purism/.local/share/applications/share-it.desktop

And we add this inside:

[Desktop Entry]
Name=Share It
Type=Application
Icon=emblem-shared
Exec=share-it.sh
Categories=Utility;

I don’t know which dependencies needs installing nor if the app works on a Librem 5 device because I’m still waiting for mine and I don’t have got the VM working now, but it should work.

Improvements are welcomed.

PS: The git repository is here


Techrepublic reviewer could not get the Librem 5 to make calls?
#2

:+1: (remaining characters)


#3

@uzanto This is super cool.

From a first quick look at this script I have only two comments to add:

1 - myip=$(ip addr show wlan0

Here you are assuming that the wifi interface is called: wlan0 when in with systemd, in several systems (but not all of them) the interface name is usually: wlp1s0, and this is most likely the case with the Librem 5.

So maybe change the name to wlp1s0, or change that variable to something more name agnostic that greps the correct IP.

That can be used in different systems.

2 - If you have a git repo with this to point to us, we can go there and contribute :smiley:


#4

Yes, as a said I copied this from the one I use in Android, I just checked the one in my laptop and I made some modifications like the way I get the IP, hostname -I | cut -f 1 -d " " I also print the qrcode in the terminal doing this, qrencode $myip:$myport -t UTF8 but I couldn’t pipe that output to yad.

Can I use https://source.puri.sm/ as git repo or it’s just for Purism team? I’ve got an account there the one that I use to translate squeekboard.

Cheers.


#5

probably, let me confirm.


#6

On older systems, it was most likely called wlan0 but newer systems are more likely to use the ironically named ‘predictable naming’ where the name is actually unpredictable but will at least be the same every time you boot.

I think the names with a ‘p’ are PCIe cards and other naming would apply to other means of connection to the system e.g. USB, SDIO.

I would suggest that for 99.9% of Librem 5 devices, just picking any interface starting with wl will get the right interface. However if the kill switch is in use, it may be that the interface disappears. So a script should take that into account if it applies.


#7

Yes, everybody can use source.puri.sm. At least I could just after registering there. :smiley:


#8

Here is the repo @joao.azevedo I uploaded the code with the improved way to get the local IP, I have to add a decent readme but it can be used by the time being.


#9

@uzanto and now I know what I am going to be doing the next few hours, testing this :wink:


#10

Hi, very nice app ideas @uzanto. (Guess the articles from @joao.azevedo and @Kyle_Rankin served as some inspiration?)

I looked how using source easybashgui in the script could make the script much more readable (accessible / literate) and working just as well with other UIs / DEs (and with just the command line!), but questioned whether it would be best to have the lib packaged or just shipped with the script.


#11

Hi, if you make the script work like that you can upload it to the git repo, If the lib is in the librem 5 repositories it’s just matter of install it.