diff --git a/conf/db_access.txt b/conf/db_access.txt new file mode 100644 index 0000000..df33042 --- /dev/null +++ b/conf/db_access.txt @@ -0,0 +1,4 @@ +# MySQL Database +name: __DB_NAME__ +user: __DB_USER__ +pass: __DB_PASS__ diff --git a/manifest.toml b/manifest.toml index dfb522d..1454a1b 100644 --- a/manifest.toml +++ b/manifest.toml @@ -65,9 +65,11 @@ ram.runtime = "50M" default = false [resources] - [resources.sources.main] - url = "https://tildegit.org/sbgodin/HtmGem/archive/v1.4.1.tar.gz" - sha256 = "4d21fbdf5f89e510052185ea9d331614338353886baaecc05d007fa1481f75ce" + [resources.sources.main] + url = "https://tildegit.org/sbgodin/HtmGem/archive/v1.4.1.tar.gz" + sha256 = "4d21fbdf5f89e510052185ea9d331614338353886baaecc05d007fa1481f75ce" + + # autoupdate.strategy = "latest_github_tag" [resources.system_user] @@ -83,3 +85,7 @@ ram.runtime = "50M" echo "mariadb-server, php8.2-mysql" fi """ + + [resources.database] + # Might not be used, but it's easier to handle it here + type = "mysql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..5fd9929 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -8,6 +8,16 @@ # PERSONAL HELPERS #================================================= +_ynh_add_gemserv_config() { + ynh_add_config --template="server.toml" --destination="/etc/gemserv/config.d/$domain.toml" + ynh_systemd_action --service_name=gemserv --action=reload +} + +_ynh_remove_gemserv_config() { + ynh_secure_remove --file="/etc/gemserv/config.d/$domain.toml" + ynh_systemd_action --service_name=gemserv --action=reload +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 1b69077..d94a247 100755 --- a/scripts/backup +++ b/scripts/backup @@ -45,10 +45,9 @@ ynh_backup --src_path="/etc/gemserv/config.d/$domain.toml" # BACKUP THE MYSQL DATABASE #================================================= -if [ $with_mysql -eq 1 ] -then - ynh_print_info --message="Backing up the MySQL database..." - ynh_mysql_dump_db --database="$db_name" > db.sql +if [ "$with_mysql" -eq 1 ]; then + ynh_print_info --message="Backing up the MySQL database..." + ynh_mysql_dump_db --database="$db_name" > db.sql fi #================================================= diff --git a/scripts/install b/scripts/install index 33353ab..73fcea5 100755 --- a/scripts/install +++ b/scripts/install @@ -10,47 +10,27 @@ source _common.sh source ynh_apps source /usr/share/yunohost/helpers +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Installing Gemserv..." + # ynh_install_apps --apps="gemserv" -yunohost app install --force gemserv #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." -if [ $with_sftp -eq 1 ] -then - groups="sftp.app" -else - groups="" +if [ "$with_sftp" -eq 1 ]; then + usermod -a -G "sftp.app" "$app" fi - ynh_system_user_create --username=$app --home_dir="$install_dir" --groups="$groups" - -if [ $with_sftp -eq 1 ] -then - # Add the password to this user - chpasswd <<< "${app}:${password}" - ynh_app_setting_set --app=$app --key=password --value="$password" -fi - -#================================================= -# CREATE A MYSQL DATABASE -#================================================= - -if [ $with_mysql -eq 1 ] -then - ynh_script_progression --message="Creating a MySQL database..." - - db_name=$(ynh_sanitize_dbid --db_name=$app) - db_user=$db_name - db_pwd=$(ynh_string_random --length=30) - - ynh_app_setting_set --app=$app --key=db_name --value=$db_name - ynh_app_setting_set --app=$app --key=db_user --value=$db_user - ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd - - ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name +if [ -n "$password" ]; then + # Add the password to this user + chpasswd <<< "${app}:${password}" + # By default, passwords are not saved + ynh_app_setting_set --app="$app" --key=password --value="$password" fi #================================================= @@ -61,18 +41,25 @@ ynh_script_progression --message="Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/www/htmgem" -chown -R $app:www-data "$install_dir" +chmod o-rwx "$install_dir" +chown -R "$app:www-data" "$install_dir" + +# Home directory of the user needs to be owned by $app to allow SFTP connections +chown "$app:$app" "$install_dir" +setfacl -m g:"$app":r-x "$install_dir" +setfacl -m g:"www-data":r-x "$install_dir" +setfacl -m g:"gemserv":r-x "$install_dir" #================================================= -# PHP-FPM CONFIGURATION +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring PHP-FPM..." +ynh_script_progression --message="Adding a configuration file..." --weight=1 -# Create a dedicated PHP-FPM config -ynh_add_fpm_config - -# Create a dedicated NGINX config -ynh_add_nginx_config +if [ "$with_mysql" -eq 1 ]; then + ynh_add_config --template="db_access.txt" --destination="$install_dir/db_access.txt" + chown "$app:www-data" "$install_dir/db_access.txt" + chmod 440 "$install_dir/db_access.txt" +fi #================================================= # SPECIFIC SETUP @@ -81,47 +68,28 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Building default capsule..." -if [ $with_sftp -eq 1 ] -then - ynh_add_config --template="../conf/index.gmi" --destination="$install_dir/www/index.gmi" +if [ "$with_sftp" -eq 1 ]; then + ynh_add_config --template="index.gmi" --destination="$install_dir/www/index.gmi" else - ynh_add_config --template="../conf/index_no_sftp.gmi" --destination="$install_dir/www/index.gmi" + ynh_add_config --template="index_no_sftp.gmi" --destination="$install_dir/www/index.gmi" fi chmod 644 "$install_dir/www/index.gmi" -chown $app:$app "$install_dir/www/index.gmi" - -if [ $with_mysql -eq 1 ]; then - # Store the database access - echo -e "# MySQL Database - name: ${db_name}\nuser: ${db_name}\npass: ${db_pwd}" > ../conf/db_access.txt - - # Copy files to the right place - cp -r "../conf/db_access.txt" "$install_dir/db_access.txt" -fi +chown "$app:$app" "$install_dir/www/index.gmi" #================================================= -# APPLY RIGHTS +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Apply rights..." +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -chown -R $app:www-data "$install_dir" +# Create a dedicated PHP-FPM config +ynh_add_fpm_config -# Home directory of the user needs to be owned by $app to allow -# SFTP connections -chown $app:$app "$install_dir" -setfacl -m g:$app:r-x "$install_dir" -setfacl -m g:www-data:r-x "$install_dir" -setfacl -m g:gemserv:r-x "$install_dir" -chmod o-rwx "$install_dir" +# Create a dedicated NGINX config +ynh_add_nginx_config -#================================================= -# ADD A CONFIGURATION -#================================================= -ynh_script_progression --message="Adding a configuration file..." - -ynh_add_config --template="../conf/server.toml" --destination="/etc/gemserv/config.d/$domain.toml" -ynh_systemd_action --service_name=gemserv --action=reload +# Create a dedicated Gemserv config +_ynh_add_gemserv_config #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 6bbe20a..17839ab 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,44 +10,18 @@ source _common.sh source ynh_apps source /usr/share/yunohost/helpers - #================================================= -# STANDARD REMOVE +# REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE THE MYSQL DATABASE -#================================================= - -if [ $with_mysql -eq 1 ]; then - ynh_script_progression --message="Removing the MySQL database..." - - # Remove a database if it exists, along with the associated user - ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -fi - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Removing PHP-FPM configuration..." - # Remove the dedicated PHP-FPM config ynh_remove_fpm_config -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." - -# Remove a directory securely -ynh_secure_remove --file="/etc/gemserv/config.d/$domain.toml" -ynh_systemd_action --service_name=gemserv --action=reload +_ynh_remove_gemserv_config #================================================= # REMOVE DEPENDENCIES @@ -55,8 +29,7 @@ ynh_systemd_action --service_name=gemserv --action=reload ynh_script_progression --message="Removing dependencies..." # Remove metapackage and its dependencies -# ynh_remove_apps -yunohost app remove gemserv +ynh_remove_apps #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 7702380..ae50cff 100755 --- a/scripts/restore +++ b/scripts/restore @@ -11,26 +11,18 @@ source ../settings/scripts/_common.sh source ../settings/scripts/ynh_apps source /usr/share/yunohost/helpers -#================================================= -# STANDARD RESTORATION STEPS #================================================= # RECREATE THE DEDICATED USER #================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." +ynh_script_progression --message="Configuring the system user..." -if [ $with_sftp -eq 1 ] -then - groups="sftp.app" -else - groups="" +if [ "$with_sftp" -eq 1 ]; then + usermod -a -G "sftp.app" "$app" fi - ynh_system_user_create --username=$app --home_dir="$install_dir" --groups="$groups" - -if [ -n "$password" ] -then - # Add the password to this user - chpasswd <<< "${app}:${password}" +if [ -n "$password" ]; then + # Add the password to this user + chpasswd <<< "${app}:${password}" fi #================================================= @@ -41,23 +33,27 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" + +# Home directory of the user needs to be owned by $app to allow SFTP connections +chown "$app:$app" "$install_dir" +setfacl -m g:"$app":r-x "$install_dir" +setfacl -m g:"www-data":r-x "$install_dir" +setfacl -m g:"gemserv":r-x "$install_dir" #================================================= # RESTORE THE MYSQL DATABASE #================================================= +if [ "$with_sql" -eq 1 ]; then + ynh_script_progression --message="Restoring the MySQL database..." --weight=1 -if [ $with_mysql -eq 1 ]; then - ynh_script_progression --message="Restoring the MySQL database..." - - ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name - ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql fi #================================================= -# RESTORE THE PHP-FPM CONFIGURATION +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" @@ -66,21 +62,6 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/gemserv/config.d/$domain.toml" ynh_systemd_action --service_name=gemserv --action=reload -#================================================= -# APPLY RIGHTS -#================================================= -ynh_script_progression --message="Apply rights..." - -chown -R $app:www-data "$install_dir" - -# Home directory of the user needs to be owned by $app to allow -# SFTP connections -chown $app:$app "$install_dir" -setfacl -m g:$app:r-x "$install_dir" -setfacl -m g:www-data:r-x "$install_dir" -setfacl -m g:gemserv:r-x "$install_dir" -chmod o-rwx "$install_dir" - #================================================= # GENERIC FINALIZATION #================================================= @@ -88,7 +69,7 @@ chmod o-rwx "$install_dir" #================================================= ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." -ynh_systemd_action --service_name=php$phpversion-fpm --action=reload +ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 68e59ae..7340373 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,30 +10,18 @@ source _common.sh source ynh_apps source /usr/share/yunohost/helpers -#================================================= -# CHECK VERSION -#================================================= - -upgrade_type=$(ynh_check_app_version_changed) - #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." -if [ $with_sftp -eq 1 ] -then - groups="sftp.app" -else - groups="" +if [ "$with_sftp" -eq 1 ]; then + usermod -a -G "sftp.app" "$app" fi -ynh_system_user_create --username=$app --home_dir="$install_dir" --groups="$groups" - -if [ -n "$password" ] -then - # Add the password to this user - chpasswd <<< "${app}:${password}" +if [ -n "$password" ]; then + # Add the password to this user + chpasswd <<< "${app}:${password}" fi # Change the user group for previous my_webapp install script @@ -43,22 +31,35 @@ usermod -g "$app" "$app" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir/www/htmgem" -fi +# Download, check integrity, uncompress and patch the source from app.src +ynh_setup_source --dest_dir="$install_dir/www/htmgem" --full_replace=1 chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +chown -R "$app:www-data" "$install_dir" + +# Home directory of the user needs to be owned by $app to allow SFTP connections +chown "$app:$app" "$install_dir" +setfacl -m g:"$app":r-x "$install_dir" +setfacl -m g:"www-data":r-x "$install_dir" +setfacl -m g:"gemserv":r-x "$install_dir" #================================================= -# PHP-FPM CONFIGURATION +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +if [ "$with_mysql" -eq 1 ]; then + ynh_add_config --template="db_access.txt" --destination="$install_dir/db_access.txt" + chown "$app:www-data" "$install_dir/db_access.txt" + chmod 440 "$install_dir/db_access.txt" +fi + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated PHP-FPM config ynh_add_fpm_config @@ -66,30 +67,7 @@ ynh_add_fpm_config # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# SPECIFIC UPGRADE -#================================================= -# APPLY RIGHTS -#================================================= -ynh_script_progression --message="Apply rights..." - -chown -R $app:www-data "$install_dir" - -# Home directory of the user needs to be owned by $app to allow -# SFTP connections -chown $app:$app "$install_dir" -setfacl -m g:$app:r-x "$install_dir" -setfacl -m g:www-data:r-x "$install_dir" -setfacl -m g:gemserv:r-x "$install_dir" -chmod o-rwx "$install_dir" - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." - -ynh_add_config --template="../conf/server.toml" --destination="/etc/gemserv/config.d/$domain.toml" -ynh_systemd_action --service_name=gemserv --action=reload +_ynh_add_gemserv_config #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml index b4f9f91..4afd12e 100644 --- a/tests.toml +++ b/tests.toml @@ -4,6 +4,10 @@ test_format = 1.0 [default] + preinstall = """ + yunohost tools update apps + yunohost app install --force gemserv + """ # ------------ # Tests to run