Last active
October 18, 2018 14:47
-
-
Save Ikke/ff6d1703d36109514db24f42b09edd0a to your computer and use it in GitHub Desktop.
Devops scripts
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 | |
source $PWD/.sync_settings | |
if [[ -z "$SYNC_HOST" ]]; then | |
echo "Please specify SYNC_HOST in .sync_settings" | |
exit 1 | |
fi | |
if [[ -z "$SYNC_HOST" ]]; then | |
echo "Please specify SYNC_PATH in .sync_settings" | |
exit 1 | |
fi | |
case "$SYNC_PATH" in | |
/|/usr|/var|/etc|/root) | |
echo "'$SYNC_PATH' is not allowed, possibly destructive" | |
exit 1 | |
;; | |
esac | |
rsync --exclude-from $PWD/.rsync_ignore -iptr --links --safe-links --delete . $SYNC_HOST:$SYNC_PATH |
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 | |
## Create a release archive using git archive to upload a tarbal to a specific host | |
## Uses a `release_settings` file in the local directory to get the server and path | |
RELEASE_ENVIRONMENT=dev | |
set -e | |
while getopts ":e:" opt | |
do | |
case $opt in | |
e) | |
RELEASE_ENVIRONMENT=$OPTARG | |
;; | |
\?) | |
echo "Unknown option found: $OPTARG" | |
exit 1 | |
esac | |
done | |
if [[ ! -f release_settings ]] | |
then | |
echo "./release_settings not found" | |
exit 1 | |
fi | |
source release_settings | |
if [[ -z "$project_name" ]] | |
then | |
echo "\$project_name not set, please set it in $PWD/release_settings" | |
exit 1 | |
fi | |
if [[ -z "$host" ]] | |
then | |
echo "\$host not set, please set it to the host to upload the release to" | |
exit 1 | |
fi | |
if [[ -z "$release_path" ]] | |
then | |
echo "\$release_path not set, please set it to the path to unpack the release to" | |
exit 1 | |
fi | |
release_date=$(date "+%Y%m%d%H%M") | |
release_version= | |
if declare -f get_version > /dev/null | |
then | |
release_version="_$(get_version)" | |
fi | |
archive_name=$(date '+%Y%m%d%H%M')$release_version | |
git archive --format=tar.gz --prefix=$archive_name/ HEAD | ssh $host "cat > ${release_path}/$project_name-$archive_name.tar.gz" | |
echo "Created release ${archive_name} at: ${release_path}/$project_name-$archive_name.tar.gz" |
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 | |
## Shows git status, updates when files change. | |
## Improvement over watch is that it doesn't lock the index all the time, causing git commands to fail | |
## Dependencies: inotify-tools | |
while true; | |
do | |
sleep 0.1 | |
ST=$(git -c color.ui=always status -sb); # First get output of git status before clearing the screen | |
tput reset; | |
echo -e "$ST" | |
inotifywait -qqr . | |
done |
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 | |
## Automatically syncs files when changes are made to the local directory | |
## Dependencies: sync_files.sh, inotify-tools | |
## | |
## Arguments: | |
## -e The environment to use. This is passed as RELEASE_ENVIRONMENT variable in the release_settings file | |
## | |
## release_settings: | |
## Variables: | |
## - project_name: the name that will be used in the release tarball | |
## - host | |
## - release_path | |
## If a function funtion called get_version is defined, it's called to retrieve the current release version | |
while true | |
do | |
inotifywait -qe create,modify,delete,move,move_self,delete_self -r --exclude .git . && | |
sleep 0.1 | |
sync_files | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment