diff --git a/README.md b/README.md index f61256c..ed3191a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ For user friendly details about Pleroma: [see here](https://blog.soykaf.com/post - Tootdon (Android + iOS) - Tootle (iOS) -**Shipped version:** 0.9.99999 +**Shipped version:** 1.1.7 ## Important points to read before installing @@ -85,7 +85,6 @@ The app can be used by multiple users. * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/pleroma%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/pleroma/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/pleroma%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/pleroma/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/pleroma%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/pleroma/) ## Limitations @@ -103,7 +102,6 @@ The app can be used by multiple users. Developers info ---------------- -**Only if you want to use a testing branch for coding, instead of merging directly into master.** Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/pleroma_ynh/tree/testing). To try the testing branch, please proceed like that. diff --git a/check_process b/check_process index b898676..491412f 100755 --- a/check_process +++ b/check_process @@ -9,7 +9,7 @@ admin="john" (USER) is_public=1 (PUBLIC|public=1|private=0) password="pass" - name="My Pleroma" + name="My_Pleroma" registration=0 (BOOLEAN) cache=1 (BOOLEAN) size="5g" @@ -21,9 +21,9 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=14d3be2f782048e64696cef85f4fb7dff1ab6181 + upgrade=1 from_commit=edf199768f57000f4df6e2c704483e1036a78203 backup_restore=1 - multi_instance=1 + multi_instance=0 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. # incorrect_path=1 port_already_use=0 diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index cd01bbe..0000000 --- a/conf/app.src +++ /dev/null @@ -1,6 +0,0 @@ -SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/archive/v0.9.99999/pleroma-v0.9.99999.tar.gz -SOURCE_SUM=b79ee12d598a162bc16ebd7ec18ee7b0b78cb623574757ad6a0fe19d6a5a23d4 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= diff --git a/conf/arm.src b/conf/arm.src new file mode 100644 index 0000000..fae8824 --- /dev/null +++ b/conf/arm.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/jobs/84826/artifacts/download +SOURCE_SUM=aeb527340dbecc5056cd3aca459ed0a0f3b41808afc492e61f998032e5c3d874 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME=pleroma-v1.1.7-arm.zip diff --git a/conf/arm64.src b/conf/arm64.src new file mode 100644 index 0000000..f827990 --- /dev/null +++ b/conf/arm64.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/jobs/84828/artifacts/download +SOURCE_SUM=74032e08b6f89321eb5545ff77fb0b1f142cba49c691d69316963d296d16b727 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME=pleroma-v1.1.7-arm64.zip diff --git a/conf/generated_config.exs b/conf/generated_config.exs deleted file mode 100644 index 8781368..0000000 --- a/conf/generated_config.exs +++ /dev/null @@ -1,73 +0,0 @@ -# Pleroma instance configuration - -# NOTE: This file should not be committed to a repo or otherwise made public -# without removing sensitive information. - -use Mix.Config - -config :pleroma, Pleroma.Web.Endpoint, - url: [host: "__DOMAIN__", scheme: "https", port: 443], - secret_key_base: "__KEY__", - http: [ip: {127, 0, 0, 1}, port: __PORT__] - -config :pleroma, :instance, - name: "__INSTANCE_NAME__", - email: "__ADMIN_EMAIL__", - limit: 5000, - registrations_open: __REG__, - dedupe_media: false - -config :pleroma, :media_proxy, - enabled: __MEDIA_CACHE__, - redirect_on_failure: true - #base_url: "https://cache.pleroma.social" - -config :pleroma, Pleroma.Repo, - adapter: Ecto.Adapters.Postgres, - username: "__DB_NAME__", - password: "__DB_PWD__", - database: "__DB_NAME__", - hostname: "localhost", - pool_size: 10 - -# Enable Strict-Transport-Security once SSL is working: -# config :pleroma, :http_security, -# sts: true - -# Configure S3 support if desired. -# The public S3 endpoint is different depending on region and provider, -# consult your S3 provider's documentation for details on what to use. -# -# config :pleroma, Pleroma.Uploaders.S3, -# bucket: "some-bucket", -# public_endpoint: "https://s3.amazonaws.com" -# -# Configure S3 credentials: -# config :ex_aws, :s3, -# access_key_id: "xxxxxxxxxxxxx", -# secret_access_key: "yyyyyyyyyyyy", -# region: "us-east-1", -# scheme: "https://" -# -# For using third-party S3 clones like wasabi, also do: -# config :ex_aws, :s3, -# host: "s3.wasabisys.com" - - -# Configure Openstack Swift support if desired. -# -# Many openstack deployments are different, so config is left very open with -# no assumptions made on which provider you're using. This should allow very -# wide support without needing separate handlers for OVH, Rackspace, etc. -# -# config :pleroma, Pleroma.Uploaders.Swift, -# container: "some-container", -# username: "api-username-yyyy", -# password: "api-key-xxxx", -# tenant_id: "", -# auth_url: "https://keystone-endpoint.provider.com", -# storage_url: "https://swift-endpoint.prodider.com/v1/AUTH_/", -# object_url: "https://cdn-endpoint.provider.com/" -# - - diff --git a/conf/systemd.service b/conf/systemd.service index 104157b..4f0cc2c 100755 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,27 +1,23 @@ [Unit] -Description=__APP__ social network -After=network.target postgresql.service +Description=__APP__ social network +After=network.target postgresql.service nginx.service [Service] -ExecReload=/bin/kill $MAINPID KillMode=process Restart=on-failure ; Name of the user that runs the Pleroma service. User=__APP__ Group=__APP__ -; Declares that Pleroma runs in production mode. -Environment="MIX_ENV=prod" ; Make sure that all paths fit your installation. ; Path to the home directory of the user running the Pleroma service. -Environment="HOME=__FINALPATH__" +Environment="HOME=__FINALPATH__/__APP__" ; Path to the folder containing the Pleroma installation. WorkingDirectory=__FINALPATH__/__APP__ -; Path to the Mix binary. -ExecStart=/usr/bin/mix phx.server -StandardOutput=syslog -StandardError=syslog +; Path to the Pleroma binary. +ExecStart=__FINALPATH__/__APP__/bin/pleroma start +ExecStop=__FINALPATH__/__APP__/bin/pleroma stop ; Some security directives. ; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops. diff --git a/conf/x86-64.src b/conf/x86-64.src new file mode 100644 index 0000000..4cf360d --- /dev/null +++ b/conf/x86-64.src @@ -0,0 +1,6 @@ +SOURCE_URL=https://git.pleroma.social/pleroma/pleroma/-/jobs/84824/artifacts/download +SOURCE_SUM=6cd69e80894af966bb88505dae572e197c96da02ba980357a606bcc948a78e36 +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=true +SOURCE_FILENAME=pleroma-v1.1.7-x86-64.zip diff --git a/manifest.json b/manifest.json index 6b27de1..d247b31 100755 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Pleroma is an OStatus-compatible social networking server written in Elixir, compatible with GNU Social and Mastodon", "fr": "Pleroma est un réseau social écrit en Elixir, compatible avec OStatus, GNU Social et Mastodon" }, - "version": "0.9.99999~ynh1", + "version": "1.1.7~ynh1", "url": "https://git.pleroma.social/pleroma/pleroma", "license": "AGPL-3.0-only", "maintainer": [ @@ -20,7 +20,7 @@ "requirements": { "yunohost": ">= 3.5" }, - "multi_instance": true, + "multi_instance": false, "services": [ "nginx" ], @@ -69,8 +69,8 @@ "en": "Choose a name for your Pleroma instance", "fr": "Choisissez un nom pour votre instance Pleroma" }, - "example": "My Pleroma", - "default": "My Pleroma" + "example": "My_Pleroma", + "default": "My_Pleroma" }, { "name": "registration", diff --git a/scripts/_common.sh b/scripts/_common.sh index 5faffde..31f2804 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,8 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="git build-essential postgresql postgresql-contrib openssl ssh sudo" -extra_pkg_dependencies="elixir erlang-dev erlang-tools erlang-parsetools erlang-eldap erlang-xmerl" +pkg_dependencies="curl unzip libncurses5 postgresql postgresql-contrib" #================================================= # PERSONAL HELPERS diff --git a/scripts/backup b/scripts/backup index 546f825..bdc445c 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,14 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -29,6 +31,7 @@ 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) + cache=$(ynh_app_setting_get --app=$app --key=cache) #================================================= @@ -38,7 +41,7 @@ cache=$(ynh_app_setting_get --app=$app --key=cache) #================================================= ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" #================================================= # BACKUP THE APP MAIN DIR @@ -69,11 +72,11 @@ ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # SPECIFIC BACKUP #================================================= -# BACKUP LOGROTATE +# BACKUP CONFIG FILE #================================================= -ynh_print_info --message="Backing up logrotate configuration..." +ynh_print_info --message="Backing up configuration file..." -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup --src_path="/etc/$app/config.exs" #================================================= # BACKUP SYSTEMD @@ -87,7 +90,10 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started $app" +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + sleep 60 +fi #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index d291b2d..65d9cfb 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -34,6 +34,23 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #db_user=$db_name #db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_print_info --message="Backing up the app before changing its url (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +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" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= @@ -53,11 +70,11 @@ fi #================================================= # STANDARD MODIFICATIONS #================================================= -# STOP SERVICE +# STOP SYSTEMD SERVICE #================================================= ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" #================================================= # MODIFY URL IN NGINX CONF @@ -111,7 +128,10 @@ ynh_store_file_checksum --file="$final_path/$app/config/prod.secret.exs" #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Running Pleroma.Web.Endpoint" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started $app" +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + sleep 60 +fi #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index 783e3bb..e443567 100755 --- a/scripts/install +++ b/scripts/install @@ -7,12 +7,13 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos__3 +source ynh_detect_arch__2 source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -23,6 +24,7 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +ynh_print_info --message="Retrieving arguments from the manifest..." domain=$YNH_APP_ARG_DOMAIN path_url="/" @@ -34,11 +36,11 @@ registration=$YNH_APP_ARG_REGISTRATION cache=$YNH_APP_ARG_CACHE size=$YNH_APP_ARG_SIZE random_key=$(ynh_string_random --length=64) +signing_salt=$(ynh_string_random --length=8) admin_email=$(ynh_user_get_info --username=$admin --key="mail") ## Bypass package_checker name not compatible with pleroma -if [ "$admin" = "package_checker" ] -then +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then admin="test" fi @@ -64,12 +66,13 @@ 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=is_public --value=$is_public -ynh_app_setting_set --app=$app --key=name --value="$name" -ynh_app_setting_set --app=$app --key=registration --value="$registration" -ynh_app_setting_set --app=$app --key=cache --value="$cache" -ynh_app_setting_set --app=$app --key=size --value="$size" -ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email" -ynh_app_setting_set --app=$app --key=random_key --value="$random_key" +ynh_app_setting_set --app=$app --key=name --value=$name +ynh_app_setting_set --app=$app --key=registration --value=$registration +ynh_app_setting_set --app=$app --key=cache --value=$cache +ynh_app_setting_set --app=$app --key=size --value=$size +ynh_app_setting_set --app=$app --key=admin_email --value=$admin_email +ynh_app_setting_set --app=$app --key=random_key --value=$random_key +ynh_app_setting_set --app=$app --key=signing_salt --value=$signing_salt #================================================= # STANDARD MODIFICATIONS @@ -78,7 +81,7 @@ ynh_app_setting_set --app=$app --key=random_key --value="$random_key" #================================================= ynh_print_info --message="Configuring firewall..." -# Find a free port +# Find an available port port=$(ynh_find_port --port=8095) ynh_app_setting_set --app=$app --key=port --value=$port @@ -89,9 +92,6 @@ ynh_print_info --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies -lsb_name="$(lsb_release --codename --short)" -ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' - #================================================= # CREATE A POSTGRESQL DATABASE #================================================= @@ -116,7 +116,8 @@ ynh_print_info --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$final_path/$app" +architecture=$(ynh_detect_arch) +ynh_setup_source --dest_dir="$final_path/$app" --source_id=$architecture #================================================= # NGINX CONFIGURATION @@ -140,66 +141,40 @@ fi #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info --message="Configuring system user ..." +ynh_print_info --message="Configuring system user..." # Create a system user ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SPECIFIC SETUP +#================================================= +# CREATE THE DATA DIRECTORY +#================================================= +ynh_print_info --message="Create the data directory..." + +# Define app's data directory +datadir="/home/yunohost.app/${app}" + +# Create app folders +mkdir -p "$datadir/" +mkdir -p "$datadir/uploads/" +mkdir -p "$datadir/static/" +mkdir -p "$datadir/static/emoji/" + +# Give permission to the datadir +chown -R "$app":"$app" "$datadir" + +ynh_app_setting_set --app=$app --key=datadir --value="$datadir" + #================================================= # MODIFY A CONFIG FILE #================================================= -cp -f ../conf/generated_config.exs "$final_path/$app/config/prod.secret.exs" +mkdir -p /etc/$app +chown -R $app /etc/$app -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__KEY__" --replace_string="$random_key" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__INSTANCE_NAME__" --replace_string="$name" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__ADMIN_EMAIL__" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/$app/config/prod.secret.exs" - -if [ $cache -eq 1 ] -then - ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs" -else - ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs" -fi - -# Set registrations open/closed -if [ $registration -eq 1 ] -then - ynh_replace_string --match_string="__REG__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs" -else - ynh_replace_string --match_string="__REG__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs" -fi - -#================================================= -# MAKE SETUP -#================================================= - -# Give permission to the final_path -chown -R "$app":"$app" "$final_path" - -pushd $final_path/$app - # App setup and db migration - sudo -u "$app" MIX_ENV=prod mix local.hex --force - sudo -u "$app" MIX_ENV=prod mix local.rebar --force - sudo -u "$app" MIX_ENV=prod mix deps.get - sudo -u "$app" MIX_ENV=prod mix ecto.migrate - - # Add user - sudo -u "$app" MIX_ENV=prod mix pleroma.user new "$admin" "$admin_email" --password "$password" --moderator --admin -y - - #Generate key pair - sudo -u "$app" MIX_ENV=prod mix web_push.gen.keypair >> "config/prod.secret.exs" - ynh_replace_string --match_string="administrator@example.com" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs" - - #Create uploads dir - mkdir uploads -popd +config="/etc/$app/config.exs" #================================================= # SETUP SYSTEMD @@ -209,44 +184,68 @@ ynh_print_info --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config +#================================================= +# MAKE SETUP +#================================================= + +# Give permission to the final_path +chown -R "$app":"$app" "$final_path" + +pushd $final_path/$app + #Workaround for static-dir error + ynh_replace_string --match_string="_dir" --replace_string="" --target_file="/var/www/pleroma/pleroma/releases/1.1.7/releases.exs" + + #Generate instance + su "$app" -s $SHELL -lc "$final_path/$app/bin/pleroma_ctl instance gen --force \ + --output $config \ + --output-psql /tmp/setup_db.psql \ + --domain $domain \ + --instance-name \"$name\" \ + --admin-email $admin_email \ + --notify-email $admin_email \ + --dbhost localhost \ + --dbname $db_name \ + --dbuser $db_user \ + --dbpass $db_pwd \ + --rum N \ + --indexable Y \ + --uploads-dir $datadir/uploads \ + --static-dir $datadir/static \ + --listen-ip 127.0.0.1 \ + --listen-port $port" + + su "$app" -s $SHELL -lc "$final_path/$app/bin/pleroma_ctl migrate" + + ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started $app" + sleep 60 + + # Add user + su pleroma -s $SHELL -lc "$final_path/$app/bin/pleroma_ctl user new $admin $admin_email --password $password --moderator --admin -y" +popd + #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/$app/config/prod.secret.exs" +ynh_store_file_checksum --file="$config" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions to app files chown -R "$app":"$app" "$final_path" #================================================= -# SETUP LOGROTATE +# INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_print_info --message="Configuring log rotation..." +ynh_print_info --message="Integrating service in YunoHost..." -# Use logrotate to manage application logfile(s) -ynh_use_logrotate - -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -#yunohost service add $app --log "/var/log/$app/APP.log" -# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -yunohost service add $app --description "$app daemon for Pleroma" --log "/var/log/$app/$app.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_print_info --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Running Pleroma.Web.Endpoint" +yunohost service add $app --description "$app daemon for Pleroma" --log_type "systemd" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index f4fb419..18ffb57 100755 --- a/scripts/remove +++ b/scripts/remove @@ -21,21 +21,29 @@ 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) -cache=$(ynh_app_setting_get --app=$app --key=cache) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= +ynh_print_info --message="Removing service integration in YunoHost..." -# Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status $app >/dev/null 2>&1 +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null then ynh_print_info --message="Removing $app service..." yunohost service remove $app fi +#================================================= +# STOP ALL PLEROMA SERVICES +#================================================= +ynh_print_info --message="Stopping all pleroma services..." + +pkill -u $app + #================================================= # STOP AND REMOVE SERVICE #================================================= @@ -77,18 +85,10 @@ ynh_print_info --message="Removing nginx web server configuration..." ynh_remove_nginx_config ynh_secure_remove --file="/etc/nginx/conf.d/$app-cache.conf" -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_print_info --message="Removing logrotate configuration..." - -# Remove the app-specific logrotate config -ynh_remove_logrotate - #================================================= # CLOSE A PORT #================================================= -ynh_print_info --message="Closing ports" +ynh_print_info --message="Closing a port" if yunohost firewall list | grep -q "\- $port$" then @@ -99,14 +99,14 @@ fi #================================================= # SPECIFIC REMOVE #================================================= -# REMOVE THE CRON FILE +# REMOVE DIRECTORIES #================================================= -# Remove a directory securely +# Remove the config directory securely ynh_secure_remove "/etc/$app/" -# Remove the log files -ynh_secure_remove "/var/log/$app/" +# Remove the data directory securely +ynh_secure_remove "$datadir/" #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index ccf2b86..f7149f3 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,13 +6,14 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh -source ../settings/scripts/ynh_add_extra_apt_repos__3 source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -35,6 +36,7 @@ db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) port=$(ynh_app_setting_get --app=$app --key=port) cache=$(ynh_app_setting_get --app=$app --key=cache) +datadir=$(ynh_app_setting_get --app=$app --key=datadir) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -76,12 +78,36 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE USER RIGHTS #================================================= +ynh_print_info --message="Restoring user rights..." # Restore permissions on app files chown -R "$app":"$app" "$final_path" #================================================= # SPECIFIC RESTORATION +#================================================= +# RECREATE THE DATA DIRECTORY +#================================================= +ynh_print_info --message="Recreate the data directory..." + +# Create app folders +mkdir -p "$datadir/" +mkdir -p "$datadir/uploads/" +mkdir -p "$datadir/static/" +mkdir -p "$datadir/static/emoji/" + +# Give permission to the datadir +chown -R "$app":"$app" "$datadir" + +ynh_app_setting_set --app=$app --key=datadir --value="$datadir" + +#================================================= +# RESTORE THE CONFIG FILE +#================================================= +ynh_print_info --message="Restoring the config file..." + +ynh_restore_file --origin_path="/etc/$app/config.exs" + #================================================= # REINSTALL DEPENDENCIES #================================================= @@ -90,9 +116,6 @@ ynh_print_info --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies -lsb_name="$(lsb_release --codename --short)" -ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' - #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= @@ -115,23 +138,21 @@ ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add $app --description "$app daemon for Pleroma" --log "/var/log/$app/$app.log" +yunohost service add $app --description "$app daemon for Pleroma" --log_type "systemd" #================================================= # START SYSTEMD SERVICE #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Running Pleroma.Web.Endpoint" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started $app" +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + sleep 60 +fi #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 91f5248..1d22f2e 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,7 +7,8 @@ #================================================= source _common.sh -source ynh_add_extra_apt_repos__3 +source ynh_package_version +source ynh_detect_arch__2 source /usr/share/yunohost/helpers #================================================= @@ -27,6 +28,7 @@ admin_email=$(ynh_app_setting_get --app=$app --key=admin_email) random_key=$(ynh_app_setting_get --app=$app --key=random_key) name=$(ynh_app_setting_get --app=$app --key=name) port=$(ynh_app_setting_get --app=$app --key=port) +db_user=$(ynh_app_setting_get --app=$app --key=db_user) db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) cache=$(ynh_app_setting_get --app=$app --key=cache) size=$(ynh_app_setting_get --app=$app --key=size) @@ -89,6 +91,17 @@ fi ynh_secure_remove --file="/etc/apt/sources.list.d/erlang-solutions.list" apt-key del A14F4FCA +#================================================= +# CHECK VERSION NUMBER +#================================================= + +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + sleep 60 +fi +abort_if_up_to_date +# previous function is what defines 'version', more precisely the 'previous version' +previous_version="${version}" + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -97,6 +110,7 @@ ynh_print_info --message="Backing up the app before upgrading (may take a while) # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + read -p "key" # restore it if the upgrade fails ynh_restore_upgradebackup ynh_clean_check_starting @@ -104,13 +118,6 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# CHECK THE PATH -#================================================= - -# Normalize the URL path syntax -path_url=$(ynh_normalize_url_path --path_url=$path_url) - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -118,18 +125,58 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) #================================================= ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" + +#================================================= +# UPGRADE TO OTP RELEASE +#================================================= +ynh_print_info --message="Upgrading to OTP release..." + +if ynh_version_gt "1.1.1~ynh1" "${previous_version}" ; then + # Define app's data directory + datadir="/home/yunohost.app/${app}" + ynh_app_setting_set --app=$app --key=datadir --value="$datadir" + + # Create app folders + mkdir -p "$datadir/" + mkdir -p "$datadir/uploads/" + mkdir -p "$datadir/static/" + mkdir -p "$datadir/static/emoji/" + + # Give permission to the datadir + chown -R "$app":"$app" "$datadir" + + rsync -a "$final_path/$app/uploads/" "$datadir/uploads/" + if [ -d "$final_path/$app/instance/static/" ]; then + rsync -a "$final_path/$app/instance/static/" "$datadir/static/" + fi + + ls -d $final_path/$app/priv/static/emoji/*/ | xargs -i sh -c 'mv "{}" "$datadir/static/emoji/$(basename {})"' + rsync -a "$final_path/$app/priv/static/emoji/" "$datadir/static/emoji/" + + mkdir -p /etc/$app + chown -R $app /etc/$app + config="/etc/$app/config.exs" + mv $final_path/$app/config/prod.secret.exs $config + ynh_replace_string --match_string="use Mix.Config" --replace_string="import Config" --target_file="$config" + + ynh_backup_if_checksum_is_different --file="$config" + + rm -r $final_path/$app/* +fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info --message="Upgrading source files..." if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_print_info --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path/$app" + architecture=$(ynh_detect_arch) + ynh_setup_source --dest_dir="$final_path/$app" --source_id=$architecture fi #================================================= @@ -160,9 +207,6 @@ ynh_print_info --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -lsb_name="$(lsb_release --codename --short)" -ynh_install_extra_app_dependencies --repo="deb http://packages.erlang-solutions.com/debian $lsb_name contrib" --package="$extra_pkg_dependencies" --key='https://packages.erlang-solutions.com/debian/erlang_solutions.asc' - #================================================= # CREATE DEDICATED USER #================================================= @@ -176,62 +220,32 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying a config file..." -ynh_backup_if_checksum_is_different --file="$final_path/$app/config/prod.secret.exs" -cp -f ../conf/generated_config.exs "$final_path/$app/config/prod.secret.exs" +config="/etc/$app/config.exs" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__KEY__" --replace_string="$random_key" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__INSTANCE_NAME__" --replace_string="$name" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__ADMIN_EMAIL__" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/$app/config/prod.secret.exs" - -if [ $cache -eq 1 ] -then - ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs" -else - ynh_replace_string --match_string="__MEDIA_CACHE__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs" -fi - -# Set registrations open/closed -if [ $registration -eq 1 ] -then - ynh_replace_string --match_string="__REG__" --replace_string="true" --target_file="$final_path/$app/config/prod.secret.exs" -else - ynh_replace_string --match_string="__REG__" --replace_string="false" --target_file="$final_path/$app/config/prod.secret.exs" -fi +ynh_backup_if_checksum_is_different --file="$config" #================================================= # MAKE UPGRADE #================================================= +ynh_print_info --message="Making upgrade..." # Give permission to the final_path chown -R "$app":"$app" "$final_path" + pushd $final_path/$app - sudo -u "$app" MIX_ENV=prod mix deps.get - sudo -u "$app" MIX_ENV=prod mix ecto.migrate - - #Generate key pair - sudo -u "$app" MIX_ENV=prod mix web_push.gen.keypair >> "config/prod.secret.exs" - ynh_replace_string --match_string="administrator@example.com" --replace_string="$admin_email" --target_file="$final_path/$app/config/prod.secret.exs" + su "$app" -s $SHELL -lc "$final_path/$app/bin/pleroma_ctl update" + su "$app" -s $SHELL -lc "$final_path/$app/bin/pleroma_ctl migrate" popd #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_print_info --message="Storing the config file checksum..." # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/$app/config/prod.secret.exs" - -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_print_info --message="Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +ynh_store_file_checksum --file="$config" #================================================= # SETUP SYSTEMD @@ -246,6 +260,7 @@ ynh_add_systemd_config #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions on app files chown -R "$app":"$app" "$final_path" @@ -263,12 +278,14 @@ then fi #================================================= -# START SERVICE +# START SYSTEMD SERVICE #================================================= ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Running Pleroma.Web.Endpoint" -sleep 10 +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Started $app" +if [ ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then + sleep 60 +fi #================================================= # RELOAD NGINX diff --git a/scripts/ynh_add_extra_apt_repos__3 b/scripts/ynh_add_extra_apt_repos__3 deleted file mode 100644 index 3276f00..0000000 --- a/scripts/ynh_add_extra_apt_repos__3 +++ /dev/null @@ -1,294 +0,0 @@ -#!/bin/bash - -# Pin a repository. -# -# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] -# | arg: -p, --package - Packages concerned by the pin. Or all, *. -# | arg: -i, --pin - Filter for the pin. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. -# -ynh_pin_repo () { - # Declare an array to define the options of this helper. - local legacy_args=pirna - declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) - local package - local pin - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - package="${package:-*}" - priority=${priority:-50} - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/preferences.d" - echo "Package: $package -Pin: $pin -Pin-Priority: $priority" \ - | $append "/etc/apt/preferences.d/$name" -} - -# Add a repository. -# -# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] -# | arg: -u, --uri - Uri of the repository. -# | arg: -s, --suite - Suite of the repository. -# | arg: -c, --component - Component of the repository. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -# -# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable -# uri suite component -# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable -# -ynh_add_repo () { - # Declare an array to define the options of this helper. - local legacy_args=uscna - declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) - local uri - local suite - local component - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - - if [ $append -eq 1 ] - then - append="tee -a" - else - append="tee" - fi - - mkdir -p "/etc/apt/sources.list.d" - # Add the new repo in sources.list.d - echo "deb $uri $suite $component" \ - | $append "/etc/apt/sources.list.d/$name.list" -} - -# Add an extra repository correctly, pin it and get the key. -# -# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -k, --key - url to get the public key. -# | arg: -p, --priority - Priority for the pin -# | arg: -n, --name - Name for the files for this repo, $app as default value. -# | arg: -a, --append - Do not overwrite existing files. -ynh_install_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=rkpna - declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) - local repo - local key - local priority - local name - local append - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - append=${append:-0} - key=${key:-0} - priority=${priority:-} - - if [ $append -eq 1 ] - then - append="--append" - wget_append="tee -a" - else - append="" - wget_append="tee" - fi - - # Split the repository into uri, suite and components. - # Remove "deb " at the beginning of the repo. - repo="${repo#deb }" - - # Get the uri - local uri="$(echo "$repo" | awk '{ print $1 }')" - - # Get the suite - local suite="$(echo "$repo" | awk '{ print $2 }')" - - # Get the components - local component="${repo##$uri $suite }" - - # Add the repository into sources.list.d - ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append - - # Pin the new repo with the default priority, so it won't be used for upgrades. - # Build $pin from the uri without http and any sub path - local pin="${uri#*://}" - pin="${pin%%/*}" - # Set a priority only if asked - if [ -n "$priority" ] - then - priority="--priority=$priority" - fi - ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append - - # Get the public key for the repo - if [ -n "$key" ] - then - mkdir -p "/etc/apt/trusted.gpg.d" - wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null - fi - - # Update the list of package with the new repo - ynh_package_update -} - -# Remove an extra repository and the assiociated configuration. -# -# usage: ynh_remove_extra_repo [--name=name] -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_remove_extra_repo () { - # Declare an array to define the options of this helper. - local legacy_args=n - declare -Ar args_array=( [n]=name= ) - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - - ynh_secure_remove "/etc/apt/sources.list.d/$name.list" - ynh_secure_remove "/etc/apt/preferences.d/$name" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" - ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" - - # Update the list of package to exclude the old repo - ynh_package_update -} - -# Install packages from an extra repository properly. -# -# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] -# | arg: -r, --repo - Complete url of the extra repository. -# | arg: -p, --package - The packages to install from this extra repository -# | arg: -k, --key - url to get the public key. -# | arg: -n, --name - Name for the files for this repo, $app as default value. -ynh_install_extra_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=rpkn - declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) - local repo - local package - local key - local name - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - name="${name:-$app}" - key=${key:-0} - - # Set a key only if asked - if [ -n "$key" ] - then - key="--key=$key" - fi - # Add an extra repository for those packages - ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name - - # Install requested dependencies from this extra repository. - ynh_add_app_dependencies --package="$package" - - # Remove this extra repository after packages are installed - ynh_remove_extra_repo --name=$app -} - -#================================================= - -# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies - -# Define and install dependencies with a equivs control file -# This helper can/should only be called once per app -# -# usage: ynh_install_app_dependencies dep [dep [...]] -# | arg: dep - the package name to install in dependence -# You can give a choice between some package with this syntax : "dep1|dep2" -# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" -# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) -# -# Requires YunoHost version 2.6.4 or higher. -ynh_install_app_dependencies () { - local dependencies=$@ - dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" - dependencies=${dependencies//|/ | } - local manifest_path="../manifest.json" - if [ ! -e "$manifest_path" ]; then - manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place - fi - - local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. - if [ ${#version} -eq 0 ]; then - version="1.0" - fi - local dep_app=${app//_/-} # Replace all '_' by '-' - - # Handle specific versions - if [[ "$dependencies" =~ [\<=\>] ]] - then - # Replace version specifications by relationships syntax - # https://www.debian.org/doc/debian-policy/ch-relationships.html - # Sed clarification - # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. - # [\<=\>] matches < = or > - # \+ matches one or more occurence of the previous characters, for >= or >>. - # [^,]\+ matches all characters except ',' - # Ex: package>=1.0 will be replaced by package (>= 1.0) - dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" - fi - - cat > /tmp/${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build -Section: misc -Priority: optional -Package: ${dep_app}-ynh-deps -Version: ${version} -Depends: ${dependencies} -Architecture: all -Description: Fake package for $app (YunoHost app) dependencies - This meta-package is only responsible of installing its dependencies. -EOF - ynh_package_install_from_equivs /tmp/${dep_app}-ynh-deps.control \ - || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies - rm /tmp/${dep_app}-ynh-deps.control - ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" -} - -ynh_add_app_dependencies () { - # Declare an array to define the options of this helper. - local legacy_args=pr - declare -Ar args_array=( [p]=package= [r]=replace) - local package - local replace - # Manage arguments with getopts - ynh_handle_getopts_args "$@" - replace=${replace:-0} - - local current_dependencies="" - if [ $replace -eq 0 ] - then - local dep_app=${app//_/-} # Replace all '_' by '-' - if ynh_package_is_installed --package="${dep_app}-ynh-deps" - then - current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " - fi - - current_dependencies=${current_dependencies// | /|} - fi - - ynh_install_app_dependencies "${current_dependencies}${package}" -} diff --git a/scripts/ynh_detect_arch__2 b/scripts/ynh_detect_arch__2 new file mode 100644 index 0000000..b1c7375 --- /dev/null +++ b/scripts/ynh_detect_arch__2 @@ -0,0 +1,25 @@ +#!/bin/bash + +# Check the architecture +# +# example: architecture=$(ynh_detect_arch) +# +# usage: ynh_detect_arch +# +# Requires YunoHost version 2.2.4 or higher. + +ynh_detect_arch(){ + local architecture + if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then + architecture="arm64" + elif [ -n "$(uname -m | grep 64)" ]; then + architecture="x86-64" + elif [ -n "$(uname -m | grep 86)" ]; then + architecture="i386" + elif [ -n "$(uname -m | grep arm)" ]; then + architecture="arm" + else + architecture="unknown" + fi + echo $architecture +} diff --git a/scripts/ynh_package_version b/scripts/ynh_package_version new file mode 100644 index 0000000..d6cdc4d --- /dev/null +++ b/scripts/ynh_package_version @@ -0,0 +1,26 @@ +#!/bin/bash + +read_json () { + sudo python3 -c "import sys, json;print(json.load(open('$1'))['$2'])" +} + +read_manifest () { + if [ -f '../manifest.json' ] ; then + read_json '../manifest.json' "$1" + else + read_json '../settings/manifest.json' "$1" + fi +} +abort_if_up_to_date () { + version=$(read_json "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" 'version' 2> /dev/null || echo '20160501-7') + last_version=$(read_manifest 'version') + if [ "${version}" = "${last_version}" ]; then + ynh_print_info "Up-to-date, nothing to do" + ynh_die "" 0 + fi +} + +ynh_version_gt () +{ + dpkg --compare-versions "$1" gt "$2" +}