diff -r 000000000000 -r bed0d5a4511f setup/setup.js.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup/setup.js.in Fri Jun 08 20:13:30 2018 +0100 @@ -0,0 +1,92 @@ +var WshShell = WScript.CreateObject("WScript.Shell"); +var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, ""); +var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject"); + +function RunSetup(args) +{ + var OKButton = 0, ErrorIcon = 16, ForReading = 1; + var path, command, i, ExecObject, text; + path = FileSystemObject.BuildPath(ScriptPath, "setup.exe"); + command = "\"" + path + "\""; + for(i = 0; i < args.Length; i++) + command += " \"" + args.Item(i) + "\""; + ExecObject = WshShell.Exec(command); + if (!ExecObject.StdErr.AtEndOfStream) + { + text = "Setup failed for an unexpected reason. Please report " + + "the following error to support@city-occupational.co.uk:\n\n" + + ExecObject.StdErr.ReadAll(); + WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon); + return false; + } + else if (ExecObject.ExitCode) + { + text = "Setup failed without giving a reason. Please report " + + "this to support@city-occupational.co.uk"; + WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon); + return false; + } + return true; +} + +function Install() +{ + var path; + path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe"); + WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe" + + " \\\"" + WScript.ScriptFullName + "\\\"" + + " --post %INSTALL_PREFIX% %TEST_RESULT%\"", + 7, true); +} + +function Uninstall() +{ + var path; + path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe"); + WshShell.Run("\"" + path + "\"" + " -u --post \"wscript.exe" + + " \\\"" + WScript.ScriptFullName + "\\\"" + " --postun\"", 7, true); +} + +function PostInstall() +{ + var OKButton = 0, InfoIcon = 64, text; + var test_result, install_prefix, path, args; + install_prefix = WScript.Arguments.Item(1); + test_result = WScript.Arguments.Item(2); + if (test_result == "pass") + { + path = FileSystemObject.BuildPath(install_prefix, + "bin\\app-manager.exe"); + WshShell.Run("\"" + path + "\" --setup \"" + ScriptPath + "\""); + } + else + { + args = { Length:0, Item:function(){return nil} }; + if (RunSetup(args)) + { + text = "Software installation completed successfully."; + WshShell.Popup(text, 0, "Software Installation", + OKButton + InfoIcon); + } + } +} + +function PostUninstall() +{ + var args = { Length:1, Item:function(){return "-u"} }; + var OKButton = 0, InfoIcon = 64, text; + if (RunSetup(args)) + { + text = "Uninstall completed successfully."; + WshShell.Popup(text, 0, "Uninstall", OKButton + InfoIcon); + } +} + +if (WScript.Arguments.Length < 1) + Install() +else if (WScript.Arguments.Item(0) == "-u") + Uninstall() +else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post") + PostInstall() +else if (WScript.Arguments.Item(0) == "--postun") + PostUninstall()