#!/bin/bash # install.sh -- the starshipos-f18.com XWiki's pages, from the "StarshipOS.com" design canvas # (build.py makes them): Main.WebHome (Home), Inquiries.WebHome, TryIt.WebHome, and the two # images, attachments of Main.WebHome. All readable by everyone; the wiki's own rights decide the # rest. Through XWiki's REST API: # # XWIKI_USER=rajames XWIKI_PASSWORD=... site/com/install.sh [https://starshipos-f18.com] # # Run it again after build.py: pages and images are replaced. It ends by checking, without # logging in, that every page and image is there. set -euo pipefail cd "$(dirname "$0")" base=${1:-https://starshipos-f18.com} rest="$base/rest/wikis/xwiki" user=${XWIKI_USER:?set XWIKI_USER} pass=${XWIKI_PASSWORD:?set XWIKI_PASSWORD} auth=(-u "$user:$pass") page() { # page <file>: create or replace <space>.WebHome local body body=$(python3 -c ' import sys from xml.sax.saxutils import escape print("<page xmlns=\"http://www.xwiki.org\"><title>%sxwiki/2.1" "%s" % (escape(sys.argv[1]), escape(open(sys.argv[2]).read())))' "$2" "$3") curl -fsS -o /dev/null -w " page $1.WebHome: %{http_code}\n" "${auth[@]}" -X PUT \ -H 'Content-Type: application/xml' --data-binary "$body" "$rest/spaces/$1/pages/WebHome" } attach() { # attach : create or replace an attachment of .WebHome curl -fsS -o /dev/null -w " attachment $1.WebHome/$2: %{http_code}\n" "${auth[@]}" -X PUT \ -H 'Content-Type: image/jpeg' --data-binary "@$2" "$rest/spaces/$1/pages/WebHome/attachments/$2" } echo "=== $base, as $user" page Main "StarshipOS" Main.WebHome.xwiki attach Main badge.jpg attach Main captain-bob.jpg page Inquiries "Inquiries" Inquiries.WebHome.xwiki page TryIt "Try StarshipOS" TryIt.WebHome.xwiki echo "=== as a guest" bad= for u in /bin/view/Main/ /bin/view/Inquiries/ /bin/view/TryIt/ \ /bin/download/Main/WebHome/badge.jpg /bin/download/Main/WebHome/captain-bob.jpg; do code=$(curl -s -o /dev/null -w '%{http_code}' "$base$u") if [ "$code" = 200 ]; then echo " $u: 200"; else echo " $u: $code -- NOT readable"; bad=1; fi done [ -z "$bad" ] || { echo "install: a guest cannot read everything; see above" >&2; exit 1; } echo "=== done: $base/bin/view/Main/"