1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/invoiceninja5_ynh.git synced 2024-09-03 19:26:23 +02:00
invoiceninja5_ynh/scripts/install
2024-06-30 19:40:27 +02:00

101 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# GENERATE KEYS AND RETRIEVE ADMIN USER INFO
#=================================================
api_secret="$(ynh_string_random --length=32)"
app_key="$(ynh_string_random --length=32)"
phantomjs_key="$(ynh_string_random --length=32)"
email_fullname="$(ynh_user_get_info --username=$admin --key=fullname)"
email="$(ynh_user_get_info --username=$admin --key=mail)"
#=================================================
# STORE KEYS TO APP SETTINGS
#=================================================
ynh_script_progression --message="Storing secrets to app settings..."
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
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_setup_source --dest_dir="$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated PHP-FPM config
ynh_add_fpm_config
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=1
ynh_add_config --template="default.env" --destination="$install_dir/.env"
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
#=================================================
# BUILD THE APPLICATION
#=================================================
ynh_script_progression --message="Building the application..." --weight=1
pushd "$install_dir"
# Run the database migrations and initially fill the db
php$phpversion artisan migrate:fresh --seed --no-interaction --verbose --force
php$phpversion artisan ninja:create-account --email $email --password "$password" --no-interaction --verbose
php$phpversion artisan optimize --no-interaction --verbose
php$phpversion artisan view:clear
php$phpversion artisan cache:clear
# install snappdf, since it isn't included by default anymore since
# 5.5.12: https://invoiceninja.github.io/docs/self-host-troubleshooting/#pdf-conversion-issues
php$phpversion vendor/bin/snappdf download
# see: https://forum.cloudron.io/topic/11932/invoice-ninja-server-500-internal-error/29
find vendor/beganovich/snappdf/versions/*-Linux_x64/chrome-linux/ -type f -name chrome* ! -name "*.*" -print -exec chmod 755 {} \;
popd
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# ADD A CRON JOB
#=================================================
ynh_script_progression --message="Adding a cron job..." --weight=1
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"