cryptonas/tools/userdocexport.sh

48 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
set -u
# TODO:
# import of images
# root directory of the cryptobox development environment
ROOT_DIR="$(dirname $(dirname $0))"
# retrieve these pages from the wiki
PAGES="CryptoBox CryptoBoxDev CryptoBoxKonzept CryptoBoxEn"
# the trailing slash is important
WIKI_HOST="https://systemausfall.org"
WIKI_URL="/wikis/howto/"
# the trailing slash is important
DEST_PATH="cbox-tree.d/usr/share/doc/cryptobox/html/"
TMP_FILE="/tmp/$(basename $0)-$$.out"
# the URL of the CGI of the cryptobox (the ampersand must be escaped!)
CBOX_CGI='/cryptobox?action=show_doc\&page='
[ ! -e "$DEST_PATH" ] && echo "$DEST_PATH does not exist" && exit 1
for PAGE in $PAGES; do
PAGE_SRC="$WIKI_HOST$WIKI_URL$PAGE"
echo "Importing $PAGE ..."
[ -e "$TMP_FILE" ] && rm "$TMP_FILE"
# download the page
echo " downloading the page ..."
wget -q -O "$TMP_FILE" "$PAGE_SRC" || { echo "Downloading ($PAGE_SRC) failed!"; exit 1; }
echo " removing header and footer ..."
# break lines before start of content
sed -i 's#<div [^>]* id="content" [^>]*>#_END_OF_HEADER_\n#' "$TMP_FILE"
sed -i 's#<div id="footer">#\n_START_OF_FOOTER_#' "$TMP_FILE"
# remove all lines before and after "body"
sed -i '1,/_END_OF_HEADER_/d; /_START_OF_FOOTER_/,$d' "$TMP_FILE"
# TODO: replace wiki-links by references to the cbox-cgi
# check if wiki-links are absolute!
echo " replacing wiki links ..."
sed -i "s#\"$WIKI_URL#\"$CBOX_CGI#g" "$TMP_FILE"
mv "$TMP_FILE" "${DEST_PATH}${PAGE}.html"
echo " finished!"
done