-
Notifications
You must be signed in to change notification settings - Fork 11
/
install
executable file
·145 lines (116 loc) · 5.33 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
path="/"
random_key=$(ynh_string_random --length=64)
ynh_app_setting_set --app="$app" --key=random_key --value="$random_key"
signing_salt=$(ynh_string_random --length=8)
ynh_app_setting_set --app="$app" --key=signing_salt --value="$signing_salt"
admin_email=$(ynh_user_get_info --username="$admin" --key="mail")
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email"
## Bypass package_checker name not compatible with pleroma
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then
admin="test"
fi
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from manifest.toml
ynh_setup_source --dest_dir="$install_dir/live"
chown -R "$app:www-data" "$install_dir"
#=================================================
# UPDATE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Configuring the PostgreSQL database..." --weight=1
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
if [ "$cache" -eq 1 ]; then
ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf"
cat ../conf/media.conf >> ../conf/nginx.conf
fi
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="$app daemon for Pleroma"
#=================================================
# MAKE SETUP
#=================================================
ynh_script_progression --message="Making setup..." --weight=1
config="/etc/$app/config.exs"
mkdir -p "/etc/$app"
chown "$app:$app" "/etc/$app"
# Generate instance
ynh_exec_warn_less ynh_exec_as "$app" -i \
"$install_dir/live/bin/pleroma_ctl" instance gen \
--force \
--output "$config" \
--output-psql /tmp/setup_db.psql \
--domain "$domain" \
--instance-name "$name" \
--admin-email "$admin_email" \
--notify-email "$admin_email" \
--dbhost localhost \
--dbname "$db_name" \
--dbuser "$db_user" \
--dbpass "$db_pwd" \
--rum N \
--indexable Y \
--db-configurable Y \
--uploads-dir "$data_dir/uploads" \
--static-dir "$data_dir/static" \
--listen-ip 127.0.0.1 \
--listen-port "$port" \
--strip-uploads-location Y \
--read-uploads-description Y \
--anonymize-uploads Y \
--dedupe-uploads Y
cat "../conf/ldap.exs" >> "$config"
ynh_replace_string --target_file="$config" \
--match_string="config :pleroma, configurable_from_database: false" \
--replace_string="config :pleroma, configurable_from_database: true"
ynh_replace_string --target_file="$config" \
--match_string="registrations_open: true" \
--replace_string="registrations_open: $(boolstr "$registration")"
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" migrate
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint"
# Add user
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" user new "$admin" "$admin_email" --password "$password" --moderator --admin -y
ynh_systemd_action --service_name="$app" --action="stop" --log_path=systemd
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config"
chmod 400 "$config"
chown "$app:$app" "$config"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint"
#=================================================
# POST INSTALL
#=================================================
# Correct path to 'static dir' in DB
# This must be done when Pleroma is running (i.e. after install and start)
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" config migrate_to_db
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last