From 887e8fa60270591636141ad2dd944f60d6cdf88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:28:03 +0100 Subject: [PATCH 01/18] v2 --- conf/amd64.src | 7 --- conf/app.src | 7 --- conf/systemd.service | 4 +- manifest.toml | 67 +++++++++++++++++++++++++++ scripts/_common.sh | 2 +- scripts/backup | 16 +++---- scripts/change_url | 64 +++++++++++++------------- scripts/install | 106 +++++++++++++++++++++---------------------- scripts/remove | 30 ++++++------ scripts/restore | 50 ++++++++++---------- scripts/upgrade | 98 +++++++++++++++++++-------------------- 11 files changed, 253 insertions(+), 198 deletions(-) delete mode 100644 conf/amd64.src delete mode 100644 conf/app.src create mode 100644 manifest.toml diff --git a/conf/amd64.src b/conf/amd64.src deleted file mode 100644 index 13d7501..0000000 --- a/conf/amd64.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/knadh/listmonk/releases/download/v2.2.0/listmonk_2.2.0_linux_amd64.tar.gz -SOURCE_SUM=c2bdccd073d768d2b8dfbfad6469c5b41cf39b44a20c263cbaebf15876463709 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=false -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 7dbafc6..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz -SOURCE_SUM=6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/systemd.service b/conf/systemd.service index a5fcd31..69d92ef 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,8 +6,8 @@ Documentation=https://listmonk.app/docs/ Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/listmonk +WorkingDirectory=__INSTALL_DIR__/ +ExecStart=__INSTALL_DIR__/listmonk Restart=always [Install] diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..16b04c4 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,67 @@ +packaging_format = 2 + +id = "listmonk" +name = "Listmonk" +description.en = "Newsletter and mailing list manager" +description.fr = "Manager de newsletter et mailing list" + +version = "2.3.0~ynh3" + +maintainers = ["Navan Chauhan"] + +[upstream] +license = "AGPL-3.0-only" +website = "https://listmonk.app/" +demo = "https://demo.listmonk.app/" +admindoc = "https://listmonk.app/docs/" +code = "https://github.com/knadh/listmonk" +cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) +fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. + +[integration] +yunohost = ">= 11.0.9" +architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +multi_instance = true +ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. +sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + +[install] + [install.domain] + # this is a generic question - ask strings are automatically handled by Yunohost's core + type = "domain" + full_domain = true + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.admin] + # this is a generic question - ask strings are automatically handled by Yunohost's core + type = "user" + + [install.password] + # this is a generic question - ask strings are automatically handled by Yunohost's core + type = "password" + +[resources] + [resources.sources.main] + url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" + sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" + + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + [[resources.apt.extras]] + repo = "deb https://dl.yarnpkg.com/debian/ stable main" + key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + packages = "yarn" + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index 594d494..251b15f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="postgresql" +#REMOVEME? pkg_dependencies="postgresql" nodejs_version=16 GO_VERSION="1.18" diff --git a/scripts/backup b/scripts/backup index 5f340bc..469071d 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,23 +14,23 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_print_info --message="Loading installation settings..." +#REMOVEME? ynh_print_info --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -41,7 +41,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/change_url b/scripts/change_url index 76b4138..18c4cf9 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -13,54 +13,54 @@ source /usr/share/yunohost/helpers # RETRIEVE ARGUMENTS #================================================= -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH +#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN +#REMOVEME? old_path=$YNH_APP_OLD_PATH -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH +#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN +#REMOVEME? new_path=$YNH_APP_NEW_PATH -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -port=$(ynh_app_setting_get --app=$app --key=port) +#REMOVEME? # Needed for helper "ynh_add_nginx_config" +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 +#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 # Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" # Restore it if the upgrade fails - ynh_restore_upgradebackup +#REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= -change_domain=0 -if [ "$old_domain" != "$new_domain" ] +#REMOVEME? change_domain=0 +#REMOVEME? if [ "$old_domain" != "$new_domain" ] then - change_domain=1 + #REMOVEME? change_domain=1 fi -change_path=0 -if [ "$old_path" != "$new_path" ] +#REMOVEME? change_path=0 +#REMOVEME? if [ "$old_path" != "$new_path" ] then - change_path=1 + #REMOVEME? change_path=1 fi #================================================= @@ -77,28 +77,30 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +ynh_change_url_nginx_config + +#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf # Change the path in the NGINX config file if [ $change_path -eq 1 ] then # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" +#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" +#REMOVEME? domain="$old_domain" +#REMOVEME? path="$new_path" # Create a dedicated NGINX config - ynh_add_nginx_config +#REMOVEME? ynh_add_nginx_config fi # Change the domain for NGINX if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf +#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path" +#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -113,9 +115,9 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 84755ff..2fd70f5 100755 --- a/scripts/install +++ b/scripts/install @@ -14,29 +14,29 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -domain=$YNH_APP_ARG_DOMAIN -path_url="/" -is_public=$YNH_APP_ARG_IS_PUBLIC -admin=$YNH_APP_ARG_ADMIN -password=$YNH_APP_ARG_PASSWORD +#REMOVEME? domain=$YNH_APP_ARG_DOMAIN +path="/" +#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC +#REMOVEME? admin=$YNH_APP_ARG_ADMIN +#REMOVEME? password=$YNH_APP_ARG_PASSWORD -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 +#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1 # Check machine architecture (in particular, we don't support 32bit machines) if [ $YNH_ARCH == "i386" ] || [ $YNH_ARCH == "armel" ] @@ -44,39 +44,39 @@ then ynh_die --message="Sorry, because of NodeJS framework, this app can't be installed on i386 (32 bits) or armel machine." fi -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +#REMOVEME? install_dir=/var/www/$app +#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" # Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url +#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1 -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url -ynh_app_setting_set --app=$app --key=admin --value=$admin -ynh_app_setting_set --app=$app --key=password --value="$password" +#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain +#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path +#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin +#REMOVEME? ynh_app_setting_set --app=$app --key=password --value="$password" #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 +#REMOVEME? ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port -port=$(ynh_find_port --port=8095) -ynh_app_setting_set --app=$app --key=port --value=$port +#REMOVEME? port=$(ynh_find_port --port=8095) +#REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=12 +#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=12 -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then @@ -84,7 +84,7 @@ then ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version # Install Yarn - ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" # Install Go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION @@ -93,53 +93,53 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 +#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # CREATE A MYSQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 +#REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name +#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app) +#REMOVEME? db_user=$db_name +#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name +#REMOVEME? ynh_psql_test_if_first_run +#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path +#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir # Download, check integrity, uncompress and patch the source from app.src if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then - ynh_setup_source --dest_dir="$final_path/build" - pushd "$final_path/build" + ynh_setup_source --dest_dir="$install_dir/build" + pushd "$install_dir/build" # Build the sources ynh_use_go - export GOPATH="$final_path/build/go" - export GOCACHE="$final_path/build/.cache" + export GOPATH="$install_dir/build/go" + export GOCACHE="$install_dir/build/.cache" ynh_use_nodejs make dist mv listmonk .. popd ynh_remove_go ynh_remove_nodejs - ynh_secure_remove --file="$final_path/build" +#REMOVEME? ynh_secure_remove --file="$install_dir/build" else - ynh_setup_source --dest_dir="$final_path" --source_id=$YNH_ARCH + ynh_setup_source --dest_dir="$install_dir" --source_id=$YNH_ARCH fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/listmonk" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod +x "$install_dir/listmonk" #================================================= # NGINX CONFIGURATION @@ -154,17 +154,17 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 -ynh_add_config --template="../conf/config.toml" --destination="$final_path/config.toml" +ynh_add_config --template="../conf/config.toml" --destination="$install_dir/config.toml" -chmod 400 "$final_path/config.toml" -chown $app:$app "$final_path/config.toml" +chmod 400 "$install_dir/config.toml" +chown $app:$app "$install_dir/config.toml" #================================================= # DATABASE CONFIGURATION #================================================= ynh_script_progression --message="Generating database..." --weight=1 -pushd "$final_path" +pushd "$install_dir" yes | ./listmonk --install popd @@ -194,28 +194,28 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring permissions..." --weight=1 +#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary -if [ $is_public -eq 1 ] +#REMOVEME? if [ $is_public -eq 1 ] then - ynh_permission_update --permission="main" --add="visitors" +#REMOVEME? ynh_permission_update --permission="main" --add="visitors" fi # Only the admin can access the admin panel of the app (if the app has an admin panel) -ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false +#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false # Everyone can access the API part # We don't want to display the tile in the SSO so we put --show_tile="false" # And we don't want the YunoHost admin to be able to remove visitors group to this permission, so we put --protected="true" -ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 3ceb755..f9fc583 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,15 +12,15 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -final_path=$(ynh_app_setting_get --app=$app --key=final_path) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) #================================================= # STANDARD REMOVE @@ -46,18 +46,18 @@ ynh_remove_systemd_config #================================================= # REMOVE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." --weight=2 +#REMOVEME? ynh_script_progression --message="Removing the PostgreSQL database..." --weight=2 # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user=$db_user --db_name=$db_name +#REMOVEME? ynh_psql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --weight=2 +#REMOVEME? ynh_script_progression --message="Removing app main directory..." --weight=2 # Remove the app directory securely -ynh_secure_remove --file="$final_path" +#REMOVEME? ynh_secure_remove --file="$install_dir" #================================================= # REMOVE NGINX CONFIGURATION @@ -70,20 +70,20 @@ ynh_remove_nginx_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=8 +#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=8 # Remove metapackage and its dependencies -ynh_remove_app_dependencies +#REMOVEME? ynh_remove_app_dependencies #================================================= # GENERIC FINALIZATION #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 +#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user -ynh_system_user_delete --username=$app +#REMOVEME? ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 52da516..eca4861 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,34 +14,34 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +#REMOVEME? ynh_clean_setup () { #### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 +#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " +#REMOVEME? test ! -d $install_dir \ + || ynh_die --message="There is already a directory: $install_dir " #================================================= # STANDARD RESTORATION STEPS @@ -55,40 +55,40 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 +#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=3 -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/listmonk" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod +x "$install_dir/listmonk" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=10 +#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=10 # Define and install dependencies -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 +#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 -ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd +#REMOVEME? ynh_psql_test_if_first_run +#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3e21ffd..cfdf2e9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -13,19 +13,19 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +#REMOVEME? app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -password=$(ynh_app_setting_get --app=$app --key=password) -port=$(ynh_app_setting_get --app=$app --key=port) +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? db_user=$db_name +#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#REMOVEME? password=$(ynh_app_setting_get --app=$app --key=password) +#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION @@ -36,16 +36,16 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 +#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { # Restore it if the upgrade fails - ynh_restore_upgradebackup +#REMOVEME? ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # STANDARD UPGRADE STEPS @@ -62,51 +62,51 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all +#REMOVEME? if ynh_legacy_permissions_exists; then +#REMOVEME? ynh_legacy_permissions_delete_all ynh_app_setting_delete --app=$app --key=is_public fi -if ! ynh_permission_exists --permission="admin"; then +#REMOVEME? if ! ynh_permission_exists --permission="admin"; then # Create the required permissions - ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false +#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false fi # Create a permission if needed -if ! ynh_permission_exists --permission="api"; then - ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? if ! ynh_permission_exists --permission="api"; then +#REMOVEME? ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" fi if ynh_compare_current_package_version --comparison le --version 2.3.0~ynh3 then - mkdir -p "$final_path/uploads" + mkdir -p "$install_dir/uploads" ynh_permission_delete --permission="admin" ynh_permission_delete --permission="api" - ynh_permission_create --permission="admin" --url="/admin" --additional_urls="/admin /api" --allowed=$admin --auth_header=false - ynh_permission_create --permission="api" --url="/public" --additional_urls="/api/public" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --additional_urls="/admin /api" --allowed=$admin --auth_header=false +#REMOVEME? ynh_permission_create --permission="api" --url="/public" --additional_urls="/api/public" --allowed="visitors" --show_tile="false" --protected="true" fi if ynh_compare_current_package_version --comparison le --version 2.3.0~ynh1 then - mkdir -p "$final_path/uploads" + mkdir -p "$install_dir/uploads" ynh_permission_delete --permission="admin" ynh_permission_delete --permission="api" - ynh_permission_create --permission="admin" --url="/admin" --additional_urls="/admin /api" --allowed=$admin --auth_header=false - ynh_permission_create --permission="api" --url="/public" --additional_urls="/api/public" --allowed="visitors" --show_tile="false" --protected="true" +#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --additional_urls="/admin /api" --allowed=$admin --auth_header=false +#REMOVEME? ynh_permission_create --permission="api" --url="/public" --additional_urls="/api/public" --allowed="visitors" --show_tile="false" --protected="true" fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -119,34 +119,34 @@ then # Download, check integrity, uncompress and patch the source from app.src if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then - ynh_setup_source --dest_dir="$final_path/build" --keep="$final_path/config.toml" + ynh_setup_source --dest_dir="$install_dir/build" --keep="$install_dir/config.toml" # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version # Install Yarn - ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" +#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" # Install Go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION - pushd "$final_path/build" + pushd "$install_dir/build" # Build the sources ynh_use_go - export GOPATH="$final_path/build/go" - export GOCACHE="$final_path/build/.cache" + export GOPATH="$install_dir/build/go" + export GOCACHE="$install_dir/build/.cache" ynh_use_nodejs make dist mv listmonk .. popd ynh_remove_go ynh_remove_nodejs - ynh_secure_remove --file="$final_path/build" +#REMOVEME? ynh_secure_remove --file="$install_dir/build" else - ynh_setup_source --dest_dir="$final_path" --source_id=$YNH_ARCH --keep="$final_path/config.toml" + ynh_setup_source --dest_dir="$install_dir" --source_id=$YNH_ARCH --keep="$install_dir/config.toml" fi fi -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/listmonk" +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod +x "$install_dir/listmonk" #================================================= # NGINX CONFIGURATION @@ -159,26 +159,26 @@ ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=10 +#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=10 -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # UPDATE A CONFIG FILE #================================================= # ynh_script_progression --message="Updating a configuration file..." --time --weight=1 -# ynh_add_config --template="../conf/config.toml" --destination="$final_path/config.toml" +# ynh_add_config --template="../conf/config.toml" --destination="$install_dir/config.toml" -# chmod 400 "$final_path/config.toml" -# chown $app:$app "$final_path/config.toml" +# chmod 400 "$install_dir/config.toml" +# chown $app:$app "$install_dir/config.toml" #================================================= # DATABASE CONFIGURATION #================================================= ynh_script_progression --message="Generating database..." --weight=1 -pushd "$final_path" +pushd "$install_dir" yes | ./listmonk --upgrade popd @@ -207,9 +207,9 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 -ynh_systemd_action --service_name=nginx --action=reload +#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT From 53e5249df5a4f1bdf64229a8c460c0f9517c33a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:38:25 +0100 Subject: [PATCH 02/18] v2 --- conf/nginx.conf | 3 +- doc/DISCLAIMER.md | 0 manifest.json | 52 --------------------- manifest.toml | 34 ++++++++------ scripts/_common.sh | 3 -- scripts/backup | 22 --------- scripts/change_url | 85 ---------------------------------- scripts/install | 110 ++------------------------------------------ scripts/remove | 47 ------------------- scripts/restore | 56 +---------------------- scripts/upgrade | 112 +-------------------------------------------- tests.toml | 7 +++ 12 files changed, 37 insertions(+), 494 deletions(-) delete mode 100644 doc/DISCLAIMER.md delete mode 100644 manifest.json create mode 100644 tests.toml diff --git a/conf/nginx.conf b/conf/nginx.conf index f17172c..903c9b4 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,5 @@ -location / { +#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; +location __PATH__/ { proxy_pass http://127.0.0.1:__PORT__/; proxy_redirect off; diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index e69de29..0000000 diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 2ac0632..0000000 --- a/manifest.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "name": "Listmonk", - "id": "listmonk", - "packaging_format": 1, - "description": { - "en": "Newsletter and mailing list manager", - "fr": "Manager de newsletter et mailing list" - }, - "version": "2.3.0~ynh3", - "url": "https://listmonk.app/", - "upstream": { - "license": "AGPL-3.0-only", - "website": "https://listmonk.app/", - "demo": "https://demo.listmonk.app/", - "admindoc": "https://listmonk.app/docs/", - "code": "https://github.com/knadh/listmonk" - }, - "license": "AGPL-3.0-only", - "maintainer": { - "name": "Navan Chauhan", - "email": "listmonk@navan.email" - }, - "requirements": { - "yunohost": ">= 11.0.9" - }, - "multi_instance": true, - "services": [ - "nginx", - "mysql" - ], - "arguments": { - "install" : [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "default": true - }, - { - "name": "admin", - "type": "user" - }, - { - "name": "password", - "type": "password" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml index 16b04c4..4536c85 100644 --- a/manifest.toml +++ b/manifest.toml @@ -15,22 +15,19 @@ website = "https://listmonk.app/" demo = "https://demo.listmonk.app/" admindoc = "https://listmonk.app/docs/" code = "https://github.com/knadh/listmonk" -cpe = "???" # FIXME: optional but recommended if relevant, this is meant to contain the Common Platform Enumeration, which is sort of a standard id for applications defined by the NIST. In particular, Yunohost may use this is in the future to easily track CVE (=security reports) related to apps. The CPE may be obtained by searching here: https://nvd.nist.gov/products/cpe/search. For example, for Nextcloud, the CPE is 'cpe:2.3:a:nextcloud:nextcloud' (no need to include the version number) -fund = "???" # FIXME: optional but recommended (or remove if irrelevant / not applicable). This is meant to be an URL where people can financially support this app, especially when its development is based on volunteers and/or financed by its community. YunoHost may later advertise it in the webadmin. [integration] -yunohost = ">= 11.0.9" -architectures = "all" # FIXME: can be replaced by a list of supported archs using the dpkg --print-architecture nomenclature (amd64/i386/armhf/arm64), for example: ["amd64", "i386"] +yunohost = ">= 11.1.14" +architectures = ["amd64", "arm64", "armhf"] multi_instance = true -ldap = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "sso" key : the "ldap" key corresponds to wether or not a user *can* login on the app using its YunoHost credentials. -sso = "?" # FIXME: replace with true, false, or "not_relevant". Not to confuse with the "ldap" key : the "sso" key corresponds to wether or not a user is *automatically logged-in* on the app when logged-in on the YunoHost portal. -disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... -ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... -ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ldap = false +sso = false +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" [install] [install.domain] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "domain" full_domain = true @@ -39,11 +36,9 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen default = "visitors" [install.admin] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "user" [install.password] - # this is a generic question - ask strings are automatically handled by Yunohost's core type = "password" [resources] @@ -51,13 +46,26 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" - [resources.system_user] + [resources.ports] + [resources.install_dir] [resources.permissions] main.url = "/" + + admin.url = "/admin" + admin.show_tile = false + admin.allowed = "admins" + + api.url = "/api" + api.show_tile = false + api.allowed = "visitors" + + [resources.apt] + packages = "postgresql" + [[resources.apt.extras]] repo = "deb https://dl.yarnpkg.com/debian/ stable main" key = "https://dl.yarnpkg.com/debian/pubkey.gpg" diff --git a/scripts/_common.sh b/scripts/_common.sh index 251b15f..ee6cfc8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -#REMOVEME? pkg_dependencies="postgresql" - nodejs_version=16 GO_VERSION="1.18" diff --git a/scripts/backup b/scripts/backup index 469071d..59c90ce 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,28 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_print_info --message="Loading installation settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= diff --git a/scripts/change_url b/scripts/change_url index 18c4cf9..3a9b28d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -9,60 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN -#REMOVEME? old_path=$YNH_APP_OLD_PATH - -#REMOVEME? new_domain=$YNH_APP_NEW_DOMAIN -#REMOVEME? new_path=$YNH_APP_NEW_PATH - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? # Needed for helper "ynh_add_nginx_config" -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. -#REMOVEME? ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -#REMOVEME? change_domain=0 -#REMOVEME? if [ "$old_domain" != "$new_domain" ] -then - #REMOVEME? change_domain=1 -fi - -#REMOVEME? change_path=0 -#REMOVEME? if [ "$old_path" != "$new_path" ] -then - #REMOVEME? change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= @@ -79,30 +25,6 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- ynh_change_url_nginx_config -#REMOVEME? nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf - -# Change the path in the NGINX config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original NGINX config file if modified -#REMOVEME? ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper -#REMOVEME? domain="$old_domain" -#REMOVEME? path="$new_path" - # Create a dedicated NGINX config -#REMOVEME? ynh_add_nginx_config -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location -#REMOVEME? ynh_delete_file_checksum --file="$nginx_conf_path" -#REMOVEME? mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location -#REMOVEME? ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - #================================================= # GENERIC FINALISATION #================================================= @@ -112,13 +34,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -#REMOVEME? #REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 2fd70f5..f73680d 100755 --- a/scripts/install +++ b/scripts/install @@ -10,112 +10,37 @@ source _common.sh source ynh_install_go source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - ### Remove this function if there's nothing to clean before calling the remove script. - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -#REMOVEME? domain=$YNH_APP_ARG_DOMAIN -path="/" -#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC -#REMOVEME? admin=$YNH_APP_ARG_ADMIN -#REMOVEME? password=$YNH_APP_ARG_PASSWORD - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -#REMOVEME? ynh_script_progression --message="Validating installation parameters..." --weight=1 - -# Check machine architecture (in particular, we don't support 32bit machines) -if [ $YNH_ARCH == "i386" ] || [ $YNH_ARCH == "armel" ] -then - ynh_die --message="Sorry, because of NodeJS framework, this app can't be installed on i386 (32 bits) or armel machine." -fi - -#REMOVEME? install_dir=/var/www/$app -#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path +password=$YNH_APP_ARG_PASSWORD #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -#REMOVEME? ynh_script_progression --message="Storing installation settings..." --weight=1 -#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain -#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path -#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin -#REMOVEME? ynh_app_setting_set --app=$app --key=password --value="$password" - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -#REMOVEME? ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -#REMOVEME? port=$(ynh_find_port --port=8095) -#REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port +ynh_app_setting_set --app=$app --key=password --value="$password" #================================================= # INSTALL DEPENDENCIES #================================================= -#REMOVEME? ynh_script_progression --message="Installing dependencies..." --weight=12 - -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +ynh_script_progression --message="Installing dependencies..." --weight=12 if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version - # Install Yarn -#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" - # Install Go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION fi -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - -#================================================= -# CREATE A MYSQL DATABASE -#================================================= -#REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2 - -#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app) -#REMOVEME? db_user=$db_name -#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name -#REMOVEME? ynh_psql_test_if_first_run -#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 -#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir - # Download, check integrity, uncompress and patch the source from app.src if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then @@ -131,12 +56,11 @@ then popd ynh_remove_go ynh_remove_nodejs -#REMOVEME? ynh_secure_remove --file="$install_dir/build" + ynh_secure_remove --file="$install_dir/build" else ynh_setup_source --dest_dir="$install_dir" --source_id=$YNH_ARCH fi -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" chmod +x "$install_dir/listmonk" @@ -191,32 +115,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=2 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -#================================================= -# SETUP SSOWAT -#================================================= -#REMOVEME? ynh_script_progression --message="Configuring permissions..." --weight=1 - -# Make app public if necessary -#REMOVEME? if [ $is_public -eq 1 ] -then -#REMOVEME? ynh_permission_update --permission="main" --add="visitors" -fi - -# Only the admin can access the admin panel of the app (if the app has an admin panel) -#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false - -# Everyone can access the API part -# We don't want to display the tile in the SSO so we put --show_tile="false" -# And we don't want the YunoHost admin to be able to remove visitors group to this permission, so we put --protected="true" -#REMOVEME? ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" - -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index f9fc583..4fec55d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -9,19 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) - #================================================= # STANDARD REMOVE #================================================= @@ -43,22 +30,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -#REMOVEME? ynh_script_progression --message="Removing the PostgreSQL database..." --weight=2 - -# Remove a database if it exists, along with the associated user -#REMOVEME? ynh_psql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -#REMOVEME? ynh_script_progression --message="Removing app main directory..." --weight=2 - -# Remove the app directory securely -#REMOVEME? ynh_secure_remove --file="$install_dir" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -67,24 +38,6 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=8 - -# Remove metapackage and its dependencies -#REMOVEME? ynh_remove_app_dependencies - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -#REMOVEME? ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index eca4861..4593439 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,39 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -#REMOVEME? test ! -d $install_dir \ - || ynh_die --message="There is already a directory: $install_dir " - #================================================= # STANDARD RESTORATION STEPS #================================================= @@ -52,14 +19,6 @@ ynh_script_progression --message="Restoring the NGINX web server configuration.. ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -67,28 +26,15 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$install_dir" -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" chmod +x "$install_dir/listmonk" -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=10 - -# Define and install dependencies -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE THE MYSQL DATABASE #================================================= -#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 -#REMOVEME? ynh_psql_test_if_first_run -#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index cfdf2e9..7a38af1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,43 +10,12 @@ source _common.sh source ynh_install_go source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -#REMOVEME? password=$(ynh_app_setting_get --app=$app --key=password) -#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) - #================================================= # CHECK VERSION #================================================= upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -56,58 +25,6 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 - -# Cleaning legacy permissions -#REMOVEME? if ynh_legacy_permissions_exists; then -#REMOVEME? ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public -fi - -#REMOVEME? if ! ynh_permission_exists --permission="admin"; then - # Create the required permissions -#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --allowed=$admin --auth_header=false -fi - -# Create a permission if needed -#REMOVEME? if ! ynh_permission_exists --permission="api"; then -#REMOVEME? ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true" -fi - -if ynh_compare_current_package_version --comparison le --version 2.3.0~ynh3 -then - mkdir -p "$install_dir/uploads" - - ynh_permission_delete --permission="admin" - ynh_permission_delete --permission="api" - -#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --additional_urls="/admin /api" --allowed=$admin --auth_header=false -#REMOVEME? ynh_permission_create --permission="api" --url="/public" --additional_urls="/api/public" --allowed="visitors" --show_tile="false" --protected="true" -fi - -if ynh_compare_current_package_version --comparison le --version 2.3.0~ynh1 -then - mkdir -p "$install_dir/uploads" - - ynh_permission_delete --permission="admin" - ynh_permission_delete --permission="api" - -#REMOVEME? ynh_permission_create --permission="admin" --url="/admin" --additional_urls="/admin /api" --allowed=$admin --auth_header=false -#REMOVEME? ynh_permission_create --permission="api" --url="/public" --additional_urls="/api/public" --allowed="visitors" --show_tile="false" --protected="true" -fi - -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -123,7 +40,7 @@ then # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version # Install Yarn -#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" + # Install Go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION pushd "$install_dir/build" @@ -137,13 +54,12 @@ then popd ynh_remove_go ynh_remove_nodejs -#REMOVEME? ynh_secure_remove --file="$install_dir/build" + ynh_secure_remove --file="$install_dir/build" else ynh_setup_source --dest_dir="$install_dir" --source_id=$YNH_ARCH --keep="$install_dir/config.toml" fi fi -chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" chmod +x "$install_dir/listmonk" @@ -156,23 +72,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=10 - -#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -# ynh_script_progression --message="Updating a configuration file..." --time --weight=1 - -# ynh_add_config --template="../conf/config.toml" --destination="$install_dir/config.toml" - -# chmod 400 "$install_dir/config.toml" -# chown $app:$app "$install_dir/config.toml" - #================================================= # DATABASE CONFIGURATION #================================================= @@ -204,13 +103,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" -#================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 - -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..91daf17 --- /dev/null +++ b/tests.toml @@ -0,0 +1,7 @@ +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ \ No newline at end of file From 1f6cfb99fadc4e7d6a3b222747053673a04c576e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:45:37 +0100 Subject: [PATCH 03/18] Update manifest.toml --- manifest.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.toml b/manifest.toml index 4536c85..eeb22ca 100644 --- a/manifest.toml +++ b/manifest.toml @@ -54,6 +54,7 @@ ram.runtime = "50M" [resources.permissions] main.url = "/" + main.auth_header = false admin.url = "/admin" admin.show_tile = false From e724dc65b20408b3183c2dc757dd01fd97f2f7cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:48:42 +0100 Subject: [PATCH 04/18] Update manifest.toml --- manifest.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/manifest.toml b/manifest.toml index eeb22ca..6c4b1bb 100644 --- a/manifest.toml +++ b/manifest.toml @@ -42,9 +42,9 @@ ram.runtime = "50M" type = "password" [resources] - [resources.sources.main] - url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" - sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" + [resources.sources] + main.url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" + main.sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" [resources.system_user] @@ -58,6 +58,7 @@ ram.runtime = "50M" admin.url = "/admin" admin.show_tile = false + admin.auth_header = false admin.allowed = "admins" api.url = "/api" @@ -67,10 +68,9 @@ ram.runtime = "50M" [resources.apt] packages = "postgresql" - [[resources.apt.extras]] - repo = "deb https://dl.yarnpkg.com/debian/ stable main" - key = "https://dl.yarnpkg.com/debian/pubkey.gpg" - packages = "yarn" + extras.repo = "deb https://dl.yarnpkg.com/debian/ stable main" + extras.key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + extras.packages = "yarn" [resources.database] type = "postgresql" From 13f879af4e5ee150ed085d44d20fa7ca0a884e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:49:20 +0100 Subject: [PATCH 05/18] Delete check_process --- check_process | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 check_process diff --git a/check_process b/check_process deleted file mode 100644 index 32fb117..0000000 --- a/check_process +++ /dev/null @@ -1,26 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - path="/path" - is_public=1 - admin="john" - password="1Strong-Password" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - #upgrade=1 from_commit=CommitHash - backup_restore=1 - multi_instance=1 - change_url=1 -;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=CommitHash - name=Name and date of the commit. - manifest_arg=domain=DOMAIN&path=PATH&is_public=1&language=fr&admin=USER&password=pass&port=666& From 590c841f62007a50dc7fc5310584afe56db4bd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:55:34 +0100 Subject: [PATCH 06/18] Update manifest.toml --- manifest.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index 6c4b1bb..e11fd29 100644 --- a/manifest.toml +++ b/manifest.toml @@ -42,9 +42,12 @@ ram.runtime = "50M" type = "password" [resources] + [resources.sources] - main.url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" - main.sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" + + [resources.sources.main] + url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" + sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" [resources.system_user] From 019269b03f2ec2825d54730387111c34f00a1ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:09:00 +0100 Subject: [PATCH 07/18] Update manifest.toml --- manifest.toml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/manifest.toml b/manifest.toml index e11fd29..1fe5ab6 100644 --- a/manifest.toml +++ b/manifest.toml @@ -46,8 +46,8 @@ ram.runtime = "50M" [resources.sources] [resources.sources.main] - url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.2.0.tar.gz" - sha256 = "6eef831f7ceef80624ae69cd7020504344410d0f8015a0e150b88d324894ca8d" + url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.3.0.tar.gz" + sha256 = "54cab80ca16dbf58ce40b7fc1ae88a9f8ed4c9d9a54387a77b1a90cb4dba3404" [resources.system_user] @@ -71,9 +71,10 @@ ram.runtime = "50M" [resources.apt] packages = "postgresql" - extras.repo = "deb https://dl.yarnpkg.com/debian/ stable main" - extras.key = "https://dl.yarnpkg.com/debian/pubkey.gpg" - extras.packages = "yarn" + [resources.apt.extras.yarn] + repo = "deb https://dl.yarnpkg.com/debian/ stable main" + key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + packages = "yarn" [resources.database] type = "postgresql" From 0906e39ac49c607f2697edb34bcbe6edd33ff655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:10:17 +0100 Subject: [PATCH 08/18] Update install --- scripts/install | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/scripts/install b/scripts/install index f73680d..47c26ab 100755 --- a/scripts/install +++ b/scripts/install @@ -22,44 +22,12 @@ password=$YNH_APP_ARG_PASSWORD ynh_app_setting_set --app=$app --key=password --value="$password" -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=12 - -if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] -then - # Install Nodejs - ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version - - # Install Go - ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 -# Download, check integrity, uncompress and patch the source from app.src -if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] -then - ynh_setup_source --dest_dir="$install_dir/build" - pushd "$install_dir/build" - # Build the sources - ynh_use_go - export GOPATH="$install_dir/build/go" - export GOCACHE="$install_dir/build/.cache" - ynh_use_nodejs - make dist - mv listmonk .. - popd - ynh_remove_go - ynh_remove_nodejs - ynh_secure_remove --file="$install_dir/build" -else - ynh_setup_source --dest_dir="$install_dir" --source_id=$YNH_ARCH -fi +ynh_setup_source --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" From 8a8dac769fb203402a075b70cf6a415c56f8fd3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:11:27 +0100 Subject: [PATCH 09/18] Fix --- scripts/upgrade | 25 +---- scripts/ynh_install_go | 247 ----------------------------------------- 2 files changed, 1 insertion(+), 271 deletions(-) delete mode 100644 scripts/ynh_install_go diff --git a/scripts/upgrade b/scripts/upgrade index 7a38af1..d1981e1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -34,30 +34,7 @@ then ynh_script_progression --message="Upgrading source files..." --weight=5 # Download, check integrity, uncompress and patch the source from app.src - if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] - then - ynh_setup_source --dest_dir="$install_dir/build" --keep="$install_dir/config.toml" - # Install Nodejs - ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version - # Install Yarn - - # Install Go - ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION - pushd "$install_dir/build" - # Build the sources - ynh_use_go - export GOPATH="$install_dir/build/go" - export GOCACHE="$install_dir/build/.cache" - ynh_use_nodejs - make dist - mv listmonk .. - popd - ynh_remove_go - ynh_remove_nodejs - ynh_secure_remove --file="$install_dir/build" - else - ynh_setup_source --dest_dir="$install_dir" --source_id=$YNH_ARCH --keep="$install_dir/config.toml" - fi + ynh_setup_source --dest_dir="$install_dir" --keep="$install_dir/config.toml" fi chmod -R o-rwx "$install_dir" diff --git a/scripts/ynh_install_go b/scripts/ynh_install_go deleted file mode 100644 index 4fbf4e9..0000000 --- a/scripts/ynh_install_go +++ /dev/null @@ -1,247 +0,0 @@ -#!/bin/bash - -ynh_go_try_bash_extension() { - if [ -x src/configure ]; then - src/configure && make -C src || { - ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." - } - fi -} - -goenv_install_dir="/opt/goenv" -go_version_path="$goenv_install_dir/versions" -# goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable. -export GOENV_ROOT="$goenv_install_dir" - -# Load the version of Go for an app, and set variables. -# -# ynh_use_go has to be used in any app scripts before using Go for the first time. -# This helper will provide alias and variables to use in your scripts. -# -# To use gem or Go, use the alias `ynh_gem` and `ynh_go` -# Those alias will use the correct version installed for the app -# For example: use `ynh_gem install` instead of `gem install` -# -# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_go` -# And propagate $PATH to sudo with $ynh_go_load_path -# Exemple: `ynh_exec_as $app $ynh_go_load_path $ynh_gem install` -# -# $PATH contains the path of the requested version of Go. -# However, $PATH is duplicated into $go_path to outlast any manipulation of $PATH -# You can use the variable `$ynh_go_load_path` to quickly load your Go version -# in $PATH for an usage into a separate script. -# Exemple: $ynh_go_load_path $final_path/script_that_use_gem.sh` -# -# -# Finally, to start a Go service with the correct version, 2 solutions -# Either the app is dependent of Go or gem, but does not called it directly. -# In such situation, you need to load PATH -# `Environment="__YNH_GO_LOAD_PATH__"` -# `ExecStart=__FINALPATH__/my_app` -# You will replace __YNH_GO_LOAD_PATH__ with $ynh_go_load_path -# -# Or Go start the app directly, then you don't need to load the PATH variable -# `ExecStart=__YNH_GO__ my_app run` -# You will replace __YNH_GO__ with $ynh_go -# -# -# one other variable is also available -# - $go_path: The absolute path to Go binaries for the chosen version. -# -# usage: ynh_use_go -# -# Requires YunoHost version 3.2.2 or higher. -ynh_use_go () { - go_version=$(ynh_app_setting_get --app=$app --key=go_version) - - # Get the absolute path of this version of Go - go_path="$go_version_path/$go_version/bin" - - # Allow alias to be used into bash script - shopt -s expand_aliases - - # Create an alias for the specific version of Go and a variable as fallback - ynh_go="$go_path/go" - alias ynh_go="$ynh_go" - - # Load the path of this version of Go in $PATH - if [[ :$PATH: != *":$go_path"* ]]; then - PATH="$go_path:$PATH" - fi - # Create an alias to easily load the PATH - ynh_go_load_path="PATH=$PATH" - - # Sets the local application-specific Go version - pushd $final_path - $goenv_install_dir/bin/goenv local $go_version - popd -} - -# Install a specific version of Go -# -# ynh_install_go will install the version of Go provided as argument by using goenv. -# -# This helper creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv -# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) -# -# Don't forget to execute go-dependent command in a login environment -# (e.g. sudo --login option) -# When not possible (e.g. in systemd service definition), please use direct path -# to goenv shims (e.g. $goenv_ROOT/shims/bundle) -# -# usage: ynh_install_go --go_version=go_version -# | arg: -v, --go_version= - Version of go to install. -# -# Requires YunoHost version 3.2.2 or higher. -ynh_install_go () { - # Declare an array to define the options of this helper. - local legacy_args=v - local -A args_array=( [v]=go_version= ) - local go_version - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - - # Load goenv path in PATH - local CLEAR_PATH="$goenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Go prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Move an existing Go binary, to avoid to block goenv - test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv - - # Install or update goenv - goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)" - if [ -n "$goenv" ]; then - ynh_print_info --message="goenv already seems installed in \`$goenv'." - pushd "${goenv%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then - echo "Trying to update with git..." - git pull -q --tags origin master - cd .. - ynh_go_try_bash_extension - fi - popd - else - ynh_print_info --message="Installing goenv with git..." - mkdir -p $goenv_install_dir - pushd $goenv_install_dir - git init -q - git remote add -f -t master origin https://github.com/syndbg/goenv.git > /dev/null 2>&1 - git checkout -q -b master origin/master - ynh_go_try_bash_extension - goenv=$goenv_install_dir/bin/goenv - popd - fi - - goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)" - if [ -n "$goenv_latest" ]; then - ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'." - pushd "${goenv_latest%/*/*}" - if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then - ynh_print_info --message="Trying to update xxenv-latest with git..." - git pull -q origin master - fi - popd - else - ynh_print_info --message="Installing xxenv-latest with git..." - mkdir -p "${goenv_install_dir}/plugins" - git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest" - fi - - # Enable caching - mkdir -p "${goenv_install_dir}/cache" - - # Create shims directory if needed - mkdir -p "${goenv_install_dir}/shims" - - # Restore /usr/local/bin in PATH - PATH=$CLEAR_PATH - - # And replace the old Go binary - test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go - - # Install the requested version of Go - local final_go_version=$(goenv latest --print $go_version) - ynh_print_info --message="Installation of Go-$final_go_version" - goenv install --skip-existing $final_go_version - - # Store go_version into the config of this app - ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version - - # Cleanup Go versions - ynh_cleanup_go - - # Set environment for Go users - echo "#goenv -export GOENV_ROOT=$goenv_install_dir -export PATH=\"$goenv_install_dir/bin:$PATH\" -eval \"\$(goenv init -)\" -#goenv" > /etc/profile.d/goenv.sh - - # Load the environment - eval "$(goenv init -)" -} - -# Remove the version of Go used by the app. -# -# This helper will also cleanup Go versions -# -# usage: ynh_remove_go -ynh_remove_go () { - local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version) - - # Load goenv path in PATH - local CLEAR_PATH="$goenv_install_dir/bin:$PATH" - - # Remove /usr/local/bin in PATH in case of Go prior installation - PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') - - # Remove the line for this app - ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version - - # Cleanup Go versions - ynh_cleanup_go -} - -# Remove no more needed versions of Go used by the app. -# -# This helper will check what Go version are no more required, -# and uninstall them -# If no app uses Go, goenv will be also removed. -# -# usage: ynh_cleanup_go -ynh_cleanup_go () { - - # List required Go versions - local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') - local required_go_versions="" - for installed_app in $installed_apps - do - local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") - if [[ $installed_app_go_version ]] - then - required_go_versions="${installed_app_go_version}\n${required_go_versions}" - fi - done - - # Remove no more needed Go versions - local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/') - for installed_go_version in $installed_go_versions - do - if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1` - then - ynh_print_info --message="Removing of Go-$installed_go_version" - $goenv_install_dir/bin/goenv uninstall --force $installed_go_version - fi - done - - # If none Go version is required - if [[ ! $required_go_versions ]] - then - # Remove goenv environment configuration - ynh_print_info --message="Removing of goenv" - ynh_secure_remove --file="$goenv_install_dir" - ynh_secure_remove --file="/etc/profile.d/goenv.sh" - fi -} From e997284a8da4e7bc35e8e0e23564da2257e18f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:11:56 +0100 Subject: [PATCH 10/18] Fix --- manifest.toml | 2 +- scripts/_common.sh | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/manifest.toml b/manifest.toml index 1fe5ab6..7b36e99 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,7 @@ code = "https://github.com/knadh/listmonk" [integration] yunohost = ">= 11.1.14" -architectures = ["amd64", "arm64", "armhf"] +architectures = ["amd64"] multi_instance = true ldap = false sso = false diff --git a/scripts/_common.sh b/scripts/_common.sh index ee6cfc8..944a65e 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -nodejs_version=16 -GO_VERSION="1.18" - #================================================= # PERSONAL HELPERS #================================================= From a732f2ad719d86703742d27c06a8db0e021c3135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:12:33 +0100 Subject: [PATCH 11/18] Update systemd.service --- conf/systemd.service | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/conf/systemd.service b/conf/systemd.service index 69d92ef..7ed37f5 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -10,5 +10,40 @@ WorkingDirectory=__INSTALL_DIR__/ ExecStart=__INSTALL_DIR__/listmonk Restart=always + +# Sandboxing options to harden security +# Depending on specificities of your service/app, you may need to tweak these +# .. but this should be a good baseline +# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html +NoNewPrivileges=yes +PrivateTmp=yes +PrivateDevices=yes +RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK +RestrictNamespaces=yes +RestrictRealtime=yes +DevicePolicy=closed +ProtectClock=yes +ProtectHostname=yes +ProtectProc=invisible +ProtectSystem=full +ProtectControlGroups=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +LockPersonality=yes +SystemCallArchitectures=native +SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged + +# Denying access to capabilities that should not be relevant for webapps +# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html +CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD +CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE +CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT +CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK +CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM +CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG +CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE +CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW +CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG + [Install] WantedBy=multi-user.target From 7130ee35700d80f7cd0c9c4bc0ddd3ea93ed812e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:19:55 +0100 Subject: [PATCH 12/18] fix --- scripts/install | 1 - scripts/upgrade | 1 - 2 files changed, 2 deletions(-) diff --git a/scripts/install b/scripts/install index 47c26ab..f08c4fc 100755 --- a/scripts/install +++ b/scripts/install @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_install_go source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index d1981e1..329fe4a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,6 @@ #================================================= source _common.sh -source ynh_install_go source /usr/share/yunohost/helpers #================================================= From 594359a0f28e55c0bc7183001c748a3182d7662a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:42:12 +0100 Subject: [PATCH 13/18] Update manifest.toml --- manifest.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index 7b36e99..2a117d4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -46,8 +46,9 @@ ram.runtime = "50M" [resources.sources] [resources.sources.main] - url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.3.0.tar.gz" - sha256 = "54cab80ca16dbf58ce40b7fc1ae88a9f8ed4c9d9a54387a77b1a90cb4dba3404" + url = "https://github.com/knadh/listmonk/releases/download/v2.2.0/listmonk_2.2.0_linux_amd64.tar.gz" + sha256 = "c2bdccd073d768d2b8dfbfad6469c5b41cf39b44a20c263cbaebf15876463709" + in_subdir = false [resources.system_user] From c4e66613952df8d125c878659ee0c8d5876b9b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 18:57:16 +0100 Subject: [PATCH 14/18] add arm --- manifest.toml | 8 +- scripts/_common.sh | 3 + scripts/install | 43 +++++++- scripts/upgrade | 30 ++++- scripts/ynh_install_go | 245 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 319 insertions(+), 10 deletions(-) create mode 100644 scripts/ynh_install_go diff --git a/manifest.toml b/manifest.toml index 2a117d4..6214e5e 100644 --- a/manifest.toml +++ b/manifest.toml @@ -46,10 +46,14 @@ ram.runtime = "50M" [resources.sources] [resources.sources.main] - url = "https://github.com/knadh/listmonk/releases/download/v2.2.0/listmonk_2.2.0_linux_amd64.tar.gz" - sha256 = "c2bdccd073d768d2b8dfbfad6469c5b41cf39b44a20c263cbaebf15876463709" + url = "https://github.com/knadh/listmonk/releases/download/v2.3.0/listmonk_2.3.0_linux_amd64.tar.gz" + sha256 = "4ad9ff7a04e13c9f8609c705e4850046ae8a3c9a03b0c4ac04e3c1d1c8fe8b7a" in_subdir = false + [resources.sources.arm] + url = "https://github.com/knadh/listmonk/archive/refs/tags/v2.3.0.tar.gz" + sha256 = "54cab80ca16dbf58ce40b7fc1ae88a9f8ed4c9d9a54387a77b1a90cb4dba3404" + [resources.system_user] [resources.ports] diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..ee6cfc8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,6 +4,9 @@ # COMMON VARIABLES #================================================= +nodejs_version=16 +GO_VERSION="1.18" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index f08c4fc..e3974bf 100755 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_go source /usr/share/yunohost/helpers #================================================= @@ -21,16 +22,50 @@ password=$YNH_APP_ARG_PASSWORD ynh_app_setting_set --app=$app --key=password --value="$password" +#================================================= +# INSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Installing dependencies..." --weight=12 + +if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] +then + # Install Nodejs + ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + + # Install Go + ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION +fi + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 -ynh_setup_source --dest_dir="$install_dir" +ynh_app_setting_set --app=$app --key=final_path --value=$final_path -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" -chmod +x "$install_dir/listmonk" +# Download, check integrity, uncompress and patch the source from app.src +if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] +then + ynh_setup_source --dest_dir="$final_path/build" --source_id=arm + pushd "$final_path/build" + # Build the sources + ynh_use_go + export GOPATH="$final_path/build/go" + export GOCACHE="$final_path/build/.cache" + ynh_use_nodejs + make dist + mv listmonk .. + popd + ynh_remove_go + ynh_remove_nodejs + ynh_secure_remove --file="$final_path/build" +else + ynh_setup_source --dest_dir="$final_path" +fi + +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod +x "$final_path/listmonk" #================================================= # NGINX CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 329fe4a..e2bbe42 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_install_go source /usr/share/yunohost/helpers #================================================= @@ -33,12 +34,33 @@ then ynh_script_progression --message="Upgrading source files..." --weight=5 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --keep="$install_dir/config.toml" + if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] + then + ynh_setup_source --dest_dir="$final_path/build" --source_id=arm --keep="$final_path/config.toml" + # Install Nodejs + ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + # Install Go + ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION + pushd "$final_path/build" + # Build the sources + ynh_use_go + export GOPATH="$final_path/build/go" + export GOCACHE="$final_path/build/.cache" + ynh_use_nodejs + make dist + mv listmonk .. + popd + ynh_remove_go + ynh_remove_nodejs + ynh_secure_remove --file="$final_path/build" + else + ynh_setup_source --dest_dir="$final_path" --keep="$final_path/config.toml" + fi fi -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" -chmod +x "$install_dir/listmonk" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" +chmod +x "$final_path/listmonk" #================================================= # NGINX CONFIGURATION diff --git a/scripts/ynh_install_go b/scripts/ynh_install_go new file mode 100644 index 0000000..d9e3555 --- /dev/null +++ b/scripts/ynh_install_go @@ -0,0 +1,245 @@ +ynh_go_try_bash_extension() { + if [ -x src/configure ]; then + src/configure && make -C src || { + ynh_print_info --message="Optional bash extension failed to build, but things will still work normally." + } + fi +} + +goenv_install_dir="/opt/goenv" +go_version_path="$goenv_install_dir/versions" +# goenv_ROOT is the directory of goenv, it needs to be loaded as a environment variable. +export GOENV_ROOT="$goenv_install_dir" + +# Load the version of Go for an app, and set variables. +# +# ynh_use_go has to be used in any app scripts before using Go for the first time. +# This helper will provide alias and variables to use in your scripts. +# +# To use gem or Go, use the alias `ynh_gem` and `ynh_go` +# Those alias will use the correct version installed for the app +# For example: use `ynh_gem install` instead of `gem install` +# +# With `sudo` or `ynh_exec_as`, use instead the fallback variables `$ynh_gem` and `$ynh_go` +# And propagate $PATH to sudo with $ynh_go_load_path +# Exemple: `ynh_exec_as $app $ynh_go_load_path $ynh_gem install` +# +# $PATH contains the path of the requested version of Go. +# However, $PATH is duplicated into $go_path to outlast any manipulation of $PATH +# You can use the variable `$ynh_go_load_path` to quickly load your Go version +# in $PATH for an usage into a separate script. +# Exemple: $ynh_go_load_path $final_path/script_that_use_gem.sh` +# +# +# Finally, to start a Go service with the correct version, 2 solutions +# Either the app is dependent of Go or gem, but does not called it directly. +# In such situation, you need to load PATH +# `Environment="__YNH_GO_LOAD_PATH__"` +# `ExecStart=__FINALPATH__/my_app` +# You will replace __YNH_GO_LOAD_PATH__ with $ynh_go_load_path +# +# Or Go start the app directly, then you don't need to load the PATH variable +# `ExecStart=__YNH_GO__ my_app run` +# You will replace __YNH_GO__ with $ynh_go +# +# +# one other variable is also available +# - $go_path: The absolute path to Go binaries for the chosen version. +# +# usage: ynh_use_go +# +# Requires YunoHost version 3.2.2 or higher. +ynh_use_go () { + go_version=$(ynh_app_setting_get --app=$app --key=go_version) + + # Get the absolute path of this version of Go + go_path="$go_version_path/$go_version/bin" + + # Allow alias to be used into bash script + shopt -s expand_aliases + + # Create an alias for the specific version of Go and a variable as fallback + ynh_go="$go_path/go" + alias ynh_go="$ynh_go" + + # Load the path of this version of Go in $PATH + if [[ :$PATH: != *":$go_path"* ]]; then + PATH="$go_path:$PATH" + fi + # Create an alias to easily load the PATH + ynh_go_load_path="PATH=$PATH" + + # Sets the local application-specific Go version + pushd $final_path + $goenv_install_dir/bin/goenv local $go_version + popd +} + +# Install a specific version of Go +# +# ynh_install_go will install the version of Go provided as argument by using goenv. +# +# This helper creates a /etc/profile.d/goenv.sh that configures PATH environment for goenv +# for every LOGIN user, hence your user must have a defined shell (as opposed to /usr/sbin/nologin) +# +# Don't forget to execute go-dependent command in a login environment +# (e.g. sudo --login option) +# When not possible (e.g. in systemd service definition), please use direct path +# to goenv shims (e.g. $goenv_ROOT/shims/bundle) +# +# usage: ynh_install_go --go_version=go_version +# | arg: -v, --go_version= - Version of go to install. +# +# Requires YunoHost version 3.2.2 or higher. +ynh_install_go () { + # Declare an array to define the options of this helper. + local legacy_args=v + local -A args_array=( [v]=go_version= ) + local go_version + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + + # Load goenv path in PATH + local CLEAR_PATH="$goenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Go prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Move an existing Go binary, to avoid to block goenv + test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv + + # Install or update goenv + goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)" + if [ -n "$goenv" ]; then + ynh_print_info --message="goenv already seems installed in \`$goenv'." + pushd "${goenv%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then + echo "Trying to update with git..." + git pull -q --tags origin master + cd .. + ynh_go_try_bash_extension + fi + popd + else + ynh_print_info --message="Installing goenv with git..." + mkdir -p $goenv_install_dir + pushd $goenv_install_dir + git init -q + git remote add -f -t master origin https://github.com/syndbg/goenv.git > /dev/null 2>&1 + git checkout -q -b master origin/master + ynh_go_try_bash_extension + goenv=$goenv_install_dir/bin/goenv + popd + fi + + goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)" + if [ -n "$goenv_latest" ]; then + ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'." + pushd "${goenv_latest%/*/*}" + if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then + ynh_print_info --message="Trying to update xxenv-latest with git..." + git pull -q origin master + fi + popd + else + ynh_print_info --message="Installing xxenv-latest with git..." + mkdir -p "${goenv_install_dir}/plugins" + git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest" + fi + + # Enable caching + mkdir -p "${goenv_install_dir}/cache" + + # Create shims directory if needed + mkdir -p "${goenv_install_dir}/shims" + + # Restore /usr/local/bin in PATH + PATH=$CLEAR_PATH + + # And replace the old Go binary + test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go + + # Install the requested version of Go + local final_go_version=$(goenv latest --print $go_version) + ynh_print_info --message="Installation of Go-$final_go_version" + goenv install --skip-existing $final_go_version + + # Store go_version into the config of this app + ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version + + # Cleanup Go versions + ynh_cleanup_go + + # Set environment for Go users + echo "#goenv +export GOENV_ROOT=$goenv_install_dir +export PATH=\"$goenv_install_dir/bin:$PATH\" +eval \"\$(goenv init -)\" +#goenv" > /etc/profile.d/goenv.sh + + # Load the environment + eval "$(goenv init -)" +} + +# Remove the version of Go used by the app. +# +# This helper will also cleanup Go versions +# +# usage: ynh_remove_go +ynh_remove_go () { + local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version) + + # Load goenv path in PATH + local CLEAR_PATH="$goenv_install_dir/bin:$PATH" + + # Remove /usr/local/bin in PATH in case of Go prior installation + PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') + + # Remove the line for this app + ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version + + # Cleanup Go versions + ynh_cleanup_go +} + +# Remove no more needed versions of Go used by the app. +# +# This helper will check what Go version are no more required, +# and uninstall them +# If no app uses Go, goenv will be also removed. +# +# usage: ynh_cleanup_go +ynh_cleanup_go () { + + # List required Go versions + local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') + local required_go_versions="" + for installed_app in $installed_apps + do + local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") + if [[ $installed_app_go_version ]] + then + required_go_versions="${installed_app_go_version}\n${required_go_versions}" + fi + done + + # Remove no more needed Go versions + local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/') + for installed_go_version in $installed_go_versions + do + if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1` + then + ynh_print_info --message="Removing of Go-$installed_go_version" + $goenv_install_dir/bin/goenv uninstall --force $installed_go_version + fi + done + + # If none Go version is required + if [[ ! $required_go_versions ]] + then + # Remove goenv environment configuration + ynh_print_info --message="Removing of goenv" + ynh_secure_remove --file="$goenv_install_dir" + ynh_secure_remove --file="/etc/profile.d/goenv.sh" + fi +} \ No newline at end of file From 0c58423df4c0616744c2cc20f7f8e90dce615597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Fri, 10 Mar 2023 19:12:11 +0100 Subject: [PATCH 15/18] Fix --- scripts/install | 20 +++++++++----------- scripts/upgrade | 18 +++++++++--------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/scripts/install b/scripts/install index e3974bf..623e247 100755 --- a/scripts/install +++ b/scripts/install @@ -41,31 +41,29 @@ fi #================================================= ynh_script_progression --message="Setting up source files..." --weight=3 -ynh_app_setting_set --app=$app --key=final_path --value=$final_path - # Download, check integrity, uncompress and patch the source from app.src if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then - ynh_setup_source --dest_dir="$final_path/build" --source_id=arm - pushd "$final_path/build" + ynh_setup_source --dest_dir="$install_dir/build" --source_id=arm + pushd "$install_dir/build" # Build the sources ynh_use_go - export GOPATH="$final_path/build/go" - export GOCACHE="$final_path/build/.cache" + export GOPATH="$install_dir/build/go" + export GOCACHE="$install_dir/build/.cache" ynh_use_nodejs make dist mv listmonk .. popd ynh_remove_go ynh_remove_nodejs - ynh_secure_remove --file="$final_path/build" + ynh_secure_remove --file="$install_dir/build" else - ynh_setup_source --dest_dir="$final_path" + ynh_setup_source --dest_dir="$install_dir" fi -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/listmonk" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod +x "$install_dir/listmonk" #================================================= # NGINX CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index e2bbe42..498e203 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -36,31 +36,31 @@ then # Download, check integrity, uncompress and patch the source from app.src if [ $YNH_ARCH == "armhf" ] || [ $YNH_ARCH == "arm64" ] then - ynh_setup_source --dest_dir="$final_path/build" --source_id=arm --keep="$final_path/config.toml" + ynh_setup_source --dest_dir="$install_dir/build" --source_id=arm --keep="$install_dir/config.toml" # Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version # Install Go ynh_exec_warn_less ynh_install_go --go_version=$GO_VERSION - pushd "$final_path/build" + pushd "$install_dir/build" # Build the sources ynh_use_go - export GOPATH="$final_path/build/go" - export GOCACHE="$final_path/build/.cache" + export GOPATH="$install_dir/build/go" + export GOCACHE="$install_dir/build/.cache" ynh_use_nodejs make dist mv listmonk .. popd ynh_remove_go ynh_remove_nodejs - ynh_secure_remove --file="$final_path/build" + ynh_secure_remove --file="$install_dir/build" else - ynh_setup_source --dest_dir="$final_path" --keep="$final_path/config.toml" + ynh_setup_source --dest_dir="$install_dir" --keep="$install_dir/config.toml" fi fi -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" -chmod +x "$final_path/listmonk" +chmod -R o-rwx "$install_dir" +chown -R $app:www-data "$install_dir" +chmod +x "$install_dir/listmonk" #================================================= # NGINX CONFIGURATION From aff5d1ef01d395c8ffa9ac75ae6982752eef4dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 16 Mar 2023 08:35:36 +0100 Subject: [PATCH 16/18] Update manifest.toml --- manifest.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manifest.toml b/manifest.toml index 6214e5e..677cd59 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,7 +5,7 @@ name = "Listmonk" description.en = "Newsletter and mailing list manager" description.fr = "Manager de newsletter et mailing list" -version = "2.3.0~ynh3" +version = "2.3.0~ynh4" maintainers = ["Navan Chauhan"] @@ -17,7 +17,7 @@ admindoc = "https://listmonk.app/docs/" code = "https://github.com/knadh/listmonk" [integration] -yunohost = ">= 11.1.14" +yunohost = ">= 11.1.15" architectures = ["amd64"] multi_instance = true ldap = false @@ -71,15 +71,15 @@ ram.runtime = "50M" api.url = "/api" api.show_tile = false + api.auth_header = false api.allowed = "visitors" [resources.apt] packages = "postgresql" - [resources.apt.extras.yarn] - repo = "deb https://dl.yarnpkg.com/debian/ stable main" - key = "https://dl.yarnpkg.com/debian/pubkey.gpg" - packages = "yarn" + extras.yarn.repo = "deb https://dl.yarnpkg.com/debian/ stable main" + extras.yarn.key = "https://dl.yarnpkg.com/debian/pubkey.gpg" + extras.yarn.packages = "yarn" [resources.database] type = "postgresql" From f963c5d4573282b45c68aaecebce967e98906ae6 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Thu, 16 Mar 2023 07:35:41 +0000 Subject: [PATCH 17/18] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1347b5e..c41448d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL (⩾ v9.4) database as its data store. -**Shipped version:** 2.3.0~ynh3 +**Shipped version:** 2.3.0~ynh4 **Demo:** https://demo.listmonk.app/ diff --git a/README_fr.md b/README_fr.md index 6ea512c..6f3ea09 100644 --- a/README_fr.md +++ b/README_fr.md @@ -19,7 +19,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po Listmonk is a standalone, self-hosted, newsletter and mailing list manager. It is fast, feature-rich, and packed into a single binary. It uses a PostgreSQL (⩾ v9.4) database as its data store. -**Version incluse :** 2.3.0~ynh3 +**Version incluse :** 2.3.0~ynh4 **Démo :** https://demo.listmonk.app/ From 9e149722004b5963be702a34e564d50db00b951d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 16 Mar 2023 08:41:11 +0100 Subject: [PATCH 18/18] Update tests.toml --- tests.toml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests.toml b/tests.toml index 91daf17..a26dece 100644 --- a/tests.toml +++ b/tests.toml @@ -2,6 +2,8 @@ test_format = 1.0 [default] - # ------------ - # Tests to run - # ------------ \ No newline at end of file + # ------------------------------- + # Commits to test upgrade from + # ------------------------------- + + test_upgrade_from.4b1297d8.name = "Upgrade from 2.3.0"