Commit 7a61c667 authored by Spctrl's avatar Spctrl

Finishing installation script. Adding extra info to be printed out + making...

Finishing installation script. Adding extra info to be printed out + making sure the pasword isn't shown when creating the Pleroma moderator user
parent e6bbd574
......@@ -13,7 +13,7 @@ ynh_delete_file_checksum () {
}
# ============= CUSTOM HELPERS =============
# Improvement on default helper who in some cases returned empty string
# Improvement on default helper who in some cases returns empty string
#
# Generate a random string
#
......
#!/bin/bash
# yunohost app install --debug ./pleroma_ynh/ --args "domain=plrm.spectral.pirate&instance_name=pirate&is_public=yes&allow_scopes=yes&instance_user=spctrl&instance_user_password=neutrinet&instance_user_password_verify=neutrinet&instance_user_mail=me@pl.ma"
#=================================================
# GENERIC START
#=================================================
......@@ -72,6 +72,8 @@ ynh_app_setting_set $app db_name $db_name
# INSTALL DEPENDENCIES
#=================================================
ynh_print_info "Installing dependencies"
# In case https capability for apt insn't installed yet
apt-get install --yes apt-transport-https
......@@ -98,14 +100,15 @@ useradd $app --home-dir=$final_path
# DOWNLOAD AND UNPACK SOURCE
#=================================================
ynh_print_info "Downloading source"
git clone https://git.pleroma.social/pleroma/pleroma $final_path/pleroma
ynh_print_info "Building the Pleroma instance"
# replace the generate_config file with a modified one to have it non-interactive
# TODO: there's a merge comming in Pleroma that makes it all non-interactive
# https://git.pleroma.social/pleroma/pleroma/merge_requests/243
# this will simplify this whole block
# TODO: There is also a helper that can create a secret and pasword
# this can simplify this whole block as well
cp ../conf/generate_config.ex $final_path/pleroma/lib/mix/tasks/generate_config.ex
chown -R $app: $final_path
......@@ -113,7 +116,6 @@ ynh_replace_string "{DOMAIN}" "$domain" "$final_path/pleroma/lib/mix/tasks/gener
ynh_replace_string "{SERVER_NAME}" "$server_name" "$final_path/pleroma/lib/mix/tasks/generate_config.ex"
ynh_replace_string "{EMAIL}" "$email" "$final_path/pleroma/lib/mix/tasks/generate_config.ex"
# Compile and build the Pleroma instance
su - $app -c "cd $final_path/pleroma;mix local.hex --force;mix deps.get;mix local.rebar --force;mix generate_config;cp config/generated_config.exs config/prod.secret.exs;"
# Replace the default Pleroma variables in the config files whit the ones to use on ynh
......@@ -135,25 +137,25 @@ cat $final_path/pleroma/config/generated_config.exs | grep "<%= .* %>" && ynh_di
cat $final_path/pleroma/config/setup_db.psql | grep "<%= .* %>" && ynh_die "$final_path/pleroma/config/setup_db.psql has unset variables"
#=================================================
# CREATE A POSTGRESQL DATABASE
# CREATE AND SETUP POSTGRESQL DATABASE
#=================================================
ynh_print_info "Setting up the database"
# Fail installation if database already exists
! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -ws $db_name || ynh_die 'The database $db_name already exists'
chmod +x $final_path/pleroma/config/setup_db.psql
su - postgres -c "psql -f $final_path/pleroma/config/setup_db.psql"
#=================================================
# SPECIFIC SETUP
#=================================================
su - $app -c "cd $final_path/pleroma;mix local.rebar --force;mix local.hex --force;MIX_ENV=prod mix ecto.migrate;"
#=================================================
# CUSTOM PLEROMA CONFIGURATION
#=================================================
ynh_print_info "Configuring the instance"
# Check and set registrations open/closed
if [ $is_public -eq 1 ]
then
......@@ -171,7 +173,7 @@ then
# Note that we leave a trailling comma. Since _config :pleroma, :fe_ is in the file, we know that there is at least one option for it as well.
ynh_replace_string "config :pleroma, :fe," "config :pleroma, :fe,\r\n scope_options_enabled: false," "$final_path/pleroma/config/prod.secret.exs"
else
# Neither the scope option nor the pleroma fe config is in the file, so we add both
# Neither the scope option nor the _config :pleroma, :fe_ is in the file, so we add both
# There isn't a second option, so no trailing comma
echo "config :pleroma, :fe," >> "$final_path/pleroma/config/prod.secret.exs"
echo " scope_options_enabled: false" >> "$final_path/pleroma/config/prod.secret.exs"
......@@ -190,14 +192,21 @@ fi
# ADD USER TO INSTANCE
#=================================================
ynh_print_info "Adding user to the instance"
# We have to set the the pasword for the postgresql DB-user first, otherwise the task fails.
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
ynh_print_OFF
su - $app -c "cd $final_path/pleroma; MIX_ENV=prod mix local.hex --force; MIX_ENV=prod mix register_user $instance_user $instance_user $instance_user_mail 'Moderator of this instance' $instance_user_password; MIX_ENV=prod mix set_moderator $instance_user true;"
ynh_print_ON
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Final configurations"
cp -rf "../conf/nginx.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_replace_string "{APP}" "$app" "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_replace_string "{PORT}" "$port" "/etc/nginx/conf.d/$domain.d/$app.conf"
......@@ -205,6 +214,8 @@ cp -rf "../conf/pleroma_cache.conf" "/etc/nginx/conf.d/$app-cache.conf"
ynh_replace_string "{APP}" "$app" "/etc/nginx/conf.d/$app-cache.conf"
ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
systemctl reload nginx
#=================================================
# SETUP SYSTEMD
#=================================================
......@@ -217,14 +228,6 @@ ynh_replace_string "{FINAL_PATH}" "$final_path" "$systemd_location/$app.service"
systemctl daemon-reload
systemctl enable --now $app.service
#=================================================
# SETUP LOGROTATE
#=================================================
# TODO: figure out what to do with this
# Use logrotate to manage application logfile(s)
# ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
......@@ -243,11 +246,11 @@ ynh_app_setting_set $app skipped_uris "/"
# FINALIZATION
#=================================================
systemctl reload nginx
ynh_print_info "Sending love to Lain"
# Restart 'cause I always have an internal server error the first time.
sleep 10
systemctl restart nginx
systemctl restart $app
echo "If you're 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_print_info "If you're 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!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment