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

218 lines
8.2 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
#=================================================
2019-03-13 16:48:29 +01:00
domain=$YNH_APP_ARG_DOMAIN
path_url=$YNH_APP_ARG_PATH
2019-03-13 16:48:29 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-11-21 16:11:09 +01:00
app=$YNH_APP_INSTANCE_NAME
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 --message="This path already contains a folder"
2019-03-13 16:48:29 +01:00
# Register (book) web path
2020-05-29 23:02:01 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2018-11-21 16:11:09 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=2
2020-06-22 23:20:57 +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
#=================================================
# STANDARD MODIFICATIONS
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
2020-05-24 20:32:52 +02:00
port=$(ynh_find_port --port=3000)
2020-05-29 22:31:43 +02:00
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
#=================================================
2020-05-21 12:49:24 +02:00
# INSTALL DEPENDENCIES
#=================================================
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
2020-05-29 22:31:43 +02:00
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 A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL 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
2020-05-23 09:14:00 +02:00
db_pwd=$(ynh_string_random --length=30)
2020-05-29 22:31:43 +02:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
2020-05-23 09:14:00 +02:00
ynh_psql_test_if_first_run
2020-05-29 22:31:43 +02:00
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
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
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-03-13 16:48:29 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2020-05-29 22:31:43 +02:00
ynh_setup_source --dest_dir=$final_path
2020-05-21 12:49:24 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-10-12 22:05:07 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2020-05-21 12:49:24 +02:00
2020-10-12 22:05:07 +02:00
# Create a dedicated NGINX config
2020-05-21 12:49:24 +02:00
ynh_add_nginx_config
2018-11-21 16:11:09 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# SPECIFIC SETUP
#==============================================
# INSTALL CODIMD
#==============================================
2020-10-12 22:05:07 +02:00
ynh_script_progression --message="Building CodiMD... (this will take some time and resources!)" --weight=240
pushd "$final_path" || ynh_die
ynh_use_nodejs
2020-06-22 18:33:34 +02:00
bin/setup
ynh_exec_warn_less yarn run build
popd || ynh_die
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
2020-06-22 23:20:57 +02:00
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="../conf/systemd.service"
ynh_add_systemd_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
#=================================================
ynh_script_progression --message="Modifying a config file..."
2018-11-21 16:11:09 +01:00
cp ../conf/config.json.example "$final_path/config.json"
2020-07-06 13:38:50 +02:00
# Main config File
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/config.json"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/config.json"
2020-07-06 15:38:54 +02:00
ynh_replace_string --match_string="__PATH__" --replace_string="${path_url:1}" --target_file="$final_path/config.json"
2020-07-06 13:38:50 +02:00
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/config.json"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/config.json"
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$final_path/config.json"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/config.json"
2019-03-13 16:48:29 +01:00
2020-07-06 13:38:50 +02:00
ynh_store_file_checksum --file="$final_path/config.json"
cp ../conf/.sequelizerc.example "$final_path/.sequelizerc"
2019-03-13 16:48:29 +01:00
2020-07-06 13:38:50 +02:00
# DB Config File
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/.sequelizerc"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/.sequelizerc"
ynh_replace_string --match_string="__DB_PASS__" --replace_string="$db_pwd" --target_file="$final_path/.sequelizerc"
ynh_store_file_checksum --file="$final_path/.sequelizerc"
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
#=================================================
# SECURE FILES AND DIRECTORIES
2019-03-13 16:48:29 +01:00
#=================================================
ynh_script_progression --message="Securing files and directories..."
2020-05-21 12:49:24 +02:00
# Set permissions to app files
2020-05-29 23:02:01 +02:00
chown -R $app:$app $final_path
2019-03-13 16:48:29 +01:00
2019-03-13 16:46:11 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
2018-11-21 16:11:09 +01:00
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2018-11-21 16:11:09 +01:00
2020-05-29 22:31:43 +02:00
yunohost service add $app --description "Collaborative Markdown notes" --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
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
2019-03-13 16:48:29 +01:00
# Start a systemd service
2020-05-29 22:31:43 +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-06-22 18:33:34 +02:00
# Make app public if necessary or protect it
2020-05-31 11:11:31 +02:00
if [ $is_public -eq 1 ]
then
2020-06-22 18:33:34 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission "main" --add "visitors"
2020-05-31 11:11:31 +02:00
fi
2019-03-13 16:48:29 +01:00
2019-11-28 02:05:34 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-10-12 22:05:07 +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
#=================================================
2020-10-12 22:05:07 +02:00
ynh_script_progression --message="Installation of CodiMD completed" --last