mirror of
https://github.com/YunoHost-Apps/dokuwiki_ynh.git
synced 2024-09-03 18:26:20 +02:00
295 lines
9.4 KiB
Bash
295 lines
9.4 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# Load common variables for all scripts.
|
|
#source _variables TODO: remove ?
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS
|
|
#=================================================
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
#=================================================
|
|
# SPECIFIC CODE
|
|
#=================================================
|
|
# DECLARE GENERIC FUNCTION
|
|
#=================================================
|
|
|
|
#config_file="$final_path/settings.json"
|
|
|
|
#get_config_value() {
|
|
# option_name="$1"
|
|
# # Get the value of this option in the config file
|
|
# grep "\"$option_name\" *:" "$config_file" | cut -d':' -f2 | sed s'/ //g' | cut -d',' -f1
|
|
#
|
|
#}
|
|
|
|
#=================================================
|
|
# LOAD VALUES
|
|
#=================================================
|
|
|
|
# Load the real value from the app config or elsewhere.
|
|
# Then get the value from the form.
|
|
# If the form has a value for a variable, take the value from the form,
|
|
# Otherwise, keep the value from the app config.
|
|
|
|
# Some bash magic explained before diving into the code
|
|
# ${VAR:-WORD}
|
|
# If VAR is not defined or null, the expansion of WORD is substituted; otherwise the value of VAR is substituted:
|
|
# See http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_10_03.html#sect_10_03_03
|
|
|
|
# is_public
|
|
old_is_public="$(ynh_app_setting_get $app is_public)"
|
|
if [ $old_is_public -eq 1 ]
|
|
then
|
|
old_is_public=true
|
|
else
|
|
old_is_public=false
|
|
fi
|
|
is_public="${YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC:-$old_is_public}"
|
|
|
|
# is_internal_users
|
|
old_is_internal_users="$(ynh_app_setting_get $app is_internal_users)"
|
|
if [ $old_is_internal_users -eq 1 ]
|
|
then
|
|
old_is_internal_users=true
|
|
else
|
|
old_is_internal_users=false
|
|
fi
|
|
is_internal_users="${YNH_CONFIG_MAIN_IS_INTERNAL_USERS_IS_INTERNAL_USERS:-$old_is_internal_users}"
|
|
|
|
|
|
# # Export
|
|
# old_export="$(ynh_app_setting_get $app export)"
|
|
# export="${YNH_CONFIG_MAIN_EXPORT_EXPORT:-$old_export}"
|
|
#
|
|
# # padOptions noColors
|
|
# old_pad_config_nocolors="$(get_config_value noColors)"
|
|
# pad_config_nocolors="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_NOCOLORS:-$old_pad_config_nocolors}"
|
|
# # padOptions showLineNumbers
|
|
# old_pad_config_showlinenumbers="$(get_config_value showLineNumbers)"
|
|
# pad_config_showlinenumbers="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOWLINENUMBERS:-$old_pad_config_showlinenumbers}"
|
|
# # padOptions chatAndUsers
|
|
# old_pad_config_chatandusers="$(get_config_value chatAndUsers)"
|
|
# pad_config_chatandusers="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_CHATANDUSERS:-$old_pad_config_chatandusers}"
|
|
# # padOptions alwaysShowChat
|
|
# old_pad_config_alwaysshowchat="$(get_config_value alwaysShowChat)"
|
|
# pad_config_alwaysshowchat="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_ALWAYSSHOWCHAT:-$old_pad_config_alwaysshowchat}"
|
|
# # Plugin option ep_markdown_default
|
|
# old_pad_config_show_markdown="$(get_config_value ep_markdown_default)"
|
|
# pad_config_show_markdown="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOW_MARKDOWN:-$old_pad_config_show_markdown}"
|
|
# # Plugin option ep_page_view_default
|
|
# old_pad_config_pageview="$(get_config_value ep_page_view_default)"
|
|
# pad_config_pageview="${YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_PAGEVIEW:-$old_pad_config_pageview}"
|
|
#
|
|
# # Mypads
|
|
# if [ -d $final_path/node_modules/ep_mypads ]
|
|
# then
|
|
# old_mypads=true
|
|
# else
|
|
# old_mypads=false
|
|
# fi
|
|
# mypads="${YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_MYPADS:-$old_mypads}"
|
|
# # Ldap for Mypads
|
|
# if grep -q "//noldap" $config_file
|
|
# then
|
|
# old_useldap=false
|
|
# else
|
|
# old_useldap=true
|
|
# fi
|
|
# useldap="${YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_USELDAP:-$old_useldap}"
|
|
|
|
#=================================================
|
|
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
|
|
#=================================================
|
|
|
|
show_config() {
|
|
# here you are supposed to read some config file/database/other then print the values
|
|
# echo "YNH_CONFIG_${PANEL_ID}_${SECTION_ID}_${OPTION_ID}=value"
|
|
|
|
ynh_return "YNH_CONFIG_MAIN_IS_PUBLIC_IS_PUBLIC=$is_public"
|
|
ynh_return "YNH_CONFIG_MAIN_IS_INTERNAL_USERS_IS_INTERNAL_USERS=$is_internal_users"
|
|
|
|
|
|
# echo "YNH_CONFIG_MAIN_EXPORT_EXPORT=$export"
|
|
#
|
|
# echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_NOCOLORS=$pad_config_nocolors"
|
|
# echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOWLINENUMBERS=$pad_config_showlinenumbers"
|
|
# echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_CHATANDUSERS=$pad_config_chatandusers"
|
|
# echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_ALWAYSSHOWCHAT=$pad_config_alwaysshowchat"
|
|
# echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_SHOW_MARKDOWN=$pad_config_show_markdown"
|
|
# echo "YNH_CONFIG_MAIN_PAD_CONFIGURATION_PAD_CONFIG_PAGEVIEW=$pad_config_pageview"
|
|
#
|
|
# echo "YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_MYPADS=$mypads"
|
|
# echo "YNH_CONFIG_MAIN_MYPADS_CONFIGURATION_USELDAP=$useldap"
|
|
}
|
|
|
|
#=================================================
|
|
# MODIFY THE CONFIGURATION
|
|
#=================================================
|
|
|
|
apply_config() {
|
|
|
|
# Change public accessibility
|
|
if [ "$is_public" = "true" ]; then
|
|
is_public=1
|
|
else
|
|
is_public=0
|
|
fi
|
|
|
|
if [ $is_public -eq 1 ]; then
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
else
|
|
ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO...
|
|
fi
|
|
ynh_app_setting_set $app is_public $is_public
|
|
yunohost app ssowatconf
|
|
|
|
|
|
|
|
# Change internal users functionnality
|
|
if [ "$is_internal_users" = "true" ]; then
|
|
is_internal_users=1
|
|
else
|
|
is_internal_users=0
|
|
fi
|
|
|
|
if [ $is_internal_users -eq 1 ]; then
|
|
ynh_app_setting_set $app skipped_uris "/"
|
|
else
|
|
ynh_app_setting_set $app skipped_uris "/admin" # etherpad admin page doesn't support SSO...
|
|
fi
|
|
ynh_app_setting_set $app is_internal_users $is_internal_users
|
|
yunohost app ssowatconf
|
|
|
|
|
|
# restart_etherpad=0
|
|
#
|
|
# # Change configuration if needed
|
|
# # padOptions noColors
|
|
# if [ "$pad_config_nocolors" != "$old_pad_config_nocolors" ]
|
|
# then
|
|
# ynh_replace_string "\(\"noColors\" *: \).*," "\1$pad_config_nocolors," "$config_file"
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # padOptions showLineNumbers
|
|
# if [ "$pad_config_showlinenumbers" != "$old_pad_config_showlinenumbers" ]
|
|
# then
|
|
# ynh_replace_string "\(\"showLineNumbers\" *: \).*," "\1$pad_config_showlinenumbers," "$config_file"
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # padOptions chatAndUsers
|
|
# if [ "$pad_config_chatandusers" != "$old_pad_config_chatandusers" ]
|
|
# then
|
|
# ynh_replace_string "\(\"chatAndUsers\" *: \).*," "\1$pad_config_chatandusers," "$config_file"
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # padOptions alwaysShowChat
|
|
# if [ "$pad_config_alwaysshowchat" != "$old_pad_config_alwaysshowchat" ]
|
|
# then
|
|
# ynh_replace_string "\(\"alwaysShowChat\" *: \).*," "\1$pad_config_alwaysshowchat," "$config_file"
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # Plugin option ep_markdown_default
|
|
# if [ "$pad_config_show_markdown" != "$old_pad_config_show_markdown" ]
|
|
# then
|
|
# ynh_replace_string "\(\"ep_markdown_default\" *: \).*," "\1$pad_config_show_markdown," "$config_file"
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # Plugin option ep_page_view_default
|
|
# if [ "$pad_config_pageview" != "$old_pad_config_pageview" ]
|
|
# then
|
|
# ynh_replace_string "\(\"ep_page_view_default\" *: \).*," "\1$pad_config_pageview," "$config_file"
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # Export
|
|
# if [ "$export" != "$old_export" ]
|
|
# then
|
|
# if [ "$export" = "abiword" ]
|
|
# then
|
|
# # if abiword isn't installed, call the action add_remove_abiword.
|
|
# if ! which abiword > /dev/null
|
|
# then
|
|
# yunohost app action run $app add_remove_abiword
|
|
# fi
|
|
# ynh_replace_string "\(\"abiword\" *: \).*," "\1\"$(which abiword)\"," "$config_file"
|
|
# ynh_replace_string "\(\"soffice\" *: \).*," "\1null," "$config_file"
|
|
# elif [ "$export" = "libreoffice" ]
|
|
# then
|
|
# # if libreoffice isn't installed, call the action add_remove_libreoffice.
|
|
# if ! which soffice > /dev/null
|
|
# then
|
|
# yunohost app action run $app add_remove_libreoffice
|
|
# fi
|
|
# ynh_replace_string "\(\"abiword\" *: \).*," "\1null," "$config_file"
|
|
# ynh_replace_string "\(\"soffice\" *: \).*," "\1\"$(which soffice)\"," "$config_file"
|
|
# else
|
|
# ynh_replace_string "\(\"abiword\" *: \).*," "\1null," "$config_file"
|
|
# ynh_replace_string "\(\"soffice\" *: \).*," "\1null," "$config_file"
|
|
# fi
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # Mypads
|
|
# if [ "$mypads" != "$old_mypads" ]
|
|
# then
|
|
# ynh_use_nodejs
|
|
# pushd "$final_path"
|
|
# if [ "$mypads" = "true" ]
|
|
# then
|
|
# npm install ep_mypads@${mypads_version}
|
|
# else
|
|
# npm uninstall ep_mypads
|
|
# fi
|
|
# popd
|
|
# chown -R $app: $final_path/node_modules
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
# # Ldap for Mypads
|
|
# if [ "$useldap" != "$old_useldap" ]
|
|
# then
|
|
# if [ "$useldap" = "true" ]
|
|
# then
|
|
# ynh_replace_string "//noldap\(.*\)" "\1 //useldap" "$final_path/settings.json"
|
|
# else
|
|
# ynh_replace_string "\(.*\) //useldap" "//noldap\1" "$final_path/settings.json"
|
|
# fi
|
|
# restart_etherpad=1
|
|
# fi
|
|
#
|
|
#
|
|
# if [ $restart_etherpad -eq 1 ]
|
|
# then
|
|
# # Wait for etherpad to be fully started
|
|
# ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120"
|
|
# fi
|
|
}
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
|
|
#=================================================
|
|
|
|
case $1 in
|
|
show) show_config;;
|
|
apply) apply_config;;
|
|
esac
|