commit a9e8b54c13f7c56fcaf15e4d18aa3ae630b63aba
Author: ssnf <ssnf@ssnf.xyz>
Date: Fri, 2 Jul 2021 01:16:51 +0000
initial commmit
Diffstat:
A | net | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
A | net.1 | | | 17 | +++++++++++++++++ |
2 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/net b/net
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+[ $(whoami) != "root" ] && echo "run this shit as root" && exit
+
+dev_scan() {
+ [ -n "$2" ] && cd $1
+ IP=$(cat ip 2>/dev/null)
+ MAC=$(cat mac 2>/dev/null)
+ GW=$(cat gw 2>/dev/null)
+ MASTER=$(cat master 2>/dev/null)
+
+ ip l s $1 up
+ ip a f dev $1
+ [ -n "$MAC" ] && ip l s $1 a $MAC
+ if [ -n "$MASTER" ]
+ then
+ if [ -z "$(ip l show "$MASTER" 2>/dev/null)" ]
+ then
+ ip l a $MASTER type bridge
+ ip l s $MASTER up
+ fi
+ ip l s $1 master $MASTER
+ fi
+ if [ -z "$IP" ]
+ then
+ ! [ -d "$1" ] && dhcpcd -4n $1 && return
+ IP=$(cat "$1"/ip)
+ GW=$(cat "$1"/ip)
+ fi
+ ip a a $IP/24 dev $1 2>/dev/null
+ ip r a default via $GW 2>/dev/null
+}
+
+cd /etc/net
+
+if [ $# -eq 0 ]
+then
+ dev_scan $(ip -o l|awk '$2~/^[ew][^u]+$/{print $2}'|sed 's/://;q')
+ killall dhcpcd 2>/dev/null
+ for dev in $(ls)
+ do
+ ! [ -d "$dev" ] && continue
+ dev_scan $dev 1 &
+ done
+fi
diff --git a/net.1 b/net.1
@@ -0,0 +1,17 @@
+.TH NET 1 net\-0.1
+.SH DEVICES
+Each device has its own directory under /etc/net.
+
+If the device is defined in /etc/net, but it does not exist, it will be created as a bridge.
+.SH ATTRIBUTES
+Each attribute is a plain text file. Each device has 4 optinonal attributes:
+.B ip, mac, gw, master.
+.SH DEFAULT DEVICE
+The default device has its attributes directly stored in /etc/net.
+
+
+If it has a directory under /etc/net, the attributes will be overwritten.
+
+The default device is the first network device listed on your system, in alphabetical order.
+
+For better end-user experience, the device must start with an 'e' or 'w', and must not have a 'u' in its name.