Commit a00a1c3c authored by Yuanle Song's avatar Yuanle Song
Browse files

mbackup.msi works on dev node.

- renmaed mbackup-for-windows.fsproj to mbackup.fsproj
  this file name is the project name. now exe is named mbackup.exe
- use framework dependent release.
- include rsync-mingw in one msi
- use installed rsync and ssh path in Program.fs
parent d2bd4ec4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,4 +4,4 @@ bin/
*.wixobj
*.wixpdb
*.msi
rsync-mingw64-files.wxs
*-files.wxs
+27 −20
Original line number Diff line number Diff line
WIX_DIR := "C:\Program Files (x86)\WiX Toolset v3.11\bin"
HEAT := "C:\Program Files (x86)\WiX Toolset v3.11\bin\heat.exe"
CANDLE := "C:\Program Files (x86)\WiX Toolset v3.11\bin\candle.exe" -arch x64
LIGHT := "C:\Program Files (x86)\WiX Toolset v3.11\bin\light.exe"
default: test
WIX_DIR := C:\Program Files (x86)\WiX Toolset v3.11\bin
HEAT := "$(WIX_DIR)\heat.exe"
CANDLE := "$(WIX_DIR)\candle.exe" -arch x64 -nologo
LIGHT := "$(WIX_DIR)\light.exe" -nologo

RSYNC_MINGW_DIR := D:\downloads\apps\rsync-w64
MBACKUP_PUBLISH_DIR := bin\Release\netcoreapp3.0\publish

default: build
help:
	@cmd /C echo 'Usage: make [build|test|release|clean|dist|all]'
all: test release dist
dist: mbackup.msi rsync-mingw64.msi
dist: mbackup.msi
release:
	dotnet publish -c Release -r win10-x64 --nologo
	dotnet publish --nologo -c Release --self-contained false
test:
	dotnet test mbackup-tests
	dotnet test --nologo mbackup-tests
check: test
build:
	dotnet build
	dotnet build --nologo
clean:
	dotnet clean
	del *.wixobj *.msi
	dotnet clean --nologo
	cmd /C 'del *.wixobj *.wixpdb *.msi rsync-mingw64-files.wxs'
%.wixobj: %.wxs
	$(CANDLE) $<
mbackup.msi: mbackup.wixobj release
	$(LIGHT) $<
# standalone rsync-mingw64
rsync-mingw64-files.wxs:
	$(HEAT) dir "D:\downloads\apps\rsync-w64" -cg RsyncHeatGenerated -dr ProgramFiles64Folder -var var.RsyncSourceDir -gg -nologo -out rsync-mingw64-files.wxs -sw5150
rsync-mingw64.msi: rsync-mingw64.wxs rsync-mingw64-files.wxs
	$(CANDLE) -dRsyncSourceDir=D:\downloads\apps\rsync-w64\  .\rsync-mingw64.wxs .\rsync-mingw64-files.wxs
	$(LIGHT) rsync-mingw64.wixobj rsync-mingw64-files.wixobj -o rsync-mingw64.msi
# END standalone rsync-mingw64
.PHONY: default all dist release test check build clean
	$(HEAT) dir $(RSYNC_MINGW_DIR) -cg RsyncHeatGenerated -dr MBACKUP_PROGRAM_FILES -var var.RsyncSourceDir -gg -nologo -out $@ -sw5150
rsync-mingw64-files.wixobj: rsync-mingw64-files.wxs
	$(CANDLE) -dRsyncSourceDir=$(RSYNC_MINGW_DIR) $<
mbackup-files.wxs: release
	$(HEAT) dir $(MBACKUP_PUBLISH_DIR) -cg MbackupHeatGenerated -dr MBACKUP_PROGRAM_FILES -var var.MbackupPublishDir -gg -nologo -out $@ -sw5150
mbackup-files.wixobj: mbackup-files.wxs
	$(CANDLE) -dMbackupPublishDir=$(MBACKUP_PUBLISH_DIR) $<
mbackup.msi: mbackup.wixobj rsync-mingw64-files.wixobj mbackup-files.wixobj
	$(LIGHT) $^ -o $@
.PHONY: default help all dist release test check build clean rsync-mingw64-files.wxs mbackup-files.wxs
+14 −12
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ with
            | Node_Name _ -> "local node's name, used in remote logging"
            | Ssh_Key _ -> "ssh private key, used when backup to remote ssh node"

let programFilesDirWin =  Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) |> ensureWinDir
let programFilesDir = toMingwPath programFilesDirWin
let mbackupProgramDirWin = programFilesDirWin + "mbackup\\"
let mbackupProgramDir = toMingwPath mbackupProgramDirWin

let appDataRoamingDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |> toMingwPath |> ensureDir
let programDataDirWin = getEnv "PROGRAMDATA" |> ensureWinDir
let programDataDir = toMingwPath programDataDirWin
@@ -115,7 +120,7 @@ let generateMbackupList (logger: Logger) =
          let lines = readMbackupListFile mbackupLocalList |> Seq.map toMingwPath
          (true, lines)
        with
        | :? System.IO.FileNotFoundException ->
        | :? FileNotFoundException ->
          (true, Seq.empty)
        | ex ->
          logger.Error "Read mbackupLocalList failed: %s" ex.Message
@@ -151,6 +156,7 @@ let main argv =

    logger.Info "user config dir: %s" userConfigDirWin
    logger.Info "runtime dir: %s" runtimeDirWin
    logger.Debug "program dir: %s" mbackupProgramDirWin

    let rsyncCmd: string list = []
    let rsyncCmd = appendWhen dryRun rsyncCmd "--dry-run"
@@ -170,13 +176,10 @@ let main argv =
    let localLogFile = runtimeDir + "mbackup.log"
    let rsyncCmd = List.append rsyncCmd [sprintf "--log-file=%s" localLogFile]

    // TODO remove usage of test dir.
    let mbackupInstallDirWinTest = "D:\\downloads\\apps\\mbackupTest\\"
    let mbackupInstallDirTest = mbackupInstallDirWinTest |> toMingwPath |> ensureDir
    let sshExeFile = mbackupInstallDirTest + "rsync-w64/usr/bin/ssh.exe"
    let sshExeFile = mbackupProgramDir + "rsync-w64/usr/bin/ssh.exe"
    let sshConfigFile = userHome + ".ssh/config"
    let sshPrivateKeyFile = results.GetResult(Ssh_Key, defaultValue = userHome + ".ssh/id_rsa") |> toMingwPath
    let rsyncCmd = List.append rsyncCmd [sprintf "-e \"%s -F %s -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\"" sshExeFile sshConfigFile sshPrivateKeyFile]
    let rsyncCmd = List.append rsyncCmd [sprintf "-e \"'%s' -F %s -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null\"" sshExeFile sshConfigFile sshPrivateKeyFile]

    // precedence: command line argument > environment variable > config file
    let normalizeTarget target =
@@ -211,13 +214,12 @@ let main argv =
        let rsyncCmd = List.append rsyncCmd ["/"]
        let rsyncCmd = List.append rsyncCmd [backupTarget]
        let rsyncArgs = rsyncCmd |> String.concat " "
        let rsyncExe = mbackupInstallDirWinTest + "rsync-w64\\usr\\bin\\rsync.exe"
        let echoExe = "C:\\Program Files\\Git\\usr\\bin\\echo.exe"
        let rsyncExe = mbackupProgramDirWin + "rsync-w64\\usr\\bin\\rsync.exe"
        try
          IO.Directory.CreateDirectory(runtimeDir) |> ignore
          IO.Directory.CreateDirectory(userConfigDir) |> ignore
          let proc = Process.Start(rsyncExe, rsyncArgs)
          Directory.CreateDirectory(runtimeDir) |> ignore
          Directory.CreateDirectory(userConfigDir) |> ignore
          logger.Info "Note: if you run the following rsync command yourself, make sure the generated file list (%s) is up-to-date.\n%s" mbackupFile (rsyncExe + " " + rsyncArgs)
          let proc = Process.Start(rsyncExe, rsyncArgs)
          if proc.WaitForExit Int32.MaxValue then
            logger.Info "mbackup exit"
            proc.ExitCode
@@ -225,7 +227,7 @@ let main argv =
            logger.Error "mbackup timed out while waiting for rsync to complete"
            ExitTimeout
        with
        | :? System.IO.IOException as ex ->
        | :? IOException as ex ->
          logger.Error "IO Error: %s %s" ex.Source ex.Message
          ExitIOError
        | ex ->
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\mbackup-for-windows.fsproj" />
    <ProjectReference Include="..\mbackup.fsproj" />
  </ItemGroup>

</Project>
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
    <RootNamespace>Mbackup</RootNamespace>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
Loading