her.esy.fun/src/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/index.html

175 lines
14 KiB
HTML
Raw Normal View History

2021-04-18 10:23:24 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>YBlog - custom website synchronisation with mobileme (2)</title>
<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/css/brutalist.css" />
<link rel="stylesheet" type="text/css" href="../../../../Scratch/css/pandoc-solarized.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="../../../../Scratch/en/blog/feed/feed.xml" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="../../../../Scratch/img/about/FlatAvatar@2x.png" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<!-- IndieAuth -->
<link href="https://twitter.com/yogsototh" rel="me">
<link href="https://github.com/yogsototh" rel="me">
<link href="mailto:yann.esposito@gmail.com" rel="me">
<link rel="pgpkey" href="../../../../pubkey.txt">
</head>
<body lang="en" class="article">
<div id="content">
<div id="header">
<div id="choix">
<span id="choixlang">
<a href="../../../../Scratch/fr/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/">French</a>
</span>
<span class="tomenu"><a href="#navigation">↓ Menu ↓</a></span>
<span class="flush"></span>
</div>
</div>
<div id="titre">
<h1>custom website synchronisation with mobileme (2)</h1>
</div>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<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>
<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>
<p>Even with this script I also have some problem. Mostly due to webdav issues. For example, renaming a folder work really badly (on Linux at least). I use webdavfs. For example:</p>
<div>
<code class="zsh"> mv folder folder2 </code>
</div>
<p>It returns OK and Ive got:</p>
<div>
<code class="zsh"> $ ls folder folder2 </code>
</div>
<p>Booh….</p>
<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… Anyway here is the code I use.</p>
<div>
<p><code class="zsh" file="webdav-framework"> #!/usr/bin/env zsh</p>
<p>function samelineprint { print -n -P "\r$*" }</p>
<h1 id="avec-1-essai-par-seconde-300-5-minutes">avec 1 essai par seconde: 300 = 5 minutes</h1>
<p>maxessais=300</p>
<h1 id="try-to-create-a-directory-until-success">try to create a directory until success</h1>
<p>function trymkdir { target=“$1” print mkdir -p $target local essai=1 while ! mkdir -p <span class="math inline">$target; do samelineprint "Echec: essai n°$</span>essai" ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done print }</p>
<h1 id="try-to-copy-until-success">try to copy until success</h1>
<p>function trycp { element=“$1” target=“$2” if [[ ! -d ${target:h} ]]; then trymkdir ${target:h} fi local essai=1 print cp $element $target while ! $element <span class="math inline">$target; do samelineprint "Echec: essai n°$</span>essai" ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done print }</p>
<h1 id="try-to-remove-until-success">try to remove until success</h1>
<p>function tryrm { target=“$1” local essai=1 local options= [[ -d $target ]] &amp;&amp; options=-rf print rm $options $target while ! rm $options <span class="math inline">$target; do samelineprint "Echec: essai n°$</span>essai" ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done essai=1 while [[ -e $element ]]; do samelineprint “rm reussi mais fichier source non disparu n°$essai” sleep 1 ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done print }</p>
<h1 id="try-to-rename-until-success">try to rename until success</h1>
<p>function tryrename { element=“$1” target=“$2” local essai=1 while [[ -e $target ]]; do samelineprint “Echec n°$essai le fichier $target existe déjà” ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 sleep 1 done print mv $element $target while ! mv $element <span class="math inline">$target; do samelineprint "Echec: essai n°$</span>essai" ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 4 done essai=1 while [[ -e $element ]]; do samelineprint “mv reussi mais fichier source non disparu n°$essai” sleep 1 ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done print }</p>
<h1 id="try-to-move-until-success">try to move until success</h1>
function trymv { element=“$1” target=“$2” local essai=1 print mv $element $target while ! mv $element <span class="math inline">$target; do samelineprint "Echec: essai n°$</span>essai" ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done essai=1 while [[ -e $element ]]; do samelineprint “mv reussi mais fichier source non disparu n°$essai” sleep 1 ((essai++)) ((essai&gt;maxessais)) &amp;&amp; exit 5 done print } </code>
</div>
<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>
<div>
<p><code class="zsh" file="publish"> #!/usr/bin/env zsh</p>
<h1 id="script-synchronisant-le-site-sur-me.com">Script synchronisant le site sur me.com</h1>
<h1 id="normalement-le-site-est-indisponible-le-moins-de-temps-possible">normalement, le site est indisponible le moins de temps possible</h1>
<h1 id="le-temps-de-deux-renommages-de-répertoire">le temps de deux renommages de répertoire</h1>
<h1 id="get-configuration">get configuration</h1>
<h1 id="mostly-directories">mostly directories</h1>
<p>source $0:h/config</p>
<h1 id="get-trycp-function-copy-until-success">get trycp function (copy until success)</h1>
<p>source $0:h/webdav-framework</p>
<p>if [[ $1 == -h ]]; then print “usage : $0:h [-h|-s|-d]” print " -a sychronise aussi lindex" print " -h affiche laide" print " -d modification directe (pas de swap)" print " -s swappe simplement les répertoires" fi</p>
<h1 id="publication-incrementale">publication incrementale</h1>
<p>function incrementalPublish { local ydestRep=<span class="math inline"><em>d</em><em>e</em><em>s</em><em>t</em><em>R</em><em>e</em><em>p</em></span>suffix localRef=“$srcRep/map.yrf” print “Creation du fichier de references” create-reference-file.sh &gt; <span class="math inline">$localRef remoteRef="/tmp/remoteSiteMapRef.$</span><span class="math inline">$.yrf" if [[ ! -e "$</span>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” rsyncPublish swap else trycp “<span class="math inline">$ydestRep/map.yrf" "$</span>remoteRef” typeset -U filesToUpdate filesToUpdate=( $(diff $localRef $remoteRef | awk /<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a>/ {print <span class="math inline">$2}' ) ) if (($</span>{#filesToUpdate} == 1)); then print “Seul le fichier <span class="math inline">${filesToUpdate} sera téléversé" elif (($</span>{#filesToUpdate}&lt;10)); then print –”<span class="math inline">${#filesToUpdate} fichiers seront téléversés :" print -- "$</span>{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 <span class="math inline"><em>s</em><em>r</em><em>c</em><em>R</em><em>e</em><em>p</em></span>element ]]; then trycp <span class="math inline"><em>s</em><em>r</em><em>c</em><em>R</em><em>e</em><em>p</em></span>element <span class="math inline"><em>y</em><em>d</em><em>e</em><em>s</em><em>t</em><em>R</em><em>e</em><em>p</em></span>element else tryrm <span class="math inline"><em>y</em><em>d</em><em>e</em><em>s</em><em>t</em><em>R</em><em>e</em><em>p</em></span>element fi done # if all went fine, copy the map file trycp $srcRep/map.yrf $ydestRep/map.yrf # remove the temporary file }</p>
<h1 id="publication-via-rsync">publication via rsync</h1>
<p>function rsyncPublish { result=1 essai=1 while (( $result &gt; 0 )); do print rsync -arv $srcRep/ $destRep.tmp if ((!testmode)); then rsync -arv $srcRep/ <span class="math inline"><em>d</em><em>e</em><em>s</em><em>t</em><em>R</em><em>e</em><em>p</em>.<em>t</em><em>m</em><em>p</em><em>f</em><em>i</em><em>r</em><em>e</em><em>s</em><em>u</em><em>l</em><em>t</em>=</span>? if (( <span class="math inline">$result &gt; 0 )); then print -P -- "%BEchec du rsync%b (essai n°$</span>essai)" &gt;&amp;2 fi ((essai++)) done }</p>
<h1 id="swap">swap</h1>
<p>function swap { print -P “%B[Directory Swap (tmp &lt;=&gt; target)]%b” [[ -e $destRep.old ]] &amp;&amp; tryrm $destRep.old</p>
<pre><code>print -- &quot; renommage du repertoire sandard vers le .old&quot;
tryrename $destRep $destRep.old
print -- &quot; renommage du repertoire tmp (nouveau) vers le standard&quot;
print -P -- &quot;%B[Site Indisponible]%b $(date)&quot;
tryrename $destRep.tmp $destRep
print -P -- &quot;%B[Site Disponible]%b $(date)&quot;
print -- &quot; renommage du repertoire old vers le tmp&quot;
tryrename $destRep.old $destRep.tmp
print -P -- &quot; publication terminée&quot;</code></pre>
<p>}</p>
<p>print “Root = $webroot” print “Dest = $destRep”</p>
if [[ “$1” = “-s” ]]; then swap else if [[ “$1” = “-d” ]]; then suffix="" else suffix=“.tmp” fi print -P “%BSync%b[${Root:t} =&gt; <span class="math inline"><em>d</em><em>e</em><em>s</em><em>t</em><em>R</em><em>e</em><em>p</em>:<em>t</em></span>suffix]” incrementalPublish fi </code>
</div>
<p>This is my way to replace <code>rsync</code> with filesystem not handling it. Hope it is usefull. Ill be happy to hear a way to handle the webdav rename folder problem. This is really annoying.</p>
<section class="footnotes">
<hr />
<ol>
<li id="fn1"><p>&lt;&gt;<a href="#fnref1" class="footnote-back"></a></p></li>
</ol>
</section>
</div>
<div id="afterarticle">
<div id="social">
<a href="../../../../Scratch/en/blog/feed/feed.xml" target="_blank" rel="noopener noreferrer nofollow" class="social">RSS</a>
·
<a href="https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/%20via%20@yogsototh" target="_blank" rel="noopener noreferrer nofollow" class="social">Tweet</a>
·
<a href="http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fyannesposito.com/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/" target="_blank" rel="noopener noreferrer nofollow" class="social">FB</a>
<br />
<a class="message" href="../../../../Scratch/en/blog/Social-link-the-right-way/">These social sharing links preserve your privacy</a>
</div>
<div id="navigation">
<a href="../../../../">Home</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/en/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/en/softwares">Softwares</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/en/about">About</a>
</div>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div id="bottom">
<div>
Published on 2009-10-28
</div>
<div>
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
</div>
<div>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Yann Esposito©</a>
</div>
<div>
Done with
<a href="http://www.vim.org" target="_blank" rel="noopener noreferrer nofollow"><strike>Vim</strike></a>
<a href="http://spacemacs.org" target="_blank" rel="noopener noreferrer nofollow">spacemacs</a>
<span class="pala">&amp;</span>
<a href="http://nanoc.ws" target="_blank" rel="noopener noreferrer nofollow"><strike>nanoc</strike></a>
<a href="http://jaspervdj.be/hakyll" target="_blank" rel="noopener noreferrer nofollow">Hakyll</a>
</div>
<hr />
<div style="max-width: 100%">
<a href="https://cardanohub.org">
<img src="../../../../Scratch/img/ada-logo.png" class="simple" style="height: 16px;
border-radius: 50%;
vertical-align:middle;
display:inline-block;" />
ADA:
</a>
<code style="display:inline-block;
word-wrap:break-word;
text-align: left;
vertical-align: top;
max-width: 85%;">
DdzFFzCqrhtAvdkmATx5Fm8NPJViDy85ZBw13p4XcNzVzvQg8e3vWLXq23JQWFxPEXK6Kvhaxxe7oJt4VMYHxpA2vtCFiP8fziohN6Yp
</code>
</div>
</div>
</div>
</div>
</div>
</body>
</html>