diff --git a/argparse.sh b/argparse.sh index 15c57f5..2a36c1b 100644 --- a/argparse.sh +++ b/argparse.sh @@ -6,7 +6,11 @@ num_args=$# date=$(date) year="${date:24:29}" -# Load bash classes +# ~~~~~~~~~~~~~~~~ Load classes ~~~~~~~~~~~~~~~~~~~~~~~~ +# Load all the bash OOP-style classes to be inherited +# by downstream scripts +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + source $WYX_DIR/src/classes/sys/sys.h sys sys source $WYX_DIR/src/classes/wgit/wgit.h @@ -16,15 +20,19 @@ wyxd wyxd source $WYX_DIR/src/classes/lib/lib.h lib lib -# Load source git data +# ~~~~~~~~~~~~~ Load source git data ~~~~~~~~~~~~~~~~~~~~ +# Check if the current directory is a git repository, +# and if so, get the branch and remote URLs across the +# different git hosting services. +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ branch="" if git rev-parse --git-dir > /dev/null 2>&1; then branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') fi remote=$(git config --get remote.origin.url) -repo_url=$(echo "$remote" | sed 's/[^ \/]*\/\([^ ]*\/[^.]*\).*/\1/') -repo_url=${repo_url%".git"} +repo_url=$(echo "$remote" | sed 's/[^ \/]*\/\([^ ]*\/[^.]*\).*/\1/' | sed 's/\.git//') git_host="" +# if [[ $remote == *"github.com"* ]]; then git_host="github" repo_url=${repo_url#"git@github.com:"} @@ -43,7 +51,11 @@ elif [[ $remote == *"azure.com"* ]]; then fi - +# ~~~~~~~~~~~~~~~~ Parse input ~~~~~~~~~~~~~~~~~~~~~~~~~ +# Parse the input into a command object and run it if +# it is valid. If the command is invalid, show an error +# message. +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if [ $num_args -eq 0 ]; then # No input - show command info wyxd.command_info @@ -57,6 +69,8 @@ else inputCommand_path="${WYX_DIR}/src/commands/$(inputCommand.path).sh" if [ -f "${inputCommand_path}" ]; then + # set trap + trap 'inputCommand.unset && echo "trap happening"' EXIT # Valid command found - run it source "${inputCommand_path}" "${@:2}" inputCommand.unset diff --git a/src/commands/port-scan.sh b/src/commands/port-scan.sh new file mode 100644 index 0000000..3e346f8 --- /dev/null +++ b/src/commands/port-scan.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +host="$1" +port_range="$2" + +sys.log.h1 "Port Scanner" +sys.log.hr +sys.log.h2 "This script scans all the open ports on a given host." +sys.log.h2 "Usage: ./port-scan.sh " +sys.log.hr +echo "" +if ! wyxd.arggt "1"; then + sys.util.inlineread "Enter the host to scan (defaults to 'localhost'): " host +fi +if ! wyxd.arggt "2"; then + sys.util.inlineread "Enter the port range to scan (defaults to 1-10000): " port_range +fi +host=$(echo "$host" | sed 's/https\?:\/\///') +host=${host:-"localhost"} +port_range=${port_range:-"1-10000"} + +sys.log.info "Scanning $host for open ports in the range $port_range with nmap..." +nmap -p "$port_range" "$host" \ No newline at end of file diff --git a/src/data/arg_scripts.csv b/src/data/arg_scripts.csv index 24fcd92..7daa372 100644 --- a/src/data/arg_scripts.csv +++ b/src/data/arg_scripts.csv @@ -64,4 +64,5 @@ update-deps,update-deps,"Update the project dependencies",true,,deps list-deps,list-deps,"List the project dependencies",true,,deps update-readme,update_readme,"Auto-update the project's readme with the available commands",false,, update-cache,update_cache,"Auto-update the project's cache with the available commands",false,, -pp,pp,"Pull-Push Git Changes to Current Branch",true,,git \ No newline at end of file +pp,pp,"Pull-Push Git Changes to Current Branch",true,,git +port-scan,port-scan,"Scan for open ports on a host",true, ,nutil \ No newline at end of file