diff --git a/README.md b/README.md old mode 100644 new mode 100755 index c6f3e67..a99365b --- a/README.md +++ b/README.md @@ -1,20 +1,4 @@ -# Plume for Yunohost -Federated blogging application. - -Shipped version: **0.2.0(Alpa 1)** - -## Interesting links - -- [YunoHost project](https://yunohost.org) -- [Plume Github page](https://github.com/Plume-org/Plume) -- [Demo instance of Plume](https://baptiste.gelez.xyz/) - -## Instruction - -1. The app require dedicated domain like plume.domain.tld -1. Updated is not yet implimented yet. -1. You have to run cargo run and answer the qestions. - **$ cd /var/www/plume && cargo run** -1. The app will need to run inside **Screen** or **tmux** till the systemd gets implimented. - +# plume_ynh +Federated blogging application https://github.com/Plume-org/Plume +Now working diff --git a/check_process b/check_process old mode 100644 new mode 100755 index 3610500..c908479 --- a/check_process +++ b/check_process @@ -6,6 +6,9 @@ ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) + admin="john" (USER) + name="my blog" + registration=0 (BOOLEAN) is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 diff --git a/conf/.env b/conf/.env old mode 100644 new mode 100755 index 40770df..7941a55 --- a/conf/.env +++ b/conf/.env @@ -1,6 +1,19 @@ +# The address of the database +# (replace USER, PASSWORD, PORT and DATABASE_NAME with your values) +# +# If you are using SQlite, use the path of the database file (`plume.db` for instance) +DATABASE_URL=postgres://__DB_USER__:__PSQLPWD__@localhost:5432/__DBNAME__ -DB_URL=postgres://__DB_USER__:__PSQLPWD__@localhost:5432/__DBNAME__ +# For PostgreSQL: migrations/postgres +# For SQlite: migrations/sqlite +MIGRATION_DIRECTORY=migrations/postgres + +# The domain on which your instance will be available BASE_URL=__DOMAIN__ ROCKET_PORT=__PORT__ ROCKET_ADDRESS=127.0.0.1 + +# Secret key used for private cookies and CSRF protection +# You can generate one with `openssl rand -base64 32` +ROCKET_SECRET_KEY= __KEY__ diff --git a/conf/app.src b/conf/app.src old mode 100644 new mode 100755 diff --git a/conf/first_run.exp b/conf/first_run.exp old mode 100644 new mode 100755 diff --git a/conf/instance.txt b/conf/instance.txt old mode 100644 new mode 100755 diff --git a/conf/nginx.conf b/conf/nginx.conf old mode 100644 new mode 100755 diff --git a/conf/pass.txt b/conf/pass.txt old mode 100644 new mode 100755 diff --git a/conf/systemd.service b/conf/systemd.service old mode 100644 new mode 100755 index d760560..8f61b04 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,12 +1,12 @@ [Unit] -Description=__APP__ service +Description=plume After=network.target [Service] Type=simple -User=__APP__ -WorkingDirectory=__FINALPATH__/ -ExecStart=/bin/sh -c 'cargo run' >> /var/log/__APP__/__APP__.log 2>&1 +User=plume +WorkingDirectory=/home/plume/Plume +ExecStart=__FINALPATH__/.cargo/bin/plume TimeoutSec=30 Restart=always diff --git a/manifest.json b/manifest.json old mode 100644 new mode 100755 index 1d863cf..9975027 --- a/manifest.json +++ b/manifest.json @@ -1,13 +1,13 @@ { - "name": "plume bloggin app for yunohost", + "name": "plume", "id": "plume", "packaging_format": 1, "description": { - "en": "Package for Plume application." + "en": "Federated blogging application" }, "version": "0.2.0", "url": "https://baptiste.gelez.xyz/", - "license": "free", + "license": "AGPL-3.0-only", "maintainer": { "name": "Anmol Sharma", "email": "anmol@datamol.org" @@ -15,7 +15,7 @@ "requirements": { "yunohost": ">= 2.7.14" }, - "multi_instance": false, + "multi_instance": true, "services": [ "nginx", "rust" @@ -30,6 +30,29 @@ }, "example": "example.com" }, + { + "name": "admin", + "type": "user", + "ask": { + "en": "Choose the Plume administrator (must be an existing YunoHost user)", + "fr": "Choisissez l'administrateur de Plume (doit être un utilisateur YunoHost existant)" + } + }, + { + "name": "name", + "ask": { + "en": "Choose a name for your Plume instance" + } + "example": "My blog" + }, + { + "name": "registration", + "type": "boolean", + "ask": { + "en": "Is registrations open to everyone?" + }, + "default": false + } { "name": "is_public", "type": "boolean", diff --git a/scripts/_common.sh b/scripts/_common.sh old mode 100644 new mode 100755 index bb04a03..9fd3604 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,4 +10,62 @@ ynh_delete_file_checksum () { local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' ynh_app_setting_delete $app $checksum_setting_name -} \ No newline at end of file +} + + +# Send an email to inform the administrator +# +# usage: ynh_send_readme_to_admin app_message [recipients] +# | arg: app_message - The message to send to the administrator. +# | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root +# example: "root admin@domain" +# If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you +# example: "root admin@domain user1 user2" +ynh_send_readme_to_admin() { + local app_message="${1:-...No specific information...}" + local recipients="${2:-root}" + + # Retrieve the email of users + find_mails () { + local list_mails="$1" + local mail + local recipients=" " + # Read each mail in argument + for mail in $list_mails + do + # Keep root or a real email address as it is + if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@" + then + recipients="$recipients $mail" + else + # But replace an user name without a domain after by its email + if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null) + then + recipients="$recipients $mail" + fi + fi + done + echo "$recipients" + } + recipients=$(find_mails "$recipients") + + local mail_subject="☁️🆈🅽🅷☁️: \`$app\` has important message for you" + + local mail_message="This is an automated message from your beloved YunoHost server. +Specific information for the application $app. +$app_message +--- +Automatic diagnosis data from YunoHost +$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')" + + # Define binary to use for mail command + if [ -e /usr/bin/bsd-mailx ] + then + local mail_bin=/usr/bin/bsd-mailx + else + local mail_bin=/usr/bin/mail.mailutils + fi + + # Send the email to the recipients + echo "$mail_message" | $mail_bin -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients" +} diff --git a/scripts/backup b/scripts/backup index 8cb4472..40babe0 100755 --- a/scripts/backup +++ b/scripts/backup @@ -31,6 +31,8 @@ final_path=$(ynh_app_setting_get $app final_path) domain=$(ynh_app_setting_get $app domain) db_name=$(ynh_app_setting_get "$app" psql_db) +# Stop Pleroma for backup +systemctl stop "$app" #================================================= # STANDARD BACKUP STEPS @@ -67,3 +69,13 @@ ynh_backup "/etc/logrotate.d/$app" ynh_backup "/etc/systemd/system/$app.service" +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx +systemctl enable "$app" +systemctl start "$app" +# App needs time to start +sleep 10 + diff --git a/scripts/install b/scripts/install index 577d54e..7e3a427 100755 --- a/scripts/install +++ b/scripts/install @@ -26,7 +26,13 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" +instance_name=$YNH_APP_ARG_NAME +admin=$YNH_APP_ARG_ADMIN +admin_email=$(ynh_user_get_info $admin 'mail') +admin_pass=$(ynh_string_random 24) +registration=$YNH_APP_ARG_REGISTRATION is_public=$YNH_APP_ARG_IS_PUBLIC +random_key=$(openssl rand -base64 32) ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -64,6 +70,11 @@ ynh_webpath_register $app $domain $path_url ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url ynh_app_setting_set $app is_public $is_public +ynh_app_setting_set $app admin $admin +ynh_app_setting_set $app instance $instance +ynh_app_setting_set $app admin_email $admin_email +ynh_app_setting_set $app registration $registraion +ynh_app_setting_set $app random_key $random_key #================================================= # STANDARD MODIFICATIONS @@ -119,11 +130,24 @@ ynh_psql_execute_as_root \ ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source "$final_path" +git clone https://github.com/Plume-org/Plume.git "$final_path/$app" # Create the media directory, where uploads will be stored (cd $final_path && mkdir media ) +# setup application config +sudo cp ../conf/.env $final_path/$app/.env +#================================================= +# MODIFY A CONFIG FILE +#================================================= +ynh_replace_string "__DBNAME__" "$db_name" "$final_path/$app/.env" +ynh_replace_string "__PSQLPWD__" "$db_pwd" "$final_path/$app/.env" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/.env" +ynh_replace_string "__PORT__" "$port" "$final_path/$app/.env" +ynh_replace_string "__DB_USER__" "$app" "$final_path/$app/.env" +ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/.env" + + #================================================= # CREATE DEDICATED USER #================================================= @@ -131,11 +155,29 @@ ynh_setup_source "$final_path" # Create a system user ynh_system_user_create $app $final_path -( cd $final_path && curl -sf -L https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly --date=2018-07-17 ) -export PATH="$PATH:/root/.cargo/bin:$final_path/.local/bin:/usr/local/sbin" -( cd $final_path && cargo build ) -( cd $final_path && cargo install diesel_cli --no-default-features --features postgres --version '=1.2.0' ) -( cd $final_path && diesel migration run --database-url postgres://$db_name:$db_pwd@localhost:5432/$app ) +# Set right permissions +chown -R $app: $final_path + + +# App settings +( cd $final_path && sudo -u "$app" curl -sf -L https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly --date=2018-07-17 ) +( cd $final_path && sudo -u "$app" export PATH="$PATH:/var/www/$app/.cargo/bin:/var/$app/.local/bin:/usr/local/sbin" ) +( cd $final_path/$app && sudo -u "$app" export FEATURES=postgres ) +( cd $final_path/$app && sudo -u "$app" cargo install diesel_cli --no-default-features --features postgres --version '=1.3.0' ) +( cd $final_path/$app && sudo -u "$app" diesel migration run ) +( cd $final_path/$app && sudo -u "$app" cargo install --no-default-features --features postgres ) +( cd $final_path/$app && sudo -u "$app" cargo install --no-default-features --features postgres --path plume-cli ) + +# Add new instance +if [ $registration -eq 1 ] +then + ( cd $final_path/$app && sudo -u "$app" plm instance new --domain "$domain" --name '$instance_name' -l 'CC-BY' ) +else + ( cd $final_path/$app && sudo -u "$app" plm instance new --private --domain "$domain" --name '$instance_name' -l 'CC-BY' ) +fi + +# Add admin user +( cd $final_path/$app && sudo -u "$app" plm users new --admin -n "$admin" -N "$admin" --email '$admin_email' --password "$admin_pass" ) #================================================= # NGINX CONFIGURATION @@ -146,39 +188,9 @@ export PATH="$PATH:/root/.cargo/bin:$final_path/.local/bin:/usr/local/sbin" # Create a dedicated nginx config ynh_add_nginx_config -# setup application config -sudo cp ../conf/.env $final_path/.env -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_replace_string "__DBNAME__" "$db_name" "$final_path/.env" -ynh_replace_string "__PSQLPWD__" "$db_pwd" "$final_path/.env" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/.env" -ynh_replace_string "__PORT__" "$port" "$final_path/.env" -ynh_replace_string "__DB_USER__" "$app" "$final_path/.env" - # Set right permissions chown -R $app: $final_path -#================================================= -# SETUP SYSTEMD -#================================================= - -### `ynh_systemd_config` is used to configure a systemd script for an app. -### It can be used for apps that use sysvinit (with adaptation) or systemd. -### Have a look at the app to be sure this app needs a systemd script. -### `ynh_systemd_config` will use the file conf/systemd.service -### If you're not using these lines: -### - You can remove those files in conf/. -### - Remove the section "BACKUP SYSTEMD" in the backup script -### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script -### - As well as the section "RESTORE SYSTEMD" in the restore script -### - And the section "SETUP SYSTEMD" in the upgrade script - -# Create a dedicated systemd config -# ynh_add_systemd_config - - #================================================= # SETUP LOGROTATE #================================================= @@ -206,8 +218,26 @@ then ynh_app_setting_set $app unprotected_uris "/" fi +# Create a dedicated systemd config +ynh_add_systemd_config +systemctl enable "$app" +systemctl start "$app" +sleep 30 #================================================= # RELOAD NGINX #================================================= systemctl reload nginx + +#================================================= +# SEND A README FOR THE ADMIN +#================================================= + +message=" $app was successfully installed :) +Please open your $app domain: https://$domain$path_url + +The admin username is: $admin +The admin password is: $admin_pass + +If you are facing any problem or want to improve this app, please open a new issue here: https://github.com/Plume-org/Plume" +ynh_send_readme_to_admin "$message" "$admin" diff --git a/scripts/psql.sh b/scripts/psql.sh old mode 100644 new mode 100755 diff --git a/scripts/remove b/scripts/remove index f40c85f..9e1157d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -49,7 +49,7 @@ fi # Remove metapackage and its dependencies ynh_remove_app_dependencies -( cd $final_path && cargo uninstall diesel_cli ) +( cd $final_path/$app && sudo -u "$app" cargo uninstall diesel_cli ) sudo /usr/local/lib/rustlib/uninstall.sh diff --git a/scripts/restore b/scripts/restore index 258f44c..9e8d363 100755 --- a/scripts/restore +++ b/scripts/restore @@ -70,7 +70,6 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_restore_file "$final_path" -( cd $final_path && curl -sf -L https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly --date=2018-05-31 ) # open port yunohost firewall allow --no-upnp TCP $port 2>&1 @@ -90,14 +89,14 @@ ynh_psql_execute_file_as_root ./db.sql "$db_name" #================================================= # Create the dedicated user (if not existing) -ynh_system_user_create $app +ynh_system_user_create $app "$final_path" #================================================= # RESTORE USER RIGHTS #================================================= # Restore permissions on app files -chown -R $app: $final_path +chown -R $app: $final_path #================================================= # RESTORE SYSTEMD @@ -115,7 +114,11 @@ ynh_restore_file "/etc/logrotate.d/$app" #================================================= # GENERIC FINALIZATION #================================================= -# RELOAD NGINX +# RELOAD NGINX AND START PLEROMA #================================================= systemctl reload nginx +systemctl enable "$app" +systemctl start "$app" +# App needs time to start +sleep 10 diff --git a/scripts/upgrade b/scripts/upgrade index 9b36e65..af7031d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,11 @@ path_url=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path) db_name=$(ynh_app_setting_get "$app" psql_db) +admin=$(ynh_app_setting_get "$app" admin) +admin_email=$(ynh_app_setting_get "$app" admin_email) +random_key=$(ynh_app_setting_get "$app" random_key) +name=$(ynh_app_setting_get "$app" name) +port=$(ynh_app_setting_get "$app" port) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -37,6 +42,22 @@ fi +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +# Stop Pleroma for upgrade +systemctl stop "$app" + #================================================= @@ -46,8 +67,53 @@ fi # Normalize the URL path syntax path_url=$(ynh_normalize_url_path $path_url) +# Open this port +yunohost firewall allow --no-upnp TCP $port 2>&1 + +#================================================= +# CREATE DEDICATED USER +#================================================= + +# Create a system user +ynh_system_user_create "$app" "$final_path" +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. +### Those deb packages will be installed as dependencies of this package. +### If you're not using this helper: +### - Remove the section "REMOVE DEPENDENCIES" in the remove script +### - As well as the section "REINSTALL DEPENDENCIES" in the restore script +### - And the section "UPGRADE DEPENDENCIES" in the upgrade script + +ynh_install_app_dependencies gettext postgresql postgresql-contrib libpq-dev git curl gcc make openssl libssl-dev pkg-config + +#================================================= +# DOWNLOAD, CHECK AND UNPACK PLEROMA SOURCE +#================================================= + +( cd $final_path/$app && git pull ) +# Give permisiion to the final_path +chown -R "$app":"$app" "$final_path" +( cd $final_path/$app && sudo -u "$app" cargo install --force ) +( cd $final_path/$app && sudo -u "$app" cargo install --path plume-cli --force ) +( cd $final_path/$app && sudo -u "$app" diesel migration run ) + + +# Recalculate and store the config file checksum into the app settings +ynh_store_file_checksum "$final_path/$app/.env" + +#================================================= +# SETUP SYSTEMD +#================================================= +# Create a dedicated systemd config +ynh_add_systemd_config + +# Set right permissions +chown -R "$app":"$app" "$final_path" #================================================= # SETUP SSOWAT @@ -65,3 +131,7 @@ fi #================================================= systemctl reload nginx +systemctl enable "$app" +systemctl restart "$app" +# App needs time to start +sleep 10