Created
December 5, 2013 15:18
-
-
Save ain/7807181 to your computer and use it in GitHub Desktop.
Release folder cleanup script for Capistrano-like folder structure
This file contains hidden or 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 | |
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