Show running Gateway commit and available updates
This commit is contained in:
1 parent
32b240469c
commit
36b2057991
12 files changed
+188
-21
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
{
|
||||
imports = [
|
||||
(builtins.getFlake "path:/etc/nixos/seiugw").nixosModules.default
|
||||
(builtins.getFlake "git+file:///etc/nixos/seiugw").nixosModules.default
|
||||
];
|
||||
|
||||
services.seiugw = {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{
|
||||
imports = [
|
||||
(builtins.getFlake "path:/etc/nixos/seiugw").nixosModules.default
|
||||
(builtins.getFlake "git+file:///etc/nixos/seiugw").nixosModules.default
|
||||
];
|
||||
|
||||
services.seiugw = {
|
||||
|
||||
@@ -13,6 +13,12 @@ let
|
||||
dhcpcdBase = builtins.head (builtins.match ".* --config ([^ ]+).*" config.systemd.services.dhcpcd.serviceConfig.ExecStart);
|
||||
networkHelper = "${pkgs.python3}/bin/python3 ${./host-network.py}";
|
||||
updateSocket = "/run/seiugw-update/request.sock";
|
||||
updateAvailability = pkgs.writeShellScript "seiugw-update-availability" ''
|
||||
export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.git ]}
|
||||
export SEIUGW_UPDATE_REMOTE=${escapeShellArg cfg.updates.remote}
|
||||
export SEIUGW_UPDATE_BRANCH=${escapeShellArg cfg.updates.branch}
|
||||
${builtins.readFile ./system-update-availability.sh}
|
||||
'';
|
||||
updateWorker = pkgs.writeShellScript "seiugw-system-update" ''
|
||||
export PATH=${lib.makeBinPath [ pkgs.coreutils pkgs.git pkgs.util-linux pkgs.systemd pkgs.curl pkgs.jq pkgs.sqlite pkgs.nix ]}:/run/current-system/sw/bin
|
||||
export NIX_PATH=${escapeShellArg "nixos-config=/etc/nixos/configuration.nix:nixpkgs=${pkgs.path}"}
|
||||
@@ -310,9 +316,12 @@ in
|
||||
Gateway__Bacnet__DeviceInstance = toString cfg.bacnet.deviceInstance;
|
||||
Gateway__Bacnet__IpPort = toString cfg.bacnet.ipPort;
|
||||
Gateway__OpcUa__Port = toString cfg.opcUa.port;
|
||||
Gateway__RunningCommit = cfg.package.sourceRevision or "";
|
||||
} // lib.optionalAttrs cfg.updates.enable {
|
||||
Gateway__UpdateSocketPath = updateSocket;
|
||||
Gateway__UpdateStatusPath = "/var/lib/seiugw-updater/status.json";
|
||||
Gateway__UpdateAvailabilityCommand = updateAvailability;
|
||||
Gateway__UpdateBranch = cfg.updates.branch;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
{ lib, buildDotnetModule, dotnetCorePackages }:
|
||||
{ lib, buildDotnetModule, dotnetCorePackages, sourceRevision ? "" }:
|
||||
|
||||
buildDotnetModule {
|
||||
pname = "seiugw";
|
||||
@@ -12,6 +12,8 @@ buildDotnetModule {
|
||||
dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;
|
||||
executables = [ "Gateway.Api" ];
|
||||
|
||||
passthru = { inherit sourceRevision; };
|
||||
|
||||
meta = {
|
||||
description = "Industrial protocol gateway for BACnet/IP, OPC UA, Modbus TCP and MQTT";
|
||||
platforms = lib.platforms.linux;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
export GIT_TERMINAL_PROMPT=0 GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1
|
||||
|
||||
running=$1
|
||||
[[ $running =~ ^[0-9a-f]{40}$ ]]
|
||||
ref="refs/heads/$SEIUGW_UPDATE_BRANCH"
|
||||
remote="$SEIUGW_UPDATE_REMOTE"
|
||||
tip=$(timeout --kill-after=1s 8s git ls-remote --exit-code --refs -- "$remote" "$ref")
|
||||
tip=${tip%%$'\t'*}
|
||||
[[ $tip =~ ^[0-9a-f]{40}$ ]]
|
||||
if [[ $tip == "$running" ]]; then
|
||||
printf 'current %s\n' "$tip"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check ancestry in a temporary repository. The update worker owns the live checkout.
|
||||
probe=$(mktemp -d)
|
||||
trap 'rm -rf -- "$probe"' EXIT
|
||||
git init --quiet --bare "$probe"
|
||||
timeout --kill-after=1s 18s git -C "$probe" fetch --quiet --no-tags -- "$remote" "$ref"
|
||||
tip=$(git -C "$probe" rev-parse FETCH_HEAD)
|
||||
if [[ $tip == "$running" ]]; then
|
||||
printf 'current %s\n' "$tip"
|
||||
elif git -C "$probe" cat-file -e "$running^{commit}" 2>/dev/null &&
|
||||
git -C "$probe" merge-base --is-ancestor "$running" "$tip"; then
|
||||
printf 'available %s\n' "$tip"
|
||||
else
|
||||
printf 'incompatible %s\n' "$tip"
|
||||
fi
|
||||
Reference in new issue
Block a user