Self Updating Powershell脚本

问题描述:

什么是自我更新(来自SVN)Powershell脚本的最佳方式?Self Updating 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 
} 

我以为这会做伎俩,即使有点天真。您有两个脚本 - 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 

我不知道有脚本更新自己是个好主意。您可以尝试从Task Scheduler中执行此操作,或者脚本必须执行此操作,然后将其分成两部分,第一部分是用户运行的部分。保持这个小而简单。第二部分是你更新svn的内容,它应该完成大部分工作。

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

+0

我试图让它自成一体。我可以创建一个主脚本来调用主脚本,但那时需要手动更新。 – Glennular 2011-04-13 13:53:00

+0

您可能会让脚本调用“at”调度程序来执行更新。它做一次性调度。键入“at /?”在命令提示符处寻求帮助。 – WebWeasel 2011-04-13 16:51:14

1)测试,需要进行更新。如果不需要,停止。

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

3)副本进行更新脚本原来的名称

4)检查副本。大小,校验和等等。你仍然有机会在这里恢复。

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

如果您需要管理员权限来覆盖脚本,则可能需要找出高程。如果你总是以提升的特权运行,那应该不重要。