forked from beudbeud/dokuwiki_ynh
-
Notifications
You must be signed in to change notification settings - Fork 17
Action scripts #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Gofannon
wants to merge
23
commits into
YunoHost-Apps:testing
Choose a base branch
from
Gofannon:action_scripts
base: testing
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Action scripts #41
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
bd578c0
[enh] Add variable to handle authentication backend
fb981af
[enh] initial version of "actions scripts"
1f8f545
Preload authchained config
a6c4196
[fix] issues spotted durring review
37b7698
Overload default config for peace of mind
07a018b
Add helper "ynh_smart_mktemp"
1eaf2df
Cleaning
c825710
cleaning 2
854ba94
[enh] Add variable to handle authentication backend
a40ae18
[enh] initial version of "actions scripts"
3a8b257
Preload authchained config
cc96361
[fix] issues spotted durring review
f927f2a
Overload default config for peace of mind
8a460dc
Add helper "ynh_smart_mktemp"
49b5bf8
Cleaning
6bd544f
cleaning 2
f774d68
Merge branch 'testing' into action_scripts
Gofannon 59cf50a
Merge branch 'testing' into action_scripts
Gofannon f944371
Switch to toml and fix scripts
50d08c6
Merge branch 'action_scripts' of github.com:Gofannon/dokuwiki_ynh int…
27e0d31
Update manifest.toml: fix "maintainers" key, empty string is hella co…
alexAubin 1d1a045
Auto-update READMEs
yunohost-bot 030e82d
Merge branch 'testing' into action_scripts
ericgaspar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| [{ | ||
| "id": "public_private", | ||
| "name": "Move to public or private", | ||
| "command": "/bin/bash scripts/actions/public_private", | ||
| "user": "root", | ||
| "accepted_return_codes": [0], | ||
| "description": { | ||
| "en": "Change the public access of the app." | ||
| }, | ||
| "arguments": [ | ||
| { | ||
| "name": "is_public", | ||
| "type": "boolean", | ||
| "ask": { | ||
| "en": "Is it a public app ? (1/0) (1=yes; 0=no)" | ||
| }, | ||
| "default": false | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "id": "internal_users", | ||
| "name": "Allow DokuWiki internal users storage in addition to Yunohost", | ||
| "command": "/bin/bash scripts/actions/internal_users", | ||
| "user": "root", | ||
| "accepted_return_codes": [0], | ||
| "description": { | ||
| "en": "Enable DokuWiki internal users." | ||
| }, | ||
| "arguments": [ | ||
| { | ||
| "name": "is_internal_users", | ||
| "type": "boolean", | ||
| "ask": { | ||
| "en": "Want to enable DokuWiki users too ? (1/0) (1=yes; 0=no)" | ||
| }, | ||
| "default": false | ||
| } | ||
| ] | ||
| }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,38 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Check available space before creating a temp directory. | ||
| # | ||
| # usage: ynh_smart_mktemp --min_size="Min size" | ||
| # | ||
| # | arg: -s, --min_size= - Minimal size needed for the temporary directory, in Mb | ||
| ynh_smart_mktemp () { | ||
| # Declare an array to define the options of this helper. | ||
| declare -Ar args_array=( [s]=min_size= ) | ||
| local min_size | ||
| # Manage arguments with getopts | ||
| ynh_handle_getopts_args "$@" | ||
|
|
||
| min_size="${min_size:-300}" | ||
| # Transform the minimum size from megabytes to kilobytes | ||
| min_size=$(( $min_size * 1024 )) | ||
|
|
||
| # Check if there's enough free space in a directory | ||
| is_there_enough_space () { | ||
| local free_space=$(df --output=avail "$1" | sed 1d) | ||
| test $free_space -ge $min_size | ||
| } | ||
|
|
||
| if is_there_enough_space /tmp; then | ||
| local tmpdir=/tmp | ||
| elif is_there_enough_space /var; then | ||
| local tmpdir=/var | ||
| elif is_there_enough_space /; then | ||
| local tmpdir=/ | ||
| elif is_there_enough_space /home; then | ||
| local tmpdir=/home | ||
| else | ||
| ynh_die "Insufficient free space to continue..." | ||
| fi | ||
|
|
||
| echo "$(sudo mktemp --directory --tmpdir="$tmpdir")" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| #!/bin/bash | ||
|
|
||
| #================================================= | ||
| # GENERIC STARTING | ||
| #================================================= | ||
| # IMPORT GENERIC HELPERS | ||
| #================================================= | ||
|
|
||
| source scripts/_common.sh | ||
| source /usr/share/yunohost/helpers | ||
|
|
||
| #================================================= | ||
| # RETRIEVE ARGUMENTS | ||
| #================================================= | ||
|
|
||
| # Get "is_internal_users" and set as lowercase | ||
| is_internal_users=${YNH_ACTION_IS_INTERNAL_USERS,,} | ||
|
|
||
| # Get the full name of the app, Example: strut__3 | ||
| app=$YNH_APP_INSTANCE_NAME | ||
|
|
||
| admin=$(ynh_app_setting_get $app admin) | ||
| is_public=$(ynh_app_setting_get $app is_public) | ||
| final_path=$(ynh_app_setting_get $app final_path) | ||
|
|
||
| auth_backend_old=$(ynh_app_setting_get $app auth_backend) | ||
| is_internal_users_old=$(ynh_app_setting_get $app is_internal_users) | ||
|
|
||
| #================================================= | ||
| # CHECK IF ARGUMENTS AND REQUIREMENTS ARE CORRECT | ||
| #================================================= | ||
|
|
||
| # Ensure that app is public | ||
| if [ $is_public -eq 0 ]; then | ||
| ynh_die "Wiki must be public if you want your people to be able to reach it. Run 'public_private' and come back here" 1 | ||
| fi | ||
|
|
||
| #================================================= | ||
| # CHECK IF AN ACTION HAS TO BE DONE | ||
| #================================================= | ||
|
|
||
| if [ $is_internal_users -eq $is_internal_users_old ] | ||
| then | ||
| ynh_die "is_internal_users is already set as $is_internal_users." 0 | ||
| fi | ||
|
|
||
| #================================================= | ||
| # SPECIFIC ACTION | ||
| #================================================= | ||
|
|
||
| ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. | ||
| ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. | ||
| ynh_backup_if_checksum_is_different "$final_path/conf/local.protected.php" | ||
|
|
||
| # Always overwrite local file with the one from package. | ||
| cp conf/local.protected.php $final_path/conf | ||
|
|
||
|
|
||
| if [ $is_internal_users -eq 1 ]; then | ||
| auth_backend="authchained" | ||
|
|
||
| # Automatically install "authchained" plugin | ||
| # Allows to use multiple users backend storage : LDAP + internal DokuWiki users | ||
| # See https://www.dokuwiki.org/plugin:authchained?s[]=chained | ||
|
|
||
| plugin_archive=dokuwiki-plugin-authchained.tar.gz | ||
| wget -nv --quiet 'https://github.com/rztuc/dokuwiki-plugin-authchained/archive/master.tar.gz' -O "$plugin_archive" -o /dev/null || true | ||
|
|
||
| # if "file is not zero size" | ||
| if [ -s "$plugin_archive" ]; then | ||
|
|
||
| tmpdir="$(ynh_smart_mktemp --min_size=1)" # Create a 1mb temporary folder | ||
| tar xzf "$plugin_archive" -C "$tmpdir" # Extract plugin to the temp folder | ||
|
|
||
| # Extract the "base" field from the plugin archive to create plugin folder name | ||
| # See https://www.dokuwiki.org/devel:plugin_info | ||
| # | ||
| # 'wildcard' is used to avoid having to find the name of the subfolder | ||
| # It should not change later but who knows... | ||
| plugin_folder_name=$(cat $tmpdir/*/plugin.info.txt | grep url | awk -F ':' '{print $3}') | ||
|
|
||
| # Define the path where plugin has to be installed | ||
| plugin_finalpath="$final_path/lib/plugins/$plugin_folder_name" | ||
| mkdir -p $plugin_finalpath | ||
|
|
||
| # Copy plugin files to DokuWiki plugin directory | ||
| # Doesn't work with "mv" so "cp" instead (taken from "upgrade" script) | ||
| cp -a $tmpdir/*/. "$plugin_finalpath/" | ||
|
|
||
| # Cleaning | ||
| ynh_secure_remove --file="$tmpdir" | ||
|
|
||
| # Set filesystem rights for new plugin | ||
| chown -R $app:root $plugin_finalpath | ||
| fi | ||
| else | ||
| auth_backend="authldap" | ||
| # TODO: Disable/remove "authchained" | ||
|
|
||
|
|
||
| ##$plugins['authchained'] = 0; in plugins.local.php | ||
| # | ||
| # | ||
| ## Use a "sub process" to start a new shell to run these commands | ||
| ## Allow to use only one "cd" and to be more efficent | ||
| #( | ||
| # cd $final_path/conf | ||
| # | ||
| # cp plugins.local.php plugins.local.php.bak | ||
| # | ||
| # # Search if configuration in "config file" is present for plugin to work | ||
| # ## -F, --fixed-strings | ||
| # ## Interpret PATTERN as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to | ||
| # ## be matched. | ||
| # ## -q, --quiet, --silent | ||
| # ## Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an | ||
| # ## error was detected. Also see the -s or --no-messages option. | ||
| # grep --quiet --fixed-strings '$plugins['authchained'] = 0;' "plugins.local.php" | ||
| # if [ $? -ne 0 ]; then | ||
| # echo "not found in file" | ||
| # # If not found, add the setting to "local.protected.php" which can only be edited by Yunohost | ||
| # # "\$conf" needs the "\" to espace the dollar and avoid echo to interprate it as a (void) variable | ||
| # #echo "\$conf['plugin']['authchained']['authtypes'] = 'authldap:authplain';" >> "$final_path/conf/local.protected.php" | ||
| # else | ||
| # echo "not found in file" | ||
| # fi | ||
| # # source: https://stackoverflow.com/questions/3557037/appending-a-line-to-a-file-only-if-it-does-not-already-exist | ||
| # | ||
| #) | ||
| fi | ||
|
|
||
|
|
||
| # Set the authentification backend | ||
| ynh_replace_string "__YNH_AUTH_BACKEND__" "$auth_backend" "$final_path/conf/local.protected.php" | ||
| # Set the "admin" user | ||
| ynh_replace_string "__YNH_ADMIN_USER__" "$admin" "$final_path/conf/local.protected.php" | ||
|
|
||
| # Recalculate and store the config file checksum into the app settings | ||
| ynh_store_file_checksum "$final_path/conf/local.protected.php" | ||
|
|
||
| # Purge cache; see https://www.dokuwiki.org/faq:pluginproblems#cache | ||
| touch $final_path/conf/local.php | ||
|
|
||
| # Update the config of the app | ||
| ynh_app_setting_set $app auth_backend $auth_backend | ||
| ynh_app_setting_set $app is_internal_users $is_internal_users |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/bin/bash | ||
|
|
||
| #================================================= | ||
| # GENERIC STARTING | ||
| #================================================= | ||
| # IMPORT GENERIC HELPERS | ||
| #================================================= | ||
|
|
||
| source /usr/share/yunohost/helpers | ||
|
|
||
| #================================================= | ||
| # RETRIEVE ARGUMENTS | ||
| #================================================= | ||
|
|
||
| # Get is_public and set as lowercase | ||
| is_public=${YNH_ACTION_IS_PUBLIC,,} | ||
|
|
||
| # Get the full name of the app, Example: strut__3 | ||
| app=$YNH_APP_INSTANCE_NAME | ||
|
|
||
| #================================================= | ||
| # CHECK IF ARGUMENTS ARE CORRECT | ||
| #================================================= | ||
|
|
||
| #================================================= | ||
| # CHECK IF AN ACTION HAS TO BE DONE | ||
| #================================================= | ||
|
|
||
| is_public_old=$(ynh_app_setting_get $app is_public) | ||
|
|
||
| if [ $is_public -eq $is_public_old ] | ||
| then | ||
| ynh_die "is_public is already set as $is_public." 0 | ||
| fi | ||
|
|
||
| #================================================= | ||
| # SPECIFIC ACTION | ||
| #================================================= | ||
| # MOVE TO PUBLIC OR PRIVATE | ||
| #================================================= | ||
|
|
||
| if [ $is_public -eq 0 ]; | ||
| then | ||
| ynh_app_setting_delete $app unprotected_uris | ||
| else | ||
| ynh_app_setting_set $app unprotected_uris "/" | ||
| fi | ||
|
|
||
| # Regen ssowat configuration | ||
| yunohost app ssowatconf | ||
|
|
||
| # Update the config of the app | ||
| ynh_app_setting_set $app is_public $is_public | ||
|
|
||
| #================================================= | ||
| # RELOAD NGINX | ||
| #================================================= | ||
|
|
||
| systemctl reload nginx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test is needed as well for
auth_backend