2015-03-17 01:15:44 +01:00
|
|
|
#!/bin/bash
|
2015-10-28 16:04:51 +01:00
|
|
|
|
2017-01-05 23:24:32 +01:00
|
|
|
# Import common cmd
|
|
|
|
source ./_common.sh
|
|
|
|
|
|
|
|
# Init script
|
|
|
|
init_script
|
2015-10-28 16:04:51 +01:00
|
|
|
|
2014-08-07 02:57:24 +02:00
|
|
|
# Retrieve arguments
|
2017-01-05 23:24:32 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
server_name=$YNH_APP_ARG_SERVER_NAME
|
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
admin_password=$YNH_APP_ARG_ADMIN_PASSWORD
|
|
|
|
is_public=$YNH_APP_ARG_PUBLIC_SITE
|
|
|
|
architecture=$YNH_APP_ARG_ARCHITECTURE
|
2015-02-10 14:42:32 +01:00
|
|
|
seafile_data=/home/yunohost.app/seafile-data
|
2017-01-05 23:24:32 +01:00
|
|
|
final_path=/var/www/$app
|
|
|
|
seafile_user=www-data
|
2016-12-27 10:44:40 +01:00
|
|
|
|
2017-01-05 23:24:32 +01:00
|
|
|
# Correct path if it is not correct
|
2017-01-31 23:25:17 +01:00
|
|
|
CHECK_PATH
|
2016-12-27 10:44:40 +01:00
|
|
|
|
|
|
|
# Check domain/path availability
|
2017-01-05 23:24:32 +01:00
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
2016-12-27 10:44:40 +01:00
|
|
|
|
|
|
|
# Download new version from sources
|
|
|
|
get_source $architecture $seafile_version
|
2015-02-10 14:42:32 +01:00
|
|
|
|
|
|
|
# Retrieve admin email
|
|
|
|
admin_email=$(sudo yunohost user info $admin | grep mail: | sed "s/mail: //g")
|
2014-08-07 02:57:24 +02:00
|
|
|
|
|
|
|
# Check dependencies
|
2015-12-26 14:15:26 +01:00
|
|
|
sudo apt-get update
|
2015-02-10 14:42:32 +01:00
|
|
|
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
|
2014-08-07 02:57:24 +02:00
|
|
|
|
|
|
|
# Copy files to the right place
|
2017-01-05 23:24:32 +01:00
|
|
|
test -e $final_path && sudo rm -rf "$final_path"
|
|
|
|
test -e $seafile_data && sudo rm -rf "$seafile_data"
|
2014-08-07 02:57:24 +02:00
|
|
|
sudo mkdir -p $final_path
|
2014-08-07 05:12:54 +02:00
|
|
|
sudo mkdir -p $final_path/installed
|
2014-08-12 03:18:09 +02:00
|
|
|
sudo mkdir -p $final_path/logs
|
2014-08-07 05:12:54 +02:00
|
|
|
sudo mkdir -p $final_path/seafile-data
|
|
|
|
sudo mkdir -p $final_path/seafile-server-$seafile_version
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo tar xzf '/tmp/seafile_src.tar.gz'
|
2015-10-28 16:38:27 +01:00
|
|
|
sudo mv seafile-server-$seafile_version/* $final_path/seafile-server-$seafile_version
|
2017-01-05 23:24:32 +01:00
|
|
|
sudo mv '/tmp/seafile_src.tar.gz' $final_path/installed/seafile-server_${seafile_version}.tar.gz
|
2014-08-07 04:42:27 +02:00
|
|
|
|
2014-08-08 05:16:24 +02:00
|
|
|
# Find available ports
|
2017-03-07 15:44:28 +01:00
|
|
|
seahub_port=$(ynh_find_port 8000)
|
|
|
|
fileserver_port=$(ynh_find_port 8082)
|
|
|
|
webdav_port=$(ynh_find_port 8080)
|
2014-08-15 02:22:39 +02:00
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# store config in yunohost
|
2016-12-27 10:44:40 +01:00
|
|
|
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 architecture $architecture
|
|
|
|
ynh_app_setting_set $app installed_version $seafile_version
|
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
|
|
|
|
2014-08-07 05:12:54 +02:00
|
|
|
# Run install script
|
2015-02-20 15:07:18 +01:00
|
|
|
sudo chmod +x ../conf/install.exp
|
2015-02-10 14:42:32 +01:00
|
|
|
sudo chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
|
2016-01-07 21:44:33 +01:00
|
|
|
sudo ../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
|
2015-12-26 13:44:01 +01:00
|
|
|
sudo sed -i "s@http://@https://@g" $final_path/conf/ccnet.conf
|
|
|
|
sudo sed -i "s@:8000@$path@g" $final_path/conf/ccnet.conf
|
|
|
|
echo 'FILE_SERVER_ROOT = "https://'$domain'/seafhttp"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'SITE_ROOT = "'$path'/"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'SERVE_STATIC = False' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'MEDIA_URL = "'$path'/media/"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'COMPRESS_URL = MEDIA_URL' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo "STATIC_URL = MEDIA_URL + 'assets/'" | sudo tee -a $final_path/conf/seahub_settings.py
|
2017-01-05 23:24:32 +01:00
|
|
|
echo "LOGIN_URL = '"$path"/accounts/login/'" | sudo 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
|
2015-12-26 13:44:01 +01:00
|
|
|
echo 'EMAIL_USE_TLS = False' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_HOST = "localhost"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_HOST_USER = "seafile@'$domain'"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_HOST_PASSWORD = ""' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'EMAIL_PORT = "25"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'DEFAULT_FROM_EMAIL = "seafile@'$domain'"' | sudo tee -a $final_path/conf/seahub_settings.py
|
|
|
|
echo 'SERVER_EMAIL = "seafile@'$domain'"' | sudo 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
|
2015-12-26 13:44:01 +01:00
|
|
|
echo '[LDAP]' | sudo tee -a $final_path/conf/ccnet.conf
|
|
|
|
echo 'HOST = ldap://localhost:389' | sudo tee -a $final_path/conf/ccnet.conf
|
|
|
|
echo 'BASE = ou=users,dc=yunohost,dc=org' | sudo tee -a $final_path/conf/ccnet.conf
|
|
|
|
echo 'LOGIN_ATTR = mail' | sudo tee -a $final_path/conf/ccnet.conf
|
2014-08-13 03:21:47 +02:00
|
|
|
|
2014-08-07 04:42:27 +02:00
|
|
|
# Add Seafile Server to startup
|
2014-08-12 03:18:09 +02:00
|
|
|
sudo cp ../conf/seafile-server /etc/init.d
|
2015-02-10 14:42:32 +01:00
|
|
|
sudo sed -i "s@SEAHUB_PORT@$seahub_port@g" /etc/init.d/seafile-server
|
|
|
|
sudo sed -i "s@SEAFILE_DIR@$final_path@g" /etc/init.d/seafile-server
|
2014-08-12 03:18:09 +02:00
|
|
|
sudo chmod +x /etc/init.d/seafile-server
|
|
|
|
sudo update-rc.d seafile-server defaults
|
2014-08-07 02:57:24 +02:00
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
2014-08-12 03:18:09 +02:00
|
|
|
sed -i "s@SEAHUB_PORT@$seahub_port@g" ../conf/nginx.conf
|
2015-02-10 14:42:32 +01:00
|
|
|
sed -i "s@SEAFILE_FILESERVER_PORT@$fileserver_port@g" ../conf/nginx.conf
|
2015-08-24 20:45:36 +02:00
|
|
|
sed -i "s@WEBDAV_PORT@$webdav_port@g" ../conf/nginx.conf
|
2014-08-07 02:57:24 +02:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/seafile.conf
|
|
|
|
|
2015-08-29 13:25:04 +02:00
|
|
|
# Add webdav
|
|
|
|
sudo cp ../conf/seafdav.conf $final_path/conf/seafdav.conf
|
|
|
|
sudo sed -i "s@WEBDAV_PORT@$webdav_port@g" $final_path/conf/seafdav.conf
|
|
|
|
|
2015-02-20 16:57:26 +01:00
|
|
|
# Copy first launch script
|
|
|
|
sudo cp ../conf/first_launch.exp $final_path
|
|
|
|
sudo chmod +x $final_path/first_launch.exp
|
|
|
|
|
2015-02-20 15:07:18 +01:00
|
|
|
# Set permissions to seafile directory
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo chown -R $seafile_user:$seafile_user $final_path
|
|
|
|
sudo 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
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-$seafile_version/seafile.sh start"
|
|
|
|
sudo su - $seafile_user -s /bin/bash -c "$final_path/first_launch.exp $final_path/seafile-server-$seafile_version $admin_email $admin_password"
|
2015-02-20 16:57:26 +01:00
|
|
|
|
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
|
2015-03-18 18:07:50 +01:00
|
|
|
sudo cp ../conf/add_sso_conf.py $final_path
|
|
|
|
sudo cp ../conf/remove_sso_conf.py $final_path
|
|
|
|
sudo python $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
|
2016-12-27 10:44:40 +01: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
|
|
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/seafile
|
|
|
|
sudo sed -i "s@SEAFILE_DIR@$final_path@g" /etc/logrotate.d/seafile
|
|
|
|
sudo service rsyslog restart
|
|
|
|
|
2015-02-20 15:07:18 +01:00
|
|
|
# register yunohost service
|
|
|
|
sudo yunohost service add seafile-server
|
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|
2015-05-20 15:13:35 +02:00
|
|
|
|
2015-08-29 13:25:04 +02:00
|
|
|
# Restart seafile
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo su - $seafile_user -s /bin/bash -c "$final_path/seafile-server-latest/seahub.sh stop"
|
2015-08-29 13:25:04 +02:00
|
|
|
sudo service seafile-server stop
|
2016-12-27 10:44:40 +01:00
|
|
|
sudo service seafile-server start
|