#!/bin/bash #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers ### Install parameters are automatically saved as settings ### ### Settings are automatically loaded as bash variables ### in every app script context, therefore typically these will exist: ### - $domain ### - $path ### - $language ### ... etc ### ### Resources defined in the manifest are provisioned prior to this script ### and corresponding settings are also available, such as: ### - $install_dir ### - $port ### - $db_name ### ... ### ### $app is the app id (i.e. 'example' for first install, ### or 'example__2', '__3', ... for multi-instance installs) #================================================= # INITIALIZE AND STORE SETTINGS #================================================= # If you need to, you can define custom settings # (or remove this section entirely if not relevant for you) ynh_app_setting_set --app=$app --key=SITENAME --value=$site_name ynh_app_setting_set --app=$app --key=SHOWCLOCK --value=$show_clock ynh_app_setting_set --app=$app --key=AMPMCLOCK --value=$am_pm_clock ynh_app_setting_set --app=$app --key=SHOWGREETING --value=$show_greeting ynh_app_setting_set --app=$app --key=SHOWSEARCH --value=$show_search ynh_app_setting_set --app=$app --key=ALTLAYOUT --value=$alt_layout ynh_app_setting_set --app=$app --key=CUSTOMWIDTH --value=$custom_width ynh_app_setting_set --app=$app --key=BGBLUR --value=$bg_blur ynh_app_setting_set --app=$app --key=BGBRIGHT --value=$bg_bright ynh_app_setting_set --app=$app --key=UNSPLASHAPIKEY --value=$unsplash_api_key ynh_app_setting_set --app=$app --key=UNSPLASHCOLLECTIONS --value=$unsplash_collections ynh_app_setting_set --app=$app --key=ALTBGPROVIDER --value=$alt_bg_provider ynh_app_setting_set --app=$app --key=OWMAPIKEY --value=$owm_api_key ynh_app_setting_set --app=$app --key=LATLONG --value=$lat_long ynh_app_setting_set --app=$app --key=METRICTEMP --value=$metric_temp ynh_app_setting_set --app=$app --key=CHECKSTATUS --value=$check_status ynh_app_setting_set --app=$app --key=STATUSCACHE --value=$status_cache ynh_app_setting_set --app=$app --key=CACHEBYPASS --value=$cache_bypass ynh_app_setting_set --app=$app --key=WWWURL --value=$www_url ynh_app_setting_set --app=$app --key=DISABLEIPV6 --value=$disable_ip6 #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 ### `ynh_setup_source` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, like a git repository. ### `ynh_setup_source` use the file manifest.toml # Download, check integrity, uncompress and patch the source from manifest.toml ynh_setup_source --dest_dir="$install_dir" #================================================= # APP INITIAL CONFIGURATION #================================================= ynh_script_progression --message="Adding $app's configuration files..." --weight=1 update-alternatives --set php /usr/bin/php8.1 export COMPOSER_HOME="/home/user/.config/composer" echo "export COMPOSER_HOME=\"/home/user/.config/composer\"" >> ~/.bashrc mkdir -p $COMPOSER_HOME #rm -f /etc/php/8.1/fpm/pool.d/jump.conf ### You can add specific configuration files. ### ### Typically, put your template conf file in ../conf/your_config_file ### The template may contain strings such as __FOO__ or __FOO_BAR__, ### which will automatically be replaced by the values of $foo and $foo_bar ### ### ynh_add_config will also keep track of the config file's checksum, ### which later during upgrade may allow to automatically backup the config file ### if it's found that the file was manually modified ### ### Check the documentation of `ynh_add_config` for more info. ynh_add_config --template="php.ini" --destination="/etc/php/8.1/cgi/conf.d/30-jump.ini" chmod 755 "/etc/php/8.1/cgi/conf.d/30-jump.ini" # FIXME: this should be handled by the core in the future ### You may need to use chmod 600 instead of 400, ### for example if the app is expected to be able to modify its own config #chmod 400 "/etc/php81/conf.d/custom.ini" #chown "$app:$app" "/etc/php81/conf.d/custom.ini" #mkdir -p /var/www/cache/application \ # && chown -R jumpapp:jumpapp /var/www/html /var/www/cache/application ### For more complex cases where you want to replace stuff using regexes, ### you shoud rely on ynh_replace_string (which is basically a wrapper for sed) ### When doing so, you also need to manually call ynh_store_file_checksum ### ### ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$install_dir/some_config_file" ### ynh_store_file_checksum --file="$install_dir/some_config_file" #================================================= # SYSTEM CONFIGURATION #================================================= ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ### `ynh_add_fpm_config` is used to set up a PHP config. ### You can remove it if your app doesn't use PHP. ### `ynh_add_fpm_config` will use the files conf/extra_php-fpm.conf ### If you're not using these lines: ### - You can remove these files in conf/. ### - Remove the section "BACKUP THE PHP-FPM CONFIGURATION" in the backup script ### - Remove also the section "REMOVE PHP-FPM CONFIGURATION" in the remove script ### - As well as the section "RESTORE THE PHP-FPM CONFIGURATION" in the restore script ### with the reload at the end of the script. ### - And the section "PHP-FPM CONFIGURATION" in the upgrade script # Create a PHP-FPM config (with conf/extra_php-fpm.conf being appended to it) ynh_add_fpm_config # Create a dedicated NGINX config using the conf/nginx.conf template ynh_add_nginx_config ### `ynh_systemd_config` is used to configure a systemd script for an app. ### It can be used for apps that use sysvinit (with adaptation) or systemd. ### Have a look at the app to be sure this app needs a systemd script. ### `ynh_systemd_config` will use the file conf/systemd.service ### If you're not using these lines: ### - You can remove those files in conf/. ### - Remove the section "BACKUP SYSTEMD" in the backup script ### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script ### - As well as the section "RESTORE SYSTEMD" in the restore script ### - And the section "SETUP SYSTEMD" in the upgrade script # Create a dedicated systemd config # ynh_add_systemd_config ### `yunohost service add` integrates a service in YunoHost. It then gets ### displayed in the admin interface and through the others `yunohost service` commands. ### (N.B.: this line only makes sense if the app adds a service to the system!) ### If you're not using these lines: ### - You can remove these files in conf/. ### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script ### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script ### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script ### Additional options starting with 3.8: ### ### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed ### which will then be checked by YunoHost's diagnosis system ### (N.B. DO NOT USE THIS if the port is only internal!!!) ### ### --test_status "some command" a custom command to check the status of the service ### (only relevant if 'systemctl status' doesn't do a good job) ### ### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service ### ### Re-calling 'yunohost service add' during the upgrade script is the right way ### to proceed if you later realize that you need to enable some flags that ### weren't enabled on old installs (be careful it'll override the existing ### service though so you should re-provide all relevant flags when doing so) # yunohost service add "$app" --description="A short description of the app" --log="/var/log/$app/$app.log" ### `ynh_use_logrotate` is used to configure a logrotate configuration for the logs of this app. ### Use this helper only if there is effectively a log file for this app. ### If you're not using this helper: ### - Remove the section "BACKUP LOGROTATE" in the backup script ### - Remove also the section "REMOVE LOGROTATE CONFIGURATION" in the remove script ### - As well as the section "RESTORE THE LOGROTATE CONFIGURATION" in the restore script ### - And the section "SETUP LOGROTATE" in the upgrade script # Use logrotate to manage application logfile(s) ynh_use_logrotate # Create a dedicated Fail2Ban config # ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login" #================================================= # SETUP APPLICATION WITH CURL #================================================= ### Use these lines only if the app installation needs to be finalized through ### web forms. We generally don't want to ask the final user, ### so we're going to use curl to automatically fill the fields and submit the ### forms. # Installation with curl ynh_script_progression --message="Finalizing installation..." --weight=1 # ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" cp $install_dir/jump-*/jumpapp/* $install_dir -r rm $install_dir/jump-* -rf # ls $install_dir # ls -al /run/php mkdir -p /var/www/cache/application #mkdir -p /var/www/cache/"$app" #chown -R "$app:$app" "$install_dir" #chown "$app:$app" "/etc/php/8.1/fpm/pool.d/$app.conf" #chown "$app:$app" "/var/log/php8.1-fpm.log" #chown "$app:$app" "/run/php/php8.1-fpm-$app.sock" #chown "$app:$app" "/var/run/php/php8.1-fpm-$app.sock" chown -R www-data "$install_dir" #chown -R www-data "/var/www/cache/application" #chown "$app:$app" "/var/log/nginx/error.log" #chown "$app:$app" "/var/run/php/php8.1-fpm-jump.sock" #chown "$app:$app" "/etc/yunohost/certs/domain.tld/crt.pem" #chown -R "$app:$app" "/etc/nginx" #chown -R "$app:$www-data" "$install_dir" #chown -R "$app:$www-data" "/etc/php" #chown -R "$app:$www-data" "/var/log/php8.1-fpm.log" #chown -R "$app:$www-data" "/run/php" #chown -R "$app:$www-data" "/var/run/" #chmod -R 755 "/etc/nginx/conf.d" #chmod -R 755 "/var/log/nginx/" #chmod -R 755 "/etc/php" #chmod -R 755 "/run/php" #chmod -R 755 "/var/run/" #chmod -R 755 "/var/www/jump" #chmod -R 700 "/etc/yunohost/certs/domain.tld/crt.pem" #chmod 755 /etc/php/8.1/fpm/pool.d/jump.conf #chmod 755 /var/log/php8.1-fpm.log #rm /run/php/php8.1-fpm* #find $(echo "$PATH" | tr ':' ' ') -type f -executable | grep nginx #composer update --lock \ #--working-dir=/app #composer self-update --1 #ynh_spawn_app_shell --app=$app <<< ls -al /var/www/jump #ynh_install_composer -v 8.1 #ynh_composer_exec -v 8.1 --working-dir=/var/www/jump --commands=--optimize-autoloader --no-dev --no-interaction # echo $install_dir composer install --no-dev \ --optimize-autoloader \ --no-interaction \ --no-progress \ --quiet \ --working-dir=$install_dir #netstat -tulpn #ls -al /run/php/ #ls -al /etc/php/8.1/fpm/ #ls -al /etc/php/8.1/fpm/pool.d/ #ls -al /var/run/php #ls -al /run/php # ls -al /var/log/nginx/ # ls -al /etc/nginx/conf.d/ # ls -al /etc/nginx/conf.d/sub.domain.tld.d/ # php-fpm8.1 -y /etc/php/8.1/fpm/pool.d/$app.conf --test #groups $app #groups # env # printenv #set # nginx -t # journalctl -u php8.1-fpm.service -b # cat /etc/systemd/system/$app.service #ls -al /etc/systemd/system/ #ynh_replace_string --match_string="listen.owner = www-data" --replace_string="listen.owner = $app" --target_file="/etc/php/8.1/fpm/pool.d/$app.conf" #ynh_replace_string --match_string="listen.group = www-data" --replace_string="listen.group = $app" --target_file="/etc/php/8.1/fpm/pool.d/$app.conf" #sudo systemctl restart php8.1-fpm #cat /etc/php/8.1/fpm/pool.d/$app.conf #ls -al /etc/nginx/conf.d/ 2> /dev/null # [ -f /etc/nginx/conf.d/sub.maindomain2.tld.d/$app.conf ] && cat /etc/nginx/conf.d/sub.maindomain2.tld.d/$app.conf # [ -f /etc/nginx/conf.d/sub.domain.tld.d/$app.conf ] && cat /etc/nginx/conf.d/sub.domain.tld.d/$app.conf # [ -f cat /var/log/$app/$app.log ] && cat /var/log/$app/$app.log if [ -e "$install_dir/backgrounds" ]; then #echo >&2 " - Backgrounds directory is mapped... symlinking." ynh_script_progression --message="- Backgrounds directory is mapped... symlinking." --weight=1 rm /$install_dir/assets/backgrounds -r ln -s /backgrounds $install_dir/assets/ if [ ! "$(ls -A $install_dir/backgrounds)" ]; then # echo >&2 " -- Empty so populating with default files." ynh_script_progression --message=" -- Empty so populating with default files." --weight=1 cp $install_dir/assets/backgrounds/* $install_dir/backgrounds -r fi fi if [ -e "$install_dir/favicon" ]; then echo >&2 " - Favicon directory is mapped... symlinking." ynh_script_progression --message=" - Favicon directory is mapped... symlinking." --weight=1 rm /var/www/html/assets/images/favicon -r ln -s $install_dir/favicon $install_dir/assets/images/ if [ ! "$(ls -A /favicon)" ]; then echo >&2 " -- Empty so populating with default favicon image." ynh_script_progression --message=" -- Empty so populating with default favicon image." --weight=1 cp $install_dir/assets/images/favicon/* $install_dir/favicon -r fi fi # if [ -e "/sites" ]; then # echo >&2 " - Sites directory is mapped... symlinking." # rm /var/www/html/sites -r # ln -s /sites /var/www/html/ # if [ ! "$(ls -A /sites)" ]; then # echo >&2 " -- Empty so populating with default files." # cp /usr/src/jumpapp/sites/* /sites -r # fi # fi # if [ -e "/search" ]; then # echo >&2 " - Search directory is mapped... symlinking." # rm /var/www/html/search -r # ln -s /search /var/www/html/ # if [ ! "$(ls -A /search)" ]; then # echo >&2 " -- Empty so populating with default files." # cp /usr/src/jumpapp/search/* /search -r # fi # fi #ynh_spawn_app_shell --app=$app <<< ls -l /etc/alternatives/php #================================================= # START SYSTEMD SERVICE #================================================= # ynh_script_progression --message="Starting $app's systemd service..." --weight=1 ### `ynh_systemd_action` is used to start a systemd service for an app. ### Only needed if you have configure a systemd service ### If you're not using these lines: ### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script ### - As well as the section "START SYSTEMD SERVICE" in the restore script ### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script ### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script # Start a systemd service #ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last