home · contact · privacy
Add wicd-cli wrapper to simplify wifi operations.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 15 Apr 2017 19:49:16 +0000 (21:49 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 15 Apr 2017 19:49:16 +0000 (21:49 +0200)
bin/wicd-wrapper.sh [new file with mode: 0755]

diff --git a/bin/wicd-wrapper.sh b/bin/wicd-wrapper.sh
new file mode 100755 (executable)
index 0000000..986343a
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+check_wifi_id_set() {
+  if ! echo "${1}" | egrep -q '^[0-9]+$'; then
+    echo 'Wifi identifier must be integer.'
+    exit 1
+  fi
+}
+
+print_usage() {
+  echo 'Available commands:'
+  echo '  eth_connect'
+  echo '  eth_disconnect'
+  echo '  wifi_scan'
+  echo '  wifi_info WIFI_ID'
+  echo '  wifi_set_wpa WIFI_ID KEY'
+  echo '  wifi_connect WIFI_ID'
+  echo '  wifi_disconnect'
+}
+
+if ! echo "${1}"; then
+  echo 'No command given.'
+  print_usage
+  exit 1
+elif [ "${1}" = 'eth_connect' ]; then
+  wicd-cli --wired --connect
+
+elif [ "${1}" = 'eth_disconnect' ]; then
+  wicd-cli --wired --disconnect
+
+elif [ "${1}" = 'wifi_scan' ]; then
+  wicd-cli --wireless --scan
+  wicd-cli --wireless --list-networks
+
+elif [ "${1}" = 'wifi_info' ]; then
+  check_wifi_id_set "${2}"
+  wicd-cli --wireless --network="${2}" --network-details
+
+elif [ "${1}" = 'wifi_set_wpa' ]; then
+  check_wifi_id_set "${2}"
+  if ! echo "${3}" ; then
+    echo 'No key set.'
+    exit 1
+  fi
+  wicd-cli --wireless --network="${2}" --network-property=enctype --set-to=wpa
+  wicd-cli --wireless --network="${2}" --network-property=key --set-to="${3}"
+
+elif [ "${1}" = 'wifi_connect' ]; then
+  check_wifi_id_set "${2}"
+  wicd-cli --wireless --network="${2}" --connect
+
+elif [ "${1}" = 'wifi_disconnect' ]; then
+  wicd-cli --wireless --disconnect
+
+else
+  echo 'Unknown command.'
+  print_usage
+  exit 1
+fi