Initial __nextcloud_app type

Overall complete, more functionalitly is currently out of scope.
This commit is contained in:
matze 2020-10-31 16:47:39 +01:00
parent 9ed1a9cbfd
commit 7490cef49e
8 changed files with 264 additions and 4 deletions

View File

@ -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 <<SU
cd '$cloud'
# Output all apps and search in which category it is
php occ --no-warnings --no-interaction --no-ansi --output=plain app:list \
| awk '\$0 == "Enabled:"{state="enabled"} \$0 == "Disabled:"{state="disabled"}
/^ - ${appid}:?/{found=1; print state; exit} END{if(!found) print "absent"}'
SU
fi
fi

View File

@ -0,0 +1,85 @@
#!/bin/sh -e
# __nextcloud_app/gencode-remote
# Handles a nextcloud app.
# Call the nextcloud occ script as the intended user. Maybe this can be a bit
# more effictive with user switching, but currently the easiest way of doing
# it.
#
# All arguments are directly passed to occ (injection alarm ;-) )
occ() {
# su creates a new shell, so it does not affect the current session
# will not use -q as it supresses errors, too
cat << SHELL
su -s /bin/sh -l "$www_user" -- -e <<'SU'
cd '$cloud' && php occ --no-warnings --no-interaction --no-ansi $@
SU
SHELL
}
# Get the app id
appid="$__object/parameter/appid"
if [ -f "$appid" ]; then
appid="$(cat "$appid")"
else
appid="$__object_id"
fi
# Get the app state
state_is="$(cat "$__object/explorer/state")"
state_should="$(cat "$__object/parameter/state")"
# Get general parameters
cloud="$(cat "$__object/parameter/cloud")"
www_user="$(cat "$__object/parameter/www-user")"
# Abort if nextcloud is not installed
if [ -z "$state_is" ]; then
printf "No nextcloud installation could be detected in '%s' ..\n" "$cloud" >&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

View File

@ -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 <https://apps.nextcloud.com/>`_
:strong:`cdist-type__nextcloud`\ (7)
:strong:`cdist-type__nextcloud_user`\ (7)
AUTHORS
-------
Matthias Stecher <matthiasstecher at gmx.de>
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.

View File

@ -0,0 +1 @@
present

View File

@ -0,0 +1 @@
www-data

View File

@ -0,0 +1,3 @@
state
appid
www-user

View File

@ -0,0 +1 @@
cloud

View File

@ -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" \