From 9e66ed673ff5afcfd1cf109618c58dca4dfc298e Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Tue, 28 Oct 2025 10:53:15 +0800 Subject: [PATCH] dist: cleanup scripts. --- dist/rootfs/var/openlan/openvpn/openvpn.md | 43 ++++++------ dist/rootfs/var/openlan/script/bridge | 67 ------------------- dist/rootfs/var/openlan/script/eth0.cfg | 5 -- dist/rootfs/var/openlan/script/ifcfg-veth0 | 9 --- dist/rootfs/var/openlan/script/ifdown-veth | 60 ----------------- dist/rootfs/var/openlan/script/ifup-veth | 78 ---------------------- 6 files changed, 21 insertions(+), 241 deletions(-) delete mode 100755 dist/rootfs/var/openlan/script/bridge delete mode 100755 dist/rootfs/var/openlan/script/eth0.cfg delete mode 100644 dist/rootfs/var/openlan/script/ifcfg-veth0 delete mode 100755 dist/rootfs/var/openlan/script/ifdown-veth delete mode 100755 dist/rootfs/var/openlan/script/ifup-veth diff --git a/dist/rootfs/var/openlan/openvpn/openvpn.md b/dist/rootfs/var/openlan/openvpn/openvpn.md index d50fcce..7c188d2 100755 --- a/dist/rootfs/var/openlan/openvpn/openvpn.md +++ b/dist/rootfs/var/openlan/openvpn/openvpn.md @@ -1,30 +1,29 @@ # OpenVPN - - yum install -y epel-release - - yum install -y openvpn - +``` +yum install -y epel-release +yum install -y openvpn +``` ## Generate Diffie-Hellman - - openssl dhparam -out /var/openlan/openvpn/dh.pem 1024 - +``` +openssl dhparam -out /var/openlan/openvpn/dh.pem 1024 +``` ## Generate TLS Auth Key - - openvpn --genkey --secret /var/openlan/openvpn/ta.key - +``` +openvpn --genkey --secret /var/openlan/openvpn/ta.key +``` # Configure OpenVPN in Network - - { - "name": "example", - "openvpn": { - "listen": "0.0.0.0:1194", - "subnet": "10.9.9.0/24" - } +``` +{ + "name": "example", + "openvpn": { + "listen": "0.0.0.0:1194", + "subnet": "10.9.9.0/24" } - +} +``` ## Restart OpenLAN Switch Service - - systemctl reload openlan-switch - +``` +systemctl reload openlan-switch +``` diff --git a/dist/rootfs/var/openlan/script/bridge b/dist/rootfs/var/openlan/script/bridge deleted file mode 100755 index 02ce54c..0000000 --- a/dist/rootfs/var/openlan/script/bridge +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -## Load configuration. -cfg="eth0.cfg" -if [ $# -ge 1 ]; then - cfg="$1" - shift -fi -if [ -e "$cfg" ]; then - . $cfg -fi - -## Check enviroment. -if [ -z "$PHY" ] || [ -z "$ADDR" ] || [ -z "$PREFIX" ]; then - echo "Variable(PHY|ADDR|PREFIX) is NULL" - exit -fi - -yum install bridge-utils -y - -## Set variable -phy="$PHY" -addr="$ADDR" -prefix="$PREFIX" -br=br-"$PHY" -gw="$GATEWAY" -dns1="$DNS1" - -## Configure script -brCfg=/etc/sysconfig/network-scripts/ifcfg-"$br" -phyCfg=/etc/sysconfig/network-scripts/ifcfg-"$phy" - -## Generate bridge configure -echo "## Generate by OpenLAN project" > $brCfg -echo "STP=\"yes\"" >> $brCfg -echo "DELAY=\"2\"" >> $brCfg -echo "TYPE=\"Bridge\"" >> $brCfg -echo "NAME=\"$br\"" >> $brCfg -echo "DEVICE=\"$br\"" >> $brCfg -echo "BOOTPROTO=\"none\"" >> $brCfg -if [ -n "$addr" ]; then - echo "IPADDR=\"$addr\"" >> $brCfg -fi -if [ -n "$prefix" ]; then - echo "PREFIX=\"$prefix\"" >> $brCfg -fi -if [ -n "$gw" ]; then - echo "GATEWAY=\"$gw\"" >> $brCfg -fi -if [ -n "$dns1" ]; then - echo "DNS1=\"$dns1\"" >> $brCfg -fi -echo "ONBOOT=\"yes\"" >> $brCfg -echo "NM_CONTROLLED=\"no\"" >> $brCfg - -## Generate physical configure -echo "## Generate by OpenLAN project" > $phyCfg -echo "TYPE=\"Ethernet\"" >> $phyCfg -echo "NAME=\"$phy\"" >> $phyCfg -echo "DEVICE=\"$phy\"" >> $phyCfg -echo "BOOTPROTO=\"none\"" >> $phyCfg -echo "ONBOOT=\"yes\"" >> $phyCfg -echo "NM_CONTROLLED=\"no\"" >> $phyCfg -echo "BRIDGE=\"$br\"" >> $phyCfg -echo "BRIDGING_OPTS=\"path_cost=4\"" >> $phyCfg # 4: 1G, 2: 10G, 19: 100Mb and 100: 1Mb. - -ifdown "$br"; ifdown "$phy"; ifup "$br"; ifup "$phy"; diff --git a/dist/rootfs/var/openlan/script/eth0.cfg b/dist/rootfs/var/openlan/script/eth0.cfg deleted file mode 100755 index 2785570..0000000 --- a/dist/rootfs/var/openlan/script/eth0.cfg +++ /dev/null @@ -1,5 +0,0 @@ -PHY="eth0" -ADDR="192.168.2.2" -PREFIX="24" -GATEWAY="" -DNS1="" diff --git a/dist/rootfs/var/openlan/script/ifcfg-veth0 b/dist/rootfs/var/openlan/script/ifcfg-veth0 deleted file mode 100644 index c79961c..0000000 --- a/dist/rootfs/var/openlan/script/ifcfg-veth0 +++ /dev/null @@ -1,9 +0,0 @@ -DEVICE="veth0" -TYPE="veth" -DEVICETYPE="Ethernet" -BOOTPROTO="static" -IPADDR="192.168.3.4" -NETMASK="255.255.255.0" -ONBOOT="no" -NM_CONTROLLED="no" -VETH_PARENT="br0" diff --git a/dist/rootfs/var/openlan/script/ifdown-veth b/dist/rootfs/var/openlan/script/ifdown-veth deleted file mode 100755 index a54d351..0000000 --- a/dist/rootfs/var/openlan/script/ifdown-veth +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -# -# Derived from initscripts-macvlan -# Copyright (C) 2014 Lars Kellogg-Stedman -# -# Adopted for veth by Oleksandr Natalenko -# Copyright (C) 2015 Lanet Network -# -# Based on Network Interface Configuration System -# Copyright (c) 1996-2009 Red Hat, Inc. all rights reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. /etc/init.d/functions - -cd /etc/sysconfig/network-scripts -. ./network-functions - -[ -f ../network ] && . ../network - -CONFIG=${1} - -need_config ${CONFIG} - -source_config - -OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-${REAL_DEVICETYPE}" - -if [ ! -x ${OTHERSCRIPT} ]; then - OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-eth" -fi - -${OTHERSCRIPT} ${CONFIG} - -if [ -n "${VETH_PARENT}" ] && [ -x /usr/sbin/brctl ]; then - ip link set \ - dev ${DEVICE}-bp down - brctl delif -- \ - ${VETH_PARENT} ${DEVICE}-bp - [ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid) - if [ -d /sys/class/net/${VETH_PARENT}/brif ] && [ $(ls -1 /sys/class/net/${VETH_PARENT}/brif | wc -l) -eq 0 ]; then - ip link set \ - dev ${VETH_PARENT} down - brctl delbr -- ${VETH_PARENT} - fi -fi - -ip link del ${DEVICE} - diff --git a/dist/rootfs/var/openlan/script/ifup-veth b/dist/rootfs/var/openlan/script/ifup-veth deleted file mode 100755 index 7cf6e98..0000000 --- a/dist/rootfs/var/openlan/script/ifup-veth +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash -# -# Derived from initscripts-macvlan -# Copyright (C) 2014 Lars Kellogg-Stedman -# -# Adopted for veth by Oleksandr Natalenko -# Copyright (C) 2015 Lanet Network -# -# Based on Network Interface Configuration System -# Copyright (c) 1996-2009 Red Hat, Inc. all rights reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. /etc/init.d/functions - -cd /etc/sysconfig/network-scripts -. ./network-functions - -[ -f ../network ] && . ../network - -CONFIG=${1} - -need_config ${CONFIG} - -source_config - -OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${REAL_DEVICETYPE}" - -if [ ! -x ${OTHERSCRIPT} ]; then - OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth" -fi - -ip link add \ - name ${DEVICE} \ - type veth \ - peer name ${DEVICE}-bp - -if [ -n "${VETH_MAC}" ]; then - ip link set \ - dev ${DEVICE} \ - address ${VETH_MAC} -fi - -if [ -n "${VETH_PARENT}" ] && [ -x /usr/sbin/brctl ]; then - if [ ! -d /sys/class/net/${VETH_PARENT}/bridge ]; then - brctl addbr -- \ - ${VETH_PARENT} 2>/dev/null - ip link set \ - dev ${VETH_PARENT} up - fi - ip addr flush dev ${DEVICE}-bp 2>/dev/null - ip link set \ - dev ${DEVICE}-bp up - ethtool_set - [ -n "${LINKDELAY}" ] && /bin/sleep ${LINKDELAY} - brctl addif -- \ - ${VETH_PARENT} ${DEVICE}-bp - for arg in $BRIDGING_OPTS ; do - key=${arg%%=*}; - value=${arg##*=}; - echo $value > /sys/class/net/${DEVICE}-bp/brport/$key - done - [ -r /var/run/radvd/radvd.pid ] && kill -HUP $(cat /var/run/radvd/radvd.pid) -fi - -${OTHERSCRIPT} ${CONFIG} -