From 6b57adbbea014be757ef9354bef04f33f255ba40 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Fri, 30 Aug 2024 23:14:38 +0200 Subject: [PATCH] winbox4: add migration script Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/wi/winbox4/package.nix | 52 +++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/wi/winbox4/package.nix b/pkgs/by-name/wi/winbox4/package.nix index ed5975f3d5e8..a3c9a7b83a9a 100644 --- a/pkgs/by-name/wi/winbox4/package.nix +++ b/pkgs/by-name/wi/winbox4/package.nix @@ -8,8 +8,10 @@ libGL, libxkbcommon, makeDesktopItem, + makeWrapper, stdenvNoCC, unzip, + writeShellApplication, xorg, zlib, }: @@ -29,6 +31,8 @@ stdenvNoCC.mkDerivation (finalAttrs: { nativeBuildInputs = [ autoPatchelfHook copyDesktopItems + # makeBinaryWrapper does not support --run + makeWrapper unzip ]; @@ -49,7 +53,9 @@ stdenvNoCC.mkDerivation (finalAttrs: { runHook preInstall install -Dm644 "assets/img/winbox.png" "$out/share/pixmaps/winbox.png" - install -Dm755 "WinBox" $out/bin/WinBox + install -Dm755 "WinBox" "$out/bin/WinBox" + + wrapProgram "$out/bin/WinBox" --run "${lib.getExe finalAttrs.migrationScript}" runHook postInstall ''; @@ -65,6 +71,45 @@ stdenvNoCC.mkDerivation (finalAttrs: { }) ]; + migrationScript = writeShellApplication { + name = "winbox-migrate"; + text = '' + XDG_DATA_HOME=''${XDG_DATA_HOME:-$HOME/.local/share} + targetFile="$XDG_DATA_HOME/MikroTik/WinBox/Addresses.cdb" + + if [ -f "$targetFile" ]; then + echo "NixOS: WinBox 4 data already present at $(dirname "$targetFile"). Skipping automatic migration." + exit 0 + fi + + # cover both wine prefix variants + # latter was used until https://github.com/NixOS/nixpkgs/pull/329626 was merged on 2024/07/24 + winePrefixes=( + "''${WINEPREFIX:-$HOME/.wine}" + "''${WINBOX_HOME:-$XDG_DATA_HOME/winbox}/wine" + ) + sourceFilePathSuffix="drive_c/users/$USER/AppData/Roaming/Mikrotik/Winbox/Addresses.cdb" + selectedSourceFile="" + + for prefix in "''${winePrefixes[@]}" + do + echo "NixOS: Probing WinBox 3 data path at $prefix..." + if [ -f "$prefix/$sourceFilePathSuffix" ]; then + selectedSourceFile="$prefix/$sourceFilePathSuffix" + break + fi + done + + if [ -z "$selectedSourceFile" ]; then + echo "NixOS: WinBox 3 data not found. Skipping automatic migration." + exit 0 + fi + + echo "NixOS: Automatically migrating WinBox 3 data..." + install -Dvm644 "$selectedSourceFile" "$targetFile" + ''; + }; + meta = { description = "Graphical configuration utility for RouterOS-based devices"; homepage = "https://mikrotik.com"; @@ -73,6 +118,9 @@ stdenvNoCC.mkDerivation (finalAttrs: { sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; license = lib.licenses.unfree; mainProgram = "WinBox"; - maintainers = with lib.maintainers; [ Scrumplex yrd ]; + maintainers = with lib.maintainers; [ + Scrumplex + yrd + ]; }; })