mirror of
https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git
synced 2024-09-03 18:36:09 +02:00
366 lines
15 KiB
Bash
366 lines
15 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC STARTING
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
|
sleep 60
|
|
fi
|
|
|
|
# Load common variables for all scripts.
|
|
source _variables
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
# Clean installation remainings that are not handled by the remove script.
|
|
ynh_clean_check_starting
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
path_url=$YNH_APP_ARG_PATH
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
ynh_print_OFF; password=$YNH_APP_ARG_PASSWORD; ynh_print_ON
|
|
language=$YNH_APP_ARG_LANGUAGE
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
export=$YNH_APP_ARG_EXPORT
|
|
mypads=$YNH_APP_ARG_MYPADS
|
|
useldap=$YNH_APP_ARG_USELDAP
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
ynh_print_OFF
|
|
if [ "${#password}" -lt 8 ] || [ "${#password}" -gt 30 ]
|
|
then
|
|
ynh_die --message="The password must be between 8 and 30 characters."
|
|
fi
|
|
ynh_print_ON
|
|
|
|
final_path=/var/www/$app
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
# Register (book) web path
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..." --weight=3
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
ynh_print_OFF; ynh_app_setting_set --app=$app --key=password --value=$password; ynh_print_ON
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
|
ynh_app_setting_set --app=$app --key=export --value=$export
|
|
ynh_app_setting_set --app=$app --key=mypads --value=$mypads
|
|
ynh_app_setting_set --app=$app --key=useldap --value=$useldap
|
|
ynh_app_setting_set --app=$app --key=overwrite_settings --value="1"
|
|
ynh_app_setting_set --app=$app --key=overwrite_credentials --value="1"
|
|
ynh_app_setting_set --app=$app --key=overwrite_nginx --value="1"
|
|
ynh_app_setting_set --app=$app --key=overwrite_systemd --value="1"
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# FIND AND OPEN A PORT
|
|
#=================================================
|
|
ynh_script_progression --message="Finding an available port..." --weight=2
|
|
|
|
# Find a free port
|
|
port=$(ynh_find_port --port=9001)
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..." --weight=120
|
|
|
|
if [ "$export" = "abiword" ]; then
|
|
ynh_exec_warn_less ynh_install_app_dependencies $abiword_app_depencencies
|
|
elif [ "$export" = "libreoffice" ]; then
|
|
ynh_exec_warn_less ynh_install_app_dependencies $libreoffice_app_dependencies
|
|
fi
|
|
|
|
#=================================================
|
|
# INSTALL NODEJS
|
|
#=================================================
|
|
ynh_script_progression --message="Installing NodeJS..." --weight=12
|
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
|
|
#=================================================
|
|
# CREATE A MYSQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a MySQL database..."
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
db_user=$db_name
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
ynh_mysql_setup_db --db_user=$db_name --db_name=$db_name
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring system user..." --weight=3
|
|
|
|
# Create a dedicated system user
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=4
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring log rotation..."
|
|
|
|
# Create log directory
|
|
mkdir -p /var/log/$app
|
|
touch /var/log/$app/etherpad.log
|
|
install_log=/var/log/$app/installation.log
|
|
touch $install_log
|
|
chown $app -R /var/log/$app
|
|
|
|
# Setup logrotate
|
|
ynh_use_logrotate --specific_user=$app/$app
|
|
|
|
#=================================================
|
|
# INSTALL ETHERPAD
|
|
#=================================================
|
|
ynh_script_progression --message="Installing Etherpad..." --weight=90
|
|
|
|
chown -R $app: $final_path
|
|
pushd $final_path
|
|
ynh_use_nodejs
|
|
ynh_exec_as $app env "$ynh_node_load_PATH" bin/installDeps.sh
|
|
popd
|
|
|
|
#=================================================
|
|
# CONFIGURE ETHERPAD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring Etherpad..." --weight=6
|
|
|
|
cp ../conf/settings.json "$final_path/settings.json"
|
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/settings.json"
|
|
if [ "$export" = "abiword" ]
|
|
then
|
|
# Get Abiword binary path
|
|
abiword_path=`which abiword`
|
|
# Set the path of abiword into Etherpad config
|
|
ynh_replace_string --match_string="\"abiword\" : null" --replace_string="\"abiword\" : \"$abiword_path\"" --target_file="$final_path/settings.json"
|
|
elif [ "$export" = "libreoffice" ]
|
|
then
|
|
# Get soffice binary path
|
|
soffice_path=`which soffice`
|
|
# Set the path of soffice into Etherpad config
|
|
ynh_replace_string --match_string="\"soffice\" : null" --replace_string="\"soffice\" : \"$soffice_path\"" --target_file="$final_path/settings.json"
|
|
fi
|
|
ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="$final_path/settings.json"
|
|
|
|
# Use ldap for mypads
|
|
if [ $mypads -eq 1 ] && [ $useldap -eq 1 ]
|
|
then
|
|
ynh_replace_string --match_string="//noldap\(.*\)" --replace_string="\1 //useldap" --target_file="$final_path/settings.json"
|
|
fi
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
ynh_store_file_checksum --file="$final_path/settings.json"
|
|
|
|
ynh_add_config --template="../conf/credentials.json" --destination="$final_path/credentials.json"
|
|
|
|
#=================================================
|
|
# SECURING FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set files ownership to etherpad
|
|
chown -R $app:$app $final_path
|
|
chmod o-rwx $final_path
|
|
# Restrict access to credentials.json
|
|
chmod 600 $final_path/credentials.json
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=4
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config --others_var="ynh_node_load_PATH"
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log"
|
|
|
|
#=================================================
|
|
# INSTALL FRAMAPAD'S PLUGINS
|
|
#=================================================
|
|
ynh_script_progression --message="Installing Etherpad plugins..." --weight=90
|
|
|
|
pushd "$final_path"
|
|
# Add Left/Center/Right/Justify to lines of text in a pad
|
|
ynh_npm install ep_align@${ep_align_version} >> $install_log 2>&1
|
|
# Framapad - Adds author names to span titles
|
|
ynh_npm install ep_author_hover@${ep_author_hover_version} >> $install_log 2>&1
|
|
# Framapad - Adds comments on sidebar and link it to the text.
|
|
ynh_npm install ep_comments_page@${ep_comments_page_version} >> $install_log 2>&1
|
|
# Framapad - Displays paragraphs, sentences, words and characters counts.
|
|
ynh_npm install ep_countable@${ep_countable_version} >> $install_log 2>&1
|
|
# Framapad - Delete pads which were never edited
|
|
ynh_npm install ep_delete_empty_pads@${ep_delete_empty_pads_version} >> $install_log 2>&1
|
|
# Framapad - Apply colors to fonts
|
|
ynh_npm install ep_font_color@${ep_font_color_version} >> $install_log 2>&1
|
|
# Framapad - Adds heading support to Etherpad Lite.
|
|
ynh_npm install ep_headings2@${ep_headings2_version} >> $install_log 2>&1
|
|
# Framapad - Edit and Export as Markdown in Etherpad
|
|
ynh_npm install ep_markdown@${ep_markdown_version} >> $install_log 2>&1
|
|
if [ $mypads -eq 1 ]; then
|
|
# Framapad - Groups and private pads for Etherpad
|
|
ynh_npm install ep_mypads@${mypads_version} >> $install_log 2>&1
|
|
fi
|
|
# Framapad - Add support to do 'Spell checking'
|
|
ynh_npm install ep_spellcheck@${ep_spellcheck_version} >> $install_log 2>&1
|
|
# Framapad - Add support for Subscript and Superscript
|
|
ynh_npm install ep_subscript_and_superscript@${ep_subscript_and_superscript_version} >> $install_log 2>&1
|
|
# Framapad - View a table of contents for your pad
|
|
ynh_npm install ep_table_of_contents@${ep_table_of_contents_version} >> $install_log 2>&1
|
|
# Framapad - User Pad Contents font size can be set in settings, this does not effect other peoples views
|
|
ynh_npm install ep_font_size@${ep_font_size_version} >> $install_log 2>&1
|
|
popd
|
|
chown -R $app: $final_path/node_modules
|
|
|
|
#=================================================
|
|
# SOME HACKS
|
|
#=================================================
|
|
|
|
if [ $mypads -eq 1 ]
|
|
then
|
|
# Add a link to Etherpad to allow anonymous pads creation from MyPads.
|
|
ynh_replace_string --match_string="^ *\"DESCRIPTION\": .*</ul>" --replace_string="&<a href=../>Pads anonymes</a>" --target_file=$final_path/node_modules/ep_mypads/static/l10n/fr.json
|
|
ynh_replace_string --match_string="^ *\"DESCRIPTION\": .*</ul>" --replace_string="&<a href=../>Anonymous pads</a>" --target_file=$final_path/node_modules/ep_mypads/static/l10n/en.json
|
|
# And a link to etherpad admin from Mypads.
|
|
ynh_replace_string --match_string="^ *\"FOOTER\": .*2.0" --replace_string="& | <a href='../admin'>Etherpad admin</a>" --target_file=$final_path/node_modules/ep_mypads/static/l10n/en.json
|
|
ynh_replace_string --match_string="^ *\"FOOTER\": .*2.0" --replace_string="& | <a href='../admin'>Etherpad admin</a>" --target_file=$final_path/node_modules/ep_mypads/static/l10n/fr.json
|
|
|
|
## Find the /div just after the field to open a pad
|
|
#mod_line=$(grep -nA5 "index.createOpenPad" $final_path/src/templates/index.html | grep "</div>" | cut -d '-' -f 1)
|
|
## In order to add a link to MyPads plugin.
|
|
#sed -i "$mod_line s@div>@&\n\t<center><br><font size="5"><a href="./mypads/">MyPads</a></font></center>@" $final_path/src/templates/index.html
|
|
sed -i '157i<center><br><font size="4"><a href="./mypads/" style="text-decoration: none; color: #555">MyPads</a></font></center>' $final_path/src/templates/index.html
|
|
fi
|
|
|
|
#=================================================
|
|
# SETUP FAIL2BAN
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring Fail2Ban..." --weight=13
|
|
|
|
# Create a dedicated Fail2Ban config
|
|
ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST> .* .POST /mypads/api/auth/login HTTP/1.1. 400" --max_retry=5
|
|
|
|
#=================================================
|
|
# SETUP SSOWAT
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring permissions..." --weight=2
|
|
|
|
if [ $is_public -eq 1 ]; then
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
fi
|
|
|
|
# Etherpad admin page doesn't support SSO...
|
|
ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin
|
|
|
|
if [ $mypads -eq 1 ]; then
|
|
ynh_permission_create --permission="mypads_admin" --url="/mypads/?/admin" --allowed=$admin
|
|
fi
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --action=reload --service_name=nginx
|
|
|
|
#=================================================
|
|
# CHECK ETHERPAD STARTING
|
|
#=================================================
|
|
ynh_script_progression --message="Restarting Etherpad..." --weight=20
|
|
|
|
# Wait for etherpad to be fully started
|
|
ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
|
|
|
|
if [ $mypads -eq 1 ]
|
|
then
|
|
ynh_replace_string --match_string="__LANGUAGE__" --replace_string="$language" --target_file="../conf/lang_mypads.sql"
|
|
mysql -u $db_name -p$db_pwd $db_name < "../conf/lang_mypads.sql"
|
|
|
|
# Wait for etherpad to be fully started
|
|
ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
|
|
fi
|
|
|
|
#=================================================
|
|
# SEND A README FOR THE ADMIN
|
|
#=================================================
|
|
|
|
# Get main domain and buid the URL of the admin panel of the app.
|
|
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
|
|
|
|
if [ $mypads -eq 1 ]
|
|
then
|
|
Informations="You can access two different admin panels, for Etherpad by accessing https://$domain${path_url%/}/admin and for MyPads by accessing https://$domain${path_url%/}/mypads/?/admin."
|
|
else
|
|
Informations="You can access the admin panel by accessing https://$domain${path_url%/}/admin."
|
|
fi
|
|
|
|
ynh_print_OFF
|
|
echo "$Informations
|
|
You can also find a config file for Etherpad at this path /var/www/etherpad_mypads/settings.json.
|
|
|
|
You can configure this app easily by using the experimental config-panel feature $admin_panel/config-panel.
|
|
You can also find some specific actions for this app by using the experimental action feature $admin_panel/actions.
|
|
|
|
If you are facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh" > mail_to_send
|
|
|
|
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="$admin" --type=install
|
|
ynh_print_ON
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|