1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dato_ynh.git synced 2024-09-03 18:16:33 +02:00
dato_ynh/scripts/install

144 lines
6.1 KiB
Text
Raw Normal View History

2021-03-11 00:34:24 +01:00
#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-02-28 22:22:42 +01:00
# INITIALIZE AND STORE SETTINGS
2021-03-11 00:34:24 +01:00
#=================================================
2024-02-28 22:22:42 +01:00
# Convert to true/false
autosynchronize=$(bool_to_str "$autosynchronize")
ynh_app_setting_set --app="$app" --key=autosynchronize --value="$autosynchronize"
2021-08-05 23:28:50 +02:00
2021-03-11 00:34:24 +01:00
#=================================================
2024-02-28 22:22:42 +01:00
# INSTALL NODEJS
2021-03-11 00:34:24 +01:00
#=================================================
2024-02-28 22:22:42 +01:00
ynh_script_progression --message="Installing NodeJS..." --weight=6
2021-03-11 00:34:24 +01:00
2024-02-28 22:22:42 +01:00
ynh_install_nodejs --nodejs_version="$nodejs_version"
2021-03-11 00:34:24 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=2
2021-08-05 23:28:50 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2024-02-28 22:22:42 +01:00
ynh_setup_source --dest_dir="$install_dir"
2021-03-11 00:34:24 +01:00
2024-02-28 22:22:42 +01:00
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
2022-07-29 01:48:52 +02:00
2021-03-11 00:34:24 +01:00
#=================================================
# BUILD NODE DEPENDENCIES
#=================================================
ynh_script_progression --message="Building node dependencies..." --weight=90
2024-02-28 22:22:42 +01:00
pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" install --loglevel warn
2021-03-11 00:34:24 +01:00
popd
#=================================================
2022-07-29 01:48:52 +02:00
# ADD A CONFIGURATION
2021-03-11 00:34:24 +01:00
#=================================================
2022-07-29 01:48:52 +02:00
ynh_script_progression --message="Adding a configuration file..." --weight=3
2021-03-11 00:34:24 +01:00
2022-07-29 01:48:52 +02:00
dato_setup_config_files
2021-03-11 00:34:24 +01:00
#=================================================
# CUSTOMIZE SETUP FOR AUTOSYNCHRONIZATION
#=================================================
if [[ $autosynchronize == true ]]; then
#=================================================
# CUSTOMIZE COUCHDB SETTINGS
#=================================================
ynh_script_progression --message="Customizing couch config..." --weight=2
# make sure that couchdb has CORS enabled and that it accepts requests from dato domain
ynh_add_config --template="../conf/couch.ini" --destination="/opt/couchdb/etc/local.d/$app.ini"
# restart couchdb service so that it takes into consideration the changes
yunohost service restart couchdb
2021-03-11 00:34:24 +01:00
#=================================================
# SETUP A COUCHDB DATO ADMIN USER
#=================================================
ynh_script_progression --message="Setting up admin user in couch..." --weight=2
# figure out couch url with password
couch_pw_url=$(echo "$couch_url" | sed -En "s+^https?://+https://$couch_admin_name:$couch_admin_password@+p")
# add admin user to couch users database
addDatoAdmin_curlResult=$(curl -X PUT "$couch_pw_url/_users/org.couchdb.user:$couch_datoadmin_name" \
2021-03-11 00:34:24 +01:00
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"name\": \"$couch_datoadmin_name\", \"password\": \"$couch_datoadmin_password\", \"roles\": [\"dato-admin\"], \"type\": \"user\"}" 2> /dev/null)
# display error message if there was an error creating dato admin user in couch
2021-09-10 14:07:06 +02:00
if [[ $addDatoAdmin_curlResult != '{"ok":true'* ]]; then
2021-03-11 00:34:24 +01:00
ynh_print_err --message="There was an error creating the dato admin user for in couch. You will probably have to do it manually (check the last section of this page for instructions: https://squeak.eauchat.org/apps/dato/?setups)."
ynh_print_err --message="Here is the error message from couchdb:"
ynh_print_err --message="$addDatoAdmin_curlResult"
2021-03-11 00:34:24 +01:00
ynh_print_err --message="Please make sure that your couchdb instance is accessible from the url you provided, with a proper SSL certificate (not a self-signed one), otherwise you will not be able to login to dato!"
fi
# modify _users db _security document
usersSecDoc=$(curl -X GET "$couch_pw_url/_users/_security")
usersSecDocModified=$(echo $usersSecDoc | jq '.members.roles += ["dato", "dato-admin"]')
usersSecDocChange_curlResult=$(curl -X PUT "$couch_pw_url/_users/_security" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "$usersSecDocModified" 2> /dev/null)
# display error message if there was an error modifying _users db _security document
2021-09-10 14:07:06 +02:00
if [[ $usersSecDocChange_curlResult != '{"ok":true'* ]]; then
ynh_print_err --message="There was an error enabling dato users to access their user profile in couch. You will have to do it manually (check the 'Configure couchdb so that it accepts requests from dato' section in the following page for instructions: https://squeak.eauchat.org/apps/dato/?setups)."
ynh_print_err --message="Here is the error message from couchdb:"
ynh_print_err --message="$usersSecDocChange_curlResult"
fi
2021-03-11 00:34:24 +01:00
fi
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2024-02-28 22:22:42 +01:00
[ -d "$install_dir/dist" ] || mkdir "$install_dir/dist"
chown -R $app:$app $install_dir/dist $install_dir/global $install_dir/config
2021-03-11 00:34:24 +01:00
2022-07-29 01:48:52 +02:00
#=================================================
2024-02-28 22:22:42 +01:00
# SYSTEM CONFIGURATION
2021-03-11 00:34:24 +01:00
#=================================================
2024-02-28 22:22:42 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2021-03-11 00:34:24 +01:00
2024-02-28 22:22:42 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2021-03-11 00:34:24 +01:00
2024-02-28 22:22:42 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="Data storage with a convenient and flexible interface" --log="/var/log/$app/$app.log"
2021-03-11 00:34:24 +01:00
2024-02-28 22:22:42 +01:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
2021-03-11 00:34:24 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-02-28 22:22:42 +01:00
ynh_script_progression --message="Starting $app's systemd service..." --weight=60
2021-03-11 00:34:24 +01:00
2021-08-05 23:28:50 +02:00
# Start a systemd service
2024-02-28 22:22:42 +01:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="electrode server listening on port" --timeout=600
2021-03-11 00:34:24 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last