2015-03-17 01:15:44 +01:00
|
|
|
#!/bin/bash
|
2015-10-28 16:04:51 +01:00
|
|
|
|
2018-02-11 01:20:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
2020-11-17 23:49:06 +01:00
|
|
|
# Import common cmd
|
|
|
|
source ./experimental_helper.sh
|
|
|
|
source ./_common.sh
|
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Stop script if errors
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
2014-08-07 02:57:24 +02:00
|
|
|
# Retrieve arguments
|
2017-01-05 23:24:32 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2020-12-12 15:03:12 +01:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2018-04-02 21:05:01 +02:00
|
|
|
server_name="$YNH_APP_ARG_SERVER_NAME"
|
2017-01-05 23:24:32 +01:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
2019-10-27 14:58:33 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2015-02-10 14:42:32 +01:00
|
|
|
seafile_data=/home/yunohost.app/seafile-data
|
2017-12-02 00:18:39 +01:00
|
|
|
final_path=/opt/yunohost/$app
|
2019-08-05 15:34:00 +02:00
|
|
|
seafile_user=$app
|
2019-06-11 22:28:26 +02:00
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
2020-12-14 16:35:22 +01:00
|
|
|
seafile_version=$(ynh_app_upstream_version)
|
2017-12-02 00:18:39 +01:00
|
|
|
|
|
|
|
# Create special path with / at the end
|
2018-05-09 16:13:36 +02:00
|
|
|
if [[ $path_url == '/' ]]
|
|
|
|
then
|
|
|
|
path_url2=$path_url
|
|
|
|
else
|
|
|
|
path_url2=$path_url"/"
|
|
|
|
fi
|
2016-12-27 10:44:40 +01:00
|
|
|
|
2019-06-11 22:28:26 +02:00
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app $app --domain $domain --path_url $path_url
|
2017-07-21 14:56:41 +02:00
|
|
|
|
|
|
|
# Check Final Path availability
|
2019-06-11 22:28:26 +02:00
|
|
|
test ! -e "$final_path" || ynh_die --message "This path already contains a folder"
|
2020-11-29 17:29:51 +01:00
|
|
|
if [ -e "$seafile_data" ]; then
|
|
|
|
old_data_dir_path="$seafile_data$(date '+%Y%m%d.%H%M%S')"
|
|
|
|
ynh_print_warn "A data directory already exist. Data was renamed to $old_data_dir_path"
|
|
|
|
mv "$seafile_data" "$old_data_dir_path"
|
|
|
|
fi
|
2017-07-21 14:56:41 +02:00
|
|
|
|
|
|
|
# Find available ports
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Finding available ports..."
|
2019-10-01 20:53:33 +02:00
|
|
|
seahub_port=$(ynh_find_port --port 8000)
|
|
|
|
fileserver_port=$(ynh_find_port --port 8082)
|
|
|
|
webdav_port=$(ynh_find_port --port 8080)
|
2017-07-21 14:56:41 +02:00
|
|
|
|
2020-02-22 20:22:07 +01:00
|
|
|
if [ $fileserver_port -eq $webdav_port ]; then
|
|
|
|
webdav_port=$(ynh_find_port --port $((fileserver_port + 1)))
|
|
|
|
fi
|
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# store config in yunohost
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
ynh_app_setting_set --app $app --key server_name --value "$server_name"
|
|
|
|
ynh_app_setting_set --app $app --key final_path --value $final_path
|
|
|
|
ynh_app_setting_set --app $app --key seafile_user --value $seafile_user
|
|
|
|
ynh_app_setting_set --app $app --key admin --value $admin
|
|
|
|
ynh_app_setting_set --app $app --key seahub_port --value $seahub_port
|
|
|
|
ynh_app_setting_set --app $app --key fileserver_port --value $fileserver_port
|
|
|
|
ynh_app_setting_set --app $app --key webdav_port --value $webdav_port
|
|
|
|
ynh_app_setting_set --app $app --key is_public --value $is_public
|
2014-08-07 02:57:24 +02:00
|
|
|
|
2018-02-11 01:20:58 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
2020-03-27 13:25:40 +01:00
|
|
|
ynh_script_progression --message="Creating base directory..."
|
|
|
|
mkdir -p $final_path
|
|
|
|
mkdir -p $final_path/installed
|
|
|
|
mkdir -p $final_path/logs
|
2020-04-28 13:57:07 +02:00
|
|
|
mkdir -p $seafile_data
|
2020-12-15 22:09:09 +01:00
|
|
|
ln -s $seafile_data $final_path/seafile-data
|
2020-03-27 13:25:40 +01:00
|
|
|
|
2019-05-07 21:52:43 +02:00
|
|
|
# Create User
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
ynh_system_user_create --username $seafile_user --home_dir $final_path
|
2019-05-07 21:52:43 +02:00
|
|
|
|
2014-08-07 02:57:24 +02:00
|
|
|
# Check dependencies
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=7
|
2017-07-21 14:56:41 +02:00
|
|
|
install_dependance
|
2014-08-07 02:57:24 +02:00
|
|
|
|
2018-01-19 20:55:44 +01:00
|
|
|
# Download new version from sources
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Installing sources files..." --weight=7
|
2018-01-19 20:55:44 +01:00
|
|
|
install_source
|
2014-08-15 03:10:10 +02:00
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# init databases
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Configuring MySQL database..."
|
|
|
|
db_user=seafile
|
|
|
|
ynh_mysql_setup_db --db_user $db_user --db_name ccnetdb
|
|
|
|
ynh_mysql_setup_db --db_user $db_user --db_name seafiledb --db_pwd "$db_pwd"
|
|
|
|
ynh_mysql_setup_db --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd"
|
|
|
|
|
|
|
|
ynh_script_progression --message="Configuring application..." --weight=3
|
2014-08-08 02:59:46 +02:00
|
|
|
|
2014-08-07 05:12:54 +02:00
|
|
|
# Run install script
|
2018-07-06 10:28:14 +02:00
|
|
|
chmod +x expect_scripts/install.exp
|
2017-07-21 14:56:41 +02:00
|
|
|
chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
|
2018-07-06 10:28:14 +02:00
|
|
|
expect_scripts/install.exp "$final_path/seafile-server-$seafile_version" "$server_name" "$domain" "$seafile_data" "$fileserver_port" "$db_pwd"
|
2014-08-07 05:12:54 +02:00
|
|
|
|
2020-09-29 22:38:08 +02:00
|
|
|
sleep 3
|
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# Update seafile config
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_replace_string --match_string http:// --replace_string https:// --target_file $final_path/conf/ccnet.conf
|
|
|
|
ynh_replace_string --match_string :8000 --replace_string $path_url --target_file $final_path/conf/ccnet.conf
|
2017-07-21 14:56:41 +02:00
|
|
|
echo 'FILE_SERVER_ROOT = "https://'$domain'/seafhttp"' | tee -a $final_path/conf/seahub_settings.py
|
2018-05-09 16:13:36 +02:00
|
|
|
echo 'SITE_ROOT = "'$path_url2'"' | tee -a $final_path/conf/seahub_settings.py
|
2017-07-21 14:56:41 +02:00
|
|
|
echo 'SERVE_STATIC = False' | tee -a $final_path/conf/seahub_settings.py
|
2018-05-09 16:13:36 +02:00
|
|
|
echo 'MEDIA_URL = "'$path_url2'media/"' | tee -a $final_path/conf/seahub_settings.py
|
2017-07-21 14:56:41 +02:00
|
|
|
echo 'COMPRESS_URL = MEDIA_URL' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo "STATIC_URL = MEDIA_URL + 'assets/'" | tee -a $final_path/conf/seahub_settings.py
|
2018-05-10 01:24:20 +02:00
|
|
|
echo "LOGIN_URL = '"$path_url2"accounts/login/'" | tee -a $final_path/conf/seahub_settings.py
|
2017-12-02 00:18:39 +01:00
|
|
|
echo "ALLOWED_HOSTS = ['"$domain"']" | tee -a $final_path/conf/seahub_settings.py
|
2014-08-13 05:14:22 +02:00
|
|
|
|
2015-03-18 16:21:10 +01:00
|
|
|
# Email configuration
|
2017-07-21 14:56:41 +02:00
|
|
|
echo 'EMAIL_USE_TLS = False' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_HOST = "localhost"' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_HOST_USER = "seafile@'$domain'"' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_PORT = "25"' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'DEFAULT_FROM_EMAIL = "seafile@'$domain'"' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'SERVER_EMAIL = "seafile@'$domain'"' | tee -a $final_path/conf/seahub_settings.py
|
2019-06-11 22:28:26 +02:00
|
|
|
echo 'EMAIL_HOST_PASSWORD = ""' | tee -a $final_path/conf/seahub_settings.py
|
2019-06-12 22:56:50 +02:00
|
|
|
echo "TIME_ZONE = \"$(cat /etc/timezone)\"" | tee -a $final_path/conf/seahub_settings.py
|
2015-03-18 16:21:10 +01:00
|
|
|
|
2019-07-30 21:58:38 +02:00
|
|
|
# SSO authentication
|
|
|
|
echo 'ENABLE_REMOTE_USER_AUTHENTICATION = True' | tee -a $final_path/conf/seahub_settings.py
|
2019-08-29 22:52:48 +02:00
|
|
|
echo "REMOTE_USER_HEADER = 'HTTP_EMAIL'" | tee -a $final_path/conf/seahub_settings.py
|
2019-07-30 21:58:38 +02:00
|
|
|
echo 'REMOTE_USER_CREATE_UNKNOWN_USER = False' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo "REMOTE_USER_PROTECTED_PATH = ['$path_url', '$path_url/accounts/login']" | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
|
2014-08-13 03:21:47 +02:00
|
|
|
# LDAP configuration
|
2017-07-21 14:56:41 +02:00
|
|
|
echo '[LDAP]' | tee -a $final_path/conf/ccnet.conf
|
|
|
|
echo 'HOST = ldap://localhost:389' | tee -a $final_path/conf/ccnet.conf
|
|
|
|
echo 'BASE = ou=users,dc=yunohost,dc=org' | tee -a $final_path/conf/ccnet.conf
|
|
|
|
echo 'LOGIN_ATTR = mail' | tee -a $final_path/conf/ccnet.conf
|
2014-08-13 03:21:47 +02:00
|
|
|
|
2017-08-09 15:34:10 +02:00
|
|
|
# Enable manually wiki
|
|
|
|
echo 'ENABLE_WIKI = True' | tee -a $final_path/conf/seahub_settings.py
|
|
|
|
|
2020-04-28 13:57:07 +02:00
|
|
|
# Enable memcached
|
|
|
|
cat >> $final_path/conf/seahub_settings.py <<EOF
|
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
|
|
|
|
'LOCATION': '127.0.0.1:11211',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Configure admin info
|
|
|
|
# It will be used the first start
|
|
|
|
admin_email=$(ynh_user_get_info --username $admin --key 'mail')
|
|
|
|
cp ../conf/create_admin.json $final_path/conf/admin.txt
|
|
|
|
ynh_replace_string --match_string __ADMIN__ --replace_string $admin_email --target_file $final_path/conf/admin.txt
|
|
|
|
ynh_replace_special_string --match_string __PASSWORD__ --replace_string $admin_password --target_file $final_path/conf/admin.txt
|
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# Fix local warning
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $final_path/seafile-server-$seafile_version/seahub.sh
|
2014-08-07 02:57:24 +02:00
|
|
|
|
2018-08-03 22:24:07 +02:00
|
|
|
# Update gunicorn config
|
2020-04-28 13:57:07 +02:00
|
|
|
sed --in-place -r "s@bind = \"127\.0\.0\.1:[[:digit:]]+\"@bind = \"127.0.0.1:$seahub_port\"@g" $final_path/conf/gunicorn.conf.py
|
2018-08-03 22:24:07 +02:00
|
|
|
|
2015-08-29 13:25:04 +02:00
|
|
|
# Add webdav
|
2017-07-21 14:56:41 +02:00
|
|
|
cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_replace_string --match_string __WEBDAV_PORT__ --replace_string $webdav_port --target_file $final_path/conf/seafdav.conf
|
2017-07-21 14:56:41 +02:00
|
|
|
|
|
|
|
# Add Seafile Server to startup
|
2019-08-05 15:36:59 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=2
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_add_systemd_config --service seafile --template seafile.service
|
|
|
|
ynh_add_systemd_config --service seahub --template seahub.service
|
2017-07-21 14:56:41 +02:00
|
|
|
|
|
|
|
# Config nginx
|
2019-08-05 15:36:59 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx..." --weight=1
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
|
2015-08-29 13:25:04 +02:00
|
|
|
|
2015-02-20 16:57:26 +01:00
|
|
|
# Copy first launch script
|
2018-07-06 10:28:14 +02:00
|
|
|
cp expect_scripts/first_launch.exp $final_path
|
2017-07-21 14:56:41 +02:00
|
|
|
chmod +x $final_path/first_launch.exp
|
2015-02-20 16:57:26 +01:00
|
|
|
|
2015-02-20 15:07:18 +01:00
|
|
|
# Set permissions to seafile directory
|
2020-04-28 13:57:07 +02:00
|
|
|
set_permission
|
2015-02-20 15:07:18 +01:00
|
|
|
|
2019-08-05 17:07:17 +02:00
|
|
|
# Sometime we have a current effect. We try to lunch seafile when not all permissions are already set.
|
|
|
|
# So wait untils all permissions are cleanly set
|
|
|
|
sleep 5
|
2019-09-10 22:51:27 +02:00
|
|
|
ynh_debug_exec ls /opt/yunohost/seafile/ccnet
|
2019-08-05 17:07:17 +02:00
|
|
|
|
2018-02-11 01:20:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
2019-06-11 22:28:26 +02:00
|
|
|
# Set all permissions
|
|
|
|
ynh_script_progression --message="Protecting directory..."
|
|
|
|
set_permission
|
|
|
|
|
2015-08-24 20:45:36 +02:00
|
|
|
# Add sso config to unprotect domain.tld/seafhttp + domain.tld/seafdav do in /etc/ssowat/conf.json.persistent
|
2021-01-26 22:54:26 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
|
|
|
ynh_permission_create --permission=file_server --url=/seafhttp --auth_header=false \
|
|
|
|
--label="File server" --protected=true --allowed=visitors
|
|
|
|
ynh_permission_create --permission=webdav --url=/seafdav --auth_header=true \
|
|
|
|
--label="Webdav" --protected=true --allowed=visitors
|
2015-03-18 17:34:29 +01:00
|
|
|
|
|
|
|
# unprotect media
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_app_setting_set --app $app --key unprotected_uris --value "/media"
|
2015-02-20 15:07:18 +01:00
|
|
|
|
2016-12-27 10:44:40 +01:00
|
|
|
if [ "$is_public" = "0" ]
|
2014-08-15 03:10:10 +02:00
|
|
|
then
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_app_setting_delete --app seafile --key unprotected_uris
|
2014-08-15 03:10:10 +02:00
|
|
|
else
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_app_setting_set --app $app --key unprotected_uris --value "/"
|
2014-08-15 03:10:10 +02:00
|
|
|
fi
|
2015-02-10 14:42:32 +01:00
|
|
|
|
2015-08-24 20:45:36 +02:00
|
|
|
# Add logrotate
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2019-10-01 20:53:33 +02:00
|
|
|
ynh_use_logrotate --logfile $final_path/logs
|
2017-12-10 11:29:36 +01:00
|
|
|
ln -s $final_path/logs /var/log/seafile
|
2015-08-24 20:45:36 +02:00
|
|
|
|
2015-02-20 15:07:18 +01:00
|
|
|
# register yunohost service
|
2019-06-11 22:28:26 +02:00
|
|
|
yunohost service add seafile
|
|
|
|
yunohost service add seahub
|
2015-05-20 15:13:35 +02:00
|
|
|
|
2019-08-05 15:36:59 +02:00
|
|
|
ynh_script_progression --message="Stoping services..." --weight=3
|
2019-06-11 22:28:26 +02:00
|
|
|
|
|
|
|
# Start service
|
|
|
|
ynh_script_progression --message="Starting seafile services..." --weight=3
|
2019-09-10 22:51:15 +02:00
|
|
|
ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
|
|
|
|
ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd"
|
|
|
|
sleep 2
|
2019-06-11 22:28:26 +02:00
|
|
|
|
2020-04-28 13:57:07 +02:00
|
|
|
# Add fail2ban
|
|
|
|
ynh_script_progression --message="Configuring fail2ban..." --weight=10
|
|
|
|
ynh_add_fail2ban_config --use_template --others_var 'final_path'
|
|
|
|
|
2019-06-11 22:28:26 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|