-
-
Save grahamc/d763b02bd660c59ed9a74d4731bb5bc2 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/sh | |
set -eu | |
CHAN=17.09 | |
DELAY=675 | |
SENTINAL=/var/lib/is-my-channel-up-to-date/out-of-date | |
fetch_local_version() { | |
nixos-version --hash | |
} | |
fetch_channel_version() { | |
curl "https://channels.nix.gsc.io/nixos-$CHAN/latest" \ | |
| cut -d' ' -f1 | |
} | |
PREV_VERSION_LOCAL="bogus" | |
VERSION_LOCAL="bogus" | |
PREV_VERSION_CHAN="bogus" | |
VERSION_CHAN="bogus" | |
while true; do | |
VERSION_LOCAL=$(fetch_local_version) | |
if [ "$VERSION_LOCAL" != "$PREV_VERSION_LOCAL" ]; then | |
printf "Local changed from %s to %s\n" \ | |
"$PREV_VERSION_LOCAL" \ | |
"$VERSION_LOCAL" >&2 | |
fi | |
PREV_VERSION_LOCAL=$VERSION_LOCAL | |
VERSION_CHAN=$(fetch_channel_version) | |
if [ "$VERSION_CHAN" != "$PREV_VERSION_CHAN" ]; then | |
printf "Channel changed from %s to %s\n" \ | |
"$PREV_VERSION_CHAN" \ | |
"$VERSION_CHAN" >&2 | |
fi | |
PREV_VERSION_CHAN=$VERSION_CHAN | |
if [ "$VERSION_CHAN" == "$VERSION_LOCAL" ]; then | |
if [ -f "$SENTINAL" ]; then | |
rm "$SENTINAL" | |
fi | |
else | |
if [ ! -f "$SENTINAL" ]; then | |
touch "$SENTINAL" | |
fi | |
fi | |
sleep "$DELAY" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment