1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-08-28 11:30:57 +00:00

Merge pull request #294 from haiwen/fix_setup_mysql

Fix setup seafile mysql script.
This commit is contained in:
Daniel Pan 2019-12-03 16:16:53 +08:00 committed by GitHub
commit bd7c08624d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 185 additions and 241 deletions

View File

@ -22,7 +22,7 @@ except ImportError:
pass pass
SERVER_MANUAL_HTTP = 'https://github.com/haiwen/seafile/wiki' SERVER_MANUAL_HTTP = 'https://download.seafile.com/published/seafile-manual/home.md'
class Utils(object): class Utils(object):
'''Groups all helper functions here''' '''Groups all helper functions here'''

View File

@ -4,6 +4,7 @@ SCRIPT=$(readlink -f "$0")
INSTALLPATH=$(dirname "${SCRIPT}") INSTALLPATH=$(dirname "${SCRIPT}")
TOPDIR=$(dirname "${INSTALLPATH}") TOPDIR=$(dirname "${INSTALLPATH}")
default_ccnet_conf_dir=${TOPDIR}/ccnet default_ccnet_conf_dir=${TOPDIR}/ccnet
default_seafile_data_dir=${TOPDIR}/seafile-data
central_config_dir=${TOPDIR}/conf central_config_dir=${TOPDIR}/conf
function check_python_executable() { function check_python_executable() {
@ -31,26 +32,20 @@ function check_python_executable() {
fi fi
} }
function read_seafile_data_dir () { function validate_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini if [[ ! -d ${default_seafile_data_dir} ]]; then
if [[ ! -f ${seafile_ini} ]]; then echo "Error: there is no seafile server data directory."
echo "${seafile_ini} not found. Now quit" echo "Have you run setup-seafile.sh before this?"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo "" echo ""
exit 1; exit 1;
fi fi
} }
check_python_executable; check_python_executable;
read_seafile_data_dir; validate_seafile_data_dir;
export CCNET_CONF_DIR=${default_ccnet_conf_dir} export CCNET_CONF_DIR=${default_ccnet_conf_dir}
export SEAFILE_CONF_DIR=${seafile_data_dir} export SEAFILE_CONF_DIR=${default_seafile_data_dir}
export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir} export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir}
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python3.6/site-packages:${INSTALLPATH}/seafile/lib64/python3.6/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH export PYTHONPATH=${INSTALLPATH}/seafile/lib/python3.6/site-packages:${INSTALLPATH}/seafile/lib64/python3.6/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH

View File

@ -6,6 +6,7 @@ SCRIPT=$(readlink -f "$0")
INSTALLPATH=$(dirname "${SCRIPT}") INSTALLPATH=$(dirname "${SCRIPT}")
TOPDIR=$(dirname "${INSTALLPATH}") TOPDIR=$(dirname "${INSTALLPATH}")
default_ccnet_conf_dir=${TOPDIR}/ccnet default_ccnet_conf_dir=${TOPDIR}/ccnet
default_seafile_data_dir=${TOPDIR}/seafile-data
default_conf_dir=${TOPDIR}/conf default_conf_dir=${TOPDIR}/conf
seaf_fsck=${INSTALLPATH}/seafile/bin/seaf-fsck seaf_fsck=${INSTALLPATH}/seafile/bin/seaf-fsck
@ -28,16 +29,10 @@ function validate_ccnet_conf_dir () {
fi fi
} }
function read_seafile_data_dir () { function validate_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini if [[ ! -d ${default_seafile_data_dir} ]]; then
if [[ ! -f ${seafile_ini} ]]; then echo "Error: there is no seafile server data directory."
echo "${seafile_ini} not found. Now quit" echo "Have you run setup-seafile.sh before this?"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo "" echo ""
exit 1; exit 1;
fi fi
@ -45,13 +40,13 @@ function read_seafile_data_dir () {
function run_seaf_fsck () { function run_seaf_fsck () {
validate_ccnet_conf_dir; validate_ccnet_conf_dir;
read_seafile_data_dir; validate_seafile_data_dir;
echo "Starting seaf-fsck, please wait ..." echo "Starting seaf-fsck, please wait ..."
echo echo
LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_fsck} \ LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_fsck} \
-c "${default_ccnet_conf_dir}" -d "${seafile_data_dir}" \ -c "${default_ccnet_conf_dir}" -d "${default_seafile_data_dir}" \
-F "${default_conf_dir}" \ -F "${default_conf_dir}" \
${seaf_fsck_opts} ${seaf_fsck_opts}

View File

@ -6,6 +6,7 @@ SCRIPT=$(readlink -f "$0")
INSTALLPATH=$(dirname "${SCRIPT}") INSTALLPATH=$(dirname "${SCRIPT}")
TOPDIR=$(dirname "${INSTALLPATH}") TOPDIR=$(dirname "${INSTALLPATH}")
default_ccnet_conf_dir=${TOPDIR}/ccnet default_ccnet_conf_dir=${TOPDIR}/ccnet
default_seafile_data_dir=${TOPDIR}/seafile-data
default_conf_dir=${TOPDIR}/conf default_conf_dir=${TOPDIR}/conf
seaf_fuse=${INSTALLPATH}/seafile/bin/seaf-fuse seaf_fuse=${INSTALLPATH}/seafile/bin/seaf-fuse
@ -44,16 +45,10 @@ function validate_ccnet_conf_dir () {
fi fi
} }
function read_seafile_data_dir () { function validate_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini if [[ ! -d ${default_seafile_data_dir} ]]; then
if [[ ! -f ${seafile_ini} ]]; then echo "Error: there is no seafile server data directory."
echo "${seafile_ini} not found. Now quit" echo "Have you run setup-seafile.sh before this?"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo "" echo ""
exit 1; exit 1;
fi fi
@ -79,7 +74,7 @@ function start_seaf_fuse () {
validate_already_running; validate_already_running;
warning_if_seafile_not_running; warning_if_seafile_not_running;
validate_ccnet_conf_dir; validate_ccnet_conf_dir;
read_seafile_data_dir; validate_seafile_data_dir;
echo "Starting seaf-fuse, please wait ..." echo "Starting seaf-fuse, please wait ..."
@ -87,7 +82,7 @@ function start_seaf_fuse () {
LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_fuse} \ LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_fuse} \
-c "${default_ccnet_conf_dir}" \ -c "${default_ccnet_conf_dir}" \
-d "${seafile_data_dir}" \ -d "${default_seafile_data_dir}" \
-F "${default_conf_dir}" \ -F "${default_conf_dir}" \
-l "${logfile}" \ -l "${logfile}" \
"$@" "$@"

View File

@ -6,6 +6,7 @@ SCRIPT=$(readlink -f "$0")
INSTALLPATH=$(dirname "${SCRIPT}") INSTALLPATH=$(dirname "${SCRIPT}")
TOPDIR=$(dirname "${INSTALLPATH}") TOPDIR=$(dirname "${INSTALLPATH}")
default_ccnet_conf_dir=${TOPDIR}/ccnet default_ccnet_conf_dir=${TOPDIR}/ccnet
default_seafile_data_dir=${TOPDIR}/seafile-data
default_conf_dir=${TOPDIR}/conf default_conf_dir=${TOPDIR}/conf
seaf_gc=${INSTALLPATH}/seafile/bin/seafserv-gc seaf_gc=${INSTALLPATH}/seafile/bin/seafserv-gc
seaf_gc_opts="" seaf_gc_opts=""
@ -30,16 +31,10 @@ function validate_ccnet_conf_dir () {
fi fi
} }
function read_seafile_data_dir () { function validate_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini if [[ ! -d ${default_seafile_data_dir} ]]; then
if [[ ! -f ${seafile_ini} ]]; then echo "Error: there is no seafile server data directory."
echo "${seafile_ini} not found. Now quit" echo "Have you run setup-seafile.sh before this?"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo "" echo ""
exit 1; exit 1;
fi fi
@ -75,13 +70,13 @@ function validate_already_running () {
function run_seaf_gc () { function run_seaf_gc () {
validate_already_running; validate_already_running;
validate_ccnet_conf_dir; validate_ccnet_conf_dir;
read_seafile_data_dir; validate_seafile_data_dir;
echo "Starting seafserv-gc, please wait ..." echo "Starting seafserv-gc, please wait ..."
LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_gc} \ LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_gc} \
-c "${default_ccnet_conf_dir}" \ -c "${default_ccnet_conf_dir}" \
-d "${seafile_data_dir}" \ -d "${default_seafile_data_dir}" \
-F "${default_conf_dir}" \ -F "${default_conf_dir}" \
${seaf_gc_opts} ${seaf_gc_opts}

View File

@ -16,10 +16,10 @@ SCRIPT=$(readlink -f "$0")
INSTALLPATH=$(dirname "${SCRIPT}") INSTALLPATH=$(dirname "${SCRIPT}")
TOPDIR=$(dirname "${INSTALLPATH}") TOPDIR=$(dirname "${INSTALLPATH}")
default_ccnet_conf_dir=${TOPDIR}/ccnet default_ccnet_conf_dir=${TOPDIR}/ccnet
default_seafile_data_dir=${TOPDIR}/seafile-data
central_config_dir=${TOPDIR}/conf central_config_dir=${TOPDIR}/conf
seaf_controller="${INSTALLPATH}/seafile/bin/seafile-controller" seaf_controller="${INSTALLPATH}/seafile/bin/seafile-controller"
export PATH=${INSTALLPATH}/seafile/bin:$PATH export PATH=${INSTALLPATH}/seafile/bin:$PATH
export ORIG_LD_LIBRARY_PATH=${LD_LIBRARY_PATH} export ORIG_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH} export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
@ -38,7 +38,7 @@ if [[ $# != 1 || ( "$1" != "start" && "$1" != "stop" && "$1" != "restart" ) ]];
fi fi
function validate_running_user () { function validate_running_user () {
real_data_dir=`readlink -f ${seafile_data_dir}` real_data_dir=`readlink -f ${default_seafile_data_dir}`
running_user=`id -un` running_user=`id -un`
data_dir_owner=`stat -c %U ${real_data_dir}` data_dir_owner=`stat -c %U ${real_data_dir}`
@ -66,16 +66,10 @@ function validate_central_conf_dir () {
fi fi
} }
function read_seafile_data_dir () { function validate_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini if [[ ! -d ${default_seafile_data_dir} ]]; then
if [[ ! -f ${seafile_ini} ]]; then echo "Error: there is no seafile server data directory."
echo "${seafile_ini} not found. Now quit" echo "Have you run setup-seafile.sh before this?"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo "" echo ""
exit 1; exit 1;
fi fi
@ -84,7 +78,7 @@ function read_seafile_data_dir () {
function test_config() { function test_config() {
if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} --test \ if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} --test \
-c "${default_ccnet_conf_dir}" \ -c "${default_ccnet_conf_dir}" \
-d "${seafile_data_dir}" \ -d "${default_seafile_data_dir}" \
-F "${central_config_dir}" ; then -F "${central_config_dir}" ; then
exit 1; exit 1;
fi fi
@ -121,7 +115,7 @@ function start_seafile_server () {
validate_already_running; validate_already_running;
validate_central_conf_dir; validate_central_conf_dir;
validate_ccnet_conf_dir; validate_ccnet_conf_dir;
read_seafile_data_dir; validate_seafile_data_dir;
validate_running_user; validate_running_user;
test_config; test_config;
@ -130,7 +124,7 @@ function start_seafile_server () {
mkdir -p $TOPDIR/logs mkdir -p $TOPDIR/logs
LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} \ LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_controller} \
-c "${default_ccnet_conf_dir}" \ -c "${default_ccnet_conf_dir}" \
-d "${seafile_data_dir}" \ -d "${default_seafile_data_dir}" \
-F "${central_config_dir}" -F "${central_config_dir}"
sleep 3 sleep 3

View File

@ -16,6 +16,7 @@ SCRIPT=$(readlink -f "$0")
INSTALLPATH=$(dirname "${SCRIPT}") INSTALLPATH=$(dirname "${SCRIPT}")
TOPDIR=$(dirname "${INSTALLPATH}") TOPDIR=$(dirname "${INSTALLPATH}")
default_ccnet_conf_dir=${TOPDIR}/ccnet default_ccnet_conf_dir=${TOPDIR}/ccnet
default_seafile_data_dir=${TOPDIR}/seafile-data
central_config_dir=${TOPDIR}/conf central_config_dir=${TOPDIR}/conf
manage_py=${INSTALLPATH}/seahub/manage.py manage_py=${INSTALLPATH}/seahub/manage.py
@ -80,16 +81,10 @@ function validate_ccnet_conf_dir () {
fi fi
} }
function read_seafile_data_dir () { function validate_seafile_data_dir () {
seafile_ini=${default_ccnet_conf_dir}/seafile.ini if [[ ! -d ${default_seafile_data_dir} ]]; then
if [[ ! -f ${seafile_ini} ]]; then echo "Error: there is no seafile server data directory."
echo "${seafile_ini} not found. Now quit" echo "Have you run setup-seafile.sh before this?"
exit 1
fi
seafile_data_dir=$(cat "${seafile_ini}")
if [[ ! -d ${seafile_data_dir} ]]; then
echo "Your seafile server data directory \"${seafile_data_dir}\" is invalid or doesn't exits."
echo "Please check it first, or create this directory yourself."
echo "" echo ""
exit 1; exit 1;
fi fi
@ -203,7 +198,7 @@ function start_seahub_fastcgi () {
function prepare_env() { function prepare_env() {
check_python_executable; check_python_executable;
validate_ccnet_conf_dir; validate_ccnet_conf_dir;
read_seafile_data_dir; validate_seafile_data_dir;
if [[ -z "$LANG" ]]; then if [[ -z "$LANG" ]]; then
echo "LANG is not set in ENV, set to en_US.UTF-8" echo "LANG is not set in ENV, set to en_US.UTF-8"
@ -215,7 +210,7 @@ function prepare_env() {
fi fi
export CCNET_CONF_DIR=${default_ccnet_conf_dir} export CCNET_CONF_DIR=${default_ccnet_conf_dir}
export SEAFILE_CONF_DIR=${seafile_data_dir} export SEAFILE_CONF_DIR=${default_seafile_data_dir}
export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir} export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir}
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python3.6/site-packages:${INSTALLPATH}/seafile/lib64/python3.6/site-packages:${INSTALLPATH}/seahub:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH export PYTHONPATH=${INSTALLPATH}/seafile/lib/python3.6/site-packages:${INSTALLPATH}/seafile/lib64/python3.6/site-packages:${INSTALLPATH}/seahub:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH

View File

@ -24,7 +24,7 @@ except ImportError:
pass pass
SERVER_MANUAL_HTTP = 'https://github.com/haiwen/seafile/wiki' SERVER_MANUAL_HTTP = 'https://download.seafile.com/published/seafile-manual/home.md'
class Utils(object): class Utils(object):
'''Groups all helper functions here''' '''Groups all helper functions here'''
@ -376,6 +376,7 @@ class AbstractDBConfigurator(AbstractConfigurator):
AbstractConfigurator.__init__(self) AbstractConfigurator.__init__(self)
self.mysql_host = 'localhost' self.mysql_host = 'localhost'
self.mysql_port = 3306 self.mysql_port = 3306
self.unix_socket = "/var/run/mysqld/mysqld.sock"
self.use_existing_db = False self.use_existing_db = False
@ -476,12 +477,15 @@ Please choose a way to initialize seafile databases:
print('done') print('done')
def check_mysql_user(self, user, password, host=None): def check_mysql_user(self, user, password, host=None, unix_socket=None):
print('\nverifying password of user %s ... ' % user, end=' ') print('\nverifying password of user %s ... ' % user, end=' ')
kwargs = dict(host=host or self.mysql_host, kwargs = dict(port=self.mysql_port,
port=self.mysql_port,
user=user, user=user,
passwd=password) passwd=password)
if unix_socket:
kwargs['unix_socket'] = unix_socket
else:
kwargs['host'] = host or self.mysql_host
try: try:
conn = pymysql.connect(**kwargs) conn = pymysql.connect(**kwargs)
@ -565,7 +569,7 @@ class NewDBConfigurator(AbstractDBConfigurator):
# accessed from localhost with unix socket. So we retry with # accessed from localhost with unix socket. So we retry with
# localhost when failing with 127.0.0.1. # localhost when failing with 127.0.0.1.
if self.mysql_host == '127.0.0.1': if self.mysql_host == '127.0.0.1':
self.root_conn = self.check_mysql_user('root', password, host='localhost') self.root_conn = self.check_mysql_user('root', password, unix_socket=self.unix_socket)
else: else:
raise raise
return password return password
@ -915,14 +919,14 @@ class CcnetConfigurator(AbstractConfigurator):
class SeafileConfigurator(AbstractConfigurator): class SeafileConfigurator(AbstractConfigurator):
def __init__(self): def __init__(self):
AbstractConfigurator.__init__(self) AbstractConfigurator.__init__(self)
self.seafile_dir = None self.seafile_dir = os.path.join(env_mgr.top_dir, 'seafile-data')
self.port = 12001 self.port = 12001
self.fileserver_port = None self.fileserver_port = None
self.seafile_conf = os.path.join(env_mgr.central_config_dir, 'seafile.conf') self.seafile_conf = os.path.join(env_mgr.central_config_dir, 'seafile.conf')
def ask_questions(self): def ask_questions(self):
if not self.seafile_dir: # if not self.seafile_dir:
self.ask_seafile_dir() # self.ask_seafile_dir()
# self.ask_port() # self.ask_port()
if not self.fileserver_port: if not self.fileserver_port:
self.ask_fileserver_port() self.ask_fileserver_port()
@ -942,7 +946,10 @@ class SeafileConfigurator(AbstractConfigurator):
time.sleep(1) time.sleep(1)
self.generate_db_conf() self.generate_db_conf()
self.write_seafile_ini()
## use default seafile-data path: seafile_data_dir=${TOPDIR}/seafile-data
# self.write_seafile_ini()
print('done') print('done')
def generate_db_conf(self): def generate_db_conf(self):

View File

@ -12,10 +12,7 @@ default_logs_dir=${TOPDIR}/logs
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH} export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
use_existing_ccnet="false" server_manual_http='https://download.seafile.com/published/seafile-manual/home.md'
use_existing_seafile="false"
server_manual_http="https://github.com/haiwen/seafile/wiki"
function welcome () { function welcome () {
echo "-----------------------------------------------------------------" echo "-----------------------------------------------------------------"
@ -72,20 +69,18 @@ function read_yes_no () {
function check_existing_ccnet () { function check_existing_ccnet () {
if [[ -d ${default_ccnet_conf_dir} ]]; then if [[ -d ${default_ccnet_conf_dir} ]]; then
echo "It seems that you have created a ccnet configuration before. " echo "\033[31m Error: \033[0m Ccnet config dir \"${default_ccnet_conf_dir}\" already exists."
echo "Would you like to use the existing configuration?" echo
exit 1;
fi
echo
}
if ! read_yes_no; then function check_existing_seafile () {
echo if [[ -d ${default_seafile_data_dir} ]]; then
echo "Please remove the existing configuration before continuing." echo "\033[31m Error: \033[0m Seafile server data dir \"${default_seafile_data_dir}\" already exists."
echo "You can do it by running \"rm -rf ${default_ccnet_conf_dir}\"" echo
echo exit 1;
exit 1;
else
echo
echo "Existing ccnet configuration is being used."
use_existing_ccnet=true
fi
fi fi
echo echo
} }
@ -201,37 +196,37 @@ function get_server_ip_or_domain () {
echo echo
} }
function get_ccnet_server_port () { # function get_ccnet_server_port () {
question="What tcp port do you want to use for ccnet server?" # question="What tcp port do you want to use for ccnet server?"
hint="10001 is the recommended port." # hint="10001 is the recommended port."
default="10001" # default="10001"
ask_question "${question}\n${hint}" "${default}" # ask_question "${question}\n${hint}" "${default}"
read server_port # read server_port
if [[ "${server_port}" == "" ]]; then # if [[ "${server_port}" == "" ]]; then
server_port="${default}" # server_port="${default}"
fi # fi
if [[ ! ${server_port} =~ ^[0-9]+$ ]]; then # if [[ ! ${server_port} =~ ^[0-9]+$ ]]; then
echo "\"${server_port}\" is not a valid port number. " # echo "\"${server_port}\" is not a valid port number. "
get_ccnet_server_port # get_ccnet_server_port
fi # fi
echo # echo
} # }
function get_seafile_server_port () { # function get_seafile_server_port () {
question="What tcp port would you like to use for seafile server?" # question="What tcp port would you like to use for seafile server?"
hint="12001 is the recommended port." # hint="12001 is the recommended port."
default="12001" # default="12001"
ask_question "${question}\n${hint}" "${default}" # ask_question "${question}\n${hint}" "${default}"
read seafile_server_port # read seafile_server_port
if [[ "${seafile_server_port}" == "" ]]; then # if [[ "${seafile_server_port}" == "" ]]; then
seafile_server_port="${default}" # seafile_server_port="${default}"
fi # fi
if [[ ! ${seafile_server_port} =~ ^[0-9]+$ ]]; then # if [[ ! ${seafile_server_port} =~ ^[0-9]+$ ]]; then
echo "\"${seafile_server_port}\" is not a valid port number. " # echo "\"${seafile_server_port}\" is not a valid port number. "
get_seafile_server_port # get_seafile_server_port
fi # fi
echo # echo
} # }
function get_fileserver_port () { function get_fileserver_port () {
question="What tcp port do you want to use for seafile fileserver?" question="What tcp port do you want to use for seafile fileserver?"
@ -250,45 +245,45 @@ function get_fileserver_port () {
} }
function get_seafile_data_dir () { # function get_seafile_data_dir () {
question="Where would you like to store your seafile data?" # question="Where would you like to store your seafile data?"
note="Please use a volume with enough free space." # note="Please use a volume with enough free space."
default=${default_seafile_data_dir} # default=${default_seafile_data_dir}
ask_question "${question} \n\033[33mNote: \033[m${note}" "${default}" # ask_question "${question} \n\033[33mNote: \033[m${note}" "${default}"
read seafile_data_dir # read seafile_data_dir
if [[ "${seafile_data_dir}" == "" ]]; then # if [[ "${seafile_data_dir}" == "" ]]; then
seafile_data_dir=${default} # seafile_data_dir=${default}
fi # fi
#
if [[ -d ${seafile_data_dir} && -f ${seafile_data_dir}/seafile.conf ]]; then # if [[ -d ${seafile_data_dir} && -f ${seafile_data_dir}/seafile.conf ]]; then
echo # echo
echo "It seems that you have already existing seafile data in ${seafile_data_dir}." # echo "It seems that you have already existing seafile data in ${seafile_data_dir}."
echo "Would you like to use the existing seafile data?" # echo "Would you like to use the existing seafile data?"
if ! read_yes_no; then # if ! read_yes_no; then
echo "You have chosen not to use existing seafile data in ${seafile_data_dir}" # echo "You have chosen not to use existing seafile data in ${seafile_data_dir}"
echo "You need to specify a different seafile data directory or remove ${seafile_data_dir} before continuing." # echo "You need to specify a different seafile data directory or remove ${seafile_data_dir} before continuing."
get_seafile_data_dir # get_seafile_data_dir
else # else
use_existing_seafile="true" # use_existing_seafile="true"
fi # fi
elif [[ -d ${seafile_data_dir} && $(ls -A ${seafile_data_dir}) != "" ]]; then # elif [[ -d ${seafile_data_dir} && $(ls -A ${seafile_data_dir}) != "" ]]; then
echo # echo
echo "${seafile_data_dir} is an existing non-empty directory. Please specify a different directory" # echo "${seafile_data_dir} is an existing non-empty directory. Please specify a different directory"
echo # echo
get_seafile_data_dir # get_seafile_data_dir
elif [[ ! ${seafile_data_dir} =~ ^/ ]]; then # elif [[ ! ${seafile_data_dir} =~ ^/ ]]; then
echo # echo
echo "\"${seafile_data_dir}\" is not an absolute path. Please specify an absolute path." # echo "\"${seafile_data_dir}\" is not an absolute path. Please specify an absolute path."
echo # echo
get_seafile_data_dir # get_seafile_data_dir
elif [[ ! -d $(dirname ${seafile_data_dir}) ]]; then # elif [[ ! -d $(dirname ${seafile_data_dir}) ]]; then
echo # echo
echo "The path $(dirname ${seafile_data_dir}) does not exist." # echo "The path $(dirname ${seafile_data_dir}) does not exist."
echo # echo
get_seafile_data_dir # get_seafile_data_dir
fi # fi
echo # echo
} # }
function gen_gunicorn_conf () { function gen_gunicorn_conf () {
mkdir -p ${default_conf_dir} mkdir -p ${default_conf_dir}
@ -336,13 +331,13 @@ fi
function copy_user_manuals() { function copy_user_manuals() {
src_docs_dir=${INSTALLPATH}/seafile/docs/ src_docs_dir=${INSTALLPATH}/seafile/docs/
library_template_dir=${seafile_data_dir}/library-template library_template_dir=${default_seafile_data_dir}/library-template
mkdir -p ${library_template_dir} mkdir -p ${library_template_dir}
cp -f ${src_docs_dir}/*.doc ${library_template_dir} cp -f ${src_docs_dir}/*.doc ${library_template_dir}
} }
function parse_params() { function parse_params() {
while getopts n:i:p:d arg; do while getopts n:i:p arg; do
case $arg in case $arg in
n) n)
server_name=${OPTARG} server_name=${OPTARG}
@ -353,9 +348,6 @@ function parse_params() {
p) p)
fileserver_port=${OPTARG} fileserver_port=${OPTARG}
;; ;;
d)
seafile_data_dir=${OPTARG}
;;
esac esac
done done
} }
@ -387,20 +379,6 @@ function validate_params() {
echo "Invalid fileserver port param" echo "Invalid fileserver port param"
err_and_quit; err_and_quit;
fi fi
if [[ "${seafile_data_dir}" == "" ]]; then
seafile_data_dir=${SEAFILE_DIR:-${default_seafile_data_dir}}
fi
if [[ -d ${seafile_data_dir} && $(ls -A ${seafile_data_dir}) != "" ]]; then
echo "${seafile_data_dir} is an existing non-empty directory. Please specify a different directory"
err_and_quit
elif [[ ! ${seafile_data_dir} =~ ^/ ]]; then
echo "\"${seafile_data_dir}\" is not an absolute path. Please specify an absolute path."
err_and_quit
elif [[ ! -d $(dirname ${seafile_data_dir}) ]]; then
echo "The path $(dirname ${seafile_data_dir}) does not exist."
err_and_quit
fi
} }
function usage() { function usage() {
@ -444,43 +422,32 @@ check_system_dependency;
sleep .5 sleep .5
check_existing_ccnet; check_existing_ccnet;
if [[ ${use_existing_ccnet} != "true" ]]; then check_existing_seafile;
if [[ "${server_name}" == "" ]]; then
get_server_name; if [[ "${server_name}" == "" ]]; then
fi get_server_name;
if [[ "${ip_or_domain}" == "" ]]; then
get_server_ip_or_domain;
fi
# get_ccnet_server_port;
fi fi
if [[ "$seafile_data_dir" == "" ]]; then if [[ "${ip_or_domain}" == "" ]]; then
get_seafile_data_dir; get_server_ip_or_domain;
fi fi
if [[ ${use_existing_seafile} != "true" ]]; then
# get_seafile_server_port if [[ "$fileserver_port" == "" ]]; then
if [[ "$fileserver_port" == "" ]]; then get_fileserver_port
get_fileserver_port
fi
fi fi
sleep .5 sleep .5
printf "\nThis is your config information:\n\n" 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 name: \033[33m${server_name}\033[m\n" printf "server ip/domain: \033[33m${ip_or_domain}\033[m\n"
printf "server ip/domain: \033[33m${ip_or_domain}\033[m\n"
else
printf "ccnet config: use existing config in \033[33m${default_ccnet_conf_dir}\033[m\n" printf "seafile data dir: \033[33m${default_seafile_data_dir}\033[m\n"
fi printf "fileserver port: \033[33m${fileserver_port}\033[m\n"
if [[ ${use_existing_seafile} != "true" ]]; then
printf "seafile data dir: \033[33m${seafile_data_dir}\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
if [[ "${need_pause}" == "1" ]]; then if [[ "${need_pause}" == "1" ]]; then
echo echo
@ -494,44 +461,45 @@ seaf_server_init=${INSTALLPATH}/seafile/bin/seaf-server-init
# ------------------------------------------- # -------------------------------------------
# Create ccnet conf # 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}" \
-F "${default_conf_dir}" \
-c "${default_ccnet_conf_dir}" \
--host "${ip_or_domain}"; then
err_and_quit;
fi
echo echo "Generating ccnet configuration in ${default_ccnet_conf_dir}..."
echo
if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH "${ccnet_init}" \
-F "${default_conf_dir}" \
-c "${default_ccnet_conf_dir}" \
--host "${ip_or_domain}"; then
err_and_quit;
fi fi
echo
sleep 0.5 sleep 0.5
# ------------------------------------------- # -------------------------------------------
# Create seafile conf # Create seafile conf
# ------------------------------------------- # -------------------------------------------
if [[ "${use_existing_seafile}" != "true" ]]; then
echo "Generating seafile configuration in ${seafile_data_dir} ..." echo "Generating seafile configuration in ${default_seafile_data_dir} ..."
echo echo
if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_server_init} \ if ! LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${seaf_server_init} \
--central-config-dir "${default_conf_dir}" \ --central-config-dir "${default_conf_dir}" \
--seafile-dir "${seafile_data_dir}" \ --seafile-dir "${default_seafile_data_dir}" \
--fileserver-port ${fileserver_port}; then --fileserver-port ${fileserver_port}; then
echo "Failed to generate seafile configuration"
err_and_quit;
fi
echo echo "Failed to generate seafile configuration"
err_and_quit;
fi fi
echo
# ------------------------------------------- # -------------------------------------------
# Write seafile.ini # Write seafile.ini
# ------------------------------------------- # -------------------------------------------
echo "${seafile_data_dir}" > "${default_ccnet_conf_dir}/seafile.ini" ## use default seafile-data path: seafile_data_dir=${TOPDIR}/seafile-data
# echo "${seafile_data_dir}" > "${default_ccnet_conf_dir}/seafile.ini"
# ------------------------------------------- # -------------------------------------------
# Generate gunicorn.conf # Generate gunicorn.conf
@ -729,7 +697,7 @@ echo
chmod 0600 "$dest_settings_py" chmod 0600 "$dest_settings_py"
chmod 0700 "$default_ccnet_conf_dir" chmod 0700 "$default_ccnet_conf_dir"
chmod 0700 "$seafile_data_dir" chmod 0700 "$default_seafile_data_dir"
chmod 0700 "$default_conf_dir" chmod 0700 "$default_conf_dir"
# ------------------------------------------- # -------------------------------------------