diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6eafba0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config +work-scripts diff --git a/README.md b/README.md index e69de29..f8a44df 100644 --- a/README.md +++ b/README.md @@ -0,0 +1 @@ +Requires *bash* installed, but can run in any shello theoretically diff --git a/asd b/asd new file mode 100755 index 0000000..55da04b --- /dev/null +++ b/asd @@ -0,0 +1,81 @@ +#!/bin/bash + +# Configure the following for your installation directory. +# The rest of the configuration is handled in $INSTALL_DIR/config +# INSTALL_DIR needs to be a full path. Absolute. Not relative. +export INSTALL_DIR=$HOME/Scripts +export CONFIG_FILE=$INSTALL_DIR/config + +# The following function is used to cleanly exit out in a script. +# It's not globally available so just copy/pasta it into your other scripts if +# you want to use it +failout() { + [ -z "$MSG" ] || echo $MSG + cat << EOF +Usage: $(basename $0) command_group command extra_inputs +EOF + exit 11 +} + +export -f failout + +# Start out by sourcing the config directory. Sourcing is MUCH faster and more +# flexible than how the old ASD was handling this. +# The config file should store all of your "default" environment variables. +source $CONFIG_FILE + + +# The following getopts allows some configuration. Namely, it allows you to +# target specific AWS regions and profiles as needed, as well as set debugging. +# Instead of getting fancy, we just override the variables +r=0 # AWS_REGION +p=0 # AWS_PROFILE +d=0 # DEBUG +while getopts ":r:p:d" o; do + case "${o}" in + r) + export AWS_REGION=${OPTARG} + ;; + p) + export AWS_PROFILE=${OPTARG} + ;; + d) + export ASD_DEBUG=1 + ;; + *) + MSG="Invalid option detected" failout + ;; + esac +done +shift $((OPTIND-1)) + +# Some preflight checks to see if the user is running this in a silly way +[ -z "$1" ] && MSG="Please provide something for us to run" failout + +# Now we try to find the script that we want to run. This is somewhat inefficient. +# It would make more sense to REQUIRE a step one, but I wanted to be able to have something +# like `asd somescript.sh` because it's just nicer. +# We used to be able to search a single dir however I have added work scripts +# and general scripts so that I can keep publicly suitable scripts public and use +# at home. While work scripts can stay protected away from a public repo. +# You could totally use submodules in git for this but whatever. +FIRST_STAGE=$(find $INSTALL_DIR/general-scripts $INSTALL_DIR/work-scripts -mindepth 1 -maxdepth 1 -iname "${1}*" | sort | head -n1) +[ -z $FIRST_STAGE ] && MSG="Did not find your scripts directory" failout # Die if we find nothing +[ -f $FIRST_STAGE ] && SS_SKIP=1 || SS_SKIP=0 # Skip second step if we find file + +# Shift out the first stage +shift 1 + +# If the first step doesn't skip the second step +if [ $SS_SKIP == 0 ] ; then + [ -z "$1" ] && MSG="Please provide a subcommand to run" failout + SECOND_STAGE=$(find $FIRST_STAGE -mindepth 1 -maxdepth 1 -iname "${1}*" | sort | head -n1) + [ -z $SECOND_STAGE ] && MSG="Could not find a match for $1" failout # Die if we find nothing + CMD=$SECOND_STAGE + shift 1 +else + CMD=$FIRST_STAGE +fi + +# Finally, we need to execute the script that we have found. +exec $CMD $@ diff --git a/config.sample b/config.sample new file mode 100644 index 0000000..c10ce79 --- /dev/null +++ b/config.sample @@ -0,0 +1,5 @@ +export PROJECTS_DIR="${HOME}/Projects" + +# The following are to configure devenv +export DEVENV_DIR=$PROJECTS_DIR/devenv +export DEVENV_REPO="ssh://git@repobase.net/j/devenv.git" diff --git a/general-scripts/aws/first-test.sh b/general-scripts/aws/first-test.sh new file mode 100755 index 0000000..e69de29 diff --git a/general-scripts/aws/second-test.sh b/general-scripts/aws/second-test.sh new file mode 100755 index 0000000..3df1e19 --- /dev/null +++ b/general-scripts/aws/second-test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo $@ diff --git a/general-scripts/dev.sh b/general-scripts/dev.sh new file mode 100755 index 0000000..04dd785 --- /dev/null +++ b/general-scripts/dev.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +## This script launches us into 'dev env'. A purely CLI driven dev environment +## running in Docker. + +## For more information, checkout repobase.net/j/devenv + +[ -z $DEVENV_DIR ] && MSG="Please define DEVENV_DIR in config" failout +[ -z $DEVENV_REPO ] && MSG="Please define DEVENV_DIR in config" failout + +[ -f $DEVENV_DIR ] && MSG="DEVENV_DIR points to a file. Wtf?" failout +[ -d $DEVENV_DIR ] || git clone $DEVENV_REPO $DEVENV_DIR + +[ -z "$1" ] && IMAGE='base' || IMAGE=$1 + +cd $DEVENV_DIR +bash run.sh $IMAGE diff --git a/general-scripts/failout.sh b/general-scripts/failout.sh new file mode 100644 index 0000000..f7e2825 --- /dev/null +++ b/general-scripts/failout.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +## A helper script that exports a function in asd +## Scripts run by asd can then use failout +## Saves definining it for every script. + +failout() { + [ -z $MSG ] || echo $MSG + exit 1 +} diff --git a/general-scripts/utils/make-all-executable.sh b/general-scripts/utils/make-all-executable.sh new file mode 100755 index 0000000..d8b5897 --- /dev/null +++ b/general-scripts/utils/make-all-executable.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +FILE_EXTENSIONS=("sh" "py") + +for EXT in "${FILE_EXTENSIONS[@]}" +do + find $SCRIPTS_DIR -type f -iname "*.${EXT}" -exec chmod +x {} \; +done