setup/setup.js.in
author J. Ali Harlow <ali@juiblex.co.uk>
Thu Jul 16 23:02:31 2020 +0100 (2020-07-16)
changeset 101 abdfa0410032
child 106 cc42fad3fe31
permissions -rw-r--r--
Prepare to release 0.5.8
ali@24
     1
var WshShell = WScript.CreateObject("WScript.Shell");
ali@24
     2
var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, "");
ali@24
     3
var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
ali@24
     4
ali@24
     5
function RunSetup(args)
ali@24
     6
{
ali@24
     7
    var OKButton = 0, ErrorIcon = 16, ForReading = 1;
ali@24
     8
    var path, command, i, ExecObject, text;
ali@24
     9
    path = FileSystemObject.BuildPath(ScriptPath, "setup.exe");
ali@24
    10
    command = "\"" + path + "\"";
ali@24
    11
    for(i = 0; i < args.Length; i++)
ali@24
    12
	command += " \"" + args.Item(i) + "\"";
ali@24
    13
    ExecObject = WshShell.Exec(command);
ali@24
    14
    if (!ExecObject.StdErr.AtEndOfStream)
ali@24
    15
    {
ali@24
    16
	text = "Setup failed for an unexpected reason. Please report "
ali@24
    17
	  + "the following error to support@city-occupational.co.uk:\n\n"
ali@24
    18
	  + ExecObject.StdErr.ReadAll();
ali@24
    19
	WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon);
ali@24
    20
	return false;
ali@24
    21
    }
ali@24
    22
    else if (ExecObject.ExitCode)
ali@24
    23
    {
ali@24
    24
	text = "Setup failed without giving a reason. Please report "
ali@24
    25
	  + "this to support@city-occupational.co.uk";
ali@24
    26
	WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon);
ali@24
    27
	return false;
ali@24
    28
    }
ali@24
    29
    return true;
ali@24
    30
}
ali@24
    31
ali@24
    32
function Install()
ali@24
    33
{
ali@24
    34
    var path;
ali@24
    35
    path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe");
ali@24
    36
    WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe"
ali@24
    37
      + " \\\"" + WScript.ScriptFullName + "\\\""
ali@24
    38
      + " --post %INSTALL_PREFIX% %TEST_RESULT%\"",
ali@24
    39
      7, true);
ali@24
    40
}
ali@24
    41
ali@24
    42
function Uninstall()
ali@24
    43
{
ali@24
    44
    var path;
ali@24
    45
    path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe");
ali@24
    46
    WshShell.Run("\"" + path + "\"" + " -u --post \"wscript.exe"
ali@24
    47
      + " \\\"" + WScript.ScriptFullName + "\\\"" + " --postun\"", 7, true);
ali@24
    48
}
ali@24
    49
ali@24
    50
function PostInstall()
ali@24
    51
{
ali@24
    52
    var OKButton = 0, InfoIcon = 64, text;
ali@24
    53
    var test_result, install_prefix, path, args;
ali@24
    54
    install_prefix = WScript.Arguments.Item(1);
ali@24
    55
    test_result = WScript.Arguments.Item(2);
ali@24
    56
    if (test_result == "pass")
ali@24
    57
    {
ali@24
    58
	path = FileSystemObject.BuildPath(install_prefix,
ali@24
    59
	  "bin\\app-manager.exe");
ali@24
    60
	WshShell.Run("\"" + path + "\" --setup \"" + ScriptPath + "\"");
ali@24
    61
    }
ali@24
    62
    else
ali@24
    63
    {
ali@24
    64
	args = { Length:0, Item:function(){return nil} };
ali@24
    65
	if (RunSetup(args))
ali@24
    66
	{
ali@24
    67
	    text = "Software installation completed successfully.";
ali@24
    68
	    WshShell.Popup(text, 0, "Software Installation",
ali@24
    69
	      OKButton + InfoIcon);
ali@24
    70
	}
ali@24
    71
    }
ali@24
    72
}
ali@24
    73
ali@24
    74
function PostUninstall()
ali@24
    75
{
ali@24
    76
    var args = { Length:1, Item:function(){return "-u"} };
ali@24
    77
    var OKButton = 0, InfoIcon = 64, text;
ali@24
    78
    if (RunSetup(args))
ali@24
    79
    {
ali@24
    80
	text = "Uninstall completed successfully.";
ali@24
    81
	WshShell.Popup(text, 0, "Uninstall", OKButton + InfoIcon);
ali@24
    82
    }
ali@24
    83
}
ali@24
    84
ali@24
    85
if (WScript.Arguments.Length < 1)
ali@24
    86
    Install()
ali@24
    87
else if (WScript.Arguments.Item(0) == "-u")
ali@24
    88
    Uninstall()
ali@24
    89
else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post")
ali@24
    90
    PostInstall()
ali@24
    91
else if (WScript.Arguments.Item(0) == "--postun")
ali@24
    92
    PostUninstall()