#!/bin/bash VERSION="$( basename "$0" ) version 2007.12.15-001. \"Few desire liberty; most wish only for a just master.\" -- Sallust, as the Roman Repblic became the Empire" ### Big text chunks USAGE="Usage: $( basename "$0" ) [options] wikispotid This is a wiki spot snapshot utility that downloads the public contents of a wiki into a local repository. The raw markup and binary attachments are included, but the edit history of entries and admin-only content such as non-readable entries and security information are not included. See also http://www.wikispot.org/ Options: -a, --archive Create dated tgz file instead of directory -h, --help Display this help. -v, --version Show version information --license Show license information Arguments: wikispotid The wiki spot ID (the 'short name') of the wiki that you want to retrieve. Copyright (c) 2007 Evan 'JabberWokky' Edwards Released under the terms of the MIT/X11 License (see --license for details)" LICENSE="Copyright (c) 2007 Evan 'JabberWokky' Edwards Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." ### Defaults OPTARCHIVE="" OPTQUIET="" USERAGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" BASEDIR="$( pwd )" ### Support functions function exitwith { echo "${*}" exit } ### Process options # Yeah, yeah, but there's only the one non-run ending arg... [ "$1" == "-a" ] && OPTARCHIVE="1" && shift [ "$1" == "--archive" ] && OPTARCHIVE="1" && shift WID="$1" URL="http://${WID}.wikispot.org" [ "$WID" == "" ] && WID='--help' [ "$WID" == "-h" ] && WID='--help' [ "$WID" == "-v" ] && WID='--version' [ "${WID}" == "--help" ] && exitwith "$USAGE" [ "${WID}" == "--license" ] && exitwith "$LICENSE" [ "${WID}" == "--version" ] && exitwith "$VERSION" ### Okay, start doing stuff. [ -d "$WID" ] && exitwith "ERROR: A directory named '$WID' already exists." lynx -dump "$URL" |grep 'The wiki' |grep -q 'does not exist!' && exitwith "ERROR: There is no wiki named '$WID'." lynx -dump "$URL" |grep -q 'has been disabled and will be permanently deleted' && exitwith "ERROR: The wiki '$WID' is pending deletion." mkdir "$WID" || exitwith "ERROR: Cannot create directory for wiki." cd "$WID" || exitwith "ERROR: Can't enter directory. That's really odd." mkdir entries || exitwith "ERROR: Cannot create directory entries." mkdir files || exitwith "ERROR: Cannot create directory files." wget -q --user-agent="$USERAGENT" -O ".favicon.png" "${URL}/Wiki_Settings/Images?sendfile=true&file=tinylogo.png" if ( grep -q 'No file' ".favicon.png" ) then rm ".favicon.png" wget -q --user-agent="$USERAGENT" -O ".favicon.png" "http://wikispot.org/Wiki_Settings/Images?sendfile=true&file=tinylogo.png" fi printf "[Desktop Entry]\nIcon=./.favicon.png\n" >.directory [ "$OPTQUIET" ] || echo "Getting list of all entries..." lynx -dump "${URL}/All_Pages" |cut -c7- |grep ^http |grep "${WID}.wikispot.org" |grep -v '?' |sort |uniq |cut -d/ -f 4- |grep -v 'All_Pages#' >entries.txt [ "$OPTQUIET" ] || echo "Getting wiki markup..." cat entries.txt |while read ENTRY do [ "$OPTQUIET" ] || echo -n . ENCENTRY="$( echo -n "$ENTRY" | urlencode | sed 's/%5F/_/g')" lynx -dump "${URL}/${ENTRY}?action=raw" >"entries/${ENCENTRY}" done [ "$OPTQUIET" ] || echo [ "$OPTQUIET" ] || echo "Getting file attachments..." cat entries.txt |while read ENTRY do [ "$OPTQUIET" ] || echo -n . ENCENTRY="$( echo -n "$ENTRY" | urlencode | sed 's/%5F/_/g' )" lynx -nonumbers -dump "${URL}/${ENTRY}?action=Files" |grep file-image |sed 's/.*file-image.png\] //' | while read FN do [ ! -d "files/${ENCENTRY}" ] && mkdir "files/${ENCENTRY}" wget -q --user-agent="$USERAGENT" -O "files/${ENCENTRY}/${FN}" "${URL}/${ENTRY}?sendfile=true&file=${FN}" done done echo " This is a snapshot of the wikispot wiki $WID on $(date +%Y.%m.%d). It was generated by spotget." >README.txt cd "$BASEDIR" [ "$OPTARCHIVE" ] && tar c "$WID" |gzip >"${WID}-$( date +%Y.%m.%d ).tgz" && rm -R "${WID}"