From 48e709a72b0b4bc568a92c30e5b212189127334a Mon Sep 17 00:00:00 2001 From: Yalh Date: Fri, 25 Jan 2019 13:07:37 +0100 Subject: [PATCH] Remove previous fixs --- README.md | 6 ++-- conf/{prod.exs => prod.secret.exs} | 0 conf/systemd.service | 2 +- scripts/install | 40 ++++++++++----------- scripts/upgrade | 57 ++++++++++++++---------------- 5 files changed, 50 insertions(+), 55 deletions(-) rename conf/{prod.exs => prod.secret.exs} (100%) diff --git a/README.md b/README.md index 87a3480..dcc8303 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,13 @@ Go to **cd /var/www/pleroma/pleroma**. **Run:** - $ sudo -u pleroma MIX_ENV=pleroma mix pleroma.user new + $ sudo -u pleroma MIX_ENV=prod mix pleroma.user new ### Password reset **Run:** - $ MIX_ENV=pleroma mix pleroma.user reset_password + $ MIX_ENV=prod mix pleroma.user reset_password This will generate a **password reset link** that you can then send to the user. @@ -72,7 +72,7 @@ You can make users **moderators**. They will then be able to **delete any post** **Run:** - $ MIX_ENV=pleroma mix pleroma.user set --[no-]admin + $ MIX_ENV=prod mix pleroma.user set --[no-]admin **--admin** option will **make the user moderator** and **--no-admin** will **take away the moderator privileges** from the user. diff --git a/conf/prod.exs b/conf/prod.secret.exs similarity index 100% rename from conf/prod.exs rename to conf/prod.secret.exs diff --git a/conf/systemd.service b/conf/systemd.service index 52c9fc9..03754c5 100755 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -3,7 +3,7 @@ Description=__APP__ social network After=network.target postgresql.service [Service] -Environment="MIX_ENV=__INSTANCE_NAME__" +Environment="MIX_ENV=prod" User=__APP__ WorkingDirectory=__FINALPATH__/__APP__ Environment="HOME=__FINALPATH__" diff --git a/scripts/install b/scripts/install index 1dcc726..c444628 100755 --- a/scripts/install +++ b/scripts/install @@ -215,31 +215,31 @@ ynh_system_user_create "$app" "$final_path" #================================================= # MODIFY A CONFIG FILE #================================================= -cp -f ../conf/prod.exs "$final_path/$app/config/$app.exs" +cp -f ../conf/prod.secret.exs "$final_path/$app/config/prod.secret.exs" cp -f ../conf/setup_db.psql "$final_path/$app/config/setup_db.psql" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/config/$app.exs" -ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/config/$app.exs" -ynh_replace_string "__INSTANCE_NAME__" "$name" "$final_path/$app/config/$app.exs" -ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/$app.exs" -ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/$app.exs" -ynh_replace_string "__ADMIN_EMAIL__" "$admin_email" "$final_path/$app/config/$app.exs" -ynh_replace_string "__PORT__" "$port" "$final_path/$app/config/$app.exs" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__INSTANCE_NAME__" "$name" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__ADMIN_EMAIL__" "$admin_email" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__PORT__" "$port" "$final_path/$app/config/prod.secret.exs" ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/setup_db.psql" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/setup_db.psql" if [ $cache -eq 1 ] then - ynh_replace_string "__MEDIA_CACHE__" "true" "$final_path/$app/config/$app.exs" + ynh_replace_string "__MEDIA_CACHE__" "true" "$final_path/$app/config/prod.secret.exs" else - ynh_replace_string "__MEDIA_CACHE__" "false" "$final_path/$app/config/$app.exs" + ynh_replace_string "__MEDIA_CACHE__" "false" "$final_path/$app/config/prod.secret.exs" fi # Set registrations open/closed if [ $registration -eq 1 ] then - ynh_replace_string "__REG__" "true" "$final_path/$app/config/$app.exs" + ynh_replace_string "__REG__" "true" "$final_path/$app/config/prod.secret.exs" else - ynh_replace_string "__REG__" "false" "$final_path/$app/config/$app.exs" + ynh_replace_string "__REG__" "false" "$final_path/$app/config/prod.secret.exs" fi @@ -249,26 +249,26 @@ fi # Give permisiion to the final_path chown -R "$app":"$app" "$final_path" # App setup and db migration -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix local.hex --force ) -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix local.rebar --force ) +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.hex --force ) +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.rebar --force ) ( cd $final_path/$app && sudo -u "$app" mix deps.get ) ynh_psql_execute_as_root \ "ALTER USER $app WITH SUPERUSER;" -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix ecto.migrate --force ) +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix ecto.migrate --force ) ynh_psql_execute_as_root \ "ALTER USER $app WITH NOSUPERUSER;" # Add user and retrieve a password reset link that you can then send to the user -admin_pass_reset_url=$( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix pleroma.user new "$admin" "$admin_email" | tail -1 ) +admin_pass_reset_url=$( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix pleroma.user new "$admin" "$admin_email" | tail -1 ) # Make user moderator -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix pleroma.user set "$admin" --moderator ) +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix pleroma.user set "$admin" --moderator ) # Make user admin -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix pleroma.user set "$admin" --admin ) +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix pleroma.user set "$admin" --admin ) #================================================= # SETUP SYSTEMD @@ -324,7 +324,7 @@ ynh_add_systemd_config ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) -#ynh_replace_string "match_string" "replace_string" "$final_path/$app/config/$app.exs" +#ynh_replace_string "match_string" "replace_string" "$final_path/$app/config/prod.secret.exs" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -335,7 +335,7 @@ ynh_add_systemd_config ### you can make a backup of this file before modifying it again if the admin had modified it. # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/$app/config/$app.exs" +ynh_store_file_checksum "$final_path/$app/config/prod.secret.exs" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 49c8c4d..5a69976 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -161,60 +161,55 @@ CREATE EXTENSION IF NOT EXISTS unaccent;CREATE EXTENSION IF NOT EXISTS citext;" yunohost firewall allow Both "$port" 2>&1 +# Give permission to the final_path +chown -R "$app":"$app" "$final_path" +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.hex --force ) +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.rebar --force ) +( cd $final_path/$app && sudo -u "$app" mix deps.get ) +ynh_psql_execute_as_root \ +"ALTER USER $app WITH SUPERUSER;" +( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix ecto.migrate --force ) +ynh_psql_execute_as_root \ +"ALTER USER $app WITH NOSUPERUSER;" + #================================================= # MODIFY A CONFIG FILE #================================================= -cp -f ../conf/prod.exs "$final_path/$app/config/$app.exs" +cp -f ../conf/prod.secret.exs "$final_path/$app/config/prod.secret.exs" cp -f ../conf/setup_db.psql "$final_path/$app/config/setup_db.psql" -ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/config/$app.exs" -ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/config/$app.exs" -ynh_replace_string "__INSTANCE_NAME__" "$name" "$final_path/$app/config/$app.exs" -ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/$app.exs" -ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/$app.exs" -ynh_replace_string "__ADMIN_EMAIL__" "$admin_email" "$final_path/$app/config/$app.exs" -ynh_replace_string "__PORT__" "$port" "$final_path/$app/config/$app.exs" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__KEY__" "$random_key" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__INSTANCE_NAME__" "$name" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__ADMIN_EMAIL__" "$admin_email" "$final_path/$app/config/prod.secret.exs" +ynh_replace_string "__PORT__" "$port" "$final_path/$app/config/prod.secret.exs" ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/setup_db.psql" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/setup_db.psql" if [ $cache -eq 1 ] then - ynh_replace_string "__MEDIA_CACHE__" "true" "$final_path/$app/config/$app.exs" + ynh_replace_string "__MEDIA_CACHE__" "true" "$final_path/$app/config/prod.secret.exs" else - ynh_replace_string "__MEDIA_CACHE__" "false" "$final_path/$app/config/$app.exs" + ynh_replace_string "__MEDIA_CACHE__" "false" "$final_path/$app/config/prod.secret.exs" fi # Set registrations open/closed if [ $registration -eq 1 ] then - ynh_replace_string "__REG__" "true" "$final_path/$app/config/$app.exs" + ynh_replace_string "__REG__" "true" "$final_path/$app/config/prod.secret.exs" else - ynh_replace_string "__REG__" "false" "$final_path/$app/config/$app.exs" + ynh_replace_string "__REG__" "false" "$final_path/$app/config/prod.secret.exs" fi # Recalculate and store the config file checksum into the app settings -ynh_store_file_checksum "$final_path/$app/config/$app.exs" +ynh_store_file_checksum "$final_path/$app/config/prod.secret.exs" ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different "$final_path/$app/config/$app.exs" +ynh_backup_if_checksum_is_different "$final_path/$app/config/prod.secret.exs" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum "$final_path/$app/config/$app.exs" - -#================================================= -# MAKE THE UPGRADE -#================================================= - -# Give permission to the final_path -chown -R "$app":"$app" "$final_path" -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix local.hex --force ) -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix local.rebar --force ) -( cd $final_path/$app && sudo -u "$app" mix deps.get ) -ynh_psql_execute_as_root \ -"ALTER USER $app WITH SUPERUSER;" -( cd $final_path/$app && sudo -u "$app" MIX_ENV=$app mix ecto.migrate --force ) -ynh_psql_execute_as_root \ -"ALTER USER $app WITH NOSUPERUSER;" - +ynh_store_file_checksum "$final_path/$app/config/prod.secret.exs" #================================================= # SETUP LOGROTATE