slitaz-boot-scripts rev 428

network.sh: add Freedesktop notification, change LXPanel Network applet interface
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Apr 21 01:35:44 2016 +0300 (2016-04-21)
parents 6373374e4683
children 90c9aecd15b4
files etc/init.d/network.sh
line diff
     1.1 --- a/etc/init.d/network.sh	Wed Mar 30 09:44:21 2016 +0200
     1.2 +++ b/etc/init.d/network.sh	Thu Apr 21 01:35:44 2016 +0300
     1.3 @@ -4,14 +4,33 @@
     1.4  # /etc/network.conf      : Main SliTaz network configuration file
     1.5  # /etc/wpa/wpa.conf      : Wi-Fi networks configuration file
     1.6  
     1.7 +
     1.8  . /etc/init.d/rc.functions
     1.9  
    1.10  CONF="${2:-/etc/network.conf}"
    1.11  echo "Loading network settings from $CONF"
    1.12  . "$CONF"
    1.13  
    1.14 +
    1.15 +# Change LXPanel Network applet settings
    1.16 +
    1.17 +if [ "$1" == 'netapplet' ]; then
    1.18 +	if [ "$WIFI" == 'yes' ]; then
    1.19 +		interface="$WIFI_INTERFACE"
    1.20 +	else
    1.21 +		interface="$INTERFACE"
    1.22 +	fi
    1.23 +
    1.24 +	for i in $(find ${XDG_CONFIG_HOME:-$HOME/.config}/lxpanel -name panel); do
    1.25 +		fgrep -q netstatus "$i" || continue
    1.26 +		sed -i '/iface/s|=.*$|='$interface'|' "$i"
    1.27 +	done
    1.28 +	exit 0
    1.29 +fi
    1.30 +
    1.31  WPA_CONF='/etc/wpa/wpa.conf'
    1.32 -[ ! -e "$WPA_CONF" ] && cp /etc/wpa/wpa_empty.conf $WPA_CONF 2> /dev/null
    1.33 +[ ! -e "$WPA_CONF" ] && cp /etc/wpa/wpa_empty.conf $WPA_CONF 2>/dev/null
    1.34 +npid='/tmp/notify_pid'
    1.35  
    1.36  # Migrate existing settings to a new format file
    1.37  
    1.38 @@ -36,10 +55,37 @@
    1.39  }
    1.40  
    1.41  
    1.42 +# Freedesktop notification
    1.43 +
    1.44 +notification() {
    1.45 +	# FIXME: this valid only for lxde-session
    1.46 +	local user="$(ps aux | grep [l]xde-session | awk 'END{print $2}')"
    1.47 +	local icon="$1" rpid=''
    1.48 +	[ -s "$npid" ] && rpid="-r $(cat $npid)"
    1.49 +	su -c "notify-send $rpid -p -i $icon 'Network' \"$2\"" - $user > $npid
    1.50 +}
    1.51 +
    1.52 +
    1.53 +# Change LXPanel Network applet interface
    1.54 +
    1.55 +ch_netapplet() {
    1.56 +	for user in $(awk -F: '$6 ~ "/home/" {print $1}' /etc/passwd); do
    1.57 +		# need to be executed as user, due to different XDG variables
    1.58 +		su -l -c "$0 netapplet" - "$user"
    1.59 +	done
    1.60 +	# restart if LXPanel running
    1.61 +	lxpanelctl restart
    1.62 +}
    1.63 +
    1.64 +
    1.65  # Use ethernet
    1.66  
    1.67  eth() {
    1.68 -	[ "$WIFI" != 'yes' ] && ifconfig $INTERFACE up && sleep 5
    1.69 +	if [ "$WIFI" != 'yes' ]; then
    1.70 +		notification network-wired "$(_ 'Starting Ethernet interface %s...' "$INTERFACE")"
    1.71 +		ifconfig $INTERFACE up
    1.72 +		sleep 5
    1.73 +	fi
    1.74  }
    1.75  
    1.76  
    1.77 @@ -59,6 +105,7 @@
    1.78  		# notwithstanding to priority when scan_ssid=1
    1.79  		current_ssid="$(wpa_cli list_networks 2>/dev/null | fgrep '[CURRENT]' | cut -f2)"
    1.80  		if [ "$current_ssid" != "$WIFI_ESSID" ]; then
    1.81 +			notification network-wireless "$(_ 'Connecting to %s...' "$WIFI_ESSID")"
    1.82  			action 'Connecting to $WIFI_ESSID...'
    1.83  			for i in $(seq 5); do
    1.84  				index=$(wpa_cli list_networks 2>/dev/null | \
    1.85 @@ -96,6 +143,7 @@
    1.86  				/etc/network.conf
    1.87  		fi
    1.88  
    1.89 +		notification network-wireless "$(_ 'Starting Wi-Fi interface %s...' "$WIFI_INTERFACE")"
    1.90  		action 'Configuring Wi-Fi interface $WIFI_INTERFACE...'
    1.91  		ifconfig $WIFI_INTERFACE up 2>/dev/null
    1.92  		if iwconfig $WIFI_INTERFACE | fgrep -q 'Tx-Power'; then
    1.93 @@ -282,6 +330,8 @@
    1.94  # Stopping everything
    1.95  
    1.96  stop() {
    1.97 +	ch_netapplet
    1.98 +	notification network-offline "$(_ 'Stopping all interfaces')"
    1.99  	echo 'Stopping all interfaces'
   1.100  	for iface in $(ifconfig | sed -e '/^[^ ]/!d' -e 's|^\([^ ]*\) .*|\1|' -e '/lo/d'); do
   1.101  		ifconfig $iface down
   1.102 @@ -300,6 +350,7 @@
   1.103  
   1.104  
   1.105  start() {
   1.106 +	ch_netapplet
   1.107  	# stopping only unspecified interfaces
   1.108  	interfaces="$(ifconfig | sed -e '/^[^ ]/!d' -e 's|^\([^ ]*\) .*|\1|' -e '/lo/d')"
   1.109  	case $WIFI in
   1.110 @@ -344,3 +395,5 @@
   1.111  EOT
   1.112  		;;
   1.113  esac
   1.114 +
   1.115 +[ -f "$npid" ] && rm "$npid"