From 3fb07c0c2d43d939800ed8afd1005814222c3ca6 Mon Sep 17 00:00:00 2001 From: KAAAsS Date: Thu, 15 Apr 2021 21:46:05 +0800 Subject: [PATCH] Add management scripts --- script/create.sh | 26 ++++++++++++++++++++++++++ script/delete.sh | 30 ++++++++++++++++++++++++++++++ script/enable.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100755 script/create.sh create mode 100755 script/delete.sh create mode 100755 script/enable.sh diff --git a/script/create.sh b/script/create.sh new file mode 100755 index 0000000..6d9abce --- /dev/null +++ b/script/create.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e + +BIRD_CONF_DIR=$(dirname "$0")/../ + +# Root check +if [[ $(id -u) -ne 0 ]]; then + echo "Run this script with root!" >&2 + exit 1 +fi + +# Check param +if [[ $# -ne 1 ]]; then + echo "Usage: $0 [config name]" >&2 + echo "Create config from example" >&2 + exit 1 +fi +CONF_NAME=$1 + +# Create conf folder +mkdir -p $BIRD_CONF_DIR/concrete + +# Copy example config +cp -r $BIRD_CONF_DIR/example $BIRD_CONF_DIR/concrete/$CONF_NAME + +echo "Config $CONF_NAME created" diff --git a/script/delete.sh b/script/delete.sh new file mode 100755 index 0000000..10927e8 --- /dev/null +++ b/script/delete.sh @@ -0,0 +1,30 @@ +#!/bin/bash +set -e + +BIRD_CONF_DIR=$(dirname "$0")/../ + +# Root check +if [[ $(id -u) -ne 0 ]]; then + echo "Run this script with root!" >&2 + exit 1 +fi + +# Check param +if [[ $# -ne 1 ]]; then + echo "Usage: $0 [config name]" >&2 + echo "Delete existing config" + exit 1 +fi +CONF_NAME=$1 + +# Create conf folder +mkdir -p $BIRD_CONF_DIR/concrete + +# Delete config +if [[ -d $BIRD_CONF_DIR/concrete/$CONF_NAME ]]; then + rm -rf $BIRD_CONF_DIR/concrete/$CONF_NAME + echo "Config $CONF_NAME deleted" +else + echo "Config $CONF_NAME not existed" >&2 + exit 2 +fi diff --git a/script/enable.sh b/script/enable.sh new file mode 100755 index 0000000..c5302db --- /dev/null +++ b/script/enable.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +BIRD_CONF_DIR=$(dirname "$0")/../ + +# Root check +if [[ $(id -u) -ne 0 ]]; then + echo "Run this script with root!" >&2 + exit 1 +fi + +# Check param +if [[ $# -ne 1 ]]; then + echo "Usage: $0 [config name]" >&2 + echo "Enable existing config" + exit 1 +fi +CONF_NAME=$1 + +# Create conf folder +mkdir -p $BIRD_CONF_DIR/concrete + +# Enable config +if [[ -d $BIRD_CONF_DIR/concrete/$CONF_NAME ]]; then + rm -f $BIRD_CONF_DIR/conf + ln -s $BIRD_CONF_DIR/concrete/$CONF_NAME $BIRD_CONF_DIR/conf + echo "Config $CONF_NAME enabled" + /usr/bin/birdc configure + echo "Config $CONF_NAME configured" +else + echo "Config $CONF_NAME not existed" >&2 + exit 2 +fi