Skip to content

Commit

Permalink
Generate config file only if it don't exists. (msi)
Browse files Browse the repository at this point in the history
  • Loading branch information
mechairoi committed Feb 6, 2015
1 parent d452ee0 commit e64bd9a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions wix/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ go get github.com/mackerelio/mackerel-agent/wix/replace
go build -o ..\build\wrapper.exe wrapper\wrapper_windows.go
go build -o ..\build\replace.exe replace\replace_windows.go



REM retrieve numeric version from git tag
FOR /F "usebackq" %%w IN (`git describe --tags --abbrev^=0`) DO SET VERSION=%%w
set VERSION=%VERSION:v=%
FOR /F "tokens=1 delims=-+" %%w IN ('ECHO %%VERSION%%') DO SET VERSION=%%w

del /F mackerel-agent.wxs
..\build\replace.exe mackerel-agent.wxs.template mackerel-agent.wxs "___VERSION___" "%VERSION%"

"%WIX%bin\candle.exe" mackerel-agent.wxs
Expand Down
2 changes: 1 addition & 1 deletion wix/mackerel-agent.sample.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pidfile = "C:\path\to\pidfile"
# root = "C:\path\to\root"
verbose = false
# apikey = "YOUR_API_KEY"
apikey = "___YOUR_API_KEY___"

# Include other config files
# include = "C:\path\to\conf\*.conf"
Expand Down
2 changes: 1 addition & 1 deletion wix/mackerel-agent.wxs.template
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<Binary Id="ReplaceExe" SourceFile="..\build\replace.exe" />
<CustomAction Id="FillApiKey" BinaryKey="ReplaceExe"
ExeCommand='"[INSTALLDIR]\mackerel-agent.sample.conf" "[INSTALLDIR]\mackerel-agent.conf" "# apikey = ""YOUR_API_KEY""" "apikey = ""[APIKEY]"""'
ExeCommand='"[INSTALLDIR]\mackerel-agent.sample.conf" "[INSTALLDIR]\mackerel-agent.conf" "___YOUR_API_KEY___" "APIKEY]"'
Execute="deferred" Return="check" Impersonate="no" />

<Feature Id='Complete' Level='1'>
Expand Down
10 changes: 7 additions & 3 deletions wix/replace/replace_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ func main() {
log.Fatal(err)
}

err = ioutil.WriteFile(outFile, []byte(strings.Replace(string(content), oldStr, newStr, -1)), 0644)
if err != nil {
log.Fatal(err)
_, err = os.Stat(outFile)
outFileIsExists := err == nil
if !(outFileIsExists) {
err = ioutil.WriteFile(outFile, []byte(strings.Replace(string(content), oldStr, newStr, -1)), 0644)
if err != nil {
log.Fatal(err)
}
}
}

0 comments on commit e64bd9a

Please sign in to comment.