<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fwolf's Blog &#187; update - Fwolf's Blog</title>
	<atom:link href="http://www.fwolf.com/blog/post/tag/update/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fwolf.com/blog</link>
	<description>随心·随意·随缘·努力～</description>
	<lastBuildDate>Wed, 07 Jul 2010 07:07:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>利用SVN更新网站</title>
		<link>http://www.fwolf.com/blog/post/127</link>
		<comments>http://www.fwolf.com/blog/post/127#comments</comments>
		<pubDate>Wed, 18 Jan 2006 18:10:16 +0000</pubDate>
		<dc:creator>Fwolf</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Svn/Git]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://www.fwolf.com/blog/?p=127</guid>
		<description><![CDATA[如果你有一个假设在公网上的SVN服务器，而你的网站所在的主机允许你使用SVN客户端，并且开放了php的exec函数，那么你有福了，你可以利用SVN作为中转，更新你的网站程序。 首先，也是前提，就是你的网站程序是用SVN管理的，那么只要你的网站主机能够访问SVN，就能够使用SVN的update功能来更新程序。 准备工作一：将网站程序加上svn的控制标记，由于SVN的控制信息都存在程序所在目录的.svn子目录中，所以需要找一个空目录，并且将网站现有程序checkout到这个目录里面来，注意是checkout而不是export，因为接下来要将最新的网站程序连同他里面包含的很多个.svn目录一同上传到服务器上去。为了不让.svn目录泄露机密，要在.htaccess文件或者是httpd.conf中设定如下规则，禁止对.svn目录的访问。 &#60;directory ~ &#34;\.svn&#34;&#62; Order Allow,Deny Deny from all &#60;/directory&#62; 准备工作二：作一段小程序，调用服务器上的svn命令行命令，update网站程序，下面是一个写好了的简单例子。 //setup update target path $target_ar&#91;'fwolf'&#93; = 'd:\fwolf'; &#160; //setup commandline $svn_cmd1 = 'd:\server\svn\bin\svn.exe update '; $svn_cmd2 = ' --username updatebot --password xxxxxx --no-auth-cache'; &#160; //output html string $html = ''; &#160; //recieve get parameter $target = isset&#40;$_GET&#91;'target'&#93;&#41; ? $_GET&#91;'target'&#93; : ''; if [...]]]></description>
			<content:encoded><![CDATA[<p>如果你有一个假设在公网上的SVN服务器，而你的网站所在的主机允许你使用SVN客户端，并且开放了php的exec函数，那么你有福了，你可以利用SVN作为中转，更新你的网站程序。</p>

<p><strong>首先，也是前提</strong>，就是你的网站程序是用SVN管理的，那么只要你的网站主机能够访问SVN，就能够使用SVN的update功能来更新程序。</p>

<p><strong>准备工作一</strong>：将网站程序加上svn的控制标记，由于SVN的控制信息都存在程序所在目录的.svn子目录中，所以需要找一个空目录，并且将网站现有程序checkout到这个目录里面来，注意是checkout而不是export，因为接下来要将最新的网站程序连同他里面包含的很多个.svn目录一同上传到服务器上去。为了不让.svn目录泄露机密，要在.htaccess文件或者是httpd.conf中设定如下规则，禁止对.svn目录的访问。</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">	&lt;directory ~ <span style="color: #933;">&quot;\.svn&quot;</span>&gt;
		Order Allow,Deny
		Deny from all
	&lt;/directory&gt;</pre></div></div>


<p><strong>准备工作二</strong>：作一段小程序，调用服务器上的svn命令行命令，update网站程序，下面是一个写好了的简单例子。</p>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #666666; font-style: italic;">//setup update target path</span>
	<span style="color: #000088;">$target_ar</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fwolf'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'d:\fwolf'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//setup commandline</span>
	<span style="color: #000088;">$svn_cmd1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'d:\server\svn\bin\svn.exe update '</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$svn_cmd2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' --username updatebot --password xxxxxx --no-auth-cache'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//output html string</span>
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>	
&nbsp;
	<span style="color: #666666; font-style: italic;">//recieve get parameter</span>
	<span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'target'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'target'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target_ar</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Target does not correct.'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//execute svn update command</span>
		<span style="color: #000088;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$svn_cmd1</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target_ar</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$svn_cmd2</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$ar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ar</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$ar</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ar</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Status: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$html</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;br /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span></pre></div></div>


<p>把这个程序放到服务器上能够访问到的地方，也可以在此基础上加上一些访问限制，那么只要访问这个程序/页面，服务器就会自动更新你的网站啦。</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">	Status: <span style="color: #000000;">0</span>
	D H:\cvswork\svntest\update_from_svn.php
	Updated to revision 44.</pre></div></div>


<p>这样，在利用SVN很好的管理网站程序的基础上，还实现了服务器程序的很方便的更新，一举两得！尤其是在程序上传不是十分方便的场合，用起来就更舒服了，我就是在更换了一个劣质防火墙，ftp无法正常使用的情况下想出这个怪招儿的:-)。</p>

<h4>Update @ 2007-07-31</h4>

<p>如果在windows主机上使用本方法，而svn服务器是采用了ssl的https://&#8230;地址，那么会遇到一点小麻烦，就是在执行<code>svn update</code>的时候，由于使用的是web的用户，在出现确认证书的提示信息时，用户是无法输入的：</p>

<pre><code>Error validating server certificate for 'https://20070731.fwolf.com':
 - The certificate is not issued by a trusted authority. Use the
   fingerprint to validate the certificate manually!
Certificate information:
 - Hostname: 20070731.fwolf.com
 - Valid: from Jul 31 06:49:53 2007 GMT until Jul 28 06:49:53 2017 GMT
 - Issuer: Fwolf, US
 - Fingerprint: 38:43:0b:29:75:1t:ba:d8:29:8f:94:9a:10:42:a0:fe:ae:93:4d:91
(R)eject, accept (t)emporarily or accept (p)ermanently?
</code></pre>

<p>这时就只能用变通的方法了，首先在dos方式中使用<code>svn up</code>，svn会自动缓存身份验证以及ssl确认信息，这些信息保存在<code>C:\Documents and Settings\Administrator\Application Data\Subversion</code>目录下，然后把这个目录整体拷贝到<code>C:\Documents and Settings\Default User\Application Data\Subversion</code>就可以了，测试环境windows2003，并且试过复制到<code>All Users</code>的对应目录无效。</p>

<p>另外修改配置文件<code>servers</code>，添加<code>ssl-trust-default-ca = yes</code>的方式在windows下好像没有作用。</p>

<h4>Update @ 2009-04-07</h4>

<p>Git（ssh证书登录）也可以这样用，略有不同，我使用的客户端是<a href="http://code.google.com/p/msysgit">msysgit</a>：</p>

<ul>
<li>Admin用户使用桌面操作(Git Bash)时，<code>.ssh</code>目录位于<code>C:\Documents and Settings\Administrator\</code>下。</li>
<li>直接使用<code>C:\Program Files\Git\bin\ssh.exe</code>当ssh客户端时，<code>.ssh</code>目录要放到<code>C:\Program Files\Git\</code>下，并且似乎忽略<code>.ssh/config</code>文件，私钥文件只认<code>identity id_rsa id_dsa</code>三个。</li>
<li>系统服务比如Apache运行时，使用上面一条的设置，很是诡异。</li>
</ul>

<p>说公钥文件只认固定的三个，是从这里猜到的：</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">	Program Files<span style="color: #000000; font-weight: bold;">/</span>Git$ <span style="color: #c20cb9; font-weight: bold;">grep</span> identity share <span style="color: #660033;">-R</span>
	share<span style="color: #000000; font-weight: bold;">/</span>git-gui<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>sshkey.tcl:   foreach name <span style="color: #7a0874; font-weight: bold;">&#123;</span>~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_dsa.pub ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>identity.pub<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span></pre></div></div>


<p>好像是写死了，并且我用config定义其他私钥它也不认。第一条中使用Git的时候没事，很正常。</p>

<p>同时，为了安全起见，apache里还要增加如下设置：</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">	&lt;Directory ~ <span style="color: #933;">&quot;\.(git|svn)&quot;</span>&gt;
		Order allow,deny
		Deny from all
		Satisfy All
	&lt;/Directory&gt;</pre></div></div>


	Tags: <a href="http://www.fwolf.com/blog/post/tag/apache" title="Apache" rel="tag">Apache</a>, <a href="http://www.fwolf.com/blog/post/tag/git" title="git" rel="tag">git</a>, <a href="http://www.fwolf.com/blog/post/tag/php" title="PHP" rel="tag">PHP</a>, <a href="http://www.fwolf.com/blog/post/tag/svn" title="svn" rel="tag">svn</a>, <a href="http://www.fwolf.com/blog/post/tag/update" title="update" rel="tag">update</a>, <a href="http://www.fwolf.com/blog/post/tag/www" title="www" rel="tag">www</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.fwolf.com/blog/post/429" title="Git起步 (2009-03-26)">Git起步</a> (6)</li>
	<li><a href="http://www.fwolf.com/blog/post/443" title="配置安全的共享web服务器（抛砖引玉） (2009-06-09)">配置安全的共享web服务器（抛砖引玉）</a> (4)</li>
	<li><a href="http://www.fwolf.com/blog/post/411" title="由一个错误学到的一些php安全配置问题 (2008-07-13)">由一个错误学到的一些php安全配置问题</a> (4)</li>
	<li><a href="http://www.fwolf.com/blog/post/347" title="升级MT dv 3.0主机到php5 (2007-08-09)">升级MT dv 3.0主机到php5</a> (9)</li>
	<li><a href="http://www.fwolf.com/blog/post/395" title="防止垃圾评论的另类方法 (2008-04-10)">防止垃圾评论的另类方法</a> (6)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.fwolf.com/blog/post/127/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
