diff --git a/snap/hooks/configure b/snap/hooks/configure new file mode 100644 index 0000000..cb49394 --- /dev/null +++ b/snap/hooks/configure @@ -0,0 +1,48 @@ +#!/bin/sh + +db_type="$(snapctl get db.type)" +db_url="$(snapctl get db.url)" +if [ "${db_type}" = "sqlite" ] +then + if [ -n "${db_url}" ] + then + echo "sqlite backend does not use db.url key" + exit 1 + fi +elif [ "${db_type}" = "postgres" ] +then + if [ -z "${db_url}" ] + then + echo "postgres backend requires db.url to be set" + exit 1 + fi +elif [ -n "${db_type}" ] +then + echo "Invalid db.type: " ${db_type} + exit 1 +fi + +base_url="$(snapctl get base-url)" +enabled="$(snapctl get enabled)" + +if [ -n ${enabled} -a \( "${enabled}" != "true" -a "${enabled}" != "false" \) ] +then + echo "Invalid 'enabled' setting: ${enabled}. Valid values are 'true' or 'false'" + exit 1 +fi + +if [ -n ${base_url} -a \( -z "${enabled}" -o "${enabled}" = "false" \) ] +then + echo "All required configuration available." + echo "Plume can now be enabled by setting 'snap set plume enabled=true' and restarting the service \ +with 'snap restart plume'" +fi + +if [ "${enabled}" = "true" -a ! -e ${SNAP_COMMON}/initial-migrations-run ] +then + cd ${SNAP} + exec ./set-environment bin/plm migration run --path ${SNAP_DATA} + touch ${SNAP_COMMON}/initial-migrations-run +fi + +exit 0 diff --git a/snap/hooks/install b/snap/hooks/install new file mode 100755 index 0000000..c14e810 --- /dev/null +++ b/snap/hooks/install @@ -0,0 +1,3 @@ +#!/bin/sh + +openssl rand -base64 32 > ${SNAP_COMMON}/rocket-secret-key diff --git a/snap/hooks/post-refresh b/snap/hooks/post-refresh new file mode 100644 index 0000000..da50b21 --- /dev/null +++ b/snap/hooks/post-refresh @@ -0,0 +1,11 @@ +#!/bin/sh + +db_type=$(snapctl get db.type) + +if [ -z "${db_type}" ] +then + exit 0 +fi + +cd ${SNAP} +exec ./set-environment bin/plm migration run --path ${SNAP_DATA} diff --git a/snap/local/set-environment b/snap/local/set-environment new file mode 100755 index 0000000..8579f4d --- /dev/null +++ b/snap/local/set-environment @@ -0,0 +1,29 @@ +#!/bin/sh + +enabled="$(snapctl get enabled)" +if [ -z "${enabled}" -o "${enabled}" != "true" ] +then + echo "Plume not yet enabled" + exit 1 +fi + +export BASE_URL="$(snapctl get base-url)" +database_type="$(snapctl get db.type)" + +if [ z"${database_type}" = z"sqlite" ] +then + export DATABASE_URL=${SNAP_DATA}/plume.db + export MIGRATION_DIR=migrations/sqlite +else + # Must be postgres, so must have set db.url + export DATABASE_URL="$(snapctl get db.url)" + export MIGRATION_DIRECTORY=migrations/postgres +fi + +ROCKET_ADDRESS="$(snapctl get listen.address)" +ROCKET_PORT="$(snapctl get listen.port)" +export ROCKET_SECRET_KEY="$(cat ${SNAP_COMMON}/rocket-secret-key)" +export SEARCH_INDEX="${SNAP_DATA}/search_index" + +cd ${SNAP} +exec $@ diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..20ec65a --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,50 @@ +name: plume +base: core18 +version: '0.3.0' # just for humans, typically '1.2+git' or '1.3.2' +summary: Multi-user blogging platform, federated over ActivityPub +description: | + Plume is a federated blogging platform, featuring: + * A blog-centric approach: you can create as much blogs as you want with your account, to keep your different publications separated. + * Media management: you can upload pictures to illustrate your articles, but also audio files if you host a podcast, and manage them all from Plume. + * Federation: Plume is part of a network of interconnected websites called the Fediverse. Each of these websites (often called instances) have their own rules and thematics, but they can all communicate with each other. + * Collaborative writing: invite other people to your blogs, and write articles together. +grade: devel # must be 'stable' to release into candidate/stable channels +confinement: strict + +apps: + plume: + daemon: simple + command: set-environment bin/plume + plugs: + - network + - network-bind + plm: + command: set-environment bin/plm + +parts: + plume: + plugin: rust + source: . + rust-revision: nightly-2019-03-23 + build-packages: + - libssl-dev + - pkg-config + - libsqlite3-dev + - gettext + after: + - cargo-web + override-build: | + export PATH=$PATH:$SNAPCRAFT_PROJECT_DIR/../.cargo/bin + cargo web deploy -p plume-front --release + cargo install --force --no-default-features --features sqlite --path . --root ${SNAPCRAFT_PART_INSTALL} + cargo install --force --no-default-features --features sqlite --path plume-cli --root ${SNAPCRAFT_PART_INSTALL} + cp -a assets migrations static target translations ${SNAPCRAFT_PART_INSTALL} + cp snap/local/set-environment ${SNAPCRAFT_PART_INSTALL} + stage-packages: + - openssl + - libsqlite3-0 + + cargo-web: + plugin: rust + source: https://github.com/koute/cargo-web.git + source-tag: 0.6.26