#!/bin/bash #================================================= # GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers # Load common variables for all scripts. source _variables #================================================= # 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 #================================================= ynh_script_progression --message="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="Check if the app can be installed" ynh_print_OFF if [ "${#password}" -lt 8 ] || [ "${#password}" -gt 30 ] then ynh_die "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" # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) # Register (book) web path ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Store settings from manifest" --weight=3 ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url ynh_app_setting_set $app admin $admin ynh_app_setting_set $app is_public $is_public ynh_print_OFF; ynh_app_setting_set $app password $password; ynh_print_ON ynh_app_setting_set $app language $language ynh_app_setting_set $app export $export ynh_app_setting_set $app mypads $mypads ynh_app_setting_set $app useldap $useldap #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= ynh_script_progression --message="Find a free port" --weight=2 # Find a free port port=$(ynh_find_port 9001) ynh_app_setting_set $app port $port #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Install dependencies" --weight=120 if [ "$export" = "abiword" ]; then ynh_install_app_dependencies $abiword_app_depencencies elif [ "$export" = "libreoffice" ]; then ynh_install_app_dependencies $libreoffice_app_dependencies fi #================================================= # INSTALL NODEJS #================================================= ynh_script_progression --message="Install NodeJS" --weight=12 ynh_install_nodejs $nodejs_version #================================================= # CREATE A MYSQL DATABASE #================================================= ynh_script_progression --message="Create a mysql database" db_name=$(ynh_sanitize_dbid $app) ynh_app_setting_set $app db_name $db_name ynh_mysql_setup_db $db_name $db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Download, check and unpack source" --weight=4 ynh_app_setting_set $app final_path $final_path # Download, check integrity and uncompress the source from app.src ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configure nginx" --weight=2 # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Create a dedicated user" --weight=3 # Create a dedicated system user ynh_system_user_create $app $final_path #================================================= # SPECIFIC SETUP #================================================= # HANDLE LOG FILES AND LOGROTATE #================================================= ynh_script_progression --message="Configure logrotate" # 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 #================================================= # INSTALL ETHERPAD #================================================= ynh_script_progression --message="Install Etherpad" --weight=90 # Install dependencies and proceed to the installation ynh_use_nodejs "$final_path/bin/installDeps.sh" > $install_log 2>&1 npm install forever -g >> $install_log 2>&1 #================================================= # CONFIGURE ETHERPAD #================================================= ynh_script_progression --message="Configure Etherpad" --weight=6 cp ../conf/settings.json "$final_path/settings.json" cp ../conf/credentials.json "$final_path/credentials.json" ynh_replace_string "__PORT__" "$port" "$final_path/settings.json" ynh_replace_string "__DB_USER__" "$db_name" "$final_path/credentials.json" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/credentials.json" ynh_replace_string "__ADMIN__" "$admin" "$final_path/credentials.json" ynh_print_OFF; ynh_replace_special_string "__PASSWD__" "$password" "$final_path/credentials.json"; ynh_print_ON if [ "$export" = "abiword" ] then # Get abiword binary path abiword_path=`which abiword` # Set the path of abiword into etherpad config ynh_replace_string "\"abiword\" : null" "\"abiword\" : \"$abiword_path\"" "$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 "\"soffice\" : null" "\"soffice\" : \"$soffice_path\"" "$final_path/settings.json" fi ynh_replace_string "__LANGUAGE__" "$language" "$final_path/settings.json" # Use ldap for mypads if [ $mypads -eq 1 ] && [ $useldap -eq 1 ] then ynh_replace_string "//noldap" "" "$final_path/settings.json" fi # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/settings.json" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "$final_path/credentials.json" #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Set files ownership to etherpad chown -R $app: $final_path # Restrict access to credentials.json chmod 600 $final_path/credentials.json #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configure systemd" --weight=4 ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app --log "/var/log/$app/etherpad.log" #================================================= # INSTALL FRAMAPAD'S PLUGINS #================================================= ynh_script_progression --message="Install Etherpad plugins" --weight=90 pushd "$final_path" # Add Left/Center/Right/Justify to lines of text in a pad npm install ep_align >> $install_log 2>&1 # Framapad - Adds author names to span titles npm install ep_author_hover >> $install_log 2>&1 # Automatically disconnects user after some period of time (Prevent server overload) npm install ep_automatic_logut >> $install_log 2>&1 # Framapad - Adds comments on sidebar and link it to the text. npm install ep_comments_page >> $install_log 2>&1 # Framapad - Displays paragraphs, sentences, words and characters counts. npm install ep_countable >> $install_log 2>&1 # Framapad - Delete pads which were never edited npm install ep_delete_empty_pads >> $install_log 2>&1 # Framapad - Apply colors to fonts npm install ep_font_color >> $install_log 2>&1 # Framapad - Adds heading support to Etherpad Lite. npm install ep_headings2 >> $install_log 2>&1 # Framapad - Edit and Export as Markdown in Etherpad npm install ep_markdown >> $install_log 2>&1 if [ $mypads -eq 1 ]; then # Framapad - Groups and private pads for etherpad npm install ep_mypads@${mypads_version} >> $install_log 2>&1 fi # Framapad - Add support to do 'page view', with a toggle on/off option in Settings, also Page Breaks with Control Enter npm install ep_page_view >> $install_log 2>&1 # Framapad - Add support to do 'Spell checking' npm install ep_spellcheck >> $install_log 2>&1 # Framapad - Add support for Subscript and Superscript npm install ep_subscript_and_superscript >> $install_log 2>&1 # Framapad - View a table of contents for your pad npm install ep_table_of_contents >> $install_log 2>&1 # Framapad - User Pad Contents font size can be set in settings, this does not effect other peoples views npm install ep_user_font_size >> $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 "^ *\"DESCRIPTION\": .*" "&Pads anonymes" $final_path/node_modules/ep_mypads/static/l10n/fr.json ynh_replace_string "^ *\"DESCRIPTION\": .*" "&Anonymous pads" $final_path/node_modules/ep_mypads/static/l10n/en.json # And a link to etherpad admin from Mypads. ynh_replace_string "^ *\"FOOTER\": .*2.0" "& | Etherpad admin" $final_path/node_modules/ep_mypads/static/l10n/en.json ynh_replace_string "^ *\"FOOTER\": .*2.0" "& | Etherpad admin" $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 "" | cut -d '-' -f 1) # In order to add a link to mypads plugin. sed -i "$mod_line s@div>@&\n\t

Mypads
@" $final_path/src/templates/index.html fi #================================================= # SETUP FAIL2BAN #================================================= ynh_script_progression --message="Configure fail2ban" --weight=13 # Create a dedicated fail2ban config ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex=" .* .POST /mypads/api/auth/login HTTP/1.1. 400" --max_retry=5 #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Setup SSOwat" if [ $is_public -eq 1 ]; then ynh_app_setting_set $app skipped_uris "/" else # etherpad admin page doesn't support SSO... ynh_app_setting_set $app skipped_uris "/admin" fi #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reload nginx" ynh_systemd_action --action=reload --service_name=nginx #================================================= # CHECK ETHERPAD STARTING #================================================= ynh_script_progression --message="Restart 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 "__LANGUAGE__" "$language" "../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 #================================================= if [ $mypads -eq 1 ] then Informations="You can access 2 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 message="$Informations Or, you can find a config file for etherpad at this path /var/www/etherpad_mypads/settings.json. Your credentials for the admin panel are: - login : $admin - password : $password 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" ynh_send_readme_to_admin "$message" "$admin" ynh_print_ON #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation completed" --last