diff --git a/type/__nextcloud_app/explorer/state b/type/__nextcloud_app/explorer/state new file mode 100755 index 0000000..d7572ce --- /dev/null +++ b/type/__nextcloud_app/explorer/state @@ -0,0 +1,38 @@ +#!/bin/sh -e +# __nextcloud_app/explorer/state + +# Outputs the current state of the app. There are: +# - `enabled` if the app is enabled +# - `disabled` if the app is disabled +# - `absent` if the app does not exist +# - nothing if nextcloud is not installed + + +# Get the app id +appid="$__object/parameter/appid" +if [ -f "$appid" ]; then + appid="$(cat "$appid")" +else + appid="$__object_id" +fi + +# Get the installation directory +cloud="$(cat "$__object/parameter/cloud")" +www_user="$(cat "$__object/parameter/www-user")" + + +# Check if the installation directory exists +if [ -d "$cloud" ]; then + # if those files exist, everything should be fine + if [ -f "$cloud/occ" ] && [ -f "$cloud/config/config.php" ]; then + # Check if the app exists in the correct user context + su -s /bin/sh -l "$www_user" -- -e <&2 + echo "Use the type __nextcloud to ensure the installation and mark it as dependency for this type!" >&2 + exit 2 +fi + + +# Check if the state changes +if [ "$state_is" != "$state_should" ]; then + # check what to do + case "$state_should" in + enabled) + if [ "$state_is" = "disabled" ]; then + occ app:enable "'$appid'" + echo enabled >> "$__messages_out" + else + occ app:install "'$appid'" + echo installed >> "$__messages_out" + fi + ;; + + disabled) + if [ "$state_is" = "absent" ]; then + occ app:install --keep-disabled "'$appid'" + echo installed >> "$__messages_out" + else + occ app:disable "'$appid'" + echo disabled >> "$__messages_out" + fi + ;; + + present) + if [ "$state_is" = "absent" ]; then + occ app:install "'$appid'" + echo installed >> "$__messages_out" + fi + # else, everything is ok + ;; + + absent) + occ app:remove "'$appid'" + echo removed >> "$__messages_out" + ;; + esac +fi diff --git a/type/__nextcloud_app/man.rst b/type/__nextcloud_app/man.rst new file mode 100644 index 0000000..2b13c5c --- /dev/null +++ b/type/__nextcloud_app/man.rst @@ -0,0 +1,131 @@ +cdist-type__nextcloud_app(7) +============================ + +NAME +---- +cdist-type__nextcloud_app - Managese a Nextcloud app installation + + +DESCRIPTION +----------- +This types manages an app for a Nextcloud installation. For now, you can only +(un-)install or enable/disable an app. + +The object id is the appid of the app which will be managed by this type. It +will be overwritten by the parameter `--appid`. See this parameter for more +information about the appid. + + +REQUIRED PARAMETERS +------------------- +cloud + The absolute path of the Nextcloud installation. + + +OPTIONAL PARAMETERS +------------------- +state + The state of the app. Can be the following: + + present *(default)* + The app is installed. + + enabled + The app is installed and enabled. + + disabled + The app is installed, but disabled. + + absent + The app is not installed. + +appid + The appid is the uniquie identifier for an app in the Nextcloud app store. + It is required to know which app should be installed, which is expressed + via the appid. Apps who are shipped by the installation can not be removed. + Doing this will throw an error at exeuction time. + + To find the appid, you must select the app in the Nextcloud app menu or on + the app page in the Nextcloud app store. Then, examine the URL and use the + lastest part (e.g. "the filename") as appid. + +www-user + The unix user which will be used to execute Nextcloud related stuff. You + should always use the same user for all Nextcloud interactions, for the + webserver and cli execution. As default, `www-data` will be used. + + +MESSAGES +-------- +installed + The app was installed. + +enabled + The app is already installed and was enabled. + +disabled + The app is already installed and was disabled. + +removed + The app was removed. + + +EXAMPLES +-------- + +.. code-block:: sh + + # nextcloud base installation + __nextcloud cloud $args + + # install the music app + require="__nextcloud/cloud" __nextcloud_app music \ + --cloud /var/www/html/cloud/ --state enabled + + # enable a shipped app (already installed) + require="__nextcloud/cloud" __nextcloud_app files_external \ + --cloud /var/www/html/cloud/ --state enabled + + # remove some app + require="__nextcloud/cloud" __nextcloud_app drawio \ + --cloud /var/www/html/cloud/ --state absent + + +NOTES +----- +Currently, it manages just if the app is installed and enabled. Further +implementation is possible, but not done yet. This contains the management of +the app settings (via ``occ config:app:*``) and further finetuning to the +possibilities of installation and enablement (force-enable an app or restrict +enablement only to some groups). + +Special app settings could also be written as a new type which completly +handles this one app with all configuration options. + +Upgrading an Nextcloud app may be possible, but not the scope of this type. +Also, the upgrade can not be done to a given version, which results that this +type will loose the control over the state of the app. Installing the app +manually or hooking into the Nextcloud code is too unsafe and complex, in +addition it will be used rarely. Most admins would propably just update the app +via the web interface. + + +SEE ALSO +-------- +`Nextcloud app store `_ + +:strong:`cdist-type__nextcloud`\ (7) +:strong:`cdist-type__nextcloud_user`\ (7) + + +AUTHORS +------- +Matthias Stecher + + +COPYING +------- +Copyright \(C) 2020 Matthias Stecher. +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/__nextcloud_app/parameter/default/state b/type/__nextcloud_app/parameter/default/state new file mode 100644 index 0000000..e7f6134 --- /dev/null +++ b/type/__nextcloud_app/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/type/__nextcloud_app/parameter/default/www-user b/type/__nextcloud_app/parameter/default/www-user new file mode 100644 index 0000000..5bbad18 --- /dev/null +++ b/type/__nextcloud_app/parameter/default/www-user @@ -0,0 +1 @@ +www-data diff --git a/type/__nextcloud_app/parameter/optional b/type/__nextcloud_app/parameter/optional new file mode 100644 index 0000000..0f2a3eb --- /dev/null +++ b/type/__nextcloud_app/parameter/optional @@ -0,0 +1,3 @@ +state +appid +www-user diff --git a/type/__nextcloud_app/parameter/required b/type/__nextcloud_app/parameter/required new file mode 100644 index 0000000..c3de202 --- /dev/null +++ b/type/__nextcloud_app/parameter/required @@ -0,0 +1 @@ +cloud diff --git a/type/__nextcloud_user/man.rst b/type/__nextcloud_user/man.rst index 39ff38a..f0ceff9 100644 --- a/type/__nextcloud_user/man.rst +++ b/type/__nextcloud_user/man.rst @@ -142,11 +142,11 @@ EXAMPLES .. code-block:: sh - # nextcloud base installation - __nextcloud cloud + # nextcloud base installation + __nextcloud cloud $args - # setups an user, but do not touch it after it was created - require="__nextcloud/cloud" __nextcloud_user foo \ + # setups an user, but do not touch it after it was created + require="__nextcloud/cloud" __nextcloud_user foo \ --cloud /var/www/html/cloud/ \ --displayname "Big Fooo" \ --email "foo@bar.tld" \