tinycm annotate plugins/export/export.cgi @ rev 121

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 12:26:25 2019 +0100 (2019-02-26)
parents 854c4a8f0972
children
rev   line source
pankso@6 1 #!/bin/sh
pankso@6 2 #
pankso@6 3 # TinyCM Plugin - Export to static content
pankso@6 4 #
pankso@6 5 . /usr/lib/slitaz/httphelper
pankso@6 6
pankso@28 7 #
pankso@54 8 # NOTE: Exporting wiki to HTML and making all urls work is a bit tricky.
pankso@54 9 # Actually it doesn't work as expected. The goal is to have a SliTaz codex
paul@33 10 # online that can be included on the ISO, so we could have an export
pankso@28 11 # including a small CGI script to simply display wiki pages via HTTPd
pankso@28 12 # knowing that with HTML we must also deal with ../../
pankso@28 13 #
pankso@28 14
pankso@6 15 if [ "$(GET export)" ]; then
pankso@6 16 d="Export"
pankso@6 17 date=$(date "+%Y%m%d")
pankso@6 18 tmpdir="$tmp/export/$$/wiki-$date"
pankso@6 19 header
pankso@6 20 html_header
pankso@6 21 user_box
pankso@60 22 if ! check_auth && ! admin_user; then
pankso@60 23 gettext "You must be admin to export content."
pankso@60 24 html_footer && exit 0
pankso@60 25 fi
pankso@6 26 cat << EOT
pankso@6 27 <h2>Export</h2>
pankso@6 28 <p>
paul@58 29 $(gettext "Create a tarball of your wiki and plugins files. EXPERIMENTAL:
pankso@54 30 Export wiki documents to HTML.")
pankso@6 31 </p>
pankso@6 32 <form method="get" action="$WEB_URL">
pankso@6 33 <select name="export">
pankso@6 34 EOT
pankso@6 35 for c in $(ls -1 content/)
pankso@6 36 do
pankso@54 37 echo "<option value=\"${c}\">$c</option>"
pankso@6 38 done
pankso@54 39 echo "<option value='wikitohtml'>wiki to HTML</option>"
pankso@6 40 cat << EOT
pankso@6 41 </select>
pankso@6 42 <input type="submit" value="$(gettext "Export")" />
pankso@6 43 </form>
pankso@6 44 EOT
paul@58 45 # HTML fixes EXPERIMENTAL Functions
pankso@6 46 css_path() {
pankso@6 47 # Sed CSS style path in all documents
pankso@6 48 sed -i s'/style.css/..\/style.css/' */*.html
pankso@6 49 sed -i s'/style.css/..\/..\/style.css/' */*/*.html
pankso@6 50 sed -i s'/style.css/..\/..\/..\/style.css/' */*/*/*.html
pankso@6 51 }
pankso@6 52 gen_tarball() {
pankso@6 53 gettext "Creating tarball"; echo -n ": "
pankso@7 54 cd $tmpdir && mkdir $tiny/$cache/export
pankso@6 55 # Clean cache
pankso@7 56 find $tiny/$cache/export -mtime +1 | xargs rm -rf
pankso@7 57 tar czf $tiny/$cache/export/$export-$date.tar.gz $export
pankso@7 58 cd $tiny/$cache/export && du -sh $export-$date.tar.gz
pankso@6 59 }
pankso@6 60 dl_link() {
pankso@6 61 gettext "Download"; echo \
pankso@6 62 ": <a href='cache/export/$export-$date.tar.gz'>$export-$date.tar.gz</a>"
pankso@6 63 }
pankso@6 64 # Export requested content
pankso@6 65 case " $(GET export) " in
pankso@54 66 *\ wikitohtml\ *)
pankso@28 67 export="wiki"
pankso@6 68 echo '<pre>'
pankso@6 69 gettext "Exporting:"; echo " $export"
pankso@6 70 mkdir -p $tmpdir/$export
pankso@6 71 gettext "Copying CSS style and images..."; echo
pankso@6 72 cp -a style.css images $tmpdir/$export
pankso@6 73 cd $content/$export
pankso@6 74 for d in $(find . -type f | sed s'!./!!')
pankso@6 75 do
pankso@6 76 d=${d%.txt}
pascal@121 77 [ "$d" = "en/help" ] && continue
pankso@6 78 gettext "Exporting: "; echo "$d.txt"
pankso@6 79 mkdir -p $tmpdir/$export/$(dirname $d)
pankso@6 80 f=$tmpdir/$export/$d.html
pankso@28 81 html_header > ${f}
pankso@28 82 sed -i '/functions.js/'d ${f}
pankso@28 83 sed -i '/favicon.ico/'d ${f}
pankso@28 84 sed -i s'/index.cgi/index.html/'/ ${f}
pankso@28 85 doc="[0-9a-zA-Z\.\#/~\_%=\?\&,\+\:@;!\(\)\*\$'\-]*"
pankso@28 86 #
paul@33 87 # The sed from wiki urls to html bug if there is 2 links
pankso@28 88 # on same line: [test|Test] tralala [en/index|English]
pankso@28 89 #
pankso@6 90 cat $d.txt | wiki_parser | sed \
pankso@28 91 s"#href='\([^]]*\)?d=\($doc\)'>#href='\2.html'>#"g >> ${f}
pankso@28 92 html_footer >> ${f}
pankso@6 93 done
pankso@6 94 cd $tmpdir/$export
pankso@28 95 css_path
pankso@6 96 gen_tarball
pankso@6 97 rm -rf $tmp/export/$$
pankso@6 98 echo '</pre>'
pankso@6 99 dl_link ;;
pankso@48 100 *\ export\ )
pankso@48 101 html_footer && exit 0 ;;
pankso@28 102 *)
pankso@54 103 export="$(GET export)"
pankso@54 104 tmpdir="content"
pankso@28 105 echo '<pre>'
pankso@54 106 gettext "Exporting:"; echo " $export"
pankso@54 107 gen_tarball
pankso@54 108 echo '</pre>'
pankso@54 109 dl_link ;;
pankso@6 110 esac
pankso@6 111
pankso@28 112 html_footer && exit 0
pankso@6 113 fi