--- wpkg/wpkg-0.9.2/wpkg.js 2005-12-09 16:15:53.000000000 -0500 +++ wpkg.js 2006-02-03 15:46:30.000000000 -0500 @@ -946,8 +946,9 @@ } } else if (checkType == "file") { if (checkCond == "exists") { + var wso = new ActiveXObject("wScript.shell") var fso = new ActiveXObject("Scripting.FileSystemObject"); - if (fso.FileExists(checkPath)) { + if (fso.FileExists( wso.expandEnvironmentStrings(checkPath) )) { return true; } } else { @@ -1019,85 +1020,148 @@ return installed; } - -/** - * Executes command of the package and registers this fact. - */ -function executeOnce(packageNode) { - var packageName = packageNode.getAttribute("name"); - - info("Executing commands for " + packageName + "..."); - - // select command lines to install - var cmds = packageNode.selectNodes("install"); - - // execute each command line - for (var i = 0; i < cmds.length; i++) { - var cmdNode = cmds(i); - var cmd = cmdNode.getAttribute("cmd"); - var timeout = cmdNode.getAttribute("timeout"); - - if (timeout == null) { - timeout = 0; - } else { - timeout = parseInt(timeout); - } - - try { - - if (debug) { info("executing command : " + cmd); } - var result = 0; - result = exec(cmd, timeout); - if (debug) { info("command returned result: " + result); } - - // if exit code is 0, return successfully - if (result == 0) { - continue; - } - - // search for exit code - var exitNode = cmdNode.selectSingleNode("exit[@code='" + - result + "']"); - - // check for special exit codes - if (exitNode != null) { - if (exitNode.getAttribute("reboot") == "true") { - // this exit code forces a reboot - info("Command of " + packageName + - " returned non-zero exit code [" + result + "]. This " + - "exit code requires an immediate reboot."); - reboot(); - } else { - // this exit code is successful - info("Command of " + packageName + - " returned non-zero exit code [" + result + "]. This " + - "exit code is not an error."); - continue; - } - } - - // command did not succeed, throw error - throw new Error(0, "Exit code returned non-successful value: " + - result + ".\n\n" + cmd); - } catch (e) { - throw new Error("Could not execute " + packageName + ". " + - e.description); - } - } - - // append new node to local xml - settings.appendChild(packageNode); - saveXml(settings, settings_file); - - // reboot the system if this package is suppose to - if (packageNode.getAttribute("reboot") == "true") { - info("Execution of commands of " + packageName + " successful, system " + - "rebooting."); - reboot(); - } else { - info("Execution of " + packageName + " successful."); - } -} + +/** Run through the install nodes and execute the actual installation + * cmds is all the install nodes, ie. packageNode.selectNodes("install") + * packageName is the name of the package + * installType one of "install", "upgrade" or "execute" + */ +function runInstall(cmds, packageName, installType) { + // execute each command line + for (var i = 0; i < cmds.length; i++) { + var cmdNode = cmds(i); + var timeout = cmdNode.getAttribute("timeout"); + + if (timeout == null) { + timeout = 0; + } else { + timeout = parseInt(timeout); + } + + + var cmd = cmdNode.getAttribute("cmd"); + if (cmd != null) { + + try { + + + if (debug) { info("executing command : " + cmd); } + + var result = 0; + result = exec(cmd, timeout); + if (debug) { info("command returned result: " + result); } + + // if exit code is 0, return successfully + if (result == 0) { + continue; + } + + // search for exit code + var exitNode = cmdNode.selectSingleNode("exit[@code='" + + result + "']"); + + if (installType == "upgrade") { + // if found, command was successful + if (exitNode != null) { + info("Command in upgrade of " + packageName + " returned " + + "non-zero exit code [" + result + "]. This exit code " + + "is not an error."); + continue; + } + } + + // check for special exit codes + if (exitNode != null) { + if (exitNode.getAttribute("reboot") == "true") { + // this exit code forces a reboot + info("Command in " + installType + " of " + packageName + + " returned non-zero exit code [" + result + "]. This " + + "exit code requires an immediate reboot."); + reboot(); + } else { + // this exit code is successful + info("Command in " + installType + " of " + packageName + + " returned non-zero exit code [" + result + "]. This " + + "exit code is not an error."); + continue; + } + } + + // command did not succeed, throw error + throw new Error(0, "Exit code returned non-successful value: " + + result + ".\n\n" + cmd); + } catch (e) { + throw new Error("Could not " + installType + " " + packageName + ". " + + e.description); + } + + // command successful, skip to the next install node + continue; + } + + var src = cmdNode.getAttribute("src"); + var dest = cmdNode.getAttribute("dest"); + if ((src != null) && (dest != null)) { + var wso = new ActiveXObject("wScript.shell"); + var fso = new ActiveXObject("Scripting.FileSystemObject"); + + // Only turn overwrite off if specifically requested + var overwrite = !(cmdNode.getAttribute("overwrite") == "no" || cmdNode.getAttribute("overwrite") == "false"); + + info("copying from " + wso.expandEnvironmentStrings(src) + " to " + wso.expandEnvironmentStrings(dest) + "overwrite: " + overwrite) + if (debug) { + info("copying from " + wso.expandEnvironmentStrings(src) + " to " + wso.expandEnvironmentStrings(dest) + "overwrite: " + overwrite) + } + + try { + // create the folder if it doesn't exist already + if (!fso.FolderExists(wso.expandEnvironmentStrings(dest))) { + fso.CreateFolder(wso.expandEnvironmentStrings(dest)); + } + + // now copy the contents of src to dest + fso.CopyFolder(wso.expandEnvironmentStrings(src), wso.expandEnvironmentStrings(dest), overwrite) + } catch(e) { + throw new Error("Could not " + installType + " " + packageName + ". " + e.message); + } + + // copy successful, skip to the next install node + continue; + } + + // if we got here, no install commands were found + throw new Error("No valid operation found in an " + installType + " command for " + packageName + ". " + + e.description); + } +} + +/** + * Executes command of the package and registers this fact. + */ +function executeOnce(packageNode) { + var packageName = packageNode.getAttribute("name"); + + info("Executing commands for " + packageName + "..."); + + // select command lines to install + var cmds = packageNode.selectNodes("install"); + + // run the install code + runInstall(cmds, "execute"); + + // append new node to local xml + settings.appendChild(packageNode); + saveXml(settings, settings_file); + + // reboot the system if this package is suppose to + if (packageNode.getAttribute("reboot") == "true") { + info("Execution of commands of " + packageName + " successful, system " + + "rebooting."); + reboot(); + } else { + info("Execution of " + packageName + " successful."); + } +} /** @@ -1126,63 +1190,10 @@ // select command lines to install var cmds = packageNode.selectNodes("install"); + + // run the install code + runInstall(cmds, packageName, "install") - // execute each command line - for (var i = 0; i < cmds.length; i++) { - var cmdNode = cmds(i); - var cmd = cmdNode.getAttribute("cmd"); - var timeout = cmdNode.getAttribute("timeout"); - - if (timeout == null) { - timeout = 0; - } else { - timeout = parseInt(timeout); - } - - try { - - - if (debug) { info("executing command : " + cmd); } - - var result = 0; - result = exec(cmd, timeout); - if (debug) { info("command returned result: " + result); } - - // if exit code is 0, return successfully - if (result == 0) { - continue; - } - - // search for exit code - var exitNode = cmdNode.selectSingleNode("exit[@code='" + - result + "']"); - - // check for special exit codes - if (exitNode != null) { - if (exitNode.getAttribute("reboot") == "true") { - // this exit code forces a reboot - info("Command in installation of " + packageName + - " returned non-zero exit code [" + result + "]. This " + - "exit code requires an immediate reboot."); - reboot(); - } else { - // this exit code is successful - info("Command in installation of " + packageName + - " returned non-zero exit code [" + result + "]. This " + - "exit code is not an error."); - continue; - } - } - - // command did not succeed, throw error - throw new Error(0, "Exit code returned non-successful value: " + - result + ".\n\n" + cmd); - } catch (e) { - throw new Error("Could not install " + packageName + ". " + - e.description); - } - } - if (!checkInstalled(packageNode)) { throw new Error("Could not install " + packageName + ". " + "Failed checking after installation."); @@ -1213,67 +1224,8 @@ // select command lines to install var cmds = newPackageNode.selectNodes("upgrade"); - // execute each command line - for (var i = 0; i < cmds.length; i++) { - var cmdNode = cmds(i); - var cmd = cmdNode.getAttribute("cmd"); - var timeout = cmdNode.getAttribute("timeout"); - - if (timeout == null) { - timeout = 0; - } else { - timeout = parseInt(timeout); - } - - try { - if (debug) { info("executing command : " + cmd); } - var result = 0; - result = exec(cmd, timeout); - if (debug) { info("command returned result: " + result); } - - - // if exit code is 0, return successfully - if (result == 0) { - continue; - } - - // search for exit code - var exitNode = cmdNode.selectSingleNode("exit[@code='" + result + - "']"); - - // if found, command was successful - if (exitNode != null) { - info("Command in upgrade of " + packageName + " returned " + - "non-zero exit code [" + result + "]. This exit code " + - "is not an error."); - continue; - } - - // check for special exit codes - if (exitNode != null) { - if (exitNode.getAttribute("reboot") = "true") { - // this exit code forces a reboot - info("Command in upgrade of " + packageName + " returned " + - "non-zero exit code [" + result + "]. This exit code " + - "requires an immediate reboot."); - reboot(); - } else { - // this exit code is successful - info("Command in upgrade of " + packageName + " returned " + - "non-zero exit code [" + result + "]. This exit code " + - "is not an error."); - continue; - } - } - - // command did not succeed, throw error - throw new Error(0, "Exit code returned non-successful value: " + - result + ".\n\n" + cmd); - } catch (e) { - throw new Error("Could not upgrade " + packageName + ". " + - e.description); - } - } + // run the install code + runInstall(cmds, "upgrade"); if (!checkInstalled(newPackageNode)) {