scratch/output/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/index.html

459 lines
17 KiB
HTML
Raw Normal View History

2011-04-20 12:29:01 +00:00
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="Apple, mobileme, WebDav, synchronisation, zsh, script">
<link rel="shortcut icon" type="image/x-icon" href="/Scratch/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/Scratch/assets/css/main.css" />
2012-04-02 21:43:39 +00:00
<link rel="stylesheet" type="text/css" href="/Scratch/css/solarized.css" />
<link rel="stylesheet" type="text/css" href="/Scratch/css/idc.css" />
2012-05-02 15:43:56 +00:00
<link href='http://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
2011-04-20 12:29:01 +00:00
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/yannespositocomen"/>
<link rel="alternate" lang="fr" xml:lang="fr" title="Synchronisation avec mobileme (2)" type="text/html" hreflang="fr" href="/Scratch/fr/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/" />
<link rel="alternate" lang="en" xml:lang="en" title="custom website synchronisation with mobileme (2)" type="text/html" hreflang="en" href="/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/" />
<script type="text/javascript" src="/Scratch/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="/Scratch/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/Scratch/js/index.js"></script>
2012-05-02 15:43:56 +00:00
<script type="text/javascript" src="/Scratch/js/highlight/highlight.pack.js"></script>
<script type="text/javascript" src="/Scratch/js/article.js"></script>
2011-04-20 12:29:01 +00:00
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<title>custom website synchronisation with mobileme (2)</title>
</head>
2011-10-18 22:30:00 +00:00
<body lang="en" class="article">
2011-04-20 12:29:01 +00:00
<script type="text/javascript">// <![CDATA[
document.write('<div id="blackpage"><img src="/Scratch/img/loading.gif" alt="loading..."/></div>');
2011-04-20 12:29:01 +00:00
// ]]>
</script>
<div id="content">
<div id="choix">
<div class="return"><a href="#entete">&darr; Menu &darr;</a></div>
<div id="choixlang">
<a href="/Scratch/fr/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/" onclick="setLanguage('fr')">en Français</a>
2011-04-20 12:29:01 +00:00
</div>
2011-09-28 16:05:55 +00:00
<div class="flush"></div>
2011-04-20 12:29:01 +00:00
</div>
<div id="titre">
<h1>
custom website synchronisation with mobileme (2)
</h1>
</div>
<div class="flush"></div>
<div class="flush"></div>
<div id="afterheader">
<div class="corps">
2011-04-20 14:52:33 +00:00
<p>I already talked about how <a href="/Scratch/en/blog/10_Synchronize_Custom_WebSite_with_mobileMe">I synchronized my website with mobileme</a>. I ameliorated this script in order to make it incremental.</p>
2011-04-20 12:29:01 +00:00
<p>Here is my new script, it first create a map which associate to each file its hash. After that it compare this file to the remote one. Then for each different file, update the content.</p>
2012-05-03 09:21:34 +00:00
<p>Even with this script I also have some problem. Mostly due to &lsquo;webdav&rsquo; issues. For example, renaming a folder work really badly (on Linux at least). I use webdavfs. For example:</p>
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
<div>
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
<pre><code class="zsh">mv folder folder2
</code></pre>
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
</div>
2012-05-03 09:21:34 +00:00
<p>It returns OK and I&rsquo;ve got: </p>
2012-05-02 15:43:56 +00:00
<div>
<pre><code class="zsh">$ ls
2011-04-20 12:29:01 +00:00
folder folder2
2012-05-02 15:43:56 +00:00
</code></pre>
</div>
2012-05-03 09:21:34 +00:00
<p>Booh&hellip;.</p>
2011-04-20 12:29:01 +00:00
2012-05-03 09:21:34 +00:00
<p>In order to handle most webdav issues I use a <em>framework</em> in zsh. It handle almost all except the correct renaming of folder. Working on it&hellip; Anyway here is the code I use.</p>
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
<div><div class="codefile"><a href="/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/code/webdav-framework">&#x27A5; webdav-framework</a></div>
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
<pre><code class="zsh">#!/usr/bin/env zsh
2011-04-20 12:29:01 +00:00
function samelineprint {
2012-05-02 15:43:56 +00:00
print -n -P -- "\r$*"
2011-04-20 12:29:01 +00:00
}
2012-05-02 15:43:56 +00:00
# avec 1 essai par seconde: 300 = 5 minutes
2011-04-20 12:29:01 +00:00
maxessais=300
2012-05-02 15:43:56 +00:00
# try to create a directory until success
2011-04-20 12:29:01 +00:00
function trymkdir {
2012-05-02 15:43:56 +00:00
target="$1"
print -- mkdir -p $target
2011-04-20 12:29:01 +00:00
local essai=1
2012-05-02 15:43:56 +00:00
while ! mkdir -p $target; do
samelineprint "Echec: essai n°$essai"
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
print
}
2012-05-02 15:43:56 +00:00
# try to copy until success
2011-04-20 12:29:01 +00:00
function trycp {
2012-05-02 15:43:56 +00:00
element="$1"
target="$2"
if [[ ! -d ${target:h} ]]; then
trymkdir ${target:h}
fi
2011-04-20 12:29:01 +00:00
local essai=1
2012-05-02 15:43:56 +00:00
print -- cp $element $target
while ! \cp $element $target; do
samelineprint "Echec: essai n°$essai"
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
print
}
2012-05-02 15:43:56 +00:00
# try to remove until success
2011-04-20 12:29:01 +00:00
function tryrm {
2012-05-02 15:43:56 +00:00
target="$1"
2011-04-20 12:29:01 +00:00
local essai=1
2012-05-02 15:43:56 +00:00
local options=''
[[ -d $target ]] &amp;&amp; options='-rf'
print -- rm $options $target
while ! rm $options $target; do
samelineprint "Echec: essai n°$essai"
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
essai=1
2012-05-02 15:43:56 +00:00
while [[ -e $element ]]; do
samelineprint "rm reussi mais fichier source non disparu n°$essai"
2011-04-20 12:29:01 +00:00
sleep 1
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
print
}
2012-05-02 15:43:56 +00:00
# try to rename until success
2011-04-20 12:29:01 +00:00
function tryrename {
2012-05-02 15:43:56 +00:00
element="$1"
target="$2"
2011-04-20 12:29:01 +00:00
local essai=1
2012-05-02 15:43:56 +00:00
while [[ -e $target ]]; do
samelineprint "Echec n°$essai le fichier $target existe déjà"
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
2011-04-20 12:29:01 +00:00
sleep 1
2012-05-02 15:43:56 +00:00
done
print -- mv $element $target
while ! mv $element $target; do
samelineprint "Echec: essai n°$essai"
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 4
done
2011-04-20 12:29:01 +00:00
essai=1
2012-05-02 15:43:56 +00:00
while [[ -e $element ]]; do
samelineprint "mv reussi mais fichier source non disparu n°$essai"
2011-04-20 12:29:01 +00:00
sleep 1
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
print
}
2012-05-02 15:43:56 +00:00
# try to move until success
2011-04-20 12:29:01 +00:00
function trymv {
2012-05-02 15:43:56 +00:00
element="$1"
target="$2"
2011-04-20 12:29:01 +00:00
local essai=1
2012-05-02 15:43:56 +00:00
print -- mv $element $target
while ! mv $element $target; do
samelineprint "Echec: essai n°$essai"
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
essai=1
2012-05-02 15:43:56 +00:00
while [[ -e $element ]]; do
samelineprint "mv reussi mais fichier source non disparu n°$essai"
2011-04-20 12:29:01 +00:00
sleep 1
((essai++))
2012-05-02 15:43:56 +00:00
((essai&gt;maxessais)) &amp;&amp; exit 5
done
2011-04-20 12:29:01 +00:00
print
}
2012-05-02 15:43:56 +00:00
</code></pre>
</div>
2011-04-20 12:29:01 +00:00
<p>And here is the code on how I synchronize my website. There is a little cryptic code. It correspond a problem caused by the bluecloth filter which is a markdown program made in ruby. Each time my email is written it is transformed differently. This is why I remove this part from the content of each html file. Without it, all my files containing email are different at each regeneration of my website.</p>
2012-05-02 15:43:56 +00:00
<div><div class="codefile"><a href="/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/code/publish">&#x27A5; publish</a></div>
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
<pre><code class="zsh">#!/usr/bin/env zsh
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
# Script synchronisant le site sur me.com
# normalement, le site est indisponible le moins de temps possible
# le temps de deux renommages de répertoire
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
# get configuration
# mostly directories
source $0:h/config
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
# get trycp function (copy until success)
source $0:h/webdav-framework
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
if [[ $1 == '-h' ]]; then
print -- "usage : $0:h [-h|-s|-d]"
print -- " -a sychronise aussi l'index"
print -- " -h affiche l'aide"
print -- " -d modification directe (pas de swap)"
print -- " -s swappe simplement les répertoires"
fi
# publication incrementale
2011-04-20 12:29:01 +00:00
function incrementalPublish {
2012-05-02 15:43:56 +00:00
local ydestRep=$destRep$suffix
localRef="$srcRep/map.yrf"
print -- "Creation du fichier de references"
create-reference-file.sh &gt; $localRef
remoteRef="/tmp/remoteSiteMapRef.$$.yrf"
if [[ ! -e "$ydestRep/map.yrf" ]]; then
# pas de fichier de reference sur la cible
print -- "pas de fichier de reference sur la cible, passage en mode rsync"
2011-04-20 12:29:01 +00:00
rsyncPublish
swap
2012-05-02 15:43:56 +00:00
else
trycp "$ydestRep/map.yrf" "$remoteRef"
2011-04-20 12:29:01 +00:00
typeset -U filesToUpdate
2012-05-02 15:43:56 +00:00
filesToUpdate=( $(diff $localRef $remoteRef | awk '/^[&lt;&gt;]/ {print $2}' ) )
if ((${#filesToUpdate} == 1)); then
print -- "Seul le fichier ${filesToUpdate} sera téléversé"
elif ((${#filesToUpdate}&lt;10)); then
print -- "${#filesToUpdate} fichiers seront téléversés :"
print -- "${filesToUpdate}"
else
print -- "${#filesToUpdate} fichiers seront téléversés"
fi
# copy all file with some differences
# except the map in case of error
for element in $filesToUpdate; do
if [[ $element == "/map.yrf" ]]; then
continue
fi
if [[ -e $srcRep$element ]]; then
trycp $srcRep$element $ydestRep$element
else
tryrm $ydestRep$element
fi
done
# if all went fine, copy the map file
trycp $srcRep/map.yrf $ydestRep/map.yrf
# remove the temporary file
\rm $remoteRef
# if we have used the tmp directory we swap
if [[ "$suffix" != "" ]]; then
2011-04-20 12:29:01 +00:00
swap
2012-05-02 15:43:56 +00:00
fi
fi
2011-04-20 12:29:01 +00:00
}
2012-05-02 15:43:56 +00:00
# publication via rsync
2011-04-20 12:29:01 +00:00
function rsyncPublish {
result=1
essai=1
2012-05-02 15:43:56 +00:00
while (( $result &gt; 0 )); do
print -- rsync -arv $srcRep/ $destRep.tmp
if ((!testmode)); then
rsync -arv $srcRep/ $destRep.tmp
fi
result=$?
if (( $result &gt; 0 )); then
print -P -- "%BEchec du rsync%b (essai n°$essai)" &gt;&amp;2
fi
2011-04-20 12:29:01 +00:00
((essai++))
2012-05-02 15:43:56 +00:00
done
2011-04-20 12:29:01 +00:00
}
2012-05-02 15:43:56 +00:00
# swap
2011-04-20 12:29:01 +00:00
function swap {
2012-05-02 15:43:56 +00:00
print -P -- "%B[Directory Swap (tmp &lt;=&gt; target)]%b"
[[ -e $destRep.old ]] &amp;&amp; tryrm $destRep.old
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
print -- " renommage du repertoire sandard vers le .old"
tryrename $destRep $destRep.old
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
print -- " renommage du repertoire tmp (nouveau) vers le standard"
print -P -- "%B[Site Indisponible]%b $(date)"
tryrename $destRep.tmp $destRep
print -P -- "%B[Site Disponible]%b $(date)"
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
print -- " renommage du repertoire old vers le tmp"
tryrename $destRep.old $destRep.tmp
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
print -P -- " publication terminée"
2011-04-20 12:29:01 +00:00
}
2012-05-02 15:43:56 +00:00
print -- "Root = $webroot"
print -- "Dest = $destRep"
2011-04-20 12:29:01 +00:00
2012-05-02 15:43:56 +00:00
if [[ "$1" = "-s" ]]; then
2011-04-20 12:29:01 +00:00
swap
2012-05-02 15:43:56 +00:00
else
if [[ "$1" = "-d" ]]; then
suffix=""
else
suffix=".tmp"
fi
print -P -- "%BSync%b[${Root:t} =&gt; ${destRep:t}$suffix]"
2011-04-20 12:29:01 +00:00
incrementalPublish
2012-05-02 15:43:56 +00:00
fi
</code></pre>
</div>
2011-04-20 12:29:01 +00:00
<p>This is my way to replace <code>rsync</code> with filesystem not handling it.
2012-05-03 09:21:34 +00:00
Hope it is usefull. I&rsquo;ll be happy to hear a way to handle the webdav rename folder problem. This is really annoying.</p>
2011-04-20 12:29:01 +00:00
</div>
2012-04-10 13:56:34 +00:00
<div id="social">
<div class="left"> <a href="https://twitter.com/share" class="twitter-share-button" data-via="yogsototh">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="left"> <div class="g-plusone" data-size="medium" data-annotation="inline" data-width="106"></div>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
</div>
<div class="flush"></div>
</div>
2011-04-20 12:29:01 +00:00
<div id="choixrss">
<a id="rss" href="http://feeds.feedburner.com/yannespositocomen">
Subscribe
</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#comment').hide();
$('#clickcomment').click(showComments);
});
function showComments() {
$('#comment').show();
$('#clickcomment').fadeOut();
}
2012-04-10 13:56:34 +00:00
document.write('<div id="clickcomment">Comments &amp; Share</div>');
2011-04-20 12:29:01 +00:00
</script>
<div class="flush"></div>
2012-04-10 13:56:34 +00:00
2011-04-20 12:29:01 +00:00
<div class="corps" id="comment">
<h2 class="first">comments</h2>
<noscript>
You must enable javascript to comment.
</noscript>
<script type="text/javascript">
var idcomments_acct = 'a307f0044511ff1b5cfca573fc0a52e7';
var idcomments_post_id = '/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/';
var idcomments_post_url = 'http://yannesposito.com/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/';
2011-04-20 12:29:01 +00:00
</script>
<span id="IDCommentsPostTitle" style="display:none"></span>
<script type='text/javascript' src='/Scratch/js/genericCommentWrapperV2.js'></script>
2011-04-20 12:29:01 +00:00
</div>
<div id="entete" class="corps_spaced">
<div id="liens">
<ul><li><a href="/Scratch/en/">Home</a></li>
<li><a href="/Scratch/en/blog/">Blog</a></li>
<li><a href="/Scratch/en/softwares/">Softwares</a></li>
<li><a href="/Scratch/en/about/">About</a></li></ul>
2011-04-20 12:29:01 +00:00
</div>
<div class="flush"></div>
<hr/>
<div id="next_before_articles">
<div id="previous_articles">
previous entries
<div class="previous_article">
<a href="/Scratch/en/blog/2009-10-Wait-to-hide-a-menu-in-jQuery/"><span class="nicer">«</span>&nbsp;Menu waiting to hide himself</a>
2011-04-20 12:29:01 +00:00
</div>
<div class="previous_article">
<a href="/Scratch/en/blog/2009-10-launch-daemon-from-command-line/"><span class="nicer">«</span>&nbsp;launch daemon from command line</a>
2011-04-20 12:29:01 +00:00
</div>
<div class="previous_article">
<a href="/Scratch/en/blog/2009-10-Focus-vs-Minimalism/"><span class="nicer">«</span>&nbsp;Focus &gt; Minimalism</a>
2011-04-20 12:29:01 +00:00
</div>
</div>
<div id="next_articles">
next entries
<div class="next_article">
<a href="/Scratch/en/blog/2009-10-30-How-to-handle-evil-IE/">How to handle evil IE&nbsp;<span class="nicer">»</span></a>
2011-04-20 12:29:01 +00:00
</div>
<div class="next_article">
<a href="/Scratch/en/blog/2009-11-12-Git-for-n00b/">Git for n00b&nbsp;<span class="nicer">»</span></a>
2011-04-20 12:29:01 +00:00
</div>
<div class="next_article">
<a href="/Scratch/en/blog/2009-12-06-iphone-call-filter/">iphone call filter&nbsp;<span class="nicer">»</span></a>
2011-04-20 12:29:01 +00:00
</div>
</div>
<div class="flush"></div>
</div>
</div>
<div id="bottom">
2012-04-02 21:43:39 +00:00
<div>
2012-04-10 13:56:34 +00:00
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
2012-04-02 21:43:39 +00:00
</div>
2011-04-20 12:29:01 +00:00
<div>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Copyright ©, Yann Esposito</a>
</div>
<div id="lastmod">
Created: 10/28/2009
2011-04-20 13:09:17 +00:00
Modified: 04/20/2011
2011-04-20 12:29:01 +00:00
</div>
<div>
Entirely done with
<a href="http://www.vim.org">Vim</a>
and
<a href="http://nanoc.stoneship.org">nanoc</a>
</div>
</div>
<div class="clear"></div>
</div>
</body>
</html>