winbox4: add migration script
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
@@ -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
|
||||
];
|
||||
};
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user