summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-08-05 05:36:43 +0200
committerSuren A. Chilingaryan <csa@suren.me>2018-08-05 05:36:43 +0200
commit05fb73ec16329981d5b3170e23fcbefaa89b71b6 (patch)
tree9f2d5c6dfcd4dc6f48f8a6f9ccaf5076f5ac58cc
parent75e98276848f84166f3245f9e242f3f259f93081 (diff)
downloadmlx-05fb73ec16329981d5b3170e23fcbefaa89b71b6.tar.gz
mlx-05fb73ec16329981d5b3170e23fcbefaa89b71b6.tar.bz2
mlx-05fb73ec16329981d5b3170e23fcbefaa89b71b6.tar.xz
mlx-05fb73ec16329981d5b3170e23fcbefaa89b71b6.zip
Add helper functions
-rw-r--r--ip/functions.sh29
-rwxr-xr-xip/ipecamera3.sh40
-rwxr-xr-xip/ipecamera4.sh25
3 files changed, 49 insertions, 45 deletions
diff --git a/ip/functions.sh b/ip/functions.sh
new file mode 100644
index 0000000..2941953
--- /dev/null
+++ b/ip/functions.sh
@@ -0,0 +1,29 @@
+function portset {
+ pci=$1
+ mode=$2
+ ./connectx_port_config -d "$pci" -c "$mode,$mode" &> /dev/null
+}
+
+function mlxconf {
+ mode=$1
+
+ pci=$(./connectx_port_config -s | grep PCI | grep -Po "\d{4}:\d{2}:\d{2}\.\d")
+ for dev in $pci; do
+ echo "Configuring: $dev"
+ portset $dev $mode
+ done
+}
+
+function ipset {
+ int="$1"
+ ip="$2"
+
+ if [ -n "$ip" ]; then
+ ip link set "$int" up
+ ip addr flush "$int"
+ ip addr show dev "$int" | grep "$ip" || ip addr add "$ip/24" dev "$int"
+ else
+ ip addr flush "$int"
+ ip link set "$int" down
+ fi
+}
diff --git a/ip/ipecamera3.sh b/ip/ipecamera3.sh
index 65fc84f..ceb78b6 100755
--- a/ip/ipecamera3.sh
+++ b/ip/ipecamera3.sh
@@ -1,28 +1,12 @@
-./connectx_port_config -d 0000:01:00.0 -c eth,eth &> /dev/null
-./connectx_port_config -d 0000:03:00.0 -c eth,eth &> /dev/null
-./connectx_port_config -d 0000:06:00.0 -c eth,eth &> /dev/null
-./connectx_port_config -d 0000:07:00.0 -c eth,eth &> /dev/null
-
-ip link set ens1 up
-ip addr show dev ens1 | grep 192.168.61.83 || ip addr add 192.168.61.83/24 dev ens1
-
-ip link set ens1d1 up
-ip addr show dev ens1d1 | grep 192.168.2.93 || ip addr add 192.168.2.93/24 dev ens1d1
-
-ip link set ens11 up
-ip addr show dev ens11 | grep 192.168.41.83 || ip addr add 192.168.41.83/24 dev ens11
-
-ip link set ens11d1 up
-ip addr show dev ens11d1 | grep 192.168.2.83 || ip addr add 192.168.2.83/24 dev ens11d1
-
-ip link set enp6s0 up
-ip addr show dev enp6s0 | grep 192.168.62.83 || ip addr add 192.168.62.83/24 dev enp6s0
-
-ip link set enp6s0d1 up
-ip addr show dev enp6s0d1 | grep 192.168.2.103 || ip addr add 192.168.2.103/24 dev enp6s0d1
-\
-ip link set enp7s0 up
-ip addr show dev enp7s0 | grep 192.168.42.83 || ip addr add 192.168.42.83/24 dev enp7s0
-
-ip link set enp7s0d1 up
-ip addr show dev enp7s0d1 | grep 192.168.2.113 || ip addr add 192.168.2.113/24 dev enp7s0d1
+. ip/functions.sh
+
+mlxconf eth
+
+ipset ens1 #192.168.61.83
+ipset ens1d1 #192.168.2.93
+ipset ens11 192.168.41.83
+ipset ens11d1 192.168.2.83
+ipset enp6s0 #192.168.62.83
+ipset enp6s0d1 #192.168.2.103
+ipset enp7s0 #192.168.42.83
+ipset enp7s0d1 #192.168.2.113
diff --git a/ip/ipecamera4.sh b/ip/ipecamera4.sh
index cfa4fe6..4f03d96 100755
--- a/ip/ipecamera4.sh
+++ b/ip/ipecamera4.sh
@@ -1,20 +1,11 @@
-./connectx_port_config -d 0000:01:00.0 -c eth,eth &> /dev/null
-./connectx_port_config -d 0000:03:00.0 -c eth,eth &> /dev/null
+. ip/functions.sh
-ip link set ens1 up
-ip addr show dev ens1 | grep 192.168.41.84 || ip addr add 192.168.41.84/24 dev ens1
+mlxconf eth
-ip link set ens1d1 up
-ip addr show dev ens1d1 | grep 192.168.2.84 || ip addr add 192.168.2.84/24 dev ens1d1
+ipset ens1 192.168.41.84
+ipset ens1d1 192.168.2.84
+ipset ens11 192.168.42.84
+ipset ens11d 192.168.46.84
+ipset enp6s0f0 #192.168.2.104
+ipset enp7s0f0 #192.168.2.114
-ip link set ens11 up
-ip addr show dev ens11 | grep 192.168.42.84 || ip addr add 192.168.42.84/24 dev ens11
-
-ip link set ens11d1 up
-ip addr show dev ens11d1 | grep 192.168.46.84 || ip addr add 192.168.46.84/24 dev ens11d1
-
-ip link set enp6s0f0 up
-ip addr show dev enp6s0f0 | grep 192.168.2.104 || ip addr add 192.168.2.104/24 dev enp6s0f0
-
-ip link set enp7s0f0 up
-ip addr show dev enp7s0f0 | grep 192.168.2.114 || ip addr add 192.168.2.114/24 dev enp7s0f0