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