aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-06-20 18:15:43 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-06-20 18:15:43 +0200
commitda903712955fb0d2a5e6b64a704910cd9fafb777 (patch)
tree9f555fc983c3ef3b4e98cddf2d14b0229884b582
parentupdate README (diff)
downloadlaurent-tools-da903712955fb0d2a5e6b64a704910cd9fafb777.tar.xz
laurent-tools-da903712955fb0d2a5e6b64a704910cd9fafb777.zip
tools: add nmcli-manage.sh - Set an interface as managed / unmanaged by Network Manager
-rwxr-xr-xtools/nmcli-manage.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/nmcli-manage.sh b/tools/nmcli-manage.sh
new file mode 100755
index 0000000..3d94e6e
--- /dev/null
+++ b/tools/nmcli-manage.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# Set an interface as managed / unmanaged by Network Manager
+# 2013 Laurent Ghigonis <laurent@gouloum.fr>
+
+# /etc/NetworkManager/NetworkManager.conf
+# [keyfile]
+# unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4
+
+NMCONF=/etc/NetworkManager/NetworkManager.conf
+progname=`basename $0`
+
+usage() {
+ echo "usage: $progname set|unset|restart <interface>"
+ exit 1
+}
+
+if [ $# -eq 2 ]; then
+ action=$1
+ iface=$2
+ mac=`ifconfig -a |grep -A5 $iface |grep ether |head -n1 |awk '{print $2}'`
+ echo "Corresponding MAC : $mac"
+ [[ $mac = "" ]] && echo "empty MAC !" && exit 1
+ grep "mac:$mac" $NMCONF >/dev/null
+ unmanaged=$?
+fi
+
+case $action in
+s|m|manage|set)
+ [[ $unmanaged -ne 0 ]] && echo "Already managed" && exit 1
+ sudo sed -i s/"mac:fe:ff:ff:ff:ff:ff"// $NMCONF
+ ;;
+u|unmanage|unset)
+ [[ $unmanaged -eq 0 ]] && echo "Already unmanaged" && exit 1
+ sudo sed -i s/"\(unmanaged-devices=\)"/"\1mac:$mac;"/ $NMCONF
+ ;;
+r|restart)
+ # done below
+ ;;
+*)
+ echo $NMCONF
+ cat $NMCONF
+ exit 1
+esac
+
+sudo systemctl restart NetworkManager.service