1+ #! /usr/bin/env bash
2+
3+ # Copyright (c) 2021-2025 community-scripts ORG
4+ # Author: dave-yap
5+ # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
6+ # Source: https://seafile.com/
7+
8+ source /dev/stdin <<< " $FUNCTIONS_FILE_PATH"
9+ color
10+ verb_ip6
11+ catch_errors
12+ setting_up_container
13+ network_check
14+ update_os
15+
16+ msg_info " Installing Dependencies (Patience)"
17+ $STD apt-get install -y \
18+ sudo \
19+ mc \
20+ wget \
21+ expect
22+ msg_ok " Installed Dependencies"
23+
24+ msg_info " Installing MariaDB"
25+ $STD apt-get install -y mariadb-server
26+ systemctl start mariadb
27+ msg_ok " Installed MariaDB"
28+
29+ msg_info " Setup MariaDB for Seafile"
30+ CCNET_DB=" ccnet_db"
31+ SEAFILE_DB=" seafile_db"
32+ SEAHUB_DB=" seahub_db"
33+ DB_USER=" seafile"
34+ DB_PASS=$( openssl rand -base64 18 | tr -dc ' a-zA-Z0-9' | cut -c1-13)
35+ 36+ ADMIN_PASS=$( openssl rand -base64 18 | tr -dc ' a-zA-Z0-9' | cut -c1-13)
37+ sudo -u mysql mysql -s -e " CREATE DATABASE $CCNET_DB CHARACTER SET utf8;"
38+ sudo -u mysql mysql -s -e " CREATE DATABASE $SEAFILE_DB CHARACTER SET utf8;"
39+ sudo -u mysql mysql -s -e " CREATE DATABASE $SEAHUB_DB CHARACTER SET utf8;"
40+ sudo -u mysql mysql -s -e " CREATE USER '$DB_USER '@'localhost' IDENTIFIED BY '$DB_PASS ';"
41+ sudo -u mysql mysql -s -e " GRANT ALL PRIVILEGES ON $CCNET_DB .* TO '$DB_USER '@localhost;"
42+ sudo -u mysql mysql -s -e " GRANT ALL PRIVILEGES ON $SEAFILE_DB .* TO '$DB_USER '@localhost;"
43+ sudo -u mysql mysql -s -e " GRANT ALL PRIVILEGES ON $SEAHUB_DB .* TO '$DB_USER '@localhost;"
44+ {
45+ echo " Application Credentials"
46+ echo " CCNET_DB: $CCNET_DB "
47+ echo " SEAFILE_DB: $SEAFILE_DB "
48+ echo " SEAHUB_DB: $SEAHUB_DB "
49+ echo " DB_USER: $DB_USER "
50+ echo " DB_PASS: $DB_PASS "
51+ echo " ADMIN_EMAIL: $ADMIN_EMAIL "
52+ echo " ADMIN_PASS: $ADMIN_PASS "
53+ } >> ~ /seafile.creds
54+ msg_ok " MariaDB setup for Seafile"
55+
56+ msg_info " Installing Seafile Python Dependencies"
57+ $STD apt-get install -y \
58+ python3 \
59+ python3-dev \
60+ python3-setuptools \
61+ python3-pip \
62+ libmariadb-dev \
63+ ldap-utils \
64+ libldap2-dev \
65+ libsasl2-dev \
66+ pkg-config
67+ $STD pip3 install \
68+ django \
69+ future \
70+ mysqlclient \
71+ pymysql \
72+ pillow \
73+ pylibmc \
74+ captcha \
75+ markupsafe \
76+ jinja2 \
77+ sqlalchemy \
78+ psd-tools \
79+ django-pylibmc \
80+ django_simple_captcha \
81+ djangosaml2 \
82+ pysaml2 \
83+ pycryptodome \
84+ cffi \
85+ lxml \
86+ python-ldap
87+ msg_ok " Installed Seafile Python Dependecies"
88+
89+ msg_info " Installing Seafile"
90+ IP=$( ip a s dev eth0 | awk ' /inet / {print $2}' | cut -d/ -f1)
91+ mkdir -p /opt/seafile
92+ useradd seafile
93+ mkdir -p /home/seafile
94+ chown seafile: /home/seafile
95+ chown seafile: /opt/seafile
96+ $STD su - seafile -c " wget -qc https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_11.0.13_x86-64.tar.gz"
97+ $STD su - seafile -c " tar -xzf seafile-server_11.0.13_x86-64.tar.gz -C /opt/seafile/"
98+ $STD su - seafile -c " expect <<EOF
99+ spawn bash /opt/seafile/seafile-server-11.0.13/setup-seafile-mysql.sh
100+ expect {
101+ \" Press ENTER to continue\" {
102+ send \" \r\"
103+ }
104+ }
105+ expect {
106+ \" What is the name of the server\" {
107+ send \" Seafile\r\"
108+ }
109+ }
110+ expect {
111+ \" What is the ip or domain of the server\" {
112+ send \" $IP \r\"
113+ }
114+ }
115+ expect {
116+ \" Which port do you want to use for the seafile fileserver\" {
117+ send \" 8082\r\"
118+ }
119+ }
120+ expect {
121+ \" 1 or 2\" {
122+ send \" 2\r\"
123+ }
124+ }
125+ expect {
126+ \" What is the host of mysql server\" {
127+ send \" localhost\r\"
128+ }
129+ }
130+ expect {
131+ \" What is the port of mysql server\" {
132+ send \" 3306\r\"
133+ }
134+ }
135+ expect {
136+ \" Which mysql user to use for seafile\" {
137+ send \" seafile\r\"
138+ }
139+ }
140+ expect {
141+ \" What is the password for mysql user\" {
142+ send \" $DB_PASS \r\"
143+ }
144+ }
145+ expect {
146+ \" Enter the existing database name for ccnet\" {
147+ send \" $CCNET_DB \r\"
148+ }
149+ }
150+ expect {
151+ \" Enter the existing database name for seafile\" {
152+ send \" $SEAFILE_DB \r\"
153+ }
154+ }
155+ expect {
156+ \" Enter the existing database name for seahub\" {
157+ send \" $SEAHUB_DB \r\"
158+ }
159+ }
160+ expect {
161+ \" Press ENTER to continue, or Ctrl-C to abort\" {
162+ send \" \r\"
163+ }
164+ }
165+ expect eof
166+ EOF"
167+ msg_ok " Installed Seafile"
168+
169+ msg_info " Setting up Memcached"
170+ $STD apt-get install -y \
171+ memcached \
172+ libmemcached-dev
173+ $STD pip3 install \
174+ pylibmc \
175+ django-pylibmc
176+ systemctl enable --now -q memcached
177+ cat << EOF >>/opt/seafile/conf/seahub_settings.py
178+ CACHES = {
179+ 'default': {
180+ 'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
181+ 'LOCATION': '127.0.0.1:11211',
182+ },
183+ }
184+ EOF
185+ msg_ok " Memcached Started"
186+
187+ msg_info " Adjusting Conf files"
188+ sed -i " 0,/127.0.0.1/s/127.0.0.1/0.0.0.0/" /opt/seafile/conf/gunicorn.conf.py
189+ sed -i " 0,/SERVICE_URL = \" http:\/\/$IP \" /s/SERVICE_URL = \" http:\/\/$IP \" /SERVICE_URL = \" http:\/\/$IP :8000\" /" /opt/seafile/conf/seahub_settings.py
190+ echo -e " \nFILE_SERVER_ROOT = \" http://$IP :8082\" " >> /opt/seafile/conf/seahub_settings.py
191+ echo -e " CSRF_TRUSTED_ORIGINS = ['http://$IP /']" >> /opt/seafile/conf/seahub_settings.py
192+ msg_ok " Conf files adjusted"
193+
194+ msg_info " Setting up Seafile"
195+ $STD su - seafile -c " bash /opt/seafile/seafile-server-latest/seafile.sh start"
196+ $STD su - seafile -c " expect <<EOF
197+ spawn bash /opt/seafile/seafile-server-latest/seahub.sh start
198+ expect {
199+ \" email\" {
200+ send \" $ADMIN_EMAIL \r\"
201+ }
202+ }
203+ expect {
204+ \" password\" {
205+ send \" $ADMIN_PASS \r\"
206+ }
207+ }
208+ expect {
209+ \" password again\" {
210+ send \" $ADMIN_PASS \r\"
211+ }
212+ }
213+ expect eof
214+ EOF"
215+ $STD su - seafile -c " bash /opt/seafile/seafile-server-latest/seahub.sh stop" || true
216+ $STD su - seafile -c " bash /opt/seafile/seafile-server-latest/seafile.sh stop" || true
217+ msg_ok " Seafile setup"
218+
219+ msg_info " Creating Services"
220+ cat << EOF >/etc/systemd/system/seafile.service
221+ [Unit]
222+ Description=Seafile File-hosting
223+ After=network.target mysql.service memcached.service
224+ Wants=mysql.service memcached.service
225+
226+ [Service]
227+ Type=forking
228+ User=seafile
229+ Group=seafile
230+ WorkingDirectory=/opt/seafile
231+
232+ ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start
233+ ExecStartPost=/opt/seafile/seafile-server-latest/seahub.sh start
234+ ExecStop=/opt/seafile/seafile-server-latest/seahub.sh stop
235+ ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop
236+
237+ Restart=on-failure
238+ RestartSec=5s
239+
240+ [Install]
241+ WantedBy=multi-user.target
242+ EOF
243+ systemctl enable --now -q seafile.service
244+ msg_ok " Created Services"
245+
246+ msg_info " Creating External Storage script"
247+ cat << 'EOF ' >~/external-storage.sh
248+ #!/bin/bash
249+ STORAGE_DIR="/path/to/your/external/storage"
250+
251+ # Move the seafile-data folder to external storage
252+ mv /opt/seafile/seafile-data $STORAGE_DIR/seafile-data
253+
254+ # Create a symlink for access
255+ ln -s $STORAGE_DIR/seafile-data /opt/seafile/seafile-data
256+ EOF
257+ chmod +x ~ /external-storage.sh
258+ msg_ok " Bash Script for External Storage created"
259+
260+ msg_info " Creating Domain access script"
261+ cat << 'EOF ' >~/domain.sh
262+ #!/bin/bash
263+ DOMAIN=$1
264+ IP=$(ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
265+ DOMAIN_NOSCHEME=$(echo $DOMAIN | sed 's|^https://||')
266+
267+ #Change the CORS to provided domain
268+ sed -i "s|CSRF_TRUSTED_ORIGINS = ['http://$IP:8000/']|CSRF_TRUSTED_ORIGINS = ['$DOMAIN']|g" /opt/seafile/conf/seahub_settings.py
269+ sed -i "s|FILE_SERVER_ROOT = \"http://$IP:8082\"|FILE_SERVER_ROOT = \"$DOMAIN/seafhttp\"|g" /opt/seafile/conf/seahub_settings.py
270+ EOF
271+ chmod +x ~ /domain.sh
272+ msg_ok " Bash Script for Domain access created"
273+
274+ motd_ssh
275+ customize
276+
277+ msg_info " Cleaning up"
278+ rm -rf /home/seafile/seafile* .tar.gz
279+ $STD apt-get -y autoremove
280+ $STD apt-get -y autoclean
281+ msg_ok " Cleaned"
0 commit comments