-
-
Save kayrus/f13c84092a7fef18c8c4 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 | |
LOCALFILE=$1 | |
LOCALHASH=$(sha1sum $LOCALFILE | awk '{print $1}') | |
for REMOTEFILE in $(etcdctl ls /_coreos.com/fleet/job/ | sed 's#.*/##'); do | |
if [ "$REMOTEFILE" == "$LOCALFILE" ]; then | |
REMOTEHASH=$(etcdctl get /_coreos.com/fleet/job/$REMOTEFILE/object | sed -r 's#.*UnitHash":\[([0-9,]+)\].*#\1#g' | tr -d '\n' | xargs -d ',' printf "%02x") | |
if [ "$REMOTEHASH" == "$LOCALHASH" ]; then | |
echo "Hashes are identical, do nothing" | |
else | |
echo "Attempting to update unit file in etcd" | |
ESCAPED_STRING=$(cat $1 | sed ":a;N;\$!ba;s#\\\#\\\\\\\#g;s#\n#\\\n#g;s#\\\"#\\\\\"#g;s#\r#\\\r#g;s#\t#\\\t#g") | |
LOCALHASH_DEC=$(echo "$LOCALHASH" | sed -r 's#(.{2})#0x\1,#g' | tr -d '\n' | xargs -d ',' printf "%d," | sed 's#,$##') | |
NEW_JSON="{\"Raw\":\"$ESCAPED_STRING\\n\"}" | |
etcdctl set /_coreos.com/fleet/unit/$LOCALHASH "$NEW_JSON" | |
NEW_OBJECT="{\"Name\":\"$LOCALFILE\",\"UnitHash\":[$LOCALHASH_DEC]}" | |
etcdctl set /_coreos.com/fleet/job/$LOCALFILE/object "$NEW_OBJECT" | |
etcdctl rm /_coreos.com/fleet/unit/$REMOTEHASH | |
fi | |
break; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updates fleet unit file. Didn't test it with unit templates.