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

212 lines
7.3 KiB
Text
Raw Normal View History

2019-03-13 14:15:09 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2022-03-27 04:08:34 +02:00
source ynh_install_ruby__2
2019-03-13 14:15:09 +01:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
2022-03-27 04:08:34 +02:00
ynh_clean_check_starting
2019-03-13 14:15:09 +01:00
}
# 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
2022-04-12 23:01:30 +02:00
path_url="/"
2019-03-13 14:15:09 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Validating installation parameters..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2019-03-13 14:15:09 +01:00
# Register (book) web path
2022-03-27 04:08:34 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2019-03-13 14:15:09 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Storing installation settings..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
#=================================================
# STANDARD MODIFICATIONS
2019-03-13 14:15:09 +01:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Finding an available port..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
2019-03-13 14:15:09 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Installing dependencies..."
2019-03-13 14:15:09 +01:00
2022-04-12 21:49:06 +02:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
2022-04-13 07:25:01 +02:00
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2019-03-13 14:15:09 +01:00
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Creating a PostgreSQL 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
2019-03-13 14:15:09 +01:00
ynh_psql_test_if_first_run
2022-03-27 04:08:34 +02:00
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Setting up source files..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
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"
mkdir -p "$final_path/files" "$final_path/log" "$final_path/tmp" "$final_path/public/plugin_assets"
chmod 750 "$final_path"
chmod 755 "$final_path/files" "$final_path/log" "$final_path/tmp" "$final_path/public/plugin_assets"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# NGINX CONFIGURATION
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Adding a configuration file..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
ynh_add_config --template="../conf/database.example.yml" --destination="$final_path/config/database.yml"
chmod 400 "$final_path/config/database.yml"
chown $app:$app "$final_path/config/database.yml"
ynh_add_config --template="../conf/configuration.yml.example" --destination="$final_path/config/configuration.yml"
chmod 400 "$final_path/config/configuration.yml"
chown $app:$app "$final_path/config/configuration.yml"
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# BUILD APP
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Building app..."
2019-03-13 14:15:09 +01:00
2019-03-13 14:24:50 +01:00
pushd $final_path
2022-03-27 04:08:34 +02:00
ynh_use_ruby
ynh_gem update --system --no-document
ynh_gem install bundler passenger --no-document
2022-04-12 23:04:01 +02:00
bundle config set --local without 'development test rmagick'
2022-03-27 04:08:34 +02:00
bundle install
ynh_exec_warn_less bundle exec rake generate_secret_token RAILS_ENV=production
ynh_exec_warn_less bundle exec rake db:migrate RAILS_ENV=production
#ynh_exec_warn_less bundle exec rake redmine:load_default_data RAILS_ENV=production
2019-03-13 14:15:09 +01:00
popd
2022-04-13 07:25:01 +02:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2022-03-27 04:08:34 +02:00
chmod 750 "$final_path/public"
chmod -R o-rwx "$final_path/public"
chown -R $app:www-data "$final_path/public"
2019-03-13 14:15:09 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Configuring a systemd service..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
# Create a dedicated systemd config
2019-03-13 14:15:09 +01:00
ynh_add_systemd_config
#=================================================
2022-03-27 04:08:34 +02:00
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Configuring log rotation..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log"
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# START SYSTEMD SERVICE
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Starting a systemd service..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="WEBrick::HTTPServer#start"
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# SETUP SSOWAT
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Configuring permissions..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
# RELOAD NGINX
2019-03-13 14:15:09 +01:00
#=================================================
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2019-03-13 14:15:09 +01:00
2022-03-27 04:08:34 +02:00
ynh_script_progression --message="Installation of $app completed"