works yay
This commit is contained in:
parent
bf21c1b469
commit
363cec25b7
9 changed files with 127 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
config
|
||||||
|
work-scripts
|
|
@ -0,0 +1 @@
|
||||||
|
Requires *bash* installed, but can run in any shello theoretically
|
81
asd
Executable file
81
asd
Executable file
|
@ -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 $@
|
5
config.sample
Normal file
5
config.sample
Normal file
|
@ -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"
|
0
general-scripts/aws/first-test.sh
Executable file
0
general-scripts/aws/first-test.sh
Executable file
3
general-scripts/aws/second-test.sh
Executable file
3
general-scripts/aws/second-test.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo $@
|
17
general-scripts/dev.sh
Executable file
17
general-scripts/dev.sh
Executable file
|
@ -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
|
10
general-scripts/failout.sh
Normal file
10
general-scripts/failout.sh
Normal file
|
@ -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
|
||||||
|
}
|
8
general-scripts/utils/make-all-executable.sh
Executable file
8
general-scripts/utils/make-all-executable.sh
Executable file
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue