Last active
August 29, 2015 14:26
-
-
Save dwallraff/dc44dd8908da65dfa1e7 to your computer and use it in GitHub Desktop.
Bash wrapper to upload a run a script to a bosh job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script will create a wrapper script with a random password | |
# upload your script and execute it with sudo. | |
# Please Note: This script requires a patched version of the BOSH cli. | |
# At this time, this patch is not publicly available. | |
# Variables | |
BOSH_JOB="<job_name>" | |
BOSH_INSTANCE=<instance number> | |
BOSH_TEMP_SCRIPT="bosh_temp_script" | |
BOSH_SCRIPT="bosh_script" | |
BOSH_PASSWORD=$(LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | fold -w ${1:-32} | head -n 1) | |
# Create bosh script to run security script | |
rm $BOSH_TEMP_SCRIPT > /dev/null | |
echo "echo $BOSH_PASSWORD | sudo -S /tmp/$BOSH_SCRIPT" > $BOSH_TEMP_SCRIPT > /dev/null | |
# Remove any old files | |
bosh ssh $BOSH_JOB/$BOSH_INSTANCE "rm /tmp/$BOSH_TEMP_SCRIPT" > /dev/null | |
bosh ssh $BOSH_JOB/$BOSH_INSTANCE "rm /tmp/$BOSH_SCRIPT" > /dev/null | |
# Upload the new files | |
bosh scp $BOSH_JOB/$BOSH_INSTANCE --upload $BOSH_TEMP_SCRIPT /tmp/$BOSH_TEMP_SCRIPT > /dev/null | |
bosh scp $BOSH_JOB/$BOSH_INSTANCE --upload $BOSH_SCRIPT /tmp/$BOSH_SCRIPT > /dev/null | |
# Run the scripts | |
bosh ssh $BOSH_JOB/$BOSH_INSTANCE --default_password $BOSH_PASSWORD "chmod +x /tmp/$BOSH_TEMP_SCRIPT; chmod +x /tmp/$BOSH_SCRIPT; /tmp/$BOSH_TEMP_SCRIPT" | |
# Cleanup | |
bosh ssh $BOSH_JOB/$BOSH_INSTANCE "rm /tmp/$BOSH_TEMP_SCRIPT" > /dev/null | |
bosh ssh $BOSH_JOB/$BOSH_INSTANCE "rm /tmp/$BOSH_SCRIPT" > /dev/null | |
rm $BOSH_TEMP_SCRIPT > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment