drist

custom modules for drist configuration tool
git clone git://git.pyratebeard.net/drist.git
Log | Files | Refs | README

post-receive.html (7418B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      5 <meta name="viewport" content="width=device-width, initial-scale=1" />
      6 <title>post-receive - stagit-scripts - Static git repository setup scripts
      7 </title>
      8 <link rel="icon" type="image/png" href="../favicon.png" />
      9 <link rel="alternate" type="application/atom+xml" title="stagit-scripts Atom Feed" href="../atom.xml" />
     10 <link rel="alternate" type="application/atom+xml" title="stagit-scripts Atom Feed (tags)" href="../tags.xml" />
     11 <link rel="stylesheet" type="text/css" href="../style.css" />
     12 </head>
     13 <body>
     14 <table><tr><td><a href="../../"><img src="../logo.png" alt="" width="32" height="32" /></a></td><td><h1>stagit-scripts</h1><span class="desc">Static git repository setup scripts
     15 </span></td></tr><tr class="url"><td></td><td>git clone <a href="https://www.brianlane.com/git/stagit-scripts">https://www.brianlane.com/git/stagit-scripts</a></td></tr><tr><td></td><td>
     16 <a href="../log.html">Log</a> | <a href="../files.html">Files</a> | <a href="../refs.html">Refs</a> | <a href="../file/README.md.html">README</a></td></tr></table>
     17 <hr/>
     18 <div id="content">
     19 <p> post-receive (1846B)</p><hr/><pre id="blob">
     20 <a href="#l1" class="line" id="l1">      1</a> #!/bin/sh
     21 <a href="#l2" class="line" id="l2">      2</a> # generic git post-receive hook.
     22 <a href="#l3" class="line" id="l3">      3</a> # change the config options below and call this script in your post-receive
     23 <a href="#l4" class="line" id="l4">      4</a> # hook or symlink it.
     24 <a href="#l5" class="line" id="l5">      5</a> #
     25 <a href="#l6" class="line" id="l6">      6</a> # usage: $0 [name]
     26 <a href="#l7" class="line" id="l7">      7</a> #
     27 <a href="#l8" class="line" id="l8">      8</a> # if name is not set the basename of the current directory is used,
     28 <a href="#l9" class="line" id="l9">      9</a> # this is the directory of the repo when called from the post-receive script.
     29 <a href="#l10" class="line" id="l10">     10</a> 
     30 <a href="#l11" class="line" id="l11">     11</a> # NOTE: needs to be set for correct locale (expects UTF-8) otherwise the
     31 <a href="#l12" class="line" id="l12">     12</a> #       default is LC_CTYPE=&quot;POSIX&quot;.
     32 <a href="#l13" class="line" id="l13">     13</a> export LC_CTYPE=&quot;en_US.UTF-8&quot;
     33 <a href="#l14" class="line" id="l14">     14</a> 
     34 <a href="#l15" class="line" id="l15">     15</a> name=&quot;$1&quot;
     35 <a href="#l16" class="line" id="l16">     16</a> if test &quot;${name}&quot; = &quot;&quot;; then
     36 <a href="#l17" class="line" id="l17">     17</a> 	name=$(basename &quot;$(pwd)&quot;)
     37 <a href="#l18" class="line" id="l18">     18</a> fi
     38 <a href="#l19" class="line" id="l19">     19</a> 
     39 <a href="#l20" class="line" id="l20">     20</a> # config
     40 <a href="#l21" class="line" id="l21">     21</a> # paths must be absolute.
     41 <a href="#l22" class="line" id="l22">     22</a> BASEURL=&quot;https://www.yourhost.com/git&quot;
     42 <a href="#l23" class="line" id="l23">     23</a> RSYNC_DEST=&quot;yourhost.com:public_html/git/&quot;
     43 <a href="#l24" class="line" id="l24">     24</a> reposdir=&quot;$HOME/stagit-repos&quot;
     44 <a href="#l25" class="line" id="l25">     25</a> 
     45 <a href="#l26" class="line" id="l26">     26</a> dir=&quot;${reposdir}/${name}&quot;
     46 <a href="#l27" class="line" id="l27">     27</a> htmldir=&quot;${reposdir}&quot;
     47 <a href="#l28" class="line" id="l28">     28</a> stagitdir=&quot;/&quot;
     48 <a href="#l29" class="line" id="l29">     29</a> destdir=&quot;${htmldir}${stagitdir}&quot;
     49 <a href="#l30" class="line" id="l30">     30</a> cachefile=&quot;.htmlcache&quot;
     50 <a href="#l31" class="line" id="l31">     31</a> # /config
     51 <a href="#l32" class="line" id="l32">     32</a> 
     52 <a href="#l33" class="line" id="l33">     33</a> if ! test -d &quot;${dir}&quot;; then
     53 <a href="#l34" class="line" id="l34">     34</a> 	echo &quot;${dir} does not exist&quot; &gt;&amp;2
     54 <a href="#l35" class="line" id="l35">     35</a> 	exit 1
     55 <a href="#l36" class="line" id="l36">     36</a> fi
     56 <a href="#l37" class="line" id="l37">     37</a> cd &quot;${dir}&quot; || exit 1
     57 <a href="#l38" class="line" id="l38">     38</a> 
     58 <a href="#l39" class="line" id="l39">     39</a> # detect git push -f
     59 <a href="#l40" class="line" id="l40">     40</a> force=0
     60 <a href="#l41" class="line" id="l41">     41</a> while read -r old new ref; do
     61 <a href="#l42" class="line" id="l42">     42</a> 	test &quot;${old}&quot; = &quot;0000000000000000000000000000000000000000&quot; &amp;&amp; continue
     62 <a href="#l43" class="line" id="l43">     43</a> 	test &quot;${new}&quot; = &quot;0000000000000000000000000000000000000000&quot; &amp;&amp; continue
     63 <a href="#l44" class="line" id="l44">     44</a> 
     64 <a href="#l45" class="line" id="l45">     45</a> 	hasrevs=$(git rev-list &quot;${old}&quot; &quot;^${new}&quot; | sed 1q)
     65 <a href="#l46" class="line" id="l46">     46</a> 	if test -n &quot;${hasrevs}&quot;; then
     66 <a href="#l47" class="line" id="l47">     47</a> 		force=1
     67 <a href="#l48" class="line" id="l48">     48</a> 		break
     68 <a href="#l49" class="line" id="l49">     49</a> 	fi
     69 <a href="#l50" class="line" id="l50">     50</a> done
     70 <a href="#l51" class="line" id="l51">     51</a> 
     71 <a href="#l52" class="line" id="l52">     52</a> printf &quot;[%s] stagit HTML pages... &quot; &quot;${name}&quot;
     72 <a href="#l53" class="line" id="l53">     53</a> 
     73 <a href="#l54" class="line" id="l54">     54</a> mkdir -p &quot;${destdir}/${name}&quot;
     74 <a href="#l55" class="line" id="l55">     55</a> cd &quot;${destdir}/${name}&quot; || exit 1
     75 <a href="#l56" class="line" id="l56">     56</a> 
     76 <a href="#l57" class="line" id="l57">     57</a> # remove commits and ${cachefile} on git push -f, this recreated later on.
     77 <a href="#l58" class="line" id="l58">     58</a> if test &quot;${force}&quot; = &quot;1&quot;; then
     78 <a href="#l59" class="line" id="l59">     59</a> 	rm -f &quot;${cachefile}&quot;
     79 <a href="#l60" class="line" id="l60">     60</a> 	rm -rf &quot;commit&quot;
     80 <a href="#l61" class="line" id="l61">     61</a> fi
     81 <a href="#l62" class="line" id="l62">     62</a> 
     82 <a href="#l63" class="line" id="l63">     63</a> # make index.
     83 <a href="#l64" class="line" id="l64">     64</a> stagit-index &quot;${reposdir}/&quot;*/ &gt; &quot;${destdir}/index.html&quot;
     84 <a href="#l65" class="line" id="l65">     65</a> 
     85 <a href="#l66" class="line" id="l66">     66</a> # Create the URL for clone
     86 <a href="#l67" class="line" id="l67">     67</a> echo &quot;${BASEURL}/${name}&quot; &gt; url
     87 <a href="#l68" class="line" id="l68">     68</a> git update-server-info
     88 <a href="#l69" class="line" id="l69">     69</a> 
     89 <a href="#l70" class="line" id="l70">     70</a> # make pages.
     90 <a href="#l71" class="line" id="l71">     71</a> stagit -c &quot;${cachefile}&quot; &quot;${reposdir}/${name}&quot;
     91 <a href="#l72" class="line" id="l72">     72</a> 
     92 <a href="#l73" class="line" id="l73">     73</a> ln -sf log.html index.html
     93 <a href="#l74" class="line" id="l74">     74</a> ln -sf ../style.css style.css
     94 <a href="#l75" class="line" id="l75">     75</a> ln -sf ../logo.png logo.png
     95 <a href="#l76" class="line" id="l76">     76</a> 
     96 <a href="#l77" class="line" id="l77">     77</a> # Update the server
     97 <a href="#l78" class="line" id="l78">     78</a> rsync -a &quot;${destdir}/&quot; &quot;${RSYNC_DEST}&quot;
     98 <a href="#l79" class="line" id="l79">     79</a> 
     99 <a href="#l80" class="line" id="l80">     80</a> echo &quot;done&quot;
    100 </pre>
    101 </div>
    102 </body>
    103 </html>