1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pleroma_ynh.git synced 2024-09-03 20:15:59 +02:00

Added option to open registration and make user moderator

This commit is contained in:
anmol 2018-11-08 20:35:36 +05:30
parent 03cbdcf4f7
commit d1e27f2476
5 changed files with 51 additions and 9 deletions

View file

@ -8,6 +8,7 @@
domain="domain.tld" (DOMAIN) domain="domain.tld" (DOMAIN)
admin="john" (USER) admin="john" (USER)
name="pleroma" name="pleroma"
registration=0 (BOOLEAN)
is_public=1 (PUBLIC|public=1|private=0) is_public=1 (PUBLIC|public=1|private=0)
; Checks ; Checks
pkg_linter=1 pkg_linter=1

View file

@ -1,6 +1,9 @@
location / { location / {
# if you do not want remote frontends to be able to access your Pleroma backend # if you do not want remote frontends to be able to access your Pleroma backend
# server, remove these lines. # server, remove these lines.
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always; add_header 'Access-Control-Allow-Methods' 'POST, PUT, DELETE, GET, PATCH, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always; add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, Idempotency-Key' always;

View file

@ -10,7 +10,7 @@ config :pleroma, :instance,
name: "__INSTANCE_NAME__", name: "__INSTANCE_NAME__",
email: "__ADMIN_EMAIL__", email: "__ADMIN_EMAIL__",
limit: 5000, limit: 5000,
registrations_open: true, registrations_open: __REG__,
dedupe_media: false dedupe_media: false
config :pleroma, :media_proxy, config :pleroma, :media_proxy,

View file

@ -44,6 +44,14 @@
} }
}, },
{ {
"name": "registration",
"type": "boolean",
"ask": {
"en": "Is registrations are open to everyone?"
},
"default": false
},
{
"name": "is_public", "name": "is_public",
"type": "boolean", "type": "boolean",
"ask": { "ask": {

View file

@ -25,9 +25,11 @@ domain=$YNH_APP_ARG_DOMAIN
path_url="/" path_url="/"
admin=$YNH_APP_ARG_ADMIN admin=$YNH_APP_ARG_ADMIN
admin_email=$(ynh_user_get_info $admin 'mail') admin_email=$(ynh_user_get_info $admin 'mail')
admin_pass=$(ynh_string_random 24)
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
random_key=$(ynh_random 64) random_key=$(ynh_random 64)
name=$YNH_APP_ARG_NAME name=$YNH_APP_ARG_NAME
registration=$YNH_APP_ARG_REGISTRATION
# This is a multi-instance app, meaning it can be installed several times independently # This is a multi-instance app, meaning it can be installed several times independently
@ -58,13 +60,13 @@ ynh_webpath_register "$app" "$domain" "$path_url"
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" admin_email "$admin_email" ynh_app_setting_set "$app" admin_email "$admin_email"
ynh_app_setting_set "$app" is_public "$is_public" ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" random_key "$random_key" ynh_app_setting_set "$app" random_key "$random_key"
ynh_app_setting_set "$app" admin "$admin" ynh_app_setting_set "$app" admin "$admin"
ynh_app_setting_set "$app" name "$name" ynh_app_setting_set "$app" name "$name"
ynh_app_setting_set "$app" registration "$registration"
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
@ -154,15 +156,29 @@ ynh_replace_string "__PORT__" "$port" "$final_path/$app/config
ynh_replace_string "__DB_NAME__" "$app" "$final_path/$app/config/setup_db.psql" 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" ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/$app/config/setup_db.psql"
# Set registrations open/closed
if [ $registration -eq 1 ]
then
ynh_replace_string "__REG__" "true" "$final_path/$app/config/prod.secret.exs"
else
ynh_replace_string "__REG__" "false" "$final_path/$app/config/prod.secret.exs"
fi
#================================================= #=================================================
# SETUP # SETUP
#================================================= #=================================================
# Give permisiion to the final_path # Give permisiion to the final_path
chown -R "$app":"$app" "$final_path" chown -R "$app":"$app" "$final_path"
# App setup and db migration
( 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.hex --force )
( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix local.rebar --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 ) ( cd $final_path/$app && sudo -u "$app" mix deps.get )
( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix ecto.migrate --force ) ( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix ecto.migrate --force )
# Add user
( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix register_user "$admin" "$admin" "$admin_email" "Moderator of this instance" "$admin_pass" )
# Make user moderator
( cd $final_path/$app && sudo -u "$app" MIX_ENV=prod mix set_moderator "$admin" true )
#================================================= #=================================================
# SETUP SSOWAT # SETUP SSOWAT
@ -186,10 +202,24 @@ chown -R "$app":"$app" "$final_path"
ynh_add_systemd_config ynh_add_systemd_config
systemctl enable "$app" systemctl enable "$app"
systemctl start "$app" systemctl start "$app"
sleep 30
#================================================= #=================================================
# RELOAD NGINX # RELOAD NGINX
#================================================= #=================================================
systemctl 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 moderator username is: $admin
The moderator 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/YunoHost-Apps/pleroma_ynh/
If you are not afraid of the terminal, check out https://git.pleroma.social/pleroma/pleroma/wikis/home to see what more you can do with your awesome instance!"
ynh_send_readme_to_admin "$message" "$admin"