Commit 97216b59 authored by Yuanle Song's avatar Yuanle Song
Browse files

allow msi upgrade; add shortcuts when installing;

- allow msi major upgrade
- add desktop and start menu shortcut for mbackup.exe file
- set HOME env variable when running rsync.exe.
  ssh.exe wants to access HOME dir.
  but this change seems not working in win 10 VM.
- add Version info in mbackup.fsproj
  - mbackup.exe supports --version option.
    - when build msi file, include version in filename
    - use printf %A to print exception detail.
parent 45a07dbc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,3 +5,4 @@ bin/
*.wixpdb
*.msi
*-files.wxs
t1*
 No newline at end of file

GetVersion.ps1

0 → 100644
+2 −0
Original line number Diff line number Diff line
[xml]$FSPROJ = Get-Content mbackup.fsproj
Write-Output $FSPROJ.Project.PropertyGroup.Version
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ type Logger() =
let appendWhen (pred: bool) (lst: string list) (s: string) = if pred then List.append lst [s] else lst

let getEnv (varName: string) = Environment.GetEnvironmentVariable varName
let setEnv (varName: string) (value: string) = Environment.SetEnvironmentVariable(varName, value)

let getEnvDefault (varName: string) (defaultValue: string) =
  let value = Environment.GetEnvironmentVariable varName
+10 −6
Original line number Diff line number Diff line
@@ -5,12 +5,16 @@ LIGHT := "$(WIX_DIR)\light.exe" -nologo

RSYNC_MINGW_DIR := D:\downloads\apps\rsync-w64
MBACKUP_PUBLISH_DIR := bin\Release\netcoreapp3.0\publish
MSI_DIR := D:\downloads\upload
VERSION := $(shell powershell -NoProfile -File GetVersion.ps1)

default: build
help:
	@cmd /C echo 'Usage: make [build|test|release|clean|dist|all]'
	@cmd /C echo "Usage: make [build|test|release|clean|dist|all]"
version:
	@cmd /C "echo Version=$(VERSION)"
all: test release dist
dist: mbackup.msi
dist: msi
release: test
	dotnet publish --nologo -c Release --self-contained false
test:
@@ -22,7 +26,7 @@ clean:
	dotnet clean --nologo
	cmd /C 'del *.wixobj *.wixpdb *.msi rsync-mingw64-files.wxs'
%.wixobj: %.wxs
	$(CANDLE) $<
	$(CANDLE) -dVersion=$(VERSION) $<
rsync-mingw64-files.wxs:
	$(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
@@ -31,6 +35,6 @@ 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
msi: mbackup.wixobj rsync-mingw64-files.wixobj mbackup-files.wixobj
	$(LIGHT) $^ -o $(MSI_DIR)\mbackup-$(VERSION).msi
.PHONY: default help all dist release test check build clean msi rsync-mingw64-files.wxs mbackup-files.wxs
+24 −2
Original line number Diff line number Diff line
@@ -21,11 +21,14 @@ open Argu
open Mbackup.Lib
open Mbackup.ConfigParser

let ExitSuccess = 0
let ExitBadParam = 1
let ExitTimeout = 2
let ExitIOError = 3
let ExitUserError = 4

let version = Reflection.Assembly.GetEntryAssembly().GetName().Version
let versionStr = version.ToString()

[<SuppressMessage("*", "UnionCasesNames")>]
type CLIArguments =
@@ -35,6 +38,7 @@ type CLIArguments =
    | [<AltCommandLine("-i")>] Itemize_Changes
    | Node_Name of nodeName: string
    | Ssh_Key of sshKeyFilename: string
    | [<AltCommandLine("-V")>] Version
    interface IArgParserTemplate with
        member s.Usage =
            match s with
@@ -44,6 +48,7 @@ type CLIArguments =
            | Itemize_Changes _ -> "add -i option to rsync"
            | Node_Name _ -> "local node's name, used in remote logging"
            | Ssh_Key _ -> "ssh private key, used when backup to remote ssh node"
            | Version _ -> "show mbackup version and exit"

let programFilesDirWin = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) |> ensureWinDir
let programFilesDir = toMingwPath programFilesDirWin
@@ -196,6 +201,11 @@ let main argv =

    let parser = ArgumentParser.Create<CLIArguments>(programName = "mbackup.exe", errorHandler = errorHandler)
    let results = parser.Parse argv

    if results.Contains Version then
        printfn "mbackup %s" versionStr
        Environment.Exit(ExitSuccess)

    let dryRun = results.Contains Dry_Run
    let itemizeChanges = results.Contains Itemize_Changes

@@ -257,7 +267,19 @@ let main argv =
            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)
            let processStartInfo =
                ProcessStartInfo(
                    FileName = rsyncExe,
                    Arguments = rsyncArgs)
            //set HOME dir to prevent ssh.exe can't access /home/<user>/.ssh error.
            try
                processStartInfo.EnvironmentVariables.Add("HOME", userHomeWin)
                setEnv "HOME" userHomeWin
            with
            | :? ArgumentException -> ()    // variable already exists
            | ex -> logger.Warning "set HOME environment variable failed: %A" ex
                // not a critical error, allow program to continue.
            let proc = Process.Start(processStartInfo)
            if proc.WaitForExit Int32.MaxValue then
                logger.Info "mbackup exit"
                proc.ExitCode
@@ -274,5 +296,5 @@ let main argv =
            logger.Error "IO Error: %s %s" ex.Source ex.Message
            ExitIOError
        | ex ->
            logger.Error "Unexpected Error: %s" ex.Message
            logger.Error "Unexpected Error: %A" ex
            ExitIOError
Loading