setup/setup.js.in
changeset 59 296eac3183bc
child 106 cc42fad3fe31
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/setup/setup.js.in	Fri Jul 08 08:26:29 2016 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +var WshShell = WScript.CreateObject("WScript.Shell");
     1.5 +var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, "");
     1.6 +var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
     1.7 +
     1.8 +function RunSetup(args)
     1.9 +{
    1.10 +    var OKButton = 0, ErrorIcon = 16, ForReading = 1;
    1.11 +    var path, command, i, ExecObject, text;
    1.12 +    path = FileSystemObject.BuildPath(ScriptPath, "setup.exe");
    1.13 +    command = "\"" + path + "\"";
    1.14 +    for(i = 0; i < args.Length; i++)
    1.15 +	command += " \"" + args.Item(i) + "\"";
    1.16 +    ExecObject = WshShell.Exec(command);
    1.17 +    if (!ExecObject.StdErr.AtEndOfStream)
    1.18 +    {
    1.19 +	text = "Setup failed for an unexpected reason. Please report "
    1.20 +	  + "the following error to support@city-occupational.co.uk:\n\n"
    1.21 +	  + ExecObject.StdErr.ReadAll();
    1.22 +	WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon);
    1.23 +	return false;
    1.24 +    }
    1.25 +    else if (ExecObject.ExitCode)
    1.26 +    {
    1.27 +	text = "Setup failed without giving a reason. Please report "
    1.28 +	  + "this to support@city-occupational.co.uk";
    1.29 +	WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon);
    1.30 +	return false;
    1.31 +    }
    1.32 +    return true;
    1.33 +}
    1.34 +
    1.35 +function Install()
    1.36 +{
    1.37 +    var path;
    1.38 +    path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe");
    1.39 +    WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe"
    1.40 +      + " \\\"" + WScript.ScriptFullName + "\\\""
    1.41 +      + " --post %INSTALL_PREFIX% %TEST_RESULT%\"",
    1.42 +      7, true);
    1.43 +}
    1.44 +
    1.45 +function Uninstall()
    1.46 +{
    1.47 +    var path;
    1.48 +    path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe");
    1.49 +    WshShell.Run("\"" + path + "\"" + " -u --post \"wscript.exe"
    1.50 +      + " \\\"" + WScript.ScriptFullName + "\\\"" + " --postun\"", 7, true);
    1.51 +}
    1.52 +
    1.53 +function PostInstall()
    1.54 +{
    1.55 +    var OKButton = 0, InfoIcon = 64, text;
    1.56 +    var test_result, install_prefix, path, args;
    1.57 +    install_prefix = WScript.Arguments.Item(1);
    1.58 +    test_result = WScript.Arguments.Item(2);
    1.59 +    if (test_result == "pass")
    1.60 +    {
    1.61 +	path = FileSystemObject.BuildPath(install_prefix,
    1.62 +	  "bin\\app-manager.exe");
    1.63 +	WshShell.Run("\"" + path + "\" --setup \"" + ScriptPath + "\"");
    1.64 +    }
    1.65 +    else
    1.66 +    {
    1.67 +	args = { Length:0, Item:function(){return nil} };
    1.68 +	if (RunSetup(args))
    1.69 +	{
    1.70 +	    text = "Software installation completed successfully.";
    1.71 +	    WshShell.Popup(text, 0, "Software Installation",
    1.72 +	      OKButton + InfoIcon);
    1.73 +	}
    1.74 +    }
    1.75 +}
    1.76 +
    1.77 +function PostUninstall()
    1.78 +{
    1.79 +    var args = { Length:1, Item:function(){return "-u"} };
    1.80 +    var OKButton = 0, InfoIcon = 64, text;
    1.81 +    if (RunSetup(args))
    1.82 +    {
    1.83 +	text = "Uninstall completed successfully.";
    1.84 +	WshShell.Popup(text, 0, "Uninstall", OKButton + InfoIcon);
    1.85 +    }
    1.86 +}
    1.87 +
    1.88 +if (WScript.Arguments.Length < 1)
    1.89 +    Install()
    1.90 +else if (WScript.Arguments.Item(0) == "-u")
    1.91 +    Uninstall()
    1.92 +else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post")
    1.93 +    PostInstall()
    1.94 +else if (WScript.Arguments.Item(0) == "--postun")
    1.95 +    PostUninstall()