From af02d7ece0dfd921d982babbc46efd014382f5af Mon Sep 17 00:00:00 2001 From: Septs Date: Tue, 21 Jul 2020 02:06:15 +0800 Subject: [PATCH] Regular update: 2020-07-20T18:06:15Z --- .scripts/generate-roa.sh | 3 +- .scripts/homepage-update.sh | 4 +- .scripts/makegraph.sh | 2 +- .scripts/pretty-output.sh | 104 +++++++++++++++++------------------- .scripts/push-to-roa.sh | 4 +- 5 files changed, 55 insertions(+), 62 deletions(-) diff --git a/.scripts/generate-roa.sh b/.scripts/generate-roa.sh index 33bee96..ab4eb6e 100755 --- a/.scripts/generate-roa.sh +++ b/.scripts/generate-roa.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# shellcheck disable=SC1091 set -euo pipefail IFS=$'\n\t' @@ -6,7 +7,7 @@ export MAX_LEN_4=29 export MAX_LEN_6=64 if [ ! -d .venv ]; then - python3 -m venv .venv + python3 -m venv .venv fi source .venv/bin/activate diff --git a/.scripts/homepage-update.sh b/.scripts/homepage-update.sh index 6ad2b99..3451257 100755 --- a/.scripts/homepage-update.sh +++ b/.scripts/homepage-update.sh @@ -1,7 +1,7 @@ #!/bin/sh set -xeu -if ! which markdown 2>&1 > /dev/null; then +if ! which markdown 2>&1 >/dev/null; then echo "need markdown" exit fi @@ -10,4 +10,4 @@ fi cat docs/header.html markdown README.md cat docs/footer.html -) > docs/index.html +) >docs/index.html diff --git a/.scripts/makegraph.sh b/.scripts/makegraph.sh index 68ca5fd..8278c3a 100755 --- a/.scripts/makegraph.sh +++ b/.scripts/makegraph.sh @@ -1,7 +1,7 @@ #!/bin/sh set -xe -if which dot 2>&1 > /dev/null ; then +if which dot 2>&1 >/dev/null; then dot -T svg nodes.dot -o nodes.svg else echo 'You need to install graphviz first' diff --git a/.scripts/pretty-output.sh b/.scripts/pretty-output.sh index 20d0ae6..06bd0f0 100755 --- a/.scripts/pretty-output.sh +++ b/.scripts/pretty-output.sh @@ -1,80 +1,73 @@ #!/usr/bin/env bash set -e - ########################################## - # =============== Colors =============== # - ########################################## +########################################## +# =============== Colors =============== # +########################################## ESC='\033' -RESET="${ESC}[0m" #Reset all attributes -BRIGHT="${ESC}[1m" #Bright -DIM="${ESC}[2m" #Dim -BLINK="${ESC}[5m" #Blink +RESET="${ESC}[0m" #Reset all attributes +BRIGHT="${ESC}[1m" #Bright +DIM="${ESC}[2m" #Dim +BLINK="${ESC}[5m" #Blink # Foreground Colours # -FBLACK="${ESC}[30m" #Black -FRED="${ESC}[31m" #Red -FGREEN="${ESC}[32m" #Green -FYELLOW="${ESC}[33m" #Yellow -FBLUE="${ESC}[34m" #Blue -FMAGENTA="${ESC}[35m" #Magenta -FCYAN="${ESC}[36m" #Cyan -FWHITE="${ESC}[37m" #White +FBLACK="${ESC}[30m" #Black +FRED="${ESC}[31m" #Red +FGREEN="${ESC}[32m" #Green +FYELLOW="${ESC}[33m" #Yellow +FBLUE="${ESC}[34m" #Blue +FMAGENTA="${ESC}[35m" #Magenta +FCYAN="${ESC}[36m" #Cyan +FWHITE="${ESC}[37m" #White # Background Colours # -BBLACK="${ESC}[40m" #Black -BRED="${ESC}[41m" #Red -BGREEN="${ESC}[42m" #Green -BYELLOW="${ESC}[43m" #Yellow -BBLUE="${ESC}[44m" #Blue -BMAGENTA="${ESC}[45m" #Magenta -BCYAN="${ESC}[46m" #Cyan -BWHITE="${ESC}[47m" #White +BBLACK="${ESC}[40m" #Black +BRED="${ESC}[41m" #Red +BGREEN="${ESC}[42m" #Green +BYELLOW="${ESC}[43m" #Yellow +BBLUE="${ESC}[44m" #Blue +BMAGENTA="${ESC}[45m" #Magenta +BCYAN="${ESC}[46m" #Cyan +BWHITE="${ESC}[47m" #White - ######################### - # Functions: # - # Make your life easier # - ######################### +######################### +# Functions: # +# Make your life easier # +######################### # Error Message that stops the script -errmsg() -{ +errmsg() { echo -en "${BRED}>>${RESET} ${FMAGENTA}${*}${RESET}" return 1 } # Normal Message -msg() -{ +msg() { echo -en "${BBLUE}>>${RESET} ${BRIGHT}${FGREEN}${*}${RESET}" } # Debug Level Verbose -dbgmsg() -{ +dbgmsg() { echo -en "${BRIGHT}${BBLUE}>>${RESET} ${BRIGHT}${FGREEN}${*}${RESET}" } # Verbose Message -vmsg() -{ +vmsg() { echo -en "${BRIGHT}${BBLUE}>>${RESET} ${BRIGHT}${FCYAN}${*}${RESET}" } # Formatted Output # for TUN30 -print_tun30() -{ +print_tun30() { printf "${FGREEN}%-20s${RESET}|${FYELLOW}%10s${RESET}| ${FCYAN}%20s ${BRIGHT}${FBLUE}<--> ${FMAGENTA}%s${RESET}\n" \ "$1" "$2" "$3" "$4" } -print_subnet() -{ +print_subnet() { printf "${FGREEN}%-20s${RESET}${BRIGHT}${FBLUE}|| ${FMAGENTA}%s${RESET}\n\t>> %s\n" \ "$1" "$2" "$3" } -print_ptp() -{ +print_ptp() { upstream_ip="${1%~*}" downstream_ip="${1#$upstream_ip}" downstream_ip="${downstream_ip#*~}" @@ -83,8 +76,7 @@ print_ptp() "$2" "$upstream_ip" "$downstream_ip" "$3" "$4" } -print_lo() -{ +print_lo() { printf "${FGREEN}%-20s${RESET}${BRIGHT}${FBLUE}||${FMAGENTA}%24s${RESET} ${BRIGHT}${FBLUE}|| ${RESET}%s\n" \ "$1" "$2" "$3" } @@ -102,19 +94,19 @@ if [ $# -lt 1 ]; then " asn, route, entity, node\n" fi -arg="$2" # Optional argument +arg="$2" # Optional argument case "$1" in asn) ( - cd asn - for i in *; do - msg "${i#asn/}\n" - source "$i" + cd asn + for i in *; do + msg "${i#asn/}\n" + source "$i" - printf "${BRIGHT}${FMAGENTA}%-16s${RESET}| ${BRIGHT}${FYELLOW}%s\n\t>> %s\n" \ - "$OWNER" "$NAME" "$DESC" - done + printf "${BRIGHT}${FMAGENTA}%-16s${RESET}| ${BRIGHT}${FYELLOW}%s\n\t>> %s\n" \ + "$OWNER" "$NAME" "$DESC" + done ) ;; route) @@ -123,13 +115,13 @@ route) subnet="${subnet/,/\/}" source "$i" case "$TYPE" in - SUBNET) print_subnet "$subnet" "$NAME" "$DESC";; - LO) print_lo "$subnet" "$NAME" "$DESC";; - *) errmsg "Invalid \$TYPE in $i\n";; + SUBNET) print_subnet "$subnet" "$NAME" "$DESC" ;; + LO) print_lo "$subnet" "$NAME" "$DESC" ;; + *) errmsg "Invalid \$TYPE in $i\n" ;; esac done ;; -entity);; +entity) ;; node) for i in node/*; do node="${i#node/}" @@ -145,7 +137,7 @@ node) done done ;; -*) errmsg "Invalid type\n";; +*) errmsg "Invalid type\n" ;; esac # vim: set tabstop=8:softtabstop=8:shiftwidth=8 diff --git a/.scripts/push-to-roa.sh b/.scripts/push-to-roa.sh index 9d7581d..06f000b 100755 --- a/.scripts/push-to-roa.sh +++ b/.scripts/push-to-roa.sh @@ -2,7 +2,7 @@ set -euo pipefail IFS=$'\n\t' -if [ ! -n "$SSHPRIVKEY" ]; then +if [ -z "$SSHPRIVKEY" ]; then echo SSHPRIVKEY is not set exit 1 fi @@ -13,7 +13,7 @@ chmod 0600 "$HOME/.ssh/id_ed25519" set -x -cd generated || exit -1 +cd generated || exit 1 git remote set-url origin git@github.com:NeoCloud/NeoNetwork-ROA.git git config user.name "NeoCloud ROA bot"