seafile_ynh/scripts/install

144 lines
5.2 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
2024-06-01 11:19:38 +02:00
source ./ynh_setup_source
2020-11-17 23:49:06 +01:00
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)
seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version"
2024-04-12 21:22:21 +02:00
ensure_vars_set
#=================================================
ynh_script_progression "Creating base directory..."
2019-05-07 21:52:43 +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"
mkdir -p "$old_data_dir_path"
2023-11-24 11:58:13 +01:00
mv -t "$old_data_dir_path" "$data_dir"/*
fi
mkdir -p /var/log/"$app"
mkdir -p "$data_dir"/{seafile-data,seahub-data}
2024-06-02 21:01:20 +02:00
mkdir -p "$install_dir"/{conf,ccnet}
2018-01-19 20:55:44 +01:00
# Download new version from sources
ynh_script_progression "Installing sources files..."
2024-04-12 21:22:21 +02:00
install_source
# init databases
ynh_script_progression "Configuring MySQL database..."
2019-06-11 22:28:26 +02:00
db_user=seafile
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 "Configuring application..."
# Run install script
2022-11-01 12:23:47 +01:00
set_permission
ynh_replace_regex --match='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \
--replace='seafile_config.seafile_dir = seafile_dir' \
--file="$seafile_code/setup-seafile-mysql.py"
ynh_replace_regex --match="Utils.error('Ccnet config dir \\\"%s\\\" already exists.' % ccnet_config.ccnet_dir)" \
--replace='patched = 1' \
--file="$seafile_code/setup-seafile-mysql.py"
run_seafile_cmd bash "/opt/seafile/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \
2023-11-24 10:59:10 +01:00
--server-name "$server_name" \
--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 \
--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
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)
ynh_app_setting_set --key=seahub_secret_key --value="$seahub_secret_key"
2023-08-08 23:21:11 +02:00
# Update seafile config files
ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_config_add --template=seafile.conf --destination="$install_dir"/conf/seafile.conf
ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_config_add --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
# Configure admin info
# It will be used the first start
admin_email=$(ynh_user_get_info --username="$admin" --key='mail')
2024-08-31 10:34:22 +02:00
cp ../conf/create_admin.json "$install_dir"/conf/admin.txt
ynh_replace --match=__ADMIN__ --replace="$admin_email" --file="$install_dir"/conf/admin.txt
ynh_replace_regex --match=__PASSWORD__ --replace="$admin_password" --file="$install_dir"/conf/admin.txt
# Use symlink to store data
if [ -e "$install_dir"/seafile-data ]; then
mv -t "$data_dir"/seafile-data "$install_dir"/seafile-data/*
ynh_safe_rm "$install_dir"/seafile-data
fi
if [ -e "$install_dir"/seahub-data ]; then
mv -t "$data_dir"/seahub-data "$install_dir"/seahub-data/*
ynh_safe_rm "$install_dir"/seahub-data
fi
if [ -e "$install_dir"/logs ]; then
mv -t /var/log/"$app" "$install_dir"/logs/*
ynh_safe_rm "$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
2017-07-21 14:56:41 +02:00
# Fix local warning
ynh_replace --match=en_US.UTF-8 --replace="${LANG:-'en_US.UTF-8'}" --file="$seafile_code/seahub.sh"
2017-07-21 14:56:41 +02:00
# Add Seafile Server to startup
ynh_script_progression "Configuring $app's systemd service..."
ynh_config_add_systemd --service=seafile --template=seafile.service
ynh_config_add_systemd --service=seahub --template=seahub.service
2017-07-21 14:56:41 +02:00
# register yunohost service
yunohost service add seafile --description 'Main service for seafile server.'
yunohost service add seahub --description 'Seafile server web interface.'
2017-07-21 14:56:41 +02:00
# Config nginx
ynh_script_progression "Configuring nginx..."
ynh_config_add_nginx
# Add logrotate
ynh_script_progression "Configuring log rotation..."
ynh_config_add_logrotate /var/log/"$app"
# Add fail2ban
ynh_script_progression "Configuring fail2ban..."
ynh_config_add_fail2ban
#=================================================
2019-06-11 22:28:26 +02:00
# Set all permissions
ynh_script_progression "Protecting directory..."
2019-06-11 22:28:26 +02:00
set_permission
# Start service
sleep 3
ynh_script_progression "Starting seafile services..."
ynh_systemctl --service=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
sleep 2
ynh_systemctl --service=seahub -l "Started Seafile hub." -p "systemd"
sleep 2
2019-06-11 22:28:26 +02:00
ynh_script_progression "Installation of $app completed"