2015-03-17 01:15:44 +01:00
|
|
|
#!/bin/bash
|
2014-08-07 02:57:24 +02:00
|
|
|
# Retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
2014-08-08 05:16:24 +02:00
|
|
|
server_name=$3
|
2015-02-20 15:07:18 +01:00
|
|
|
admin=$4
|
|
|
|
admin_password=$5
|
|
|
|
is_public=$6
|
2014-08-07 04:42:27 +02:00
|
|
|
final_path=/var/www/seafile
|
2015-02-10 14:42:32 +01:00
|
|
|
seafile_data=/home/yunohost.app/seafile-data
|
|
|
|
seafile_version=4.0.6
|
|
|
|
|
|
|
|
# Retrieve admin email
|
|
|
|
admin_email=$(sudo yunohost user info $admin | grep mail: | sed "s/mail: //g")
|
2014-08-07 02:57:24 +02:00
|
|
|
|
2014-08-15 02:22:39 +02:00
|
|
|
port=''
|
|
|
|
findPort () {
|
|
|
|
port=$1
|
|
|
|
|
|
|
|
sudo yunohost app checkport $port
|
|
|
|
while [[ ! $? -eq 0 ]]
|
|
|
|
do
|
|
|
|
port=$(($port + 1))
|
|
|
|
sudo yunohost app checkport $port
|
|
|
|
done
|
|
|
|
|
|
|
|
return $port
|
|
|
|
}
|
|
|
|
|
2014-08-07 02:57:24 +02:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a seafile
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check dependencies
|
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
|
|
|
|
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
|
2014-08-12 03:18:09 +02:00
|
|
|
sudo tar xzf ../sources/'seafile-server_'$seafile_version'_x86-64.tar'
|
2014-08-08 02:59:46 +02:00
|
|
|
sudo mv seafile-server-$seafile_version/* $final_path/seafile-server-$seafile_version
|
2014-08-07 05:12:54 +02:00
|
|
|
sudo mv ../sources/'seafile-server_'$seafile_version'_x86-64.tar' $final_path/installed
|
2014-08-07 04:42:27 +02:00
|
|
|
|
2014-08-08 05:16:24 +02:00
|
|
|
# Find available ports
|
2014-08-15 02:22:39 +02:00
|
|
|
findPort 10001
|
|
|
|
ccnet_port=$port
|
|
|
|
findPort 12001
|
|
|
|
seafile_port=$port
|
|
|
|
findPort 8000
|
|
|
|
seahub_port=$port
|
2015-02-10 14:42:32 +01:00
|
|
|
findPort 8082
|
|
|
|
fileserver_port=$port
|
2014-08-15 02:22:39 +02:00
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# store config in yunohost
|
2014-08-15 02:22:39 +02:00
|
|
|
sudo yunohost app setting seafile ccnet_port -v $ccnet_port
|
|
|
|
sudo yunohost app setting seafile seafile_port -v $seafile_port
|
|
|
|
sudo yunohost app setting seafile seahub_port -v $seahub_port
|
2015-02-10 14:42:32 +01:00
|
|
|
sudo yunohost app setting seafile fileserver_port -v $fileserver_port
|
2014-08-15 03:10:10 +02:00
|
|
|
sudo yunohost app setting seafile is_public -v $is_public
|
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# init databases
|
|
|
|
db_user=seafile
|
|
|
|
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
|
|
|
sudo yunohost app initdb -d ccnetdb -p $db_pwd $db_user
|
|
|
|
sudo yunohost app initdb -d seafiledb -p $db_pwd $db_user
|
|
|
|
sudo yunohost app initdb -d seahubdb -p $db_pwd $db_user
|
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
|
2015-02-20 15:07:18 +01:00
|
|
|
sudo ../conf/install.exp $server_name $domain $ccnet_port $seafile_data $seafile_port $fileserver_port $db_pwd
|
2014-08-07 05:12:54 +02:00
|
|
|
|
2015-02-10 14:42:32 +01:00
|
|
|
# Update seafile config
|
|
|
|
sudo sed -i "s@http://@https://@g" $final_path/ccnet/ccnet.conf
|
2014-08-12 03:18:09 +02:00
|
|
|
sudo sed -i "s@:8000@$path@g" $final_path/ccnet/ccnet.conf
|
2015-02-10 14:42:32 +01:00
|
|
|
echo 'FILE_SERVER_ROOT = "https://'$domain'/seafhttp"' | sudo tee -a $final_path/seahub_settings.py
|
2014-08-12 03:18:09 +02:00
|
|
|
echo 'SITE_ROOT = "'$path'/"' | sudo tee -a $final_path/seahub_settings.py
|
2015-02-20 15:07:18 +01:00
|
|
|
echo 'SERVE_STATIC = False' | sudo tee -a $final_path/seahub_settings.py
|
|
|
|
echo 'MEDIA_URL = "'$path'/media/"' | sudo tee -a $final_path/seahub_settings.py
|
2014-08-13 05:14:22 +02:00
|
|
|
|
2014-08-13 03:21:47 +02:00
|
|
|
# LDAP configuration
|
|
|
|
echo '[LDAP]' | sudo tee -a $final_path/ccnet/ccnet.conf
|
|
|
|
echo 'HOST = ldap://localhost:389' | sudo tee -a $final_path/ccnet/ccnet.conf
|
|
|
|
echo 'BASE = ou=users,dc=yunohost,dc=org' | sudo tee -a $final_path/ccnet/ccnet.conf
|
2014-08-15 02:22:39 +02:00
|
|
|
echo 'LOGIN_ATTR = mail' | sudo tee -a $final_path/ccnet/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
|
2014-08-07 02:57:24 +02:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/seafile.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
|
|
|
|
sudo chown -R www-data:www-data $final_path
|
|
|
|
sudo chown -R www-data:www-data $seafile_data
|
|
|
|
|
2014-08-13 03:21:47 +02:00
|
|
|
# Open port
|
2014-08-15 02:22:39 +02:00
|
|
|
sudo yunohost firewall allow $ccnet_port
|
|
|
|
sudo yunohost firewall allow $seafile_port
|
|
|
|
|
2015-02-20 16:57:26 +01:00
|
|
|
# Start seafile, seahub and populate admin account
|
|
|
|
sudo su - www-data -c "/var/www/seafile/seafile-server-4.0.6/seafile.sh start"
|
|
|
|
sudo su - www-data -c "$final_path/first_launch.exp $admin_email $admin_password"
|
|
|
|
|
|
|
|
#sudo yunohost app setting seafile skipped_urls -v "/media"
|
|
|
|
#sudo yunohost app setting seafile unprotected_urls -v "/"
|
2015-02-20 15:07:18 +01:00
|
|
|
|
2015-03-17 01:15:44 +01:00
|
|
|
if [ "$is_public" = "No" ]
|
2014-08-15 03:10:10 +02:00
|
|
|
then
|
2015-03-17 01:15:44 +01:00
|
|
|
sudo yunohost app setting seafile unprotected_urls -d
|
2014-08-15 03:10:10 +02:00
|
|
|
else
|
2015-03-17 01:15:44 +01:00
|
|
|
sudo yunohost app setting seafile unprotected_urls -v "/"
|
2014-08-15 03:10:10 +02:00
|
|
|
fi
|
2015-02-10 14:42:32 +01:00
|
|
|
|
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
|