Skip to content

Instantly share code, notes, and snippets.

@tanelpuhu
Last active March 21, 2018 21:24
Show Gist options
  • Save tanelpuhu/7a2c3c73b9a57fabd3a527fc0b4e0ae2 to your computer and use it in GitHub Desktop.
Save tanelpuhu/7a2c3c73b9a57fabd3a527fc0b4e0ae2 to your computer and use it in GitHub Desktop.
#!/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