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
|
|
|
|
#=================================================
|
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# Source YunoHost helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Stop script if errors
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-01-05 23:24:32 +01:00
|
|
|
# Import common cmd
|
2018-02-11 01:20:58 +01:00
|
|
|
source ./experimental_helper.sh
|
2017-01-05 23:24:32 +01:00
|
|
|
source ./_common.sh
|
|
|
|
|
2014-08-07 02:57:24 +02:00
|
|
|
# Retrieve arguments
|
2017-01-05 23:24:32 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2018-05-09 16:13:36 +02:00
|
|
|
path_url=$(ynh_normalize_url_path $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
|
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
|
|
|
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
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
|
|
|
|
seafile_user=seafile
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# Check domain/path availability
|
2018-05-09 16:13:36 +02:00
|
|
|
test $(ynh_webpath_available $domain $path_url) == 'True' || ynh_die "$domain$path_url is not available, please use an other domain or path."
|
|
|
|
ynh_webpath_register $app $domain $path_url
|
2017-07-21 14:56:41 +02:00
|
|
|
|
|
|
|
# Check Final Path availability
|
|
|
|
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
|
|
|
|
|
|
|
# Find available ports
|
|
|
|
seahub_port=$(ynh_find_port 8000)
|
|
|
|
fileserver_port=$(ynh_find_port 8082)
|
|
|
|
webdav_port=$(ynh_find_port 8080)
|
|
|
|
|
|
|
|
# store config in yunohost
|
2018-04-02 21:05:01 +02:00
|
|
|
ynh_app_setting_set $app server_name "$server_name"
|
2017-07-21 14:56:41 +02:00
|
|
|
ynh_app_setting_set $app final_path $final_path
|
|
|
|
ynh_app_setting_set $app seafile_user $seafile_user
|
|
|
|
ynh_app_setting_set $app admin $admin
|
|
|
|
ynh_app_setting_set $app seahub_port $seahub_port
|
|
|
|
ynh_app_setting_set $app fileserver_port $fileserver_port
|
|
|
|
ynh_app_setting_set $app webdav_port $webdav_port
|
|
|
|
ynh_app_setting_set $app is_public $is_public
|
|
|
|
ynh_app_setting_set $app installed_version $seafile_version
|
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# Retrieve admin email
|
2017-07-21 14:56:41 +02:00
|
|
|
admin_email=$(yunohost user info $admin | grep mail: | sed "s/mail: //g")
|
2014-08-07 02:57:24 +02:00
|
|
|
|
2018-02-11 01:20:58 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
|
2014-08-07 02:57:24 +02:00
|
|
|
# Check dependencies
|
2017-07-21 14:56:41 +02:00
|
|
|
install_dependance
|
2014-08-07 02:57:24 +02:00
|
|
|
|
|
|
|
# Copy files to the right place
|
2018-01-19 20:55:44 +01:00
|
|
|
test -e $seafile_data && ynh_secure_remove "$seafile_data"
|
2017-07-21 14:56:41 +02:00
|
|
|
mkdir -p $final_path
|
|
|
|
mkdir -p $final_path/installed
|
|
|
|
mkdir -p $final_path/logs
|
|
|
|
mkdir -p $final_path/seafile-data
|
2018-01-19 20:55:44 +01:00
|
|
|
|
|
|
|
# Download new version from sources
|
|
|
|
install_source
|
2014-08-15 03:10:10 +02:00
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# init databases
|
2016-12-27 10:44:40 +01:00
|
|
|
dbuser=seafile
|
|
|
|
db_pwd=$(ynh_string_random 15)
|
|
|
|
ynh_app_setting_set "$app" mysqlpwd "$db_pwd"
|
|
|
|
ynh_mysql_create_db ccnetdb "$dbuser" "$db_pwd"
|
|
|
|
ynh_mysql_create_db seafiledb "$dbuser" "$db_pwd"
|
|
|
|
ynh_mysql_create_db seahubdb "$dbuser" "$db_pwd"
|
2014-08-08 02:59:46 +02:00
|
|
|
|
2017-12-10 10:45:51 +01:00
|
|
|
# Create User
|
|
|
|
ynh_system_user_create $seafile_user $final_path
|
|
|
|
|
2014-08-07 05:12:54 +02:00
|
|
|
# Run install script
|
2017-07-21 14:56:41 +02:00
|
|
|
chmod +x ../conf/install.exp
|
|
|
|
chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
|
2018-04-02 20:31:38 +02:00
|
|
|
../conf/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
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# Update seafile config
|
2017-07-21 14:56:41 +02:00
|
|
|
ynh_replace_string http:// https:// $final_path/conf/ccnet.conf
|
2018-05-09 16:13:36 +02:00
|
|
|
ynh_replace_string :8000 $path_url $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
|
|
|
|
echo "LOGIN_URL = '"$path2"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_HOST_PASSWORD = ""' | 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
|
2015-03-18 16:21:10 +01:00
|
|
|
|
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
|
|
|
|
|
2017-07-21 14:56:41 +02:00
|
|
|
# Fix local warning
|
2018-04-03 01:48:33 +02:00
|
|
|
ynh_replace_string en_US.UTF-8 ${LANG:-'en_US.UTF-8'} $final_path/seafile-server-$seafile_version/seahub.sh
|
2014-08-07 02:57:24 +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
|
|
|
|
ynh_replace_string WEBDAV_PORT $webdav_port $final_path/conf/seafdav.conf
|
|
|
|
|
|
|
|
# Add Seafile Server to startup
|
|
|
|
cp ../conf/seafile-server /etc/init.d
|
|
|
|
ynh_replace_string SEAHUB_PORT $seahub_port /etc/init.d/seafile-server
|
|
|
|
ynh_replace_string SEAFILE_DIR $final_path /etc/init.d/seafile-server
|
2017-09-30 18:14:22 +02:00
|
|
|
ynh_replace_string SEAFILE_USER $seafile_user /etc/init.d/seafile-server
|
2017-07-21 14:56:41 +02:00
|
|
|
chmod +x /etc/init.d/seafile-server
|
2017-08-09 15:34:10 +02:00
|
|
|
systemctl daemon-reload
|
2017-07-21 14:56:41 +02:00
|
|
|
update-rc.d seafile-server defaults
|
|
|
|
|
|
|
|
# Config nginx
|
|
|
|
config_nginx
|
2015-08-29 13:25:04 +02:00
|
|
|
|
2015-02-20 16:57:26 +01:00
|
|
|
# Copy first launch script
|
2017-07-21 14:56:41 +02:00
|
|
|
cp ../conf/first_launch.exp $final_path
|
|
|
|
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
|
2017-07-21 14:56:41 +02:00
|
|
|
chown -R $seafile_user:$seafile_user $final_path
|
|
|
|
chown -R $seafile_user:$seafile_user $seafile_data
|
2015-02-20 15:07:18 +01:00
|
|
|
|
2015-02-20 16:57:26 +01:00
|
|
|
# Start seafile, seahub and populate admin account
|
2017-07-21 14:56:41 +02:00
|
|
|
su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-$seafile_version/seafile.sh start"
|
2018-01-30 11:32:02 +01:00
|
|
|
# We escape all char witch needed.
|
|
|
|
ynh_replace_special_string "__ADMIN_PASSWORD__" $admin_password "$final_path/first_launch.exp"
|
|
|
|
su - $seafile_user -s /bin/bash -c "$final_path/first_launch.exp $final_path/seafile-server-$seafile_version $admin_email"
|
|
|
|
ynh_secure_remove "$final_path/first_launch.exp"
|
2015-02-20 16:57:26 +01:00
|
|
|
|
2018-02-11 01:20:58 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
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
|
2017-07-21 14:56:41 +02:00
|
|
|
cp ../conf/add_sso_conf.py $final_path
|
|
|
|
cp ../conf/remove_sso_conf.py $final_path
|
2018-03-09 20:37:26 +01:00
|
|
|
python3 $final_path/add_sso_conf.py
|
2015-03-18 17:34:29 +01:00
|
|
|
|
|
|
|
# unprotect media
|
2016-12-27 10:44:40 +01:00
|
|
|
ynh_app_setting_set seafile unprotected_uris "/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
|
2016-12-27 10:44:40 +01:00
|
|
|
ynh_app_setting_delete seafile unprotected_uris
|
2014-08-15 03:10:10 +02:00
|
|
|
else
|
2017-07-21 14:56:41 +02:00
|
|
|
ynh_app_setting_set seafile unprotected_uris "/"
|
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
|
2017-12-02 00:18:39 +01:00
|
|
|
ynh_use_logrotate $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
|
2017-07-21 14:56:41 +02:00
|
|
|
yunohost service add seafile-server
|
2015-05-20 15:13:35 +02:00
|
|
|
|
2015-08-29 13:25:04 +02:00
|
|
|
# Restart seafile
|
2017-07-21 14:56:41 +02:00
|
|
|
su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-latest/seahub.sh stop"
|
|
|
|
systemctl stop seafile-server.service
|
2017-08-09 15:34:10 +02:00
|
|
|
sleep 2
|
|
|
|
|
|
|
|
# We kill all process lunched by the script
|
|
|
|
pkill -f seafile-controller || true
|
|
|
|
pkill -f seaf-server || true
|
|
|
|
|
|
|
|
systemctl start seafile-server.service
|