Skip to content

Instantly share code, notes, and snippets.

@grahamc
Created October 10, 2017 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grahamc/d763b02bd660c59ed9a74d4731bb5bc2 to your computer and use it in GitHub Desktop.
Save grahamc/d763b02bd660c59ed9a74d4731bb5bc2 to your computer and use it in GitHub Desktop.
#!/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