diff --git a/type/__wikijs/files/config.yml.sh b/type/__wikijs/files/config.yml.sh new file mode 100755 index 0000000..6f9943f --- /dev/null +++ b/type/__wikijs/files/config.yml.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +if [ $# -ne 1 ]; +then + echo "You have to give me the database password as an argument:" + echo "on some systems, anyone can read env(1)." + exit 1; +fi + +cat << EOF +port: 80 +db: + type: postgres + host: localhost + port: 5432 + user: ${DB_USER:?} + pass: $1 + db: ${DB_NAME:?} + ssl: false +ssl: + enabled: ${SSL} + port: 443 + provider: letsencrypt + domain: ${__target_host:?} + subscriberEmail: ${LE_EMAIL:?} +pool: + min: 2 + max: 10 +bindIP: 0.0.0.0 +logLevel: warn +offline: false +ha: false +dataPath: ./data +EOF diff --git a/type/__wikijs/files/wikijs-openrc b/type/__wikijs/files/wikijs-openrc new file mode 100644 index 0000000..e484647 --- /dev/null +++ b/type/__wikijs/files/wikijs-openrc @@ -0,0 +1,10 @@ +#!/sbin/openrc-run + +command='/usr/bin/node' +command_args='server' +command_background=true +description="Run wiki.js" +directory='/var/wiki' +error_log=/var/log/"$RC_SVCNAME".err +output_log=/var/log/"$RC_SVCNAME".log +pidfile="/run/$RC_SVCNAME.pid" diff --git a/type/__wikijs/gencode-remote b/type/__wikijs/gencode-remote new file mode 100644 index 0000000..2faf559 --- /dev/null +++ b/type/__wikijs/gencode-remote @@ -0,0 +1,25 @@ +#!/bin/sh + +# Check for installation +cat << EOF +if [ -f '/var/wiki/LICENSE' ]; +then + # Assume everything is done already. + exit 0; +fi +EOF + +# Download and copy source +cat << EOF +TMPDIR=\$(mktemp -d) +cd \$TMPDIR || exit 1 +wget https://github.com/Requarks/wiki/releases/download/2.4.107/wiki-js.tar.gz +tar xf wiki-js.tar.gz -C /var/wiki +EOF + +# Install deps and launch +cat << EOF +cd /var/wiki || exit 1 +npm install +service start wikijs +EOF diff --git a/type/__wikijs/man.rst b/type/__wikijs/man.rst new file mode 100644 index 0000000..6573b60 --- /dev/null +++ b/type/__wikijs/man.rst @@ -0,0 +1,55 @@ +cdist-type__wikijs(7) +======================== + +NAME +---- +cdist-type__wikijs - Deploy the wiki.js software. + +DESCRIPTION +----------- + +See wiki.js.org for more information. This type deploys with a postgresql +database, since it is the upstream recommended for production, and they seem to +strongly suggest that in thenext releases, they will not support anything else. + +Currently, this type servers wikijs as standalone, listening on ports 80 and +443, and with a service file for OpenRC. Feel free to contribute a +generalisation if you require one. + +REQUIRED PARAMETERS +------------------- + +database-password + The password to the PSQL database. + +OPTIONAL PARAMETERS +------------------- + +database + The name of the PSQL database to connect to. If omitted, then 'wikijs' is + used. + +database-user + The name of the PSQL database user to connec as. If omitted, then 'wikijs' is + used. + +letsencrypt-mail + If the SSL parameter is passed, then we setup wikijs to automatically obtain + certificates: this is the email used to sign up to a LE account. + +BOOLEAN PARAMETERS +------------------ + +ssl + Whether or not to enable the wikijs automatic obtention of LE certificates. + +AUTHORS +------- +Joachim Desroches + +COPYING +------- +Copyright \(C) 2020 Joachim Desroches. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/type/__wikijs/manifest b/type/__wikijs/manifest new file mode 100644 index 0000000..7ee42ac --- /dev/null +++ b/type/__wikijs/manifest @@ -0,0 +1,60 @@ +#!/bin/sh + +os="$(cat "${__global:?}"/explorer/os)" + +case "$os" in + alpine) + : + ;; + *) + echo "This type has no implementation for $os. Aborting." >&2; + exit 1; +esac + +DB_USER=wikijs +if [ -f "${__object:?}/parameter/database-user" ]; +then + DB_USER="$(cat "${__object:?}/parameter/database-user")" +fi +export DB_USER + +DB_NAME=wikijs +if [ -f "${__object:?}/parameter/database" ]; +then + DB_NAME="$(cat "${__object:?}/parameter/database")" +fi +export DB_NAME + +SSL=false +if [ -f "${__object:?}/parameter/ssl" ]; +then + SSL=true +fi +export SSL + +if ! [ "$SSL" = "false" ]; +then + if [ -f "${__object:?}/parameter/letsencrypt-mail" ]; + then + LE_EMAIL="$(cat "${__object:?}/parameter/letsencrypt-mail")" + export LE_EMAIL + else + echo "You must specify an email account if you request SSL." + echo "Hit me." + exit 1 + fi +fi + +db_pass="$(cat "${__object:?}/parameter/database-password")" + +__package nodejs +__package nghttp2-dev # Required for some reason, else a symbol is missing +__package npm +__directory /var/wiki/ +__file /etc/init.d/wikijs --source "${__files:?}/files/wikijs-openrc" +require='__file/etc/init.d/wikijs' __start_on_boot wikijs + +mkdir -p "${__object:?}/files" +"${__type:?}/files/config.yml.sh" "$db_pass" > "${__object:?}/files/config.yml" +require='__directory/var/wiki' \ + __file /var/wiki/config.yml --source "${__object:?}/files/config.yml" diff --git a/type/__wikijs/parameter/boolean b/type/__wikijs/parameter/boolean new file mode 100644 index 0000000..a2647ce --- /dev/null +++ b/type/__wikijs/parameter/boolean @@ -0,0 +1 @@ +ssl diff --git a/type/__wikijs/parameter/optional b/type/__wikijs/parameter/optional new file mode 100644 index 0000000..9c309c9 --- /dev/null +++ b/type/__wikijs/parameter/optional @@ -0,0 +1,3 @@ +database +database-user +letsencrypt-mail diff --git a/type/__wikijs/parameter/required b/type/__wikijs/parameter/required new file mode 100644 index 0000000..8a109a1 --- /dev/null +++ b/type/__wikijs/parameter/required @@ -0,0 +1 @@ +database-password diff --git a/type/__wikijs/singleton b/type/__wikijs/singleton new file mode 100644 index 0000000..e69de29