seafile_ynh/scripts/install

117 lines
4.3 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# 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
2020-12-14 16:35:22 +01:00
seafile_version=$(ynh_app_upstream_version)
# Create special path with / at the end
2023-08-08 23:21:11 +02:00
if [[ $path == '/' ]]
then
2023-08-08 23:21:11 +02:00
path2=$path
else
2023-08-08 23:21:11 +02:00
path2=$path"/"
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2020-03-27 13:25:40 +01:00
ynh_script_progression --message="Creating base directory..."
2023-08-08 23:21:11 +02:00
ln -s $data_dir $install_dir/seafile-data
2019-05-07 21:52:43 +02:00
# Check dependencies
2017-07-21 14:56:41 +02:00
install_dependance
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
2023-08-08 23:21:11 +02:00
ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version
# 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
# Run install script
mv_expect_scripts
2023-08-08 23:21:11 +02:00
chmod +x $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh
2022-11-01 12:23:47 +01:00
set_permission
2023-08-08 23:21:11 +02:00
sudo -u $seafile_user $expect_scripts_dir/install.exp "$install_dir/seafile-server-$seafile_version" "$server_name" "$domain" "$fileserver_port" "$db_pwd"
2020-09-29 22:38:08 +02:00
sleep 3
2023-08-08 23:21:11 +02:00
# Retrive values from auto generated config file
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*"[\w-]+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2)
ccnet_id=$(grep -P 'ID\s*=\s*\w+$' $install_dir/conf/ccnet.conf | cut -d= -f2 | grep -o -P '\w+')
ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key
ynh_app_setting_set --app $app --key ccnet_id --value $ccnet_id
# Update seafile config files
ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py
ynh_add_config --template=ccnet.conf --destination=$install_dir/conf/ccnet.conf
ynh_add_config --template=gunicorn.conf.py --destination=$install_dir/conf/gunicorn.conf.py
ynh_add_config --template=seafdav.conf --destination=$install_dir/conf/seafdav.conf
# Configure admin info
# It will be used the first start
admin_email=$(ynh_user_get_info --username $admin --key 'mail')
2023-08-08 23:21:11 +02:00
cp ../conf/create_admin.json $install_dir/conf/admin.txt
ynh_replace_string --match_string __ADMIN__ --replace_string $admin_email --target_file $install_dir/conf/admin.txt
ynh_replace_special_string --match_string __PASSWORD__ --replace_string $admin_password --target_file $install_dir/conf/admin.txt
2017-07-21 14:56:41 +02:00
# Fix local warning
2023-08-08 23:21:11 +02:00
ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh
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'
#=================================================
# GENERIC FINALIZATION
#=================================================
2019-06-11 22:28:26 +02:00
# Set all permissions
ynh_script_progression --message="Protecting directory..."
set_permission
# Add logrotate
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Configuring log rotation..."
2023-08-08 23:21:11 +02:00
ynh_use_logrotate --logfile $install_dir/logs
ln -s $install_dir/logs /var/log/seafile
# register yunohost service
2019-06-11 22:28:26 +02:00
yunohost service add seafile
yunohost service add seahub
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
ynh_systemd_action --service_name seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
sleep 2
ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd"
sleep 2
2019-06-11 22:28:26 +02:00
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." --weight=10
2021-08-28 01:38:46 +02:00
ynh_add_fail2ban_config --use_template
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Installation of $app completed" --last