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

194 lines
7.6 KiB
Text
Raw Normal View History

2018-11-21 16:11:09 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2020-05-21 12:49:24 +02:00
source _common.sh
2018-11-21 16:11:09 +01:00
source /usr/share/yunohost/helpers
#=================================================
2019-03-13 16:48:29 +01:00
# MANAGE SCRIPT FAILURE
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_clean_setup () {
ynh_clean_check_starting
}
2019-03-13 16:48:29 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2019-03-13 16:46:11 +01:00
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
app=$YNH_APP_INSTANCE_NAME
2019-03-13 16:48:29 +01:00
domain=$YNH_APP_ARG_DOMAIN
2019-11-27 16:27:54 +01:00
path_url="/"
2019-03-13 16:48:29 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2018-11-21 16:11:09 +01:00
2019-03-13 16:48:29 +01:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
# Register (book) web path
2019-11-28 10:30:38 +01:00
ynh_webpath_register "$app" "$domain" $path_url
2018-11-21 16:11:09 +01:00
2020-05-21 12:49:24 +02:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
ynh_script_progression --message="Configuring firewall..." --weight=2
2019-11-28 02:05:34 +01:00
2020-05-21 12:49:24 +02:00
# Find an available port
port=$(ynh_find_port --port=3002)
ynh_app_setting_set --app="$app" --key="port" --value="$port"
2019-11-28 02:05:34 +01:00
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# STORE SETTINGS FROM MANIFEST
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Storing installation settings..." --weight=2
2018-11-21 16:11:09 +01:00
2020-05-21 12:49:24 +02:00
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="is_public" --value="$is_public"
ynh_app_setting_set --app="$app" --key="final_path" --value="$final_path"
2018-11-21 16:35:21 +01:00
2019-03-13 16:48:29 +01:00
#==============================================
2020-05-21 12:49:24 +02:00
# INSTALL DEPENDENCIES
2019-03-13 16:48:29 +01:00
#==============================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Installing dependencies..." --weight=20
2019-03-13 16:48:29 +01:00
2020-05-21 12:49:24 +02:00
ynh_install_app_dependencies $pkg_dependencies
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2018-11-21 16:35:21 +01:00
2019-11-28 02:05:34 +01:00
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
2019-03-13 16:48:29 +01:00
#==============================================
# CREATE DB
#==============================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Creating a database..." --weight=2
2019-03-13 16:48:29 +01:00
2020-05-21 12:49:24 +02:00
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_user" --db_name="$db_name"
2018-11-21 19:24:30 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-11-21 19:24:30 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Setting up source files..." --weight=2
2018-11-21 19:24:30 +01:00
2019-03-13 16:48:29 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2020-05-21 12:49:24 +02:00
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
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# MODIFY A CONFIG FILE
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# Main config File
2020-05-21 12:49:24 +02:00
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/config.json.example"
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/config.json.example"
2019-11-28 10:30:38 +01:00
cp ../conf/config.json.example "$final_path"/config.json
2019-11-28 02:05:34 +01:00
ynh_store_file_checksum "$final_path/config.json"
2019-03-13 16:48:29 +01:00
# DB Config File
2020-05-21 12:49:24 +02:00
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="../conf/.sequelizerc.example"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="../conf/.sequelizerc.example"
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="../conf/.sequelizerc.example"
2019-11-28 10:30:38 +01:00
cp ../conf/.sequelizerc.example "$final_path"/.sequelizerc
2019-03-13 16:48:29 +01:00
#==============================================
# INSTALL CODIMD
#==============================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Building application... (this will take some time and resources!)" --weight=240
2020-05-21 12:49:24 +02:00
pushd "$final_path" || ynh_die
2020-05-21 12:49:24 +02:00
yarn install --frozen-lockfile && ynh_exec_warn_less yarn run build
2020-05-21 12:49:24 +02:00
popd || ynh_die
2018-11-21 20:09:14 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
# GENERIC FINALIZATION
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# CREATE DEDICATED USER
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Configuring system user..." --weight=3
2019-03-13 16:48:29 +01:00
# Create a system user
2019-11-28 10:30:38 +01:00
ynh_system_user_create "$app"
2020-05-21 12:49:24 +02:00
2019-11-28 10:30:38 +01:00
chown -R "$app":"$app" "$final_path"
2019-03-13 16:48:29 +01:00
2020-05-21 12:49:24 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=2
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
2019-03-13 16:46:11 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
# SETUP SYSTEMD
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__NODE__" --replace_string="$nodejs_path" --target_file="../conf/systemd.service"
2018-11-21 16:11:09 +01:00
2019-11-28 02:05:34 +01:00
ynh_add_systemd_config
2018-11-21 16:11:09 +01:00
2020-05-21 12:49:24 +02:00
yunohost service add "$app" --description "CodiMD daemon" --log="/var/log/$app/$app.log"
2018-11-21 16:11:09 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
# START SYSTEMD SERVICE
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Starting $app..." --weight=2
2019-03-13 16:48:29 +01:00
2020-05-21 12:49:24 +02:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="HTTP Server listening"
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# SETUP SSOWAT
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Configuring SSOwat..." --weight=1
2018-11-21 16:11:09 +01:00
2020-05-21 12:49:24 +02:00
# Make app public if necessary or protect it
[ $is_public -eq 0 ] || ynh_permission_update --permission "main" --add "visitors"
2019-03-13 16:48:29 +01:00
2019-11-28 02:05:34 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Reloading nginx web server..." --weight=2
2019-11-28 02:05:34 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last