自动更新Powershell脚本
拥有自我更新(从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这可以解决问题,即使有点天真。您有两个脚本 -
StartApp.ps1
,它们对更新进行任何必要的检查。运行后,然后链接MainApp.ps1
这是应用程序本身,这就是要更新的内容。StartApp.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 chainsMainApp.ps1
which is the app itself, this is what would get updated.StartApp.ps1 - kicks off app but also does the update check:
我不确定让脚本自行更新是个好主意。您可以尝试从任务计划程序中执行此操作,或者如果脚本必须执行此操作,则将其分为两部分,第一部分是用户运行的部分。保持这个小而简单。第二部分是您从 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.
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.