自动更新Powershell脚本

发布于 2024-11-01 03:37:21 字数 318 浏览 0 评论 0原文

拥有自我更新(从 SVN)Powershell 脚本的最佳方式是什么?

它应该能够启动一个新进程,然后调用 SVN update $script; './$script',在确保当前进程已结束后。

if ((svn st -u --quiet $script) -match "\*"){
     $scriptToRun = 'SVN update $script; "./$script"'
     ##start new process that will end this process and execute $scriptToRun
}

What would be the best way to have a self updating (from SVN) Powershell script?

It should be able to start a new process and then call SVN update $script; './$script', after making sure the current process has ended.

if ((svn st -u --quiet $script) -match "\*"){
     $scriptToRun = 'SVN update $script; "./$script"'
     ##start new process that will end this process and execute $scriptToRun
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄人书 2024-11-08 03:37:21

我认为这可以解决问题,即使有点天真。您有两个脚本 - StartApp.ps1,它们对更新进行任何必要的检查。运行后,然后链接 MainApp.ps1 这是应用程序本身,这就是要更新的内容。

StartApp.ps1 - 启动应用程序,但也会进行更新检查:

# Bootstrap app
#
# Check for updates here

if(some_check_to_determine_if_update_required)
{
    # Execute whatever external source control commands required but wait until 
    # done:
    Start-Process -Wait -FilePath "<path_to_svn>" -ArgumentList <args_you_need>
}

# Launch the (now possibly updated) app
.\MainApp.ps1

I thought this would do the trick, even if a little naive. You have two scripts - StartApp.ps1 which does any necessary checks for updates. After running it then chains MainApp.ps1 which is the app itself, this is what would get updated.

StartApp.ps1 - kicks off app but also does the update check:

# Bootstrap app
#
# Check for updates here

if(some_check_to_determine_if_update_required)
{
    # Execute whatever external source control commands required but wait until 
    # done:
    Start-Process -Wait -FilePath "<path_to_svn>" -ArgumentList <args_you_need>
}

# Launch the (now possibly updated) app
.\MainApp.ps1
盛夏尉蓝 2024-11-08 03:37:21

我不确定让脚本自行更新是个好主意。您可以尝试从任务计划程序中执行此操作,或者如果脚本必须执行此操作,则将其分为两部分,第一部分是用户运行的部分。保持这个小而简单。第二部分是您从 svn 更新的内容,它应该完成大部分工作。

基本上是处理参数和自动更新的小型用户脚本。第二部分完成大部分工作并自动更新。

I'm not sure it's a good idea to have a script update itself. You might try doing it from the Task Scheduler or if the script must do it then break it into 2 parts the first one is what the user runs. Keep this small and simple. The second part is what you update out of svn and it should do the bulk of the work.

Basically small user script that handles arguments and autoupdate. Second part that does the bulk of the work and gets autoupdated.

别靠近我心 2024-11-08 03:37:21

1)测试是否需要更新。如果不需要就停止。

2) 重命名您的执行脚本文件。

3) 将更新后的脚本复制到原始名称

4) 验证副本。大小、校验和之类的。你还有机会在这里康复。

5) 执行新脚本并退出正在运行的脚本。

如果您需要管理员权限来覆盖脚本,您可能必须计算出海拔高度。如果您总是以更高的权限运行,那应该不重要。

1) Test if update is required. Stop if not needed.

2) Rename your executing script file.

3) Copy updated script to the original name

4) VERIFY copy. size, checksum, something. You still have a chance to recover here.

5) Execute the new script and exit running one.

You may have to figure out elevation if you need admin rights to overwrite the script. If you always run with elevated privileges, that shouldn't matter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文