mirror of
https://github.com/YunoHost-Apps/seafile_ynh.git
synced 2024-09-03 20:26:01 +02:00
119 lines
4.2 KiB
Bash
119 lines
4.2 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
|
|
# Import common cmd
|
|
source ./experimental_helper.sh
|
|
source ./_common.sh
|
|
|
|
# Source YunoHost helpers
|
|
source /usr/share/yunohost/helpers
|
|
|
|
seafile_version=$(ynh_app_upstream_version)
|
|
|
|
# Create special path with / at the end
|
|
if [[ $path == '/' ]]
|
|
then
|
|
path2=$path
|
|
else
|
|
path2=$path"/"
|
|
fi
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating base directory..."
|
|
ln -s $data_dir $install_dir/seafile-data
|
|
|
|
# Download new version from sources
|
|
ynh_script_progression --message="Installing sources files..." --weight=7
|
|
ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version
|
|
|
|
ynh_script_progression --message="Installing python dependancies..."
|
|
install_dependance
|
|
|
|
# init databases
|
|
ynh_script_progression --message="Configuring MySQL database..."
|
|
db_user=seafile
|
|
db_helper=ynh_"mysql"_setup_db
|
|
$db_helper --db_user $db_user --db_name ccnetdb --db_pwd "$db_pwd"
|
|
$db_helper --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd"
|
|
|
|
ynh_script_progression --message="Configuring application..." --weight=3
|
|
|
|
# Run install script
|
|
expect_scripts_dir=$(mktemp -d)
|
|
cp expect_scripts/install.exp $expect_scripts_dir
|
|
chmod u=rwx,o= -R $expect_scripts_dir
|
|
chown $YNH_APP_ID -R $expect_scripts_dir
|
|
chmod u+x $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh
|
|
set_permission
|
|
sudo -u $YNH_APP_ID $expect_scripts_dir/install.exp "$install_dir/seafile-server-$seafile_version" "$server_name" "$domain" "$port_fileserver" "$db_name" "$db_pwd"
|
|
|
|
sleep 5
|
|
|
|
# Retrive values from auto generated config file
|
|
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2)
|
|
ynh_app_setting_set --app $app --key seahub_secret_key --value $seahub_secret_key
|
|
|
|
# Update seafile config files
|
|
ynh_add_config --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py
|
|
ynh_add_config --template=seafile.conf --destination=$install_dir/conf/seafile.conf
|
|
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')
|
|
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
|
|
|
|
# Fix local warning
|
|
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
|
|
|
|
# Add Seafile Server to startup
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
ynh_add_systemd_config --service seafile --template seafile.service
|
|
ynh_add_systemd_config --service seahub --template seahub.service
|
|
|
|
# register yunohost service
|
|
yunohost service add seafile
|
|
yunohost service add seahub
|
|
|
|
# Config nginx
|
|
ynh_script_progression --message="Configuring nginx..."
|
|
ynh_add_nginx_config
|
|
|
|
# Add logrotate
|
|
ynh_script_progression --message="Configuring log rotation..."
|
|
ynh_use_logrotate --logfile $install_dir/logs
|
|
ln -s $install_dir/logs /var/log/seafile
|
|
|
|
# Add fail2ban
|
|
ynh_script_progression --message="Configuring fail2ban..."
|
|
touch $install_dir/logs/seahub.log
|
|
ynh_add_fail2ban_config --use_template
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
# Set all permissions
|
|
ynh_script_progression --message="Protecting directory..."
|
|
set_permission
|
|
|
|
# Start service
|
|
sleep 3
|
|
|
|
ynh_script_progression --message="Starting seafile services..."
|
|
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
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|