1
1
Fork 0

added wireguard-peers.sh

This commit is contained in:
david 2024-04-06 22:10:16 +02:00
parent 1eaf3ad2ba
commit 476269b769
1 changed files with 138 additions and 0 deletions

138
wireguard-peers.sh Executable file
View File

@ -0,0 +1,138 @@
#!/usr/bin/env bash
## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ##
## wireguard-peers.sh ##
## ##
## Simplify your Wireguard peer management ##
## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ##
##
## Information
## (don't touch unless you are me)
##
NAME="wireguard-peers.sh"
DESCRIPTION="Simplify your Wireguard peer management"
VERSION="0.1.0"
AUTHOR="david@socialnerds.org"
LICENSE="MIT"
WEBSITE="https://git.socialnerds.org/david/scripts"
CHANGELOG=("[2024-04-06][v0.1.0] Initial version")
##
## Configuration
##
EXECUTABLE="$(basename $0)"
LIBRARIES="lib.sh"
DEPENDENCIES=""
REQUIRE_ROOT=0
##
## Functions
##
# Print help information
function print_help() {
printf "%s\n\n%s\n%b\n\n%s\n %-15s %s\n %-15s %s\n %-15s %s\n %-15s %s\n" \
"$DESCRIPTION" "Usage:" "$LIB_BOLD$EXECUTABLE <options>$LIB_CLEAR" "Options:" \
"-h, --help" "Print help screen and exit" \
"-i, --info" "Print script information and exit" \
"-v, --verbose" "More verbose output" \
"-q, --quiet" "No output except errors (overrides -v)"
}
##
## Preflight
##
# Load BASH libraries
SCRIPT_PATH=$(readlink -f "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
for LIBRARY in $LIBRARIES; do
if [[ -r "$SCRIPT_DIR/$LIBRARY" ]]; then
#echo "Loading library file [$SCRIPT_DIR/$LIBRARY]"
source "$SCRIPT_DIR/$LIBRARY"
else
echo "Error: Cannot load library file [$SCRIPT_DIR/$LIBRARY]"
exit 1
fi
done
# Check for root privileges
if ! lib_amiroot && [[ $REQUIRE_ROOT -eq 1 ]]; then
lib_print "!You need to have root privileges"
exit 1
fi
# Check for dependencies
MISSING_COMMANDS=$(lib_missing_commands $DEPENDENCIES)
if [[ -n "$MISSING_COMMANDS" ]]; then
lib_print "!One or more commands missing [$MISSING_COMMANDS]"
lib_print "Try installing them with your package manager"
exit 1
fi
##
## Liftoff
##
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
case $1 in
-h|--help)
H=1
;;
-i|--info)
I=1
;;
-v|--verbose)
V=1
;;
-q|--quiet)
Q=1
;;
*)
lib_print "!Unknown option [$1]"
lib_print "Try --help or -h for available options"
exit 1
;;
esac
shift
done
if [[ "$1" == '--' ]]; then
shift
fi
if [[ $I -eq 1 ]]; then
lib_print_info
exit 0
elif [[ $H -eq 1 ]]; then
print_help
exit 0
fi
if [[ -z "$1" ]]; then
print_help
exit 0
else
lib_print "Supplied option: $1"
lib_print "!super error"
lib_print "?super test"
lib_print "$(lib_gen_string 64)"
fi
##
## Here be dragons
##
exit 0