2020-05-02 10:17:12 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-01-05 23:51:07 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2020-05-02 10:17:12 +02:00
#=================================================
2024-01-05 23:51:07 +01:00
ynh_script_progression --message="Setting up source files..." --weight=1
2020-05-02 10:17:12 +02:00
2024-01-05 23:51:07 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2020-05-02 10:17:12 +02:00
#=================================================
2024-01-05 23:51:07 +01:00
# ADD A CONFIGURATION
2020-05-02 10:17:12 +02:00
#=================================================
2024-01-05 23:51:07 +01:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
2020-05-02 10:17:12 +02:00
2021-05-18 02:53:36 +02:00
api_secret="$(ynh_string_random --length=32)"
app_key="$(ynh_string_random --length=32)"
phantomjs_key=$(ynh_string_random --length=32)
2024-01-05 23:51:07 +01:00
mail_from_address="$(ynh_user_get_info "$admin" mail)"
mail_from_name="$(ynh_user_get_info "$admin" firstname) $(ynh_user_get_info "$admin" lastname)"
2020-05-02 10:17:12 +02:00
2021-05-18 02:53:36 +02:00
ynh_app_setting_set --app=$app --key=api_secret --value=$api_secret
ynh_app_setting_set --app=$app --key=app_key --value=$app_key
ynh_app_setting_set --app=$app --key=phantomjs_key --value=$phantomjs_key
ynh_app_setting_set --app=$app --key=mail_from_address --value=$mail_from_address
ynh_app_setting_set --app=$app --key=mail_from_name --value=$mail_from_name
2020-06-07 15:31:15 +02:00
2024-01-05 23:51:07 +01:00
ynh_add_config --template="../conf/.env" --destination="$install_dir/.env"
2022-09-01 02:13:26 +02:00
2024-01-05 23:51:07 +01:00
chmod 600 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
2022-09-01 02:13:26 +02:00
2020-05-02 10:17:12 +02:00
#=================================================
2022-09-01 02:13:26 +02:00
# INSTALL PHANTOMJS
#=================================================
ynh_script_progression --message="Installing PhantomJS..." --weight=1
2020-05-02 10:17:12 +02:00
2024-01-05 23:51:07 +01:00
_install_phantomjs
2020-05-02 10:17:12 +02:00
#=================================================
2020-06-15 15:10:10 +02:00
# BUILD THE APPLICATION
2020-06-07 15:31:15 +02:00
#=================================================
2022-09-01 02:13:26 +02:00
ynh_script_progression --message="Building the application..." --weight=1
2020-06-07 15:31:15 +02:00
2024-01-05 23:51:07 +01:00
pushd "$install_dir"
# Run the database migrations and initially fill the db
"php$phpversion" artisan migrate --force
"php$phpversion" artisan db:seed --force
2021-08-22 19:23:23 +02:00
2024-01-05 23:51:07 +01:00
# thanks to cloudron for this!
# This comments the check at https://github.com/invoiceninja/invoiceninja/blob/cadd1a3b44aed3dc5bd28d623efd4bb51c6d895a/app/Http/Controllers/AppController.php#L47
# We pre-setup various parts already thus the .env file has to exist
sed -e "s/^.*app is already configured.*/ /" -i app/Http/Controllers/AppController.php
2020-06-15 15:10:10 +02:00
popd
2020-05-02 17:16:41 +02:00
2020-05-09 21:20:43 +02:00
#=================================================
2024-01-05 23:51:07 +01:00
# SYSTEM CONFIGURATION
2020-05-09 21:20:43 +02:00
#=================================================
2024-01-05 23:51:07 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2020-05-09 21:20:43 +02:00
2024-01-05 23:51:07 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2020-05-09 21:20:43 +02:00
2024-01-05 23:51:07 +01:00
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
ynh_add_config --template="../conf/invoiceninja.cron" --destination="/etc/cron.d/$app"
2021-05-16 15:47:40 +02:00
chmod 644 "/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
2020-05-09 21:20:43 +02:00
2020-05-02 10:17:12 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2022-09-01 02:13:26 +02:00
ynh_script_progression --message="Installation of $app completed" --last