Skip to content

Instantly share code, notes, and snippets.

@ain
Created December 5, 2013 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ain/7807181 to your computer and use it in GitHub Desktop.
Save ain/7807181 to your computer and use it in GitHub Desktop.
Release folder cleanup script for Capistrano-like folder structure
#!/bin/bash
KEPT_RELEASES=5
CWD=/Users/ain/temp
# Check for Bash config
# On FreeBSD/OS X GNU ls is required for -v option
if [ -f ~/.bashrc ]; then
shopt -s expand_aliases
source ~/.bashrc
fi
pwd $CWD
for release in `ls -vr releases/`; do
path="releases/$release"
if [ -d $path ]; then
KEPT_RELEASES=$[$KEPT_RELEASES - 1]
if [ `readlink current` == $path ]; then
echo "[ok] skipping $path, current release"
elif (( $KEPT_RELEASES < 0 )); then
if [[ `rm -rf $path` -eq 0 ]]; then
echo "[x] removed $path"
else
echo "[!] failed to remove $path!"
fi
else
echo "[ok] kept $path"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment