Install4j:运行 用于回滚操作的批处理文件/脚本文件
Install4j: run batch file/ script file for rollback action
在 linux 中,我希望我的更新程序 运行 用于回滚操作的脚本文件(实际上是将某些文件权限更改为另一个用户而不是 root)。所以,我能想到的可能方法是:
使用操作:"Run executable or batch file" 执行回滚和 运行 脚本,因为它使用 root 权限。
在执行回滚操作时,运行 脚本或调用已创建 "Run executable or batch file" 的任何方法都具有来自 InstallerEventListener
的根权限。
在回滚操作中使用ProcessBuilder
(我已经将其用于正常操作)
但是在 install4j 文档中我找不到任何可以帮助我做到这一点的方法。我正在阅读有关 InstallerContext.runElevated 的文档,但它似乎不是我要找的东西。
更新:
结果直接 运行 使用 ProcessBuilder
在 "run script" 操作中使用具有最大提升权限(root)的脚本完成任务。但我仍然有兴趣知道事件监听器是否有可能从中触发一个动作。
在事件侦听器代码中,您可以像这样以编程方式运行操作:
import com.install4j.runtime.beans.actions.misc.*;
RunExecutableAction action = new RunExecutableAction();
action.setExecutable(...);
action.setWorkingDirectory(...);
// other configuration
action.execute(context);
要以最大权限执行它,请执行如下操作:
context.runElevated(new RemoteCallable() {
@Override
public Serializable execute() {
RunExecutableAction action = new RunExecutableAction();
action.setExecutable(...);
action.setWorkingDirectory(...);
// other configuration
return action.execute(context);
}
}, true);
在 linux 中,我希望我的更新程序 运行 用于回滚操作的脚本文件(实际上是将某些文件权限更改为另一个用户而不是 root)。所以,我能想到的可能方法是:
使用操作:"Run executable or batch file" 执行回滚和 运行 脚本,因为它使用 root 权限。
在执行回滚操作时,运行 脚本或调用已创建 "Run executable or batch file" 的任何方法都具有来自
InstallerEventListener
的根权限。在回滚操作中使用
ProcessBuilder
(我已经将其用于正常操作)
但是在 install4j 文档中我找不到任何可以帮助我做到这一点的方法。我正在阅读有关 InstallerContext.runElevated 的文档,但它似乎不是我要找的东西。
更新:
结果直接 运行 使用 ProcessBuilder
在 "run script" 操作中使用具有最大提升权限(root)的脚本完成任务。但我仍然有兴趣知道事件监听器是否有可能从中触发一个动作。
在事件侦听器代码中,您可以像这样以编程方式运行操作:
import com.install4j.runtime.beans.actions.misc.*;
RunExecutableAction action = new RunExecutableAction();
action.setExecutable(...);
action.setWorkingDirectory(...);
// other configuration
action.execute(context);
要以最大权限执行它,请执行如下操作:
context.runElevated(new RemoteCallable() {
@Override
public Serializable execute() {
RunExecutableAction action = new RunExecutableAction();
action.setExecutable(...);
action.setWorkingDirectory(...);
// other configuration
return action.execute(context);
}
}, true);