From e64bd9a6da2324c8e9ab450ebeebadd40908d7e4 Mon Sep 17 00:00:00 2001 From: mechairoi Date: Fri, 6 Feb 2015 16:01:11 +0900 Subject: [PATCH] Generate config file only if it don't exists. (msi) --- wix/build.bat | 4 ++-- wix/mackerel-agent.sample.conf | 2 +- wix/mackerel-agent.wxs.template | 2 +- wix/replace/replace_windows.go | 10 +++++++--- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/wix/build.bat b/wix/build.bat index 43aa82aff..13ebadd23 100755 --- a/wix/build.bat +++ b/wix/build.bat @@ -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 diff --git a/wix/mackerel-agent.sample.conf b/wix/mackerel-agent.sample.conf index 33ba9a18b..f19f37d1d 100644 --- a/wix/mackerel-agent.sample.conf +++ b/wix/mackerel-agent.sample.conf @@ -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" diff --git a/wix/mackerel-agent.wxs.template b/wix/mackerel-agent.wxs.template index 260e539b7..a17924878 100644 --- a/wix/mackerel-agent.wxs.template +++ b/wix/mackerel-agent.wxs.template @@ -33,7 +33,7 @@ diff --git a/wix/replace/replace_windows.go b/wix/replace/replace_windows.go index 641fc9d90..6f42a6f49 100644 --- a/wix/replace/replace_windows.go +++ b/wix/replace/replace_windows.go @@ -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) + } } }