Created
July 1, 2016 16:52
-
-
Save mzupan/23bb76f35da47e6080aeb6b56af14c8e 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
#!/bin/bash | |
if [ "$(id -u)" = "0" ]; then | |
echo | |
echo "Do not run as root. Run as your user" | |
exit 2 | |
fi | |
usage() { echo "Usage: $0 -t <time needed> <salt-feature-branch>" 1>&2; exit 1; } | |
while getopts ":h:t:" o; do | |
case "${o}" in | |
t) | |
t="now + ${OPTARG}" | |
;; | |
h) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
s=$1 | |
if [ -z "${t}" ]; then | |
t="11:59 tomorrow" | |
fi | |
if [ -z "${s}" ]; then | |
usage | |
fi | |
sudo sh -c "cd /etc/salt; git pull origin > /dev/null" | |
# | |
# checking if already claimed | |
sudo sh -c "cd /etc/salt; git branch | grep '*' | grep dev >/dev/null" | |
if [ $? -eq 1 ]; then | |
echo | |
echo "/etc/salt already claimed by someone!" | |
echo | |
echo "You can force a release by using" | |
echo " sudo release-salt -f" | |
echo | |
exit 2 | |
fi | |
sudo sh -c "cd /etc/salt; git branch | grep ${s} > /dev/null" | |
if [ $? -eq 0 ]; then | |
sudo sh -c "cd /etc/salt; git checkout ${s}" | |
sudo sh -c "cd /etc/salt; git pull origin" | |
else | |
sudo sh -c "cd /etc/salt; git checkout -b ${s} origin/${s}" | |
fi | |
date=$(sudo sh -c "at -f '/usr/sbin/release-salt' ${t} 2>&1 | awk '{print \$(NF-1),\" \",\$NF}'") | |
echo | |
echo "You have claimed salt until ${date}" |
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
#!/bin/sh | |
user=`logname` | |
env=$(cat /etc/env) | |
while getopts "f" o; do | |
case "${o}" in | |
f) | |
force=1 | |
;; | |
*) | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
cd /etc/salt | |
git pull origin >/dev/null | |
if [[ $env == "prod" ]] | |
then | |
git checkout master >/dev/null | |
else | |
git checkout dev >/dev/null | |
fi | |
# | |
# remove the at job since this was forced | |
if [ -n "${force}" ]; then | |
find /var/spool/at/spool/ -exec grep -q "salt" {} \; -delete | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment