From 6ace375a6c50ece1642e6d393dbb99a22caef4b4 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Oct 2020 22:05:10 +0200 Subject: [PATCH 1/9] Add dependency --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index f2efa95..4cb929b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="build-essential inotify-tools postgresql postgresql-client postgresql-contrib git curl gnupg openssl postgis make gcc libc-dev argon2 imagemagick webp gifsicle jpegoptim optipng pngquant cmake" +pkg_dependencies="build-essential inotify-tools postgresql postgresql-client postgresql-contrib git curl unzip gnupg openssl postgis make gcc libc-dev argon2 imagemagick webp gifsicle jpegoptim optipng pngquant cmake" extra_pkg_dependencies="elixir esl-erlang" NODEJS_VERSION=12 From 85deb71343be1a812a969f59ebf0777cd636a67d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Oct 2020 22:10:19 +0200 Subject: [PATCH 2/9] When it's done, don't forget to remove the setup_db.psql file. --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index 4b73a61..a8a1c88 100644 --- a/scripts/install +++ b/scripts/install @@ -155,6 +155,7 @@ pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix deps.get sudo -u "$app" MIX_ENV=prod mix compile sudo -u "$app" MIX_ENV=prod mix mobilizon.instance gen --force --output $config --output-psql /tmp/setup_db.psql --domain $domain --instance-name $name --admin-email $admin_email --dbhost localhost --dbname $db_name --dbuser $db_user --dbpass $db_pwd --listen-port $port + ynh_secure_remove --file="/tmp/setup_db.psql" sudo -u "$app" MIX_ENV=prod mix ecto.migrate sudo -u "$app" MIX_ENV=prod mix mobilizon.users.new "$admin_email" --admin --password "$password" popd From 2d64c17ed7414741ac149870856100b4813c2b6d Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Oct 2020 22:19:45 +0200 Subject: [PATCH 3/9] The nginx configuration has been changed with improvements and support for custom error pages. --- conf/nginx.conf | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index f90d0fb..8a76cee 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -4,28 +4,46 @@ location / { rewrite ^ https://$server_name$request_uri? permanent; } - gzip off; - proxy_http_version 1.1; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + gzip on; + gzip_disable "msie6"; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_buffers 16 8k; + gzip_http_version 1.1; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml; - # For Websocket support + # the nginx default is 1m, not enough for large media uploads + client_max_body_size 16m; + + proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; - - proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://localhost:__PORT__; - client_max_body_size 16m; - location ~* \.(css|js)$ { root __FINALPATH__/mobilizon/priv/static; etag off; - expires 1y; access_log off; - add_header Cache-Control public; + add_header Cache-Control "public, max-age=31536000, immutable"; + } + + location ~ ^/(media|proxy) { + etag off; + access_log off; + add_header Cache-Control "public, max-age=31536000, immutable"; + proxy_pass http://localhost:__PORT__; + } + + error_page 500 501 502 503 504 @error; + location @error { + root __FINALPATH__/mobilizon/priv/errors; + try_files /error.html 502; } # Include SSOWAT user panel. From eaffa4f2e291927ce871379ea0edb31ad1361592 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Oct 2020 22:22:16 +0200 Subject: [PATCH 4/9] Update README.md --- README.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/README.md b/README.md index ff7b1b7..b223be7 100644 --- a/README.md +++ b/README.md @@ -17,22 +17,7 @@ Mobilizon is a tool designed to create platforms for managing communities and ev ## Important points to read before installing -1. **Mobilizon** is in early development, like an Alpha, all functionalities are not available 1. **Mobilizon** require a dedicated **root domain**, eg. mobilizon.domain.tld -1. Even if requested during installation: admin, language and password variables are not used -1. Admin Dashboard is still not implemented -1. When your mobilizon instance is installed, you need to register. -1. When registered, to be admin you have to manually goes in PostgreSQL, database $app, table users, and change the role value to `administrator` instead of `user` (other role available: `moderator`) - -Example to manually put user with id=1 as administrator: -```bash -su -l postgres -psql -\c mobilizon -UPDATE public.users SET role='administrator' where id=1; -\q -exit -``` ## Screenshots From e27075e3c8b016e7159aee118ab7e901262b72ee Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Oct 2020 22:34:29 +0200 Subject: [PATCH 5/9] Apply last example_ynh --- issue_template.md | 33 +++++++++++++++++++++------------ manifest.json | 2 +- scripts/change_url | 8 ++------ scripts/install | 2 +- scripts/remove | 4 ++-- scripts/upgrade | 38 +++++++++++++++++++++++--------------- 6 files changed, 50 insertions(+), 37 deletions(-) diff --git a/issue_template.md b/issue_template.md index e7ad54a..4713927 100644 --- a/issue_template.md +++ b/issue_template.md @@ -1,22 +1,24 @@ --- name: Bug report -about: Create a report to help us debug, it would be nice to fill the template as much as you can to help us, help you and help us all. +about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. --- **How to post a meaningful bug report** 1. *Read this whole template first.* -2. *Determine if you are on the right place:* +2. *Make sure you are on the right place:* - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change url...), you are on the right place!* - - *Otherwise, the issue may be due to Mobilizon itself. Refer to its documentation or repository for help.* - - *If you have a doubt, post here, we will figure it out together.* -3. *Delete the italic comments as you write over them below, and remove this guide.* + - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.* + - *In doubt, ask here and we will figure it out together.* +3. *Delete these italic comments as you write over them below, and remove this guide.* --- -**Describe the bug** +### Describe the bug + *A clear and concise description of what the bug is.* -**Versions** +### Context + - Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* - YunoHost version: x.x.x - I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* @@ -25,8 +27,8 @@ about: Create a report to help us debug, it would be nice to fill the template a - Using, or trying to install package version/branch: - If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* -**To Reproduce** -*Steps to reproduce the behavior.* +### Steps to reproduce + - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh sudo yunohost app install mobilizon @@ -38,9 +40,16 @@ about: Create a report to help us debug, it would be nice to fill the template a 3. *Scroll down to '....'* 4. *See error* -**Expected behavior** +### Expected behavior + *A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* -**Logs** -*After a failed command, YunoHost makes the log available to you, but also to others, thanks to `yunohost log display [log name] --share`. The actual command, with the correct log name, is displayed at the end of the failed attempt in the CLI. Execute it and copy here the share link it outputs.* +### Logs + +*When an operation fails, YunoHost provides a simple way to share the logs.* +- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* +- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* + +*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* + *If applicable and useful, add screenshots to help explain your problem.* diff --git a/manifest.json b/manifest.json index 6bf5035..b5e3189 100644 --- a/manifest.json +++ b/manifest.json @@ -35,7 +35,7 @@ "type": "user", "ask": { "en": "Choose an admin user", - "fr": "Choisissez l’administrateur" + "fr": "Choisissez l'administrateur" }, "example": "johndoe" }, diff --git a/scripts/change_url b/scripts/change_url index ab619ce..8a9902b 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -113,14 +113,10 @@ fi ynh_script_progression --message="Modifying a config file..." config="$final_path/$app/config/prod.secret.exs" +ynh_backup_if_checksum_is_different --file="$config" + ynh_replace_string --match_string="$old_domain" --replace_string="$new_domain" --target_file="$config" -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." - -ynh_backup_if_checksum_is_different --file="$config" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$config" diff --git a/scripts/install b/scripts/install index a8a1c88..74fbefd 100644 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + ynh_clean_check_starting } # Exit if an error occurs during the execution of the script ynh_abort_if_errors diff --git a/scripts/remove b/scripts/remove index 97cc9be..7a6b0af 100644 --- a/scripts/remove +++ b/scripts/remove @@ -31,7 +31,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # 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_script_progression --message="Removing $app service..." + ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi @@ -49,7 +49,7 @@ ynh_remove_systemd_config ynh_script_progression --message="Removing the PostgreSQL database..." # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name" +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE DEPENDENCIES diff --git a/scripts/upgrade b/scripts/upgrade index 491432a..c48cb70 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -171,23 +171,24 @@ ynh_script_progression --message="Making setup..." chown -R "$app":"$app" "$final_path" pushd $final_path/$app/js - ynh_use_nodejs - sudo -u $app env PATH=$PATH yarn install - sudo -u $app env PATH=$PATH yarn run build + ynh_use_nodejs + sudo -u $app env PATH=$PATH yarn install + sudo -u $app env PATH=$PATH yarn run build popd pushd $final_path/$app - 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 compile - sudo -u "$app" MIX_ENV=prod mix ecto.migrate + 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 compile + sudo -u "$app" MIX_ENV=prod mix ecto.migrate popd #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= ynh_script_progression --message="Storing the config file checksum..." + # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$config" @@ -209,6 +210,20 @@ ynh_script_progression --message="Securing files and directories..." # Set permissions on app files chown -R "$app":"$app" "$final_path" +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "$app daemon for Mobilizon" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Mobilizon.Web.Endpoint at" + #================================================= # SETUP SSOWAT #================================================= @@ -221,13 +236,6 @@ then ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Access Mobilizon.Web.Endpoint at" - #================================================= # RELOAD NGINX #================================================= From ea32d93e8e143fe172d45eedebe4830e75ba7eb7 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Wed, 14 Oct 2020 22:52:11 +0200 Subject: [PATCH 6/9] Implement LDAP --- conf/ldap.exs | 11 +++++++++++ scripts/install | 1 + scripts/upgrade | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 conf/ldap.exs diff --git a/conf/ldap.exs b/conf/ldap.exs new file mode 100644 index 0000000..692720e --- /dev/null +++ b/conf/ldap.exs @@ -0,0 +1,11 @@ +config :mobilizon, Mobilizon.Service.Auth.Authenticator, Mobilizon.Service.Auth.LDAPAuthenticator +config :mobilizon, :ldap, + enabled: true, + host: "localhost", + port: 389, + ssl: false, + # sslopts: [], + tls: false, + # tlsopts: [], + base: "ou=users,dc=yunohost,dc=org", + uid: "uid" diff --git a/scripts/install b/scripts/install index 74fbefd..a691d98 100644 --- a/scripts/install +++ b/scripts/install @@ -155,6 +155,7 @@ pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix deps.get sudo -u "$app" MIX_ENV=prod mix compile sudo -u "$app" MIX_ENV=prod mix mobilizon.instance gen --force --output $config --output-psql /tmp/setup_db.psql --domain $domain --instance-name $name --admin-email $admin_email --dbhost localhost --dbname $db_name --dbuser $db_user --dbpass $db_pwd --listen-port $port + cat "../conf/ldap.exs" >> "$config" ynh_secure_remove --file="/tmp/setup_db.psql" sudo -u "$app" MIX_ENV=prod mix ecto.migrate sudo -u "$app" MIX_ENV=prod mix mobilizon.users.new "$admin_email" --admin --password "$password" diff --git a/scripts/upgrade b/scripts/upgrade index c48cb70..a1f7624 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -91,6 +91,23 @@ ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped" +#================================================= +# UPGRADE FROM PREVIOUS VERSION +#================================================= + +if ynh_version_gt "1.0.0-rc1~ynh1" "${previous_version}" ; then + ynh_script_progression --message="Upgrade configuration to 1.0.0-rc1~ynh1..." + + config="$final_path/$app/config/prod.secret.exs" + ynh_backup_if_checksum_is_different --file="$config" + + # Implement ldap + cat "../conf/ldap.exs" >> "$config" + + # Recalculate and store the checksum of the file for the next upgrade. + ynh_store_file_checksum --file="$config" +fi + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= From 300150aa0c497a883c544b4dc23538e5c5ace3f3 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 15 Oct 2020 03:21:30 +0200 Subject: [PATCH 7/9] [emerg] named location "@error" can be on the server level only --- conf/nginx.conf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 8a76cee..cff60cc 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -41,11 +41,12 @@ location / { } error_page 500 501 502 503 504 @error; - location @error { - root __FINALPATH__/mobilizon/priv/errors; - try_files /error.html 502; - } # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } + +location @error { + root __FINALPATH__/mobilizon/priv/errors; + try_files /error.html 502; +} \ No newline at end of file From 95d2414c10788970437a1df00970ea0195df10de Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 15 Oct 2020 18:36:52 +0200 Subject: [PATCH 8/9] Fix cat: ../conf/ldap.exs: No such file or directory --- scripts/install | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index a691d98..d98fd3f 100644 --- a/scripts/install +++ b/scripts/install @@ -155,7 +155,11 @@ pushd $final_path/$app sudo -u "$app" MIX_ENV=prod mix deps.get sudo -u "$app" MIX_ENV=prod mix compile sudo -u "$app" MIX_ENV=prod mix mobilizon.instance gen --force --output $config --output-psql /tmp/setup_db.psql --domain $domain --instance-name $name --admin-email $admin_email --dbhost localhost --dbname $db_name --dbuser $db_user --dbpass $db_pwd --listen-port $port - cat "../conf/ldap.exs" >> "$config" +popd + +cat "../conf/ldap.exs" >> "$config" + +pushd $final_path/$app ynh_secure_remove --file="/tmp/setup_db.psql" sudo -u "$app" MIX_ENV=prod mix ecto.migrate sudo -u "$app" MIX_ENV=prod mix mobilizon.users.new "$admin_email" --admin --password "$password" From 19e4846c5a57dca7497712fb370cf883ac972d01 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Thu, 15 Oct 2020 20:31:49 +0200 Subject: [PATCH 9/9] Missing ynh_package_version --- scripts/upgrade | 1 + scripts/ynh_package_version | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 scripts/ynh_package_version diff --git a/scripts/upgrade b/scripts/upgrade index a1f7624..cbad65f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_package_version source /usr/share/yunohost/helpers #================================================= 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" +}