Last active
March 21, 2018 21:24
-
-
Save tanelpuhu/7a2c3c73b9a57fabd3a527fc0b4e0ae2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -e | |
set -u | |
mkdir -p ~/bin | |
GIT_WORK_TREE=~/bin git checkout -f | |
GIT_SHA=$(git rev-parse --short HEAD) | |
echo "DATE: $(date)" | |
echo "GIT_SHA: ${GIT_SHA}" | |
setup_couchtomato(){ | |
echo "Changes in couchtomato, running migration..." | |
~/bin/couchtomato -v migrate | |
} | |
setup_crontab(){ | |
CRONFILE=$1 | |
echo "Changes in crontab, installing new cron..." | |
# Archive old one | |
/usr/bin/crontab -l > ${CRONFILE}.$(date +%y%m%d%H%M%s) | |
# Delete really old ones... | |
find ${CRONFILE}.* -type f -mtime +30 -exec rm -v {} \; | |
# Apply new one | |
/usr/bin/crontab ${CRONFILE} | |
} | |
sha_setup(){ | |
FUNC=$1 | |
SOURCE_FILE=$2 | |
SHA_FILE=${SOURCE_FILE}.sha1 | |
if [[ -f ${SOURCE_FILE} ]]; then | |
( | |
sha1sum --status -c ${SHA_FILE} | |
) || ( | |
${FUNC} ${SOURCE_FILE} | |
sha1sum ${SOURCE_FILE} > ${SHA_FILE} | |
) | |
fi | |
} | |
sha_setup setup_couchtomato ~/bin/couchtomato | |
sha_setup setup_crontab ~/bin/cld/crontab | |
echo "Deployed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment