list-upgradable: obtain and print nixos system version

This commit is contained in:
Astro 2021-09-08 01:36:26 +02:00
parent 3b93b16370
commit b349a48ec8
1 changed files with 7 additions and 3 deletions

View File

@ -117,13 +117,17 @@
in nixpkgs.lib.optionalString (addr != null) ''
echo -n -e "${name}: $RED"
RUNNING=$(ssh -o PreferredAuthentications=publickey -o StrictHostKeyChecking=accept-new root@"${addr}" "readlink /run/current-system")
if [ $? = 0 ]; then
if [ $? = 0 ] && [ -n "$RUNNING" ]; then
CURRENT=$(nix eval --raw ".#nixosConfigurations.${name}.config.system.build.toplevel" 2>/dev/null)
RUNNING_VER=$(basename $RUNNING|rev|cut -d - -f 1|rev)
CURRENT_VER=$(basename $CURRENT|rev|cut -d - -f 1|rev)
if [ "$RUNNING" = "$CURRENT" ]; then
echo -e "$GREEN"current
echo -e "$GREEN"current"$NORMAL $RUNNING_VER"
elif [ "$RUNNING_VER" = "$CURRENT_VER" ]; then
echo -e "$GREEN"modified"$NORMAL $RUNNING_VER"
else
echo -e "$YELLOW"outdated
echo -e "$YELLOW"outdated"$NORMAL $RUNNING_VER < $CURRENT_VER"
fi
fi
echo -n -e "$NORMAL"