diff options
author | Stephane Desneux <stephane.desneux@open.eurogiciel.org> | 2014-04-11 22:29:15 +0200 |
---|---|---|
committer | Stephane Desneux <stephane.desneux@open.eurogiciel.org> | 2014-04-11 22:29:15 +0200 |
commit | 5453526b8bd997652ccea38fac867145d2dd8524 (patch) | |
tree | c6cb2588927308ad43dab966a1ec62e5d529f4f8 | |
parent | 64df19c7ed345ddabdd82f3d92953ab252167511 (diff) | |
download | desktop-skin-5453526b8bd997652ccea38fac867145d2dd8524.tar.gz desktop-skin-5453526b8bd997652ccea38fac867145d2dd8524.tar.bz2 desktop-skin-5453526b8bd997652ccea38fac867145d2dd8524.zip |
added wifi connection script
Change-Id: I4e651ae19e63e4fd3704d07539a9949b13f0d19e
Signed-off-by: Stephane Desneux <stephane.desneux@open.eurogiciel.org>
-rw-r--r-- | Script/wifi | 156 | ||||
-rw-r--r-- | packaging/desktop-skin.spec | 4 |
2 files changed, 158 insertions, 2 deletions
diff --git a/Script/wifi b/Script/wifi new file mode 100644 index 0000000..3cd456d --- /dev/null +++ b/Script/wifi @@ -0,0 +1,156 @@ +#!/bin/bash + +# Helper script to activate/desactivate WLAN from command line + +# Usage : +# wifi connect <ssid> <passphrase> +# wifi disconnect <ssid> + +##################################################### + +### global vars ### + +script=$(basename $0) +configpath=/var/lib/connman # connman config directory +ssid="" # ssid of wifi network to reach +passphrase="" # passphrase of wifi network to reach +service="" # service identifier of the network service to reach +fullservice="" # <ssid><service> + +function error() { + + echo ERROR: "$@" >&2 + echo "Usage: $script connect <ssid> <passphrase>" >&2 + echo "Usage: $script disconnect <ssid>" >&2 + exit 1 +} + +function wifi_enable() { + +command=$(connmanctl technologies | grep -A 4 wifi | sed -n '4p') + +if [[ $command == *True ]] +then + echo ">>> Wifi is already enabled ... Ok" +else + echo ">>> Enabling wifi ..." + command=$(connmanctl enable wifi) + if [[ $command == Enabled* ]] + then + echo $command + else + echo ">>> Cannot enable wifi !" + exit 1 + fi +fi + +} + +function wifi_scan() { + +echo -e "\n>>> Scanning for available wifi networks..." +connmanctl scan wifi +connmanctl scan wifi + +} + +function wifi_status() { +command=$(connmanctl technologies | grep -A 5 wifi | sed -n '4p') + +if [[ $command == *True ]] +then + echo -e "\n>>> Already connected to a wifi network" + exit 0 +fi + +} + +function wifi_config() { + +echo -e "\n>>> Setting up wifi connection..." +fullservice=$(connmanctl services | cut -c 5- | sed 's/ \+ /:/g' | grep $ssid:) + +if [[ -n $fullservice ]] + then + echo "Target ssid found - config is :" + else + echo "Target ssid not found !" + exit 1 +fi + +ssid=$(echo "$fullservice" | awk -F: '{print $1}') +service=$(echo "$fullservice" | awk -F: '{print $2}') + +echo "SSID : $ssid" +echo "Service Id : $service" +echo "Passphrase : $passphrase" + +printf "[service_$service] +Name = $ssid +Type = wifi +Passphrase = $passphrase +"> $configpath/$ssid.config + + + +echo "Configuration writed" + +} + +function wifi_connect() { + +echo -e "\n>>> Performing connection ..." +output=$(/usr/sbin/connmanctl connect $service) + +if [[ $output == Connected* ]] +then + echo "...Ok." + echo $output +else + echo "...connection failed !" + echo $output + rm -rf $configpath/$ssid.config + echo "Check your SSID or your passphrase" + exit 1 +fi + +} + +function wifi_disconnect() { + +service=$(/usr/sbin/connmanctl services | cut -c 5- | sed 's/ \+ /:/g' | grep $ssid: | awk -F: '{print $2}') +output=$(/usr/sbin/connmanctl disconnect $service) + +if [[ $output == Disconnected* ]] +then + echo "...Ok." + echo $output + rm -rf /var/lib/connman/$ssid.config + +else + echo "...disconnection failed !" + echo $output + exit 1 +fi +} + +case $1 in + connect) + ssid=$2 + passphrase=$3 + [ -z "$ssid" ] && error "No ssid defined !" + [ -z "$passphrase" ] && error "No passphrase definedi !" + wifi_enable + wifi_scan + wifi_status + wifi_config + wifi_connect + ;; + disconnect) + ssid=$2 + [ -z "$ssid" ] && error "No ssid defined !" + wifi_disconnect + ;; + *) + error "Command line doesn't have any option !" +esac diff --git a/packaging/desktop-skin.spec b/packaging/desktop-skin.spec index 39fb2bf..34377e4 100644 --- a/packaging/desktop-skin.spec +++ b/packaging/desktop-skin.spec @@ -22,6 +22,7 @@ Provides desktop visuals and test programs mkdir -p %{buildroot}%{_bindir} install -m 755 Script/launch_cam.sh %{buildroot}%{_bindir} install -m 755 Script/launch_video.sh %{buildroot}%{_bindir} +install -m 755 Script/wifi %{buildroot}%{_bindir} mkdir -p %{buildroot}%{_datadir}/media/videos install -m 644 Video/AmazingNature_480p.mp4 %{buildroot}%{_datadir}/media/videos @@ -39,8 +40,7 @@ mkdir -p %{buildroot}%{_datadir}/backgrounds/tizen install -m 644 backgrounds/tizen/golfe-morbihan.jpg %{buildroot}%{_datadir}/backgrounds/tizen/golfe-morbihan.jpg %files -%{_bindir}/launch_cam.sh -%{_bindir}/launch_video.sh +%{_bindir}/* %{_datadir}/media/videos/AmazingNature_480p.mp4 %{_datadir}/media/photos/* |