Skip to content

Instantly share code, notes, and snippets.

@jtomaszon
Created February 19, 2015 20:00
Show Gist options
  • Save jtomaszon/b2b77bd3cb539ccf8f37 to your computer and use it in GitHub Desktop.
Save jtomaszon/b2b77bd3cb539ccf8f37 to your computer and use it in GitHub Desktop.
A nice script to cleanup some 'cap' releases
#!/bin/bash
# If not set APP_DIR variable, fail
[ -z ${APP_DIR} ] && echo "Usage: Define APP_DIR before the script" && exit 1
LOG=/home/user/cleanupReleases.log
logger -p info -t cleanupReleases "Starting cleanup on ${APP_DIR}... "
CLEANUP=$(ls -dt ${APP_DIR}/releases/* | awk 'NR>1')
[ -z "$CLEANUP" ] && echo "Nothing to cleanup" && exit 2
echo ${CLEANUP} | tee -a ${LOG} | xargs rm -fR
if [ $? -eq 0 ]; then
CHANNEL='#some'
USERNAME='casper'
MESSAGE='Cleanup Complete'
PATHS=$(echo ${CLEANUP} | tr ' ' '\n')
curl -X POST \
--data-urlencode "payload={\"channel\": \"${CHANNEL}\", \"username\": \"${USERNAME}\", \"text\": \"${MESSAGE}\", \"icon_emoji\": \":ghost:\",
\"attachments\":[
{
\"fallback\":\"$(hostname)\",
\"pretext\":\"$(hostname)\",
\"color\":\"#00D000\",
\"fields\":[
{
\"title\":\"Path:\",
\"value\":\"${APP_DIR}/releases\",
\"short\":false
}
]
}
]
}" \
<webhook-url>
exit 0
fi
exit 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment