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
|
2024-05-16 22:11:22 +02:00
|
|
|
source ./ynh_setup_source
|
2017-07-21 14:56:41 +02:00
|
|
|
|
2020-12-14 16:35:22 +01:00
|
|
|
seafile_version=$(ynh_app_upstream_version)
|
2017-12-02 00:18:39 +01:00
|
|
|
|
2024-04-21 01:50:52 +02:00
|
|
|
install_pkg_conf
|
2024-04-20 23:17:25 +02:00
|
|
|
|
2024-04-12 21:22:21 +02:00
|
|
|
ensure_vars_set
|
|
|
|
|
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..."
|
2019-05-07 21:52:43 +02:00
|
|
|
|
2024-04-12 22:19:27 +02:00
|
|
|
if [ -n "$(ls -A "$data_dir")" ]; then
|
2023-11-24 11:58:13 +01:00
|
|
|
old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')"
|
|
|
|
ynh_print_warn "Data directory was not empty. Data was moved to $old_data_dir_path"
|
2024-04-12 22:19:27 +02:00
|
|
|
mkdir -p "$old_data_dir_path"
|
2023-11-24 11:58:13 +01:00
|
|
|
mv -t "$old_data_dir_path" "$data_dir"/*
|
|
|
|
fi
|
|
|
|
|
2024-04-12 22:19:27 +02:00
|
|
|
mkdir -p /var/log/"$app"
|
|
|
|
mkdir -p "$data_dir"/{seafile-data,seahub-data}
|
|
|
|
|
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
|
2024-04-12 21:22:21 +02:00
|
|
|
install_source
|
2014-08-15 03:10:10 +02:00
|
|
|
|
2023-10-04 07:54:30 +02:00
|
|
|
ynh_script_progression --message="Installing python dependancies..."
|
|
|
|
install_dependance
|
|
|
|
|
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
|
2024-04-26 21:55:00 +02:00
|
|
|
ynh_''mysql_setup_db --db_user="$db_user" --db_name=ccnetdb --db_pwd="$db_pwd"
|
|
|
|
ynh_''mysql_setup_db --db_user="$db_user" --db_name=seahubdb --db_pwd="$db_pwd"
|
2019-06-11 22:28:26 +02:00
|
|
|
|
|
|
|
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
|
2022-11-01 12:23:47 +01:00
|
|
|
set_permission
|
2024-04-26 21:55:00 +02:00
|
|
|
ynh_replace_special_string --match_string='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \
|
2023-11-24 12:45:03 +01:00
|
|
|
--replace_string 'seafile_config.seafile_dir = seafile_dir' \
|
2024-04-12 22:19:27 +02:00
|
|
|
--target_file "$install_dir/seafile-server-$seafile_version/setup-seafile-mysql.py"
|
|
|
|
sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \
|
2023-11-24 10:59:10 +01:00
|
|
|
--server-name "$server_name" \
|
2024-04-12 22:19:27 +02:00
|
|
|
--server-ip "$domain" \
|
|
|
|
--fileserver-port "$port_fileserver" \
|
2023-11-24 12:45:03 +01:00
|
|
|
--use-existing-db 1 \
|
2023-11-24 10:59:10 +01:00
|
|
|
--mysql-host localhost \
|
|
|
|
--mysql-port 3306 \
|
2024-04-12 22:19:27 +02:00
|
|
|
--mysql-user "$db_user" \
|
2023-11-24 10:59:10 +01:00
|
|
|
--mysql-user-passwd "$db_pwd" \
|
2024-04-12 21:22:21 +02:00
|
|
|
-s "$db_name" \
|
|
|
|
-c ccnetdb \
|
|
|
|
-b seahubdb
|
2020-09-29 22:38:08 +02:00
|
|
|
|
2023-08-08 23:21:11 +02:00
|
|
|
# Retrive values from auto generated config file
|
2024-04-12 22:19:27 +02:00
|
|
|
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)
|
2024-04-26 21:55:00 +02:00
|
|
|
ynh_app_setting_set --app="$app" --key=seahub_secret_key --value="$seahub_secret_key"
|
2023-08-08 23:21:11 +02:00
|
|
|
|
|
|
|
# Update seafile config files
|
2024-04-12 21:22:21 +02:00
|
|
|
ynh_add_jinja_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
|
|
|
|
ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
|
2020-04-28 13:57:07 +02:00
|
|
|
|
|
|
|
# Configure admin info
|
|
|
|
# It will be used the first start
|
2024-04-26 21:55:00 +02:00
|
|
|
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
|
2024-04-26 21:55:00 +02:00
|
|
|
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
|
2024-04-12 22:19:27 +02:00
|
|
|
|
|
|
|
# Use symlink to store data
|
|
|
|
if [ -e "$install_dir"/seafile-data ]; then
|
|
|
|
mv -t "$data_dir"/seafile-data "$install_dir"/seafile-data/*
|
|
|
|
ynh_secure_remove --file="$install_dir"/seafile-data
|
|
|
|
fi
|
|
|
|
if [ -e "$install_dir"/seahub-data ]; then
|
|
|
|
mv -t "$data_dir"/seahub-data "$install_dir"/seahub-data/*
|
|
|
|
ynh_secure_remove --file="$install_dir"/seahub-data
|
|
|
|
fi
|
|
|
|
if [ -e "$install_dir"/logs ]; then
|
|
|
|
mv -t /var/log/"$app" "$install_dir"/logs/*
|
|
|
|
ynh_secure_remove --file="$install_dir"/logs
|
|
|
|
fi
|
|
|
|
ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data
|
|
|
|
ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data
|
|
|
|
ln -s /var/log/"$app" "$install_dir"/logs
|
2020-04-28 13:57:07 +02:00
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# Fix local warning
|
2024-04-26 23:35:14 +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
|
2023-09-27 19:21:58 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2024-04-26 21:55:00 +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
|
|
|
|
2023-09-27 19:21:58 +02:00
|
|
|
# register yunohost service
|
2024-02-20 21:28:59 +01:00
|
|
|
yunohost service add seafile --description 'Main service for seafile server.'
|
|
|
|
yunohost service add seahub --description 'Seafile server web interface.'
|
2023-09-27 19:21:58 +02:00
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# Config nginx
|
2023-09-27 19:21:58 +02:00
|
|
|
ynh_script_progression --message="Configuring nginx..."
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
# Add logrotate
|
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2024-04-12 22:19:27 +02:00
|
|
|
ynh_use_logrotate --logfile=/var/log/"$app"
|
2023-09-27 19:21:58 +02:00
|
|
|
|
|
|
|
# Add fail2ban
|
|
|
|
ynh_script_progression --message="Configuring fail2ban..."
|
|
|
|
ynh_add_fail2ban_config --use_template
|
2015-08-29 13:25:04 +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
|
|
|
|
|
|
|
|
# Start service
|
2023-09-27 19:21:58 +02:00
|
|
|
sleep 3
|
|
|
|
|
|
|
|
ynh_script_progression --message="Starting seafile services..."
|
2024-04-26 21:55:00 +02:00
|
|
|
ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
|
2021-03-15 12:28:58 +01:00
|
|
|
sleep 2
|
2024-04-26 21:55:00 +02:00
|
|
|
ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd"
|
2019-09-10 22:51:15 +02:00
|
|
|
sleep 2
|
2019-06-11 22:28:26 +02:00
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|