mirror of
https://github.com/YunoHost-Apps/seafile_ynh.git
synced 2024-09-03 20:26:01 +02:00
parent
ef95be2c67
commit
b206f1f24d
10 changed files with 139 additions and 908 deletions
62
conf/install.exp
Normal file
62
conf/install.exp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#!/usr/bin/expect
|
||||||
|
set timeout 10
|
||||||
|
|
||||||
|
set server_name [lindex $argv 0]
|
||||||
|
set domain [lindex $argv 1]
|
||||||
|
set ccnet_port [lindex $argv 2]
|
||||||
|
set seafile_data [lindex $argv 3]
|
||||||
|
set seafile_port [lindex $argv 4]
|
||||||
|
set fileserver_port [lindex $argv 5]
|
||||||
|
set db_pwd [lindex $argv 6]
|
||||||
|
|
||||||
|
spawn /var/www/seafile/seafile-server-4.0.6/setup-seafile-mysql.sh
|
||||||
|
|
||||||
|
expect "Press ENTER to continue"
|
||||||
|
send "\r";
|
||||||
|
|
||||||
|
expect "What is the name of the server? It will be displayed on the client."
|
||||||
|
send "$server_name\r";
|
||||||
|
|
||||||
|
expect "What is the ip or domain of the server?"
|
||||||
|
send "$domain\r";
|
||||||
|
|
||||||
|
expect "Which port do you want to use for the ccnet server?"
|
||||||
|
send "$ccnet_port\r";
|
||||||
|
|
||||||
|
expect "Where do you want to put your seafile data?"
|
||||||
|
send "$seafile_data\r";
|
||||||
|
|
||||||
|
expect "Which port do you want to use for the seafile server?"
|
||||||
|
send "$seafile_port\r";
|
||||||
|
|
||||||
|
expect "Which port do you want to use for the seafile fileserver?"
|
||||||
|
send "$fileserver_port\r";
|
||||||
|
|
||||||
|
expect "Use existing ccnet/seafile/seahub databases"
|
||||||
|
send "2\r";
|
||||||
|
|
||||||
|
expect "What is the host of mysql server?"
|
||||||
|
send "localhost\r";
|
||||||
|
|
||||||
|
expect "What is the port of mysql server?"
|
||||||
|
send "3306\r";
|
||||||
|
|
||||||
|
expect "Which mysql user to use for seafile?"
|
||||||
|
send "seafile\r";
|
||||||
|
|
||||||
|
expect "What is the password for mysql user"
|
||||||
|
send "$db_pwd\r";
|
||||||
|
|
||||||
|
expect "Enter the existing database name for ccnet:"
|
||||||
|
send "ccnetdb\r";
|
||||||
|
|
||||||
|
expect "Enter the existing database name for seafile:"
|
||||||
|
send "seafiledb\r";
|
||||||
|
|
||||||
|
expect "Enter the existing database name for seahub:"
|
||||||
|
send "seahubdb\r";
|
||||||
|
|
||||||
|
expect "Press ENTER to continue, or Ctrl-C to abort"
|
||||||
|
send "\r";
|
||||||
|
|
||||||
|
interact
|
|
@ -3,7 +3,7 @@ location PATHTOCHANGE {
|
||||||
if ($scheme = http) {
|
if ($scheme = http) {
|
||||||
rewrite ^ https://$server_name$request_uri? permanent;
|
rewrite ^ https://$server_name$request_uri? permanent;
|
||||||
}
|
}
|
||||||
client_max_body_size 10G;
|
client_max_body_size 0;
|
||||||
|
|
||||||
fastcgi_pass 127.0.0.1:SEAHUB_PORT;
|
fastcgi_pass 127.0.0.1:SEAHUB_PORT;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ location PATHTOCHANGE {
|
||||||
fastcgi_param SERVER_ADDR $server_addr;
|
fastcgi_param SERVER_ADDR $server_addr;
|
||||||
fastcgi_param SERVER_PORT $server_port;
|
fastcgi_param SERVER_PORT $server_port;
|
||||||
fastcgi_param SERVER_NAME $server_name;
|
fastcgi_param SERVER_NAME $server_name;
|
||||||
fastcgi_param HTTPS on;
|
fastcgi_param REMOTE_ADDR $remote_addr;
|
||||||
|
|
||||||
access_log /var/log/nginx/seahub.access.log;
|
access_log /var/log/nginx/seahub.access.log;
|
||||||
error_log /var/log/nginx/seahub.error.log;
|
error_log /var/log/nginx/seahub.error.log;
|
||||||
|
@ -28,14 +28,15 @@ location PATHTOCHANGE {
|
||||||
include conf.d/yunohost_panel.conf.inc;
|
include conf.d/yunohost_panel.conf.inc;
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* ^PATHTOCHANGE/media/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt|woff|ttf))$ {
|
|
||||||
root ALIASTOCHANGEseafile-server-latest/;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /seafhttp {
|
location /seafhttp {
|
||||||
rewrite ^/seafhttp(.*)$ $1 break;
|
rewrite ^/seafhttp(.*)$ $1 break;
|
||||||
proxy_pass http://127.0.0.1:SEAFILE_FILESERVER_PORT;
|
proxy_pass http://127.0.0.1:SEAFILE_FILESERVER_PORT;
|
||||||
client_max_body_size 0;
|
client_max_body_size 0;
|
||||||
}
|
proxy_connect_timeout 36000s;
|
||||||
|
proxy_read_timeout 36000s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
location PATHTOCHANGE/media {
|
||||||
|
root ALIASTOCHANGEseafile-server-latest/seahub;
|
||||||
|
}
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
### BEGIN INIT INFO
|
||||||
# Provides: seafile-server
|
# Provides: seafile-server
|
||||||
# Should-Start: seafile-server
|
# Required-Start: $local_fs $remote_fs $network mysql
|
||||||
# Required-Start: $all
|
# Required-Stop: $local_fs
|
||||||
# Required-Stop:
|
|
||||||
# Default-Start: 2 3 4 5
|
# Default-Start: 2 3 4 5
|
||||||
# Default-Stop: 0 1 6
|
# Default-Stop: 0 1 6
|
||||||
# Short-Description: start seafile-server at boot time
|
# Short-Description: Starts Seafile Server
|
||||||
|
# Description: starts Seafile Server
|
||||||
### END INIT INFO
|
### END INIT INFO
|
||||||
#
|
|
||||||
# Change the value of "user" to your linux user name
|
|
||||||
user=root
|
|
||||||
|
|
||||||
# Change the value of "seafile_dir" to your path of seafile installation
|
# Change the value of "user" to your linux user name
|
||||||
|
user=www-data
|
||||||
|
|
||||||
|
# Change the value of "script_path" to your path of seafile installation
|
||||||
seafile_dir=SEAFILE_DIR
|
seafile_dir=SEAFILE_DIR
|
||||||
script_path=${seafile_dir}/seafile-server-latest
|
script_path=${seafile_dir}/seafile-server-latest
|
||||||
seafile_init_log=${seafile_dir}/logs/seafile.init.log
|
seafile_init_log=${seafile_dir}/logs/seafile.init.log
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
"fr": "Stockage Cloud Open Source"
|
"fr": "Stockage Cloud Open Source"
|
||||||
},
|
},
|
||||||
"developer": {
|
"developer": {
|
||||||
"name": "ElieSauveterre",
|
"name": "",
|
||||||
"email": "contact@mikangali.om",
|
"email": "",
|
||||||
"url": "http://www.mikangali.com/"
|
"url": ""
|
||||||
},
|
},
|
||||||
"multi_instance": "false",
|
"multi_instance": "false",
|
||||||
"arguments": {
|
"arguments": {
|
||||||
|
@ -16,14 +16,16 @@
|
||||||
{
|
{
|
||||||
"name": "domain",
|
"name": "domain",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose a domain for Seafile"
|
"en": "Choose a domain for Seafile",
|
||||||
|
"fr": "Choisissez un domaine pour Seafile"
|
||||||
},
|
},
|
||||||
"example": "domain.org"
|
"example": "domain.org"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "path",
|
"name": "path",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose a path for Seafile"
|
"en": "Choose a path for Seafile",
|
||||||
|
"fr": "Choisissez un chemin pour Seafile"
|
||||||
},
|
},
|
||||||
"example": "/seafile",
|
"example": "/seafile",
|
||||||
"default": "/seafile"
|
"default": "/seafile"
|
||||||
|
@ -31,25 +33,12 @@
|
||||||
{
|
{
|
||||||
"name": "server_name",
|
"name": "server_name",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Choose a name"
|
"en": "Choose a name",
|
||||||
|
"fr": "Choisissez un nom"
|
||||||
},
|
},
|
||||||
"example": "Seafile",
|
"example": "Seafile",
|
||||||
"default": "Seafile"
|
"default": "Seafile"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "admin_email",
|
|
||||||
"ask": {
|
|
||||||
"en": "Enter an email for the administrator"
|
|
||||||
},
|
|
||||||
"example": "homer@domain.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "admin_password",
|
|
||||||
"ask": {
|
|
||||||
"en": "Enter a password for the administrator"
|
|
||||||
},
|
|
||||||
"example": "**Sup3rS3cr3t**"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "public_site",
|
"name": "public_site",
|
||||||
"ask": {
|
"ask": {
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
domain=$1
|
domain=$1
|
||||||
path=$2
|
path=$2
|
||||||
server_name=$3
|
server_name=$3
|
||||||
admin_email=$4
|
is_public=$4
|
||||||
admin_password=$5
|
|
||||||
is_public=$6
|
|
||||||
final_path=/var/www/seafile
|
final_path=/var/www/seafile
|
||||||
seafile_data=$final_path/seafile-data
|
seafile_data=/home/yunohost.app/seafile-data
|
||||||
seafile_version=3.1.1
|
seafile_version=4.0.6
|
||||||
|
|
||||||
|
# Retrieve admin email
|
||||||
|
admin_email=$(sudo yunohost user info $admin | grep mail: | sed "s/mail: //g")
|
||||||
|
|
||||||
port=''
|
port=''
|
||||||
findPort () {
|
findPort () {
|
||||||
|
@ -31,7 +32,7 @@ if [[ ! $? -eq 0 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check dependencies
|
# Check dependencies
|
||||||
sudo apt-get install -y python2.7 python-setuptools python-simplejson python-imaging python-mysqldb sqlite3
|
sudo apt-get install -qq python2.7 python-setuptools python-simplejson python-imaging python-mysqldb python-flup expect
|
||||||
|
|
||||||
# Copy files to the right place
|
# Copy files to the right place
|
||||||
sudo mkdir -p $final_path
|
sudo mkdir -p $final_path
|
||||||
|
@ -51,42 +52,36 @@ findPort 10001
|
||||||
ccnet_port=$port
|
ccnet_port=$port
|
||||||
findPort 12001
|
findPort 12001
|
||||||
seafile_port=$port
|
seafile_port=$port
|
||||||
findPort 8082
|
|
||||||
seafile_fileserver_port=$port
|
|
||||||
findPort 8000
|
findPort 8000
|
||||||
seahub_port=$port
|
seahub_port=$port
|
||||||
|
findPort 8082
|
||||||
|
fileserver_port=$port
|
||||||
|
|
||||||
|
# store config in yunohost
|
||||||
sudo yunohost app setting seafile ccnet_port -v $ccnet_port
|
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 seafile_port -v $seafile_port
|
||||||
sudo yunohost app setting seafile seafile_fileserver_port -v $seafile_fileserver_port
|
|
||||||
sudo yunohost app setting seafile seahub_port -v $seahub_port
|
sudo yunohost app setting seafile seahub_port -v $seahub_port
|
||||||
|
sudo yunohost app setting seafile fileserver_port -v $fileserver_port
|
||||||
sudo yunohost app setting seafile is_public -v $is_public
|
sudo yunohost app setting seafile is_public -v $is_public
|
||||||
|
|
||||||
|
# init databases
|
||||||
# Modify install script with parameters
|
db_user=seafile
|
||||||
sed -i "s@SERVER_NAME@$server_name@g" ../sources/setup-seafile.sh
|
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')
|
||||||
sed -i "s@DOMAIN@$domain@g" ../sources/setup-seafile.sh
|
sudo yunohost app initdb -d ccnetdb -p $db_pwd $db_user
|
||||||
sed -i "s@CCNET_PORT@$ccnet_port@g" ../sources/setup-seafile.sh
|
sudo yunohost app initdb -d seafiledb -p $db_pwd $db_user
|
||||||
sed -i "s@SEAFILE_DATA@$seafile_data@g" ../sources/setup-seafile.sh
|
sudo yunohost app initdb -d seahubdb -p $db_pwd $db_user
|
||||||
sed -i "s@SEAFILE_PORT@$seafile_port@g" ../sources/setup-seafile.sh
|
|
||||||
sed -i "s@SEAFILE_FILESERVER_PORT@$seafile_fileserver_port@g" ../sources/setup-seafile.sh
|
|
||||||
sed -i "s/ADMIN_EMAIL/$admin_email/g" ../sources/check_init_admin.py
|
|
||||||
sed -i "s/ADMIN_PASSWORD/$admin_password/g" ../sources/check_init_admin.py
|
|
||||||
|
|
||||||
# Run install script
|
# Run install script
|
||||||
sudo cp ../sources/check_init_admin.py $final_path/seafile-server-$seafile_version
|
sudo cp ../conf/install.exp $final_path/seafile-server-$seafile_version
|
||||||
sudo cp ../sources/setup-seafile.sh $final_path/seafile-server-$seafile_version
|
sudo chmod +x $final_path/seafile-server-$seafile_version/install.exp
|
||||||
sudo chmod +x $final_path/seafile-server-$seafile_version/setup-seafile.sh
|
sudo chmod +x $final_path/seafile-server-$seafile_version/setup-seafile-mysql.sh
|
||||||
sudo $final_path/seafile-server-$seafile_version/setup-seafile.sh
|
sudo $final_path/seafile-server-$seafile_version/install.exp $server_name $domain $ccnet_port $seafile_data $seafile_port $fileserver_port $db_pwd
|
||||||
|
|
||||||
# Update config
|
# Update seafile config
|
||||||
|
sudo sed -i "s@http://@https://@g" $final_path/ccnet/ccnet.conf
|
||||||
sudo sed -i "s@:8000@$path@g" $final_path/ccnet/ccnet.conf
|
sudo sed -i "s@:8000@$path@g" $final_path/ccnet/ccnet.conf
|
||||||
echo 'SERVE_STATIC = False' | sudo tee -a $final_path/seahub_settings.py
|
echo 'FILE_SERVER_ROOT = "https://'$domain'/seafhttp"' | sudo tee -a $final_path/seahub_settings.py
|
||||||
echo 'MEDIA_URL = "'$path'/media/"' | sudo tee -a $final_path/seahub_settings.py
|
|
||||||
echo 'SITE_ROOT = "'$path'/"' | sudo tee -a $final_path/seahub_settings.py
|
echo 'SITE_ROOT = "'$path'/"' | sudo tee -a $final_path/seahub_settings.py
|
||||||
echo 'FILE_SERVER_ROOT = "http://'$domain$path'"' | sudo tee -a $final_path/seahub_settings.py
|
|
||||||
|
|
||||||
|
|
||||||
# LDAP configuration
|
# LDAP configuration
|
||||||
echo '[LDAP]' | sudo tee -a $final_path/ccnet/ccnet.conf
|
echo '[LDAP]' | sudo tee -a $final_path/ccnet/ccnet.conf
|
||||||
|
@ -94,40 +89,23 @@ 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
|
echo 'BASE = ou=users,dc=yunohost,dc=org' | sudo tee -a $final_path/ccnet/ccnet.conf
|
||||||
echo 'LOGIN_ATTR = mail' | sudo tee -a $final_path/ccnet/ccnet.conf
|
echo 'LOGIN_ATTR = mail' | sudo tee -a $final_path/ccnet/ccnet.conf
|
||||||
|
|
||||||
|
|
||||||
# Symlink for media ( because only $path is accessible, not /seahub )
|
|
||||||
sudo ln -s $final_path/seafile-server-$seafile_version/seahub/media/ $final_path/seafile-server-$seafile_version/seafile/media
|
|
||||||
|
|
||||||
# Add Seafile Server to startup
|
# Add Seafile Server to startup
|
||||||
sed -i "s@SEAHUB_PORT@$seahub_port@g" ../conf/seafile-server
|
|
||||||
sed -i "s@SEAFILE_DIR@$final_path@g" ../conf/seafile-server
|
|
||||||
sudo cp ../conf/seafile-server /etc/init.d
|
sudo cp ../conf/seafile-server /etc/init.d
|
||||||
|
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
|
||||||
sudo chmod +x /etc/init.d/seafile-server
|
sudo chmod +x /etc/init.d/seafile-server
|
||||||
sudo cp ../conf/seafile-server.conf /etc/init
|
|
||||||
sudo update-rc.d seafile-server defaults
|
sudo update-rc.d seafile-server defaults
|
||||||
|
|
||||||
# Start Seafile Server
|
|
||||||
sudo $final_path/seafile-server-$seafile_version/seafile.sh start
|
|
||||||
sudo $final_path/seafile-server-$seafile_version/seahub.sh start-fastcgi $seahub_port
|
|
||||||
|
|
||||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
||||||
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
||||||
sed -i "s@SEAHUB_PORT@$seahub_port@g" ../conf/nginx.conf
|
sed -i "s@SEAHUB_PORT@$seahub_port@g" ../conf/nginx.conf
|
||||||
sed -i "s@SEAFILE_FILESERVER_PORT@$seafile_fileserver_port@g" ../conf/nginx.conf
|
sed -i "s@SEAFILE_FILESERVER_PORT@$fileserver_port@g" ../conf/nginx.conf
|
||||||
sed -i "s@SEAFILE_PATH@$final_path@g" ../conf/nginx.conf
|
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/seafile.conf
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/seafile.conf
|
||||||
|
|
||||||
|
|
||||||
# Reload Nginx and regenerate SSOwat conf
|
|
||||||
sudo service nginx reload
|
|
||||||
sudo yunohost app ssowatconf
|
|
||||||
|
|
||||||
# Open port
|
# Open port
|
||||||
sudo yunohost firewall allow $ccnet_port
|
sudo yunohost firewall allow $ccnet_port
|
||||||
sudo yunohost firewall allow $seafile_port
|
sudo yunohost firewall allow $seafile_port
|
||||||
sudo yunohost firewall allow $seahub_port
|
|
||||||
|
|
||||||
|
|
||||||
if [ "$is_public" = "No" ];
|
if [ "$is_public" = "No" ];
|
||||||
then
|
then
|
||||||
|
@ -136,3 +114,10 @@ then
|
||||||
else
|
else
|
||||||
sudo yunohost app setting seafile skipped_uris -v "/"
|
sudo yunohost app setting seafile skipped_uris -v "/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Reload Nginx and regenerate SSOwat conf
|
||||||
|
sudo service nginx reload
|
||||||
|
sudo yunohost app ssowatconf
|
||||||
|
|
||||||
|
# Start Seafile Server
|
||||||
|
sudo service seafile-server start
|
|
@ -1,19 +1,23 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
domain=$(sudo yunohost app setting seafile domain)
|
domain=$(sudo yunohost app setting seafile domain)
|
||||||
|
root_pwd=$(sudo cat /etc/yunohost/mysql)
|
||||||
|
|
||||||
cd /var/www/seafile/seafile-server-*
|
sudo service seafile-server stop
|
||||||
sudo ./seafile.sh stop
|
|
||||||
sudo ./seahub.sh stop
|
|
||||||
|
|
||||||
sudo rm -rf /var/www/seafile
|
sudo rm -rf /var/www/seafile
|
||||||
sudo rm -f /etc/nginx/conf.d/$domain.d/seafile.conf
|
sudo rm -f /etc/nginx/conf.d/$domain.d/seafile.conf
|
||||||
sudo rm -f /etc/init.d/seafile-server
|
sudo rm -f /etc/init.d/seafile-server
|
||||||
sudo rm -f /etc/init/seafile-server.conf
|
sudo rm -rf /home/yunohost.app/seafile-data
|
||||||
|
|
||||||
|
# Remove databases
|
||||||
|
mysql -u root -p$root_pwd -e "DROP DATABASE ccnetdb ; DROP DATABASE seafiledb ; DROP DATABASE seahubdb ; DROP USER seafile@localhost ;"
|
||||||
|
|
||||||
ccnet_port=$(sudo yunohost app setting seafile ccnet_port)
|
ccnet_port=$(sudo yunohost app setting seafile ccnet_port)
|
||||||
seafile_port=$(sudo yunohost app setting seafile seafile_port)
|
seafile_port=$(sudo yunohost app setting seafile seafile_port)
|
||||||
seahub_port=$(sudo yunohost app setting seafile seahub_port)
|
|
||||||
|
|
||||||
sudo yunohost firewall disallow $ccnet_port
|
sudo yunohost firewall disallow $ccnet_port
|
||||||
sudo yunohost firewall disallow $seafile_port
|
sudo yunohost firewall disallow $seafile_port
|
||||||
sudo yunohost firewall disallow $seahub_port
|
|
||||||
|
# Restart services
|
||||||
|
sudo service nginx reload
|
||||||
|
sudo yunohost app ssowatconf
|
|
@ -1,371 +0,0 @@
|
||||||
#coding: UTF-8
|
|
||||||
|
|
||||||
'''This script would check if there is admin, and prompt the user to create a new one if non exist'''
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import time
|
|
||||||
import re
|
|
||||||
import shutil
|
|
||||||
import glob
|
|
||||||
import subprocess
|
|
||||||
import hashlib
|
|
||||||
import getpass
|
|
||||||
import uuid
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from ConfigParser import ConfigParser
|
|
||||||
|
|
||||||
try:
|
|
||||||
import readline # pylint: disable=W0611
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
SERVER_MANUAL_HTTP = 'https://github.com/haiwen/seafile/wiki'
|
|
||||||
|
|
||||||
class Utils(object):
|
|
||||||
'''Groups all helper functions here'''
|
|
||||||
@staticmethod
|
|
||||||
def welcome():
|
|
||||||
'''Show welcome message'''
|
|
||||||
welcome_msg = '''\
|
|
||||||
-----------------------------------------------------------------
|
|
||||||
This script will guide you to setup your seafile server using MySQL.
|
|
||||||
Make sure you have read seafile server manual at
|
|
||||||
|
|
||||||
%s
|
|
||||||
|
|
||||||
Press ENTER to continue
|
|
||||||
-----------------------------------------------------------------''' % SERVER_MANUAL_HTTP
|
|
||||||
print welcome_msg
|
|
||||||
raw_input()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def highlight(content):
|
|
||||||
'''Add ANSI color to content to get it highlighted on terminal'''
|
|
||||||
return '\x1b[33m%s\x1b[m' % content
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def info(msg):
|
|
||||||
print msg
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def error(msg):
|
|
||||||
'''Print error and exit'''
|
|
||||||
print
|
|
||||||
print 'Error: ' + msg
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def run_argv(argv, cwd=None, env=None, suppress_stdout=False, suppress_stderr=False):
|
|
||||||
'''Run a program and wait it to finish, and return its exit code. The
|
|
||||||
standard output of this program is supressed.
|
|
||||||
|
|
||||||
'''
|
|
||||||
with open(os.devnull, 'w') as devnull:
|
|
||||||
if suppress_stdout:
|
|
||||||
stdout = devnull
|
|
||||||
else:
|
|
||||||
stdout = sys.stdout
|
|
||||||
|
|
||||||
if suppress_stderr:
|
|
||||||
stderr = devnull
|
|
||||||
else:
|
|
||||||
stderr = sys.stderr
|
|
||||||
|
|
||||||
proc = subprocess.Popen(argv,
|
|
||||||
cwd=cwd,
|
|
||||||
stdout=stdout,
|
|
||||||
stderr=stderr,
|
|
||||||
env=env)
|
|
||||||
return proc.wait()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def run(cmdline, cwd=None, env=None, suppress_stdout=False, suppress_stderr=False):
|
|
||||||
'''Like run_argv but specify a command line string instead of argv'''
|
|
||||||
with open(os.devnull, 'w') as devnull:
|
|
||||||
if suppress_stdout:
|
|
||||||
stdout = devnull
|
|
||||||
else:
|
|
||||||
stdout = sys.stdout
|
|
||||||
|
|
||||||
if suppress_stderr:
|
|
||||||
stderr = devnull
|
|
||||||
else:
|
|
||||||
stderr = sys.stderr
|
|
||||||
|
|
||||||
proc = subprocess.Popen(cmdline,
|
|
||||||
cwd=cwd,
|
|
||||||
stdout=stdout,
|
|
||||||
stderr=stderr,
|
|
||||||
env=env,
|
|
||||||
shell=True)
|
|
||||||
return proc.wait()
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def prepend_env_value(name, value, env=None, seperator=':'):
|
|
||||||
'''prepend a new value to a list'''
|
|
||||||
if env is None:
|
|
||||||
env = os.environ
|
|
||||||
|
|
||||||
try:
|
|
||||||
current_value = env[name]
|
|
||||||
except KeyError:
|
|
||||||
current_value = ''
|
|
||||||
|
|
||||||
new_value = value
|
|
||||||
if current_value:
|
|
||||||
new_value += seperator + current_value
|
|
||||||
|
|
||||||
env[name] = new_value
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def must_mkdir(path):
|
|
||||||
'''Create a directory, exit on failure'''
|
|
||||||
try:
|
|
||||||
os.mkdir(path)
|
|
||||||
except OSError, e:
|
|
||||||
Utils.error('failed to create directory %s:%s' % (path, e))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def must_copy(src, dst):
|
|
||||||
'''Copy src to dst, exit on failure'''
|
|
||||||
try:
|
|
||||||
shutil.copy(src, dst)
|
|
||||||
except Exception, e:
|
|
||||||
Utils.error('failed to copy %s to %s: %s' % (src, dst, e))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def find_in_path(prog):
|
|
||||||
if 'win32' in sys.platform:
|
|
||||||
sep = ';'
|
|
||||||
else:
|
|
||||||
sep = ':'
|
|
||||||
|
|
||||||
dirs = os.environ['PATH'].split(sep)
|
|
||||||
for d in dirs:
|
|
||||||
d = d.strip()
|
|
||||||
if d == '':
|
|
||||||
continue
|
|
||||||
path = os.path.join(d, prog)
|
|
||||||
if os.path.exists(path):
|
|
||||||
return path
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_python_executable():
|
|
||||||
'''Return the python executable. This should be the PYTHON environment
|
|
||||||
variable which is set in setup-seafile-mysql.sh
|
|
||||||
|
|
||||||
'''
|
|
||||||
return os.environ['PYTHON']
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def read_config(fn):
|
|
||||||
'''Return a case sensitive ConfigParser by reading the file "fn"'''
|
|
||||||
cp = ConfigParser()
|
|
||||||
cp.optionxform = str
|
|
||||||
cp.read(fn)
|
|
||||||
|
|
||||||
return cp
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def write_config(cp, fn):
|
|
||||||
'''Return a case sensitive ConfigParser by reading the file "fn"'''
|
|
||||||
with open(fn, 'w') as fp:
|
|
||||||
cp.write(fp)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def ask_question(desc,
|
|
||||||
key=None,
|
|
||||||
note=None,
|
|
||||||
default=None,
|
|
||||||
validate=None,
|
|
||||||
yes_or_no=False,
|
|
||||||
password=False):
|
|
||||||
'''Ask a question, return the answer.
|
|
||||||
@desc description, e.g. "What is the port of ccnet?"
|
|
||||||
|
|
||||||
@key a name to represent the target of the question, e.g. "port for
|
|
||||||
ccnet server"
|
|
||||||
|
|
||||||
@note additional information for the question, e.g. "Must be a valid
|
|
||||||
port number"
|
|
||||||
|
|
||||||
@default the default value of the question. If the default value is
|
|
||||||
not None, when the user enter nothing and press [ENTER], the default
|
|
||||||
value would be returned
|
|
||||||
|
|
||||||
@validate a function that takes the user input as the only parameter
|
|
||||||
and validate it. It should return a validated value, or throws an
|
|
||||||
"InvalidAnswer" exception if the input is not valid.
|
|
||||||
|
|
||||||
@yes_or_no If true, the user must answer "yes" or "no", and a boolean
|
|
||||||
value would be returned
|
|
||||||
|
|
||||||
@password If true, the user input would not be echoed to the
|
|
||||||
console
|
|
||||||
|
|
||||||
'''
|
|
||||||
assert key or yes_or_no
|
|
||||||
# Format description
|
|
||||||
print
|
|
||||||
if note:
|
|
||||||
desc += '\n' + note
|
|
||||||
|
|
||||||
desc += '\n'
|
|
||||||
if yes_or_no:
|
|
||||||
desc += '[ yes or no ]'
|
|
||||||
else:
|
|
||||||
if default:
|
|
||||||
desc += '[ default "%s" ]' % default
|
|
||||||
else:
|
|
||||||
desc += '[ %s ]' % key
|
|
||||||
|
|
||||||
desc += ' '
|
|
||||||
while True:
|
|
||||||
# prompt for user input
|
|
||||||
if password:
|
|
||||||
answer = getpass.getpass(desc).strip()
|
|
||||||
else:
|
|
||||||
answer = raw_input(desc).strip()
|
|
||||||
|
|
||||||
# No user input: use default
|
|
||||||
if not answer:
|
|
||||||
if default:
|
|
||||||
answer = default
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Have user input: validate answer
|
|
||||||
if yes_or_no:
|
|
||||||
if answer not in ['yes', 'no']:
|
|
||||||
print Utils.highlight('\nPlease answer yes or no\n')
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
return answer == 'yes'
|
|
||||||
else:
|
|
||||||
if validate:
|
|
||||||
try:
|
|
||||||
return validate(answer)
|
|
||||||
except InvalidAnswer, e:
|
|
||||||
print Utils.highlight('\n%s\n' % e)
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
return answer
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def validate_port(port):
|
|
||||||
try:
|
|
||||||
port = int(port)
|
|
||||||
except ValueError:
|
|
||||||
raise InvalidAnswer('%s is not a valid port' % Utils.highlight(port))
|
|
||||||
|
|
||||||
if port <= 0 or port > 65535:
|
|
||||||
raise InvalidAnswer('%s is not a valid port' % Utils.highlight(port))
|
|
||||||
|
|
||||||
return port
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidAnswer(Exception):
|
|
||||||
def __init__(self, msg):
|
|
||||||
Exception.__init__(self)
|
|
||||||
self.msg = msg
|
|
||||||
def __str__(self):
|
|
||||||
return self.msg
|
|
||||||
|
|
||||||
### END of Utils
|
|
||||||
####################
|
|
||||||
|
|
||||||
class RPC(object):
|
|
||||||
def __init__(self):
|
|
||||||
import ccnet
|
|
||||||
ccnet_dir = os.environ['CCNET_CONF_DIR']
|
|
||||||
self.rpc_client = ccnet.CcnetThreadedRpcClient(ccnet.ClientPool(ccnet_dir))
|
|
||||||
|
|
||||||
def get_db_email_users(self):
|
|
||||||
return self.rpc_client.get_emailusers('DB', 0, 1)
|
|
||||||
|
|
||||||
def create_admin(self, email, user):
|
|
||||||
return self.rpc_client.add_emailuser(email, user, 1, 1)
|
|
||||||
|
|
||||||
def need_create_admin():
|
|
||||||
users = rpc.get_db_email_users()
|
|
||||||
return len(users) == 0
|
|
||||||
|
|
||||||
def create_admin(email, passwd):
|
|
||||||
if rpc.create_admin(email, passwd) < 0:
|
|
||||||
raise Exception('failed to create admin')
|
|
||||||
else:
|
|
||||||
print '\n\n'
|
|
||||||
print '----------------------------------------'
|
|
||||||
print 'Successfully created seafile admin'
|
|
||||||
print '----------------------------------------'
|
|
||||||
print '\n\n'
|
|
||||||
|
|
||||||
def ask_admin_email():
|
|
||||||
print
|
|
||||||
print '----------------------------------------'
|
|
||||||
print 'It\'s the first time you start the seafile server. Now let\'s create the admin account'
|
|
||||||
print '----------------------------------------'
|
|
||||||
def validate(email):
|
|
||||||
# whitespace is not allowed
|
|
||||||
if re.match(r'[\s]', email):
|
|
||||||
raise InvalidAnswer('%s is not a valid email address' % Utils.highlight(email))
|
|
||||||
# must be a valid email address
|
|
||||||
if not re.match(r'^.+@.*\..+$', email):
|
|
||||||
raise InvalidAnswer('%s is not a valid email address' % Utils.highlight(email))
|
|
||||||
|
|
||||||
return email
|
|
||||||
|
|
||||||
key = 'admin email'
|
|
||||||
question = 'What is the ' + Utils.highlight('email') + ' for the admin account?'
|
|
||||||
return Utils.ask_question(question,
|
|
||||||
key=key,
|
|
||||||
validate=validate)
|
|
||||||
|
|
||||||
def ask_admin_password():
|
|
||||||
def validate(password):
|
|
||||||
key = 'admin password again'
|
|
||||||
question = 'Enter the ' + Utils.highlight('password again:')
|
|
||||||
password_again = Utils.ask_question(question,
|
|
||||||
key=key,
|
|
||||||
password=True)
|
|
||||||
|
|
||||||
if password_again != password:
|
|
||||||
raise InvalidAnswer('password mismatch')
|
|
||||||
|
|
||||||
return password
|
|
||||||
|
|
||||||
key = 'admin password'
|
|
||||||
question = 'What is the ' + Utils.highlight('password') + ' for the admin account?'
|
|
||||||
return Utils.ask_question(question,
|
|
||||||
key=key,
|
|
||||||
password=True,
|
|
||||||
validate=validate)
|
|
||||||
|
|
||||||
rpc = RPC()
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if not need_create_admin():
|
|
||||||
return
|
|
||||||
|
|
||||||
email = 'ADMIN_EMAIL'
|
|
||||||
passwd = 'ADMIN_PASSWORD'
|
|
||||||
|
|
||||||
create_admin(email, passwd)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print '\n\n\n'
|
|
||||||
print Utils.highlight('Aborted.')
|
|
||||||
print
|
|
||||||
sys.exit(1)
|
|
||||||
except Exception, e:
|
|
||||||
print e
|
|
||||||
print Utils.highlight('Error happened during creating seafile admin.')
|
|
||||||
print
|
|
|
@ -1 +0,0 @@
|
||||||
1bf5b06237ff1e54ba1cafb1f44b4f62e9bf496c
|
|
1
sources/seafile-server_4.0.6_x86-64.tar.REMOVED.git-id
Normal file
1
sources/seafile-server_4.0.6_x86-64.tar.REMOVED.git-id
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ccd4dd526f76614765521791672befffd622116b
|
|
@ -1,440 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
SCRIPT=$(readlink -f "$0")
|
|
||||||
INSTALLPATH=$(dirname "${SCRIPT}")
|
|
||||||
TOPDIR=$(dirname "${INSTALLPATH}")
|
|
||||||
default_ccnet_conf_dir=${TOPDIR}/ccnet
|
|
||||||
default_seafile_data_dir=${TOPDIR}/seafile-data
|
|
||||||
default_seahub_db=${TOPDIR}/seahub.db
|
|
||||||
default_conf_dir=${TOPDIR}/conf
|
|
||||||
|
|
||||||
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
|
|
||||||
|
|
||||||
use_existing_ccnet="false"
|
|
||||||
use_existing_seafile="false"
|
|
||||||
|
|
||||||
server_manual_http="https://github.com/haiwen/seafile/wiki"
|
|
||||||
|
|
||||||
function welcome () {
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo "This script will guide you to config and setup your seafile server."
|
|
||||||
echo -e "\nMake sure you have read seafile server manual at \n\n\t${server_manual_http}\n"
|
|
||||||
echo -e "Note: This script will guide your to setup seafile server using sqlite3,"
|
|
||||||
echo "which may have problems if your disk is on a NFS/CIFS/USB."
|
|
||||||
echo "In these cases, we sugguest you setup seafile server using MySQL."
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function err_and_quit () {
|
|
||||||
printf "\n\n\033[33mError occured during setup. \nPlease fix possible issues and run the script again.\033[m\n\n"
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function on_ctrl_c_pressed () {
|
|
||||||
printf "\n\n\033[33mYou have pressed Ctrl-C. Setup is interrupted.\033[m\n\n"
|
|
||||||
exit 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
# clean newly created ccnet/seafile configs when exit on SIGINT
|
|
||||||
trap on_ctrl_c_pressed 2
|
|
||||||
|
|
||||||
function check_sanity () {
|
|
||||||
if ! [[ -d ${INSTALLPATH}/seahub && -d ${INSTALLPATH}/seafile \
|
|
||||||
&& -d ${INSTALLPATH}/runtime ]]; then
|
|
||||||
echo
|
|
||||||
echo "The seafile-server diretory doesn't contain all needed files."
|
|
||||||
echo "Please make sure you have extracted all files and folders from tarball."
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function read_yes_no () {
|
|
||||||
printf "[yes|no] "
|
|
||||||
read yesno;
|
|
||||||
while [[ "${yesno}" != "yes" && "${yesno}" != "no" ]]
|
|
||||||
do
|
|
||||||
printf "please answer [yes|no] "
|
|
||||||
read yesno;
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "${yesno}" == "no" ]]; then
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_existing_ccnet () {
|
|
||||||
if [[ -d ${default_ccnet_conf_dir} ]]; then
|
|
||||||
echo "It seems that you have created a ccnet configuration before. "
|
|
||||||
echo "Would you like to use the existing configuration?"
|
|
||||||
|
|
||||||
if ! read_yes_no; then
|
|
||||||
echo
|
|
||||||
echo "Please remove the existing configuration before continuing."
|
|
||||||
echo "You can do it by running \"rm -rf ${default_ccnet_conf_dir}\""
|
|
||||||
echo
|
|
||||||
exit 1;
|
|
||||||
else
|
|
||||||
echo
|
|
||||||
echo "Existing ccnet configuration is being used."
|
|
||||||
use_existing_ccnet=true
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_python_executable() {
|
|
||||||
if [[ "$PYTHON" != "" && -x $PYTHON ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if which python2.7 2>/dev/null 1>&2; then
|
|
||||||
PYTHON=python2.7
|
|
||||||
elif which python27 2>/dev/null 1>&2; then
|
|
||||||
PYTHON=python27
|
|
||||||
elif which python2.6 2>/dev/null 1>&2; then
|
|
||||||
PYTHON=python2.6
|
|
||||||
elif which python26 2>/dev/null 1>&2; then
|
|
||||||
PYTHON=python26
|
|
||||||
else
|
|
||||||
echo
|
|
||||||
echo "Can't find a python executable of version 2.6 or above in PATH"
|
|
||||||
echo "Please install python 2.6+ before continuing."
|
|
||||||
echo "If it is installed in a non-standard PATH, please set the PYTHON environment variable"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Find python: $PYTHON"
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_python_module () {
|
|
||||||
module=$1
|
|
||||||
name=$2
|
|
||||||
hint=$3
|
|
||||||
printf " Checking python module: ${name} ... "
|
|
||||||
if ! $PYTHON -c "import ${module}" 2>/dev/null 1>&2; then
|
|
||||||
echo
|
|
||||||
printf "\033[33m ${name} \033[m is not installed, Please install it first.\n"
|
|
||||||
if [[ "${hint}" != "" ]]; then
|
|
||||||
printf "${hint}"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
echo -e "Done."
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_python () {
|
|
||||||
echo "Checking python on this machine ..."
|
|
||||||
check_python_executable
|
|
||||||
if ! which $PYTHON 2>/dev/null 1>&2; then
|
|
||||||
echo "No $PYTHON found on this machine. Please install it first."
|
|
||||||
err_and_quit;
|
|
||||||
else
|
|
||||||
if ($Python --version 2>&1 | grep "3\\.[0-9].\\.[0-9]") 2>/dev/null 1>&2 ; then
|
|
||||||
printf "\033[33m Python version 3.x \033[m detected\n"
|
|
||||||
echo "Python 3.x is not supported. Please use python 2.x."
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $PYTHON == "python2.6" ]]; then
|
|
||||||
py26="2.6"
|
|
||||||
fi
|
|
||||||
hint="\nOn Debian/Ubntu: apt-get install python-setuptools\nOn CentOS/RHEL: yum install python${py26}-distribute"
|
|
||||||
check_python_module pkg_resources setuptools "${hint}"
|
|
||||||
hint="\nOn Debian/Ubntu: apt-get install python-imaging\nOn CentOS/RHEL: yum install python${py26}-imaging"
|
|
||||||
check_python_module PIL python-imaging "${hint}"
|
|
||||||
check_python_module sqlite3 python-sqlite3
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_sqlite3 () {
|
|
||||||
echo -n "Checking for sqlite3 ..."
|
|
||||||
if ! which sqlite3 2>/dev/null 1>&2; then
|
|
||||||
echo -e "\nSqlite3 is not found. install it first.\n"
|
|
||||||
echo "On Debian/Ubuntu: apt-get install sqlite3"
|
|
||||||
echo "On CentOS/RHEL: yum install sqlite"
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
printf "Done.\n\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_system_dependency () {
|
|
||||||
printf "Checking packages needed by seafile ...\n\n"
|
|
||||||
check_python;
|
|
||||||
check_sqlite3;
|
|
||||||
printf "Checking Done.\n\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
function ask_question () {
|
|
||||||
question=$1
|
|
||||||
default=$2
|
|
||||||
key=$3
|
|
||||||
printf "${question}"
|
|
||||||
printf "\n"
|
|
||||||
if [[ "${default}" != "" && "${default}" != "nodefault" ]] ; then
|
|
||||||
printf "[default: ${default} ] "
|
|
||||||
elif [[ "${key}" != "" ]]; then
|
|
||||||
printf "[${key}]: "
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function gen_seafdav_conf () {
|
|
||||||
mkdir -p ${default_conf_dir}
|
|
||||||
seafdav_conf=${default_conf_dir}/seafdav.conf
|
|
||||||
if ! $(cat > ${seafdav_conf} <<EOF
|
|
||||||
[WEBDAV]
|
|
||||||
enabled = false
|
|
||||||
port = 8080
|
|
||||||
fastcgi = false
|
|
||||||
share_name = /
|
|
||||||
EOF
|
|
||||||
); then
|
|
||||||
echo "failed to generate seafdav.conf";
|
|
||||||
err_and_quit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function copy_user_manuals() {
|
|
||||||
src_docs_dir=${INSTALLPATH}/seafile/docs/
|
|
||||||
library_template_dir=${seafile_data_dir}/library-template
|
|
||||||
mkdir -p ${library_template_dir}
|
|
||||||
cp -f ${src_docs_dir}/*.doc ${library_template_dir}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# Main workflow of this script
|
|
||||||
# -------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
check_sanity;
|
|
||||||
welcome;
|
|
||||||
check_system_dependency;
|
|
||||||
|
|
||||||
|
|
||||||
check_existing_ccnet;
|
|
||||||
if [[ ${use_existing_ccnet} != "true" ]]; then
|
|
||||||
server_name=SERVER_NAME
|
|
||||||
ip_or_domain=DOMAIN;
|
|
||||||
server_port=CCNET_PORT
|
|
||||||
fi
|
|
||||||
|
|
||||||
seafile_data_dir=SEAFILE_DATA
|
|
||||||
if [[ ${use_existing_seafile} != "true" ]]; then
|
|
||||||
seafile_server_port=SEAFILE_PORT
|
|
||||||
fileserver_port=SEAFILE_FILESERVER_PORT
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep .5
|
|
||||||
|
|
||||||
printf "\nThis is your config information:\n\n"
|
|
||||||
|
|
||||||
if [[ ${use_existing_ccnet} != "true" ]]; then
|
|
||||||
printf "server name: \033[33m${server_name}\033[m\n"
|
|
||||||
printf "server ip/domain: \033[33m${ip_or_domain}\033[m\n"
|
|
||||||
printf "server port: \033[33m${server_port}\033[m\n"
|
|
||||||
else
|
|
||||||
printf "ccnet config: use existing config in \033[33m${default_ccnet_conf_dir}\033[m\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${use_existing_seafile} != "true" ]]; then
|
|
||||||
printf "seafile data dir: \033[33m${seafile_data_dir}\033[m\n"
|
|
||||||
printf "seafile port: \033[33m${seafile_server_port}\033[m\n"
|
|
||||||
printf "fileserver port: \033[33m${fileserver_port}\033[m\n"
|
|
||||||
else
|
|
||||||
printf "seafile data dir: use existing data in \033[33m${seafile_data_dir}\033[m\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ccnet_init=${INSTALLPATH}/seafile/bin/ccnet-init
|
|
||||||
seaf_server_init=${INSTALLPATH}/seafile/bin/seaf-server-init
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# Create ccnet conf
|
|
||||||
# -------------------------------------------
|
|
||||||
if [[ "${use_existing_ccnet}" != "true" ]]; then
|
|
||||||
echo "Generating ccnet configuration in ${default_ccnet_conf_dir}..."
|
|
||||||
echo
|
|
||||||
if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH "${ccnet_init}" -c "${default_ccnet_conf_dir}" --name "${server_name}" --port "${server_port}" --host "${ip_or_domain}"; then
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 0.5
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# Create seafile conf
|
|
||||||
# -------------------------------------------
|
|
||||||
if [[ "${use_existing_seafile}" != "true" ]]; then
|
|
||||||
echo "Generating seafile configuration in ${seafile_data_dir} ..."
|
|
||||||
echo
|
|
||||||
if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_server_init} --seafile-dir "${seafile_data_dir}" \
|
|
||||||
--port ${seafile_server_port} --fileserver-port ${fileserver_port}; then
|
|
||||||
|
|
||||||
echo "Failed to generate seafile configuration"
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# Write seafile.ini
|
|
||||||
# -------------------------------------------
|
|
||||||
|
|
||||||
echo "${seafile_data_dir}" > "${default_ccnet_conf_dir}/seafile.ini"
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# Generate seafevents.conf
|
|
||||||
# -------------------------------------------
|
|
||||||
|
|
||||||
gen_seafdav_conf;
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# generate seahub/settings.py
|
|
||||||
# -------------------------------------------
|
|
||||||
dest_settings_py=${TOPDIR}/seahub_settings.py
|
|
||||||
seahub_secret_keygen=${INSTALLPATH}/seahub/tools/secret_key_generator.py
|
|
||||||
|
|
||||||
if [[ ! -f ${dest_settings_py} ]]; then
|
|
||||||
echo -n "SECRET_KEY = " >> "${dest_settings_py}"
|
|
||||||
key=$($PYTHON "${seahub_secret_keygen}")
|
|
||||||
echo "\"${key}\"" >> "${dest_settings_py}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# Seahub related config
|
|
||||||
# -------------------------------------------
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo "Seahub is the web interface for seafile server."
|
|
||||||
echo "Now let's setup seahub configuration. Press [ENTER] to continue"
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo
|
|
||||||
|
|
||||||
|
|
||||||
# echo "Please specify the email address and password for the seahub administrator."
|
|
||||||
# echo "You can use them to login as admin on your seahub website."
|
|
||||||
# echo
|
|
||||||
|
|
||||||
function get_seahub_admin_email () {
|
|
||||||
question="Please specify the email address for the seahub administrator:"
|
|
||||||
ask_question "${question}" "nodefault" "seahub admin email"
|
|
||||||
read seahub_admin_email
|
|
||||||
if [[ "${seahub_admin_email}" == "" ]]; then
|
|
||||||
echo "Seahub admin user name cannot be empty."
|
|
||||||
get_seahub_admin_email;
|
|
||||||
elif [[ ! ${seahub_admin_email} =~ ^.+@.*\..+$ ]]; then
|
|
||||||
echo "${seahub_admin_email} is not a valid email address"
|
|
||||||
get_seahub_admin_email;
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_seahub_admin_passwd () {
|
|
||||||
echo
|
|
||||||
question="Please specify the password you would like to use for seahub administrator:"
|
|
||||||
ask_question "${question}" "nodefault" "seahub admin password"
|
|
||||||
read -s seahub_admin_passwd
|
|
||||||
echo
|
|
||||||
question="Please enter the password again:"
|
|
||||||
ask_question "${question}" "nodefault" "seahub admin password again"
|
|
||||||
read -s seahub_admin_passwd_again
|
|
||||||
echo
|
|
||||||
if [[ "${seahub_admin_passwd}" != "${seahub_admin_passwd_again}" ]]; then
|
|
||||||
printf "\033[33mThe passwords didn't match.\033[m"
|
|
||||||
get_seahub_admin_passwd;
|
|
||||||
elif [[ "${seahub_admin_passwd}" == "" ]]; then
|
|
||||||
echo "Password cannot be empty."
|
|
||||||
get_seahub_admin_passwd;
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "Creating seahub database now... "
|
|
||||||
echo
|
|
||||||
|
|
||||||
export CCNET_CONF_DIR=$default_ccnet_conf_dir
|
|
||||||
export SEAFILE_CONF_DIR=$seafile_data_dir
|
|
||||||
|
|
||||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.6/site-packages:${INSTALLPATH}/seafile/lib64/python2.6/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
|
|
||||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
|
|
||||||
|
|
||||||
manage_py=${INSTALLPATH}/seahub/manage.py
|
|
||||||
pushd "${INSTALLPATH}/seahub" 2>/dev/null 1>&2
|
|
||||||
if ! $PYTHON manage.py syncdb; then
|
|
||||||
popd 2>/dev/null 1>&2
|
|
||||||
echo "Failed to sync seahub database."
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
popd 2>/dev/null 1>&2
|
|
||||||
echo
|
|
||||||
echo "Done."
|
|
||||||
|
|
||||||
# prepare avatar folder
|
|
||||||
|
|
||||||
media_dir=${INSTALLPATH}/seahub/media
|
|
||||||
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
|
|
||||||
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
|
|
||||||
|
|
||||||
if [[ ! -d ${dest_avatar_dir} ]]; then
|
|
||||||
mkdir -p "${TOPDIR}/seahub-data"
|
|
||||||
mv "${orig_avatar_dir}" "${dest_avatar_dir}"
|
|
||||||
ln -s ../../../seahub-data/avatars ${media_dir}
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Make a seafile-server symlink, like this:
|
|
||||||
# /data/haiwen/
|
|
||||||
# -- seafile-server-2.0.4
|
|
||||||
# -- seafile-server-latest # symlink to 2.0.4
|
|
||||||
seafile_server_symlink=${TOPDIR}/seafile-server-latest
|
|
||||||
echo
|
|
||||||
echo -n "creating seafile-server-latest symbolic link ... "
|
|
||||||
if ! ln -s $(basename ${INSTALLPATH}) ${seafile_server_symlink}; then
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
echo "Failed to create symbolic link ${seafile_server_symlink}"
|
|
||||||
err_and_quit;
|
|
||||||
fi
|
|
||||||
echo "done"
|
|
||||||
echo
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# copy user manuals to library template
|
|
||||||
# -------------------------------------------
|
|
||||||
copy_user_manuals;
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------------------
|
|
||||||
# final message
|
|
||||||
# -------------------------------------------
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo "Your seafile server configuration has been completed successfully."
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo
|
|
||||||
echo "run seafile server: ./seafile.sh { start | stop | restart }"
|
|
||||||
echo "run seahub server: ./seahub.sh { start <port> | stop | restart <port> }"
|
|
||||||
echo
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo "If the server is behind a firewall, remember to open these tcp ports:"
|
|
||||||
echo "-----------------------------------------------------------------"
|
|
||||||
echo
|
|
||||||
echo "port of ccnet server: ${server_port}"
|
|
||||||
echo "port of seafile server: ${seafile_server_port}"
|
|
||||||
echo "port of seafile fileserver: ${fileserver_port}"
|
|
||||||
echo "port of seahub: 8000"
|
|
||||||
echo
|
|
||||||
echo -e "When problems occur, refer to\n"
|
|
||||||
echo -e " ${server_manual_http}\n"
|
|
||||||
echo "for more information."
|
|
||||||
echo
|
|
Loading…
Reference in a new issue