mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-16 15:18:58 +00:00
Modify scripts to support python3.
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#coding: UTF-8
|
||||
"""Generate the breakpad symbol file and place it in the directory structure
|
||||
required by breakpad `minidump_stackwalk` tool.
|
||||
|
||||
The directory is ./symbols/seaf-daemon.exe/${symbol_id}/seaf-daemon.exe.sym,
|
||||
where symbol_id is the first line of the "dump_syms" output.
|
||||
"""
|
||||
|
||||
import os
|
||||
from os.path import abspath, basename, exists, dirname, join
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import optparse
|
||||
|
||||
|
||||
def call(*a, **kw):
|
||||
kw.setdefault('shell', True)
|
||||
subprocess.check_call(*a, **kw)
|
||||
|
||||
|
||||
def get_command_output(cmd, **kw):
|
||||
shell = not isinstance(cmd, list)
|
||||
return subprocess.check_output(cmd, shell=shell, **kw)
|
||||
|
||||
|
||||
def main():
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('--output', help='the path of the symbol file.')
|
||||
args, _ = parser.parse_args()
|
||||
|
||||
seafile_src_dir = dirname(abspath(dirname(__file__)))
|
||||
os.chdir(seafile_src_dir)
|
||||
program = 'seaf-daemon.exe' if os.name == 'nt' else 'seaf-daemon'
|
||||
seaf_daemon = join('daemon', '.libs', program)
|
||||
if not exists(seaf_daemon):
|
||||
seaf_daemon = join('daemon', program)
|
||||
if not exists(seaf_daemon):
|
||||
raise RuntimeError('seaf-daemon executable not found!')
|
||||
symbols = get_command_output('dump_syms {}'.format(seaf_daemon))
|
||||
|
||||
if args.output:
|
||||
symbol_file = args.output
|
||||
else:
|
||||
symbol_id = symbols.splitlines()[0].split()[3]
|
||||
symbol_dir = join('symbols', program, symbol_id)
|
||||
if not exists(symbol_dir):
|
||||
os.makedirs(symbol_dir)
|
||||
symbol_file = join(symbol_dir, '{}.sym'.format(program))
|
||||
print('symbols written to {}'.format(symbol_file))
|
||||
with open(symbol_file, 'w') as fp:
|
||||
fp.write(symbols)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -259,7 +259,7 @@ def check_seahub_thirdpart(thirdpartdir):
|
||||
'Django',
|
||||
# 'Djblets',
|
||||
'gunicorn',
|
||||
'flup',
|
||||
#'flup',
|
||||
'chardet',
|
||||
'python_dateutil',
|
||||
#'django_picklefield',
|
||||
|
@@ -284,8 +284,8 @@ class RPC(object):
|
||||
import ccnet
|
||||
ccnet_dir = os.environ['CCNET_CONF_DIR']
|
||||
central_config_dir = os.environ['SEAFILE_CENTRAL_CONF_DIR']
|
||||
self.rpc_client = ccnet.CcnetThreadedRpcClient(
|
||||
ccnet.ClientPool(ccnet_dir, central_config_dir=central_config_dir))
|
||||
ccnet_named_pipe_path = ccnet_dir + '/' + 'ccnet-rpc.sock'
|
||||
self.rpc_client = ccnet.CcnetThreadedRpcClient(ccnet_named_pipe_path)
|
||||
|
||||
def get_db_email_users(self):
|
||||
return self.rpc_client.get_emailusers('DB', 0, 1)
|
||||
|
@@ -1,378 +0,0 @@
|
||||
# coding: UTF-8
|
||||
|
||||
import sys
|
||||
import os
|
||||
import configparser
|
||||
import glob
|
||||
|
||||
HAS_MYSQLDB = True
|
||||
try:
|
||||
import MySQLdb
|
||||
except ImportError:
|
||||
HAS_MYSQLDB = False
|
||||
|
||||
HAS_SQLITE3 = True
|
||||
try:
|
||||
import sqlite3
|
||||
except ImportError:
|
||||
HAS_SQLITE3 = False
|
||||
|
||||
class EnvManager(object):
|
||||
def __init__(self):
|
||||
self.upgrade_dir = os.path.dirname(__file__)
|
||||
self.install_path = os.path.dirname(self.upgrade_dir)
|
||||
self.top_dir = os.path.dirname(self.install_path)
|
||||
self.ccnet_dir = os.environ['CCNET_CONF_DIR']
|
||||
self.seafile_dir = os.environ['SEAFILE_CONF_DIR']
|
||||
self.central_config_dir = os.environ.get('SEAFILE_CENTRAL_CONF_DIR')
|
||||
|
||||
|
||||
env_mgr = EnvManager()
|
||||
|
||||
|
||||
class Utils(object):
|
||||
@staticmethod
|
||||
def highlight(content, is_error=False):
|
||||
'''Add ANSI color to content to get it highlighted on terminal'''
|
||||
if is_error:
|
||||
return '\x1b[1;31m%s\x1b[m' % content
|
||||
else:
|
||||
return '\x1b[1;32m%s\x1b[m' % content
|
||||
|
||||
@staticmethod
|
||||
def info(msg):
|
||||
print(Utils.highlight('[INFO] ') + msg)
|
||||
|
||||
@staticmethod
|
||||
def warning(msg):
|
||||
print(Utils.highlight('[WARNING] ') + msg)
|
||||
|
||||
@staticmethod
|
||||
def error(msg):
|
||||
print(Utils.highlight('[ERROR] ') + msg)
|
||||
sys.exit(1)
|
||||
|
||||
@staticmethod
|
||||
def read_config(config_path, defaults):
|
||||
if not os.path.exists(config_path):
|
||||
Utils.error('Config path %s doesn\'t exist, stop db upgrade' %
|
||||
config_path)
|
||||
cp = configparser.ConfigParser(defaults)
|
||||
cp.read(config_path)
|
||||
return cp
|
||||
|
||||
|
||||
class MySQLDBInfo(object):
|
||||
def __init__(self, host, port, username, password, db, unix_socket=None):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.db = db
|
||||
self.unix_socket = unix_socket
|
||||
|
||||
|
||||
class DBUpdater(object):
|
||||
def __init__(self, version, name):
|
||||
self.sql_dir = os.path.join(env_mgr.upgrade_dir, 'sql', version, name)
|
||||
pro_path = os.path.join(env_mgr.install_path, 'pro')
|
||||
self.is_pro = os.path.exists(pro_path)
|
||||
|
||||
@staticmethod
|
||||
def get_instance(version):
|
||||
'''Detect whether we are using mysql or sqlite3'''
|
||||
ccnet_db_info = DBUpdater.get_ccnet_mysql_info(version)
|
||||
seafile_db_info = DBUpdater.get_seafile_mysql_info(version)
|
||||
seahub_db_info = DBUpdater.get_seahub_mysql_info()
|
||||
|
||||
if ccnet_db_info and seafile_db_info and seahub_db_info:
|
||||
Utils.info('You are using MySQL')
|
||||
if not HAS_MYSQLDB:
|
||||
Utils.error('Python MySQLdb module is not found')
|
||||
updater = MySQLDBUpdater(version, ccnet_db_info, seafile_db_info, seahub_db_info)
|
||||
|
||||
elif (ccnet_db_info is None) and (seafile_db_info is None) and (seahub_db_info is None):
|
||||
Utils.info('You are using SQLite3')
|
||||
if not HAS_SQLITE3:
|
||||
Utils.error('Python sqlite3 module is not found')
|
||||
updater = SQLiteDBUpdater(version)
|
||||
|
||||
else:
|
||||
def to_db_string(info):
|
||||
if info is None:
|
||||
return 'SQLite3'
|
||||
else:
|
||||
return 'MySQL'
|
||||
Utils.error('Error:\n ccnet is using %s\n seafile is using %s\n seahub is using %s\n'
|
||||
% (to_db_string(ccnet_db_info),
|
||||
to_db_string(seafile_db_info),
|
||||
to_db_string(seahub_db_info)))
|
||||
|
||||
return updater
|
||||
|
||||
def update_db(self):
|
||||
ccnet_sql = os.path.join(self.sql_dir, 'ccnet.sql')
|
||||
seafile_sql = os.path.join(self.sql_dir, 'seafile.sql')
|
||||
seahub_sql = os.path.join(self.sql_dir, 'seahub.sql')
|
||||
seafevents_sql = os.path.join(self.sql_dir, 'seafevents.sql')
|
||||
|
||||
if os.path.exists(ccnet_sql):
|
||||
Utils.info('updating ccnet database...')
|
||||
self.update_ccnet_sql(ccnet_sql)
|
||||
|
||||
if os.path.exists(seafile_sql):
|
||||
Utils.info('updating seafile database...')
|
||||
self.update_seafile_sql(seafile_sql)
|
||||
|
||||
if os.path.exists(seahub_sql):
|
||||
Utils.info('updating seahub database...')
|
||||
self.update_seahub_sql(seahub_sql)
|
||||
|
||||
if os.path.exists(seafevents_sql):
|
||||
self.update_seafevents_sql(seafevents_sql)
|
||||
|
||||
@staticmethod
|
||||
def get_ccnet_mysql_info(version):
|
||||
config_path = env_mgr.central_config_dir
|
||||
|
||||
ccnet_conf = os.path.join(config_path, 'ccnet.conf')
|
||||
defaults = {
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '3306',
|
||||
'UNIX_SOCKET': '',
|
||||
}
|
||||
|
||||
config = Utils.read_config(ccnet_conf, defaults)
|
||||
db_section = 'Database'
|
||||
|
||||
if not config.has_section(db_section):
|
||||
return None
|
||||
|
||||
type = config.get(db_section, 'ENGINE')
|
||||
if type != 'mysql':
|
||||
return None
|
||||
|
||||
try:
|
||||
host = config.get(db_section, 'HOST')
|
||||
port = config.getint(db_section, 'PORT')
|
||||
username = config.get(db_section, 'USER')
|
||||
password = config.get(db_section, 'PASSWD')
|
||||
db = config.get(db_section, 'DB')
|
||||
unix_socket = config.get(db_section, 'UNIX_SOCKET')
|
||||
except configparser.NoOptionError as e:
|
||||
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
||||
return info
|
||||
|
||||
@staticmethod
|
||||
def get_seafile_mysql_info(version):
|
||||
config_path = env_mgr.central_config_dir
|
||||
|
||||
seafile_conf = os.path.join(config_path, 'seafile.conf')
|
||||
defaults = {
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '3306',
|
||||
'UNIX_SOCKET': '',
|
||||
}
|
||||
config = Utils.read_config(seafile_conf, defaults)
|
||||
db_section = 'database'
|
||||
|
||||
if not config.has_section(db_section):
|
||||
return None
|
||||
|
||||
type = config.get(db_section, 'type')
|
||||
if type != 'mysql':
|
||||
return None
|
||||
|
||||
try:
|
||||
host = config.get(db_section, 'host')
|
||||
port = config.getint(db_section, 'port')
|
||||
username = config.get(db_section, 'user')
|
||||
password = config.get(db_section, 'password')
|
||||
db = config.get(db_section, 'db_name')
|
||||
unix_socket = config.get(db_section, 'unix_socket')
|
||||
except configparser.NoOptionError as e:
|
||||
Utils.error('Database config in seafile.conf is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
||||
return info
|
||||
|
||||
@staticmethod
|
||||
def get_seahub_mysql_info():
|
||||
sys.path.insert(0, env_mgr.top_dir)
|
||||
if env_mgr.central_config_dir:
|
||||
sys.path.insert(0, env_mgr.central_config_dir)
|
||||
try:
|
||||
import seahub_settings # pylint: disable=F0401
|
||||
except ImportError as e:
|
||||
Utils.error('Failed to import seahub_settings.py: %s' % e)
|
||||
|
||||
if not hasattr(seahub_settings, 'DATABASES'):
|
||||
return None
|
||||
|
||||
try:
|
||||
d = seahub_settings.DATABASES['default']
|
||||
if d['ENGINE'] != 'django.db.backends.mysql':
|
||||
return None
|
||||
|
||||
host = d.get('HOST', '127.0.0.1')
|
||||
port = int(d.get('PORT', 3306))
|
||||
username = d['USER']
|
||||
password = d['PASSWORD']
|
||||
db = d['NAME']
|
||||
unix_socket = host if host.startswith('/') else None
|
||||
except KeyError:
|
||||
Utils.error('Database config in seahub_settings.py is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
||||
return info
|
||||
|
||||
def update_ccnet_sql(self, ccnet_sql):
|
||||
raise NotImplementedError
|
||||
|
||||
def update_seafile_sql(self, seafile_sql):
|
||||
raise NotImplementedError
|
||||
|
||||
def update_seahub_sql(self, seahub_sql):
|
||||
raise NotImplementedError
|
||||
|
||||
def update_seafevents_sql(self, seafevents_sql):
|
||||
raise NotImplementedError
|
||||
|
||||
class CcnetSQLiteDB(object):
|
||||
def __init__(self, ccnet_dir):
|
||||
self.ccnet_dir = ccnet_dir
|
||||
|
||||
def get_db(self, dbname):
|
||||
dbs = (
|
||||
'ccnet.db',
|
||||
'GroupMgr/groupmgr.db',
|
||||
'misc/config.db',
|
||||
'OrgMgr/orgmgr.db',
|
||||
'PeerMgr/usermgr.db',
|
||||
)
|
||||
for db in dbs:
|
||||
if os.path.splitext(os.path.basename(db))[0] == dbname:
|
||||
return os.path.join(self.ccnet_dir, db)
|
||||
|
||||
class SQLiteDBUpdater(DBUpdater):
|
||||
def __init__(self, version):
|
||||
DBUpdater.__init__(self, version, 'sqlite3')
|
||||
|
||||
self.ccnet_db = CcnetSQLiteDB(env_mgr.ccnet_dir)
|
||||
self.seafile_db = os.path.join(env_mgr.seafile_dir, 'seafile.db')
|
||||
self.seahub_db = os.path.join(env_mgr.top_dir, 'seahub.db')
|
||||
self.seafevents_db = os.path.join(env_mgr.top_dir, 'seafevents.db')
|
||||
|
||||
def update_db(self):
|
||||
super(SQLiteDBUpdater, self).update_db()
|
||||
for sql_path in glob.glob(os.path.join(self.sql_dir, 'ccnet', '*.sql')):
|
||||
self.update_ccnet_sql(sql_path)
|
||||
|
||||
def apply_sqls(self, db_path, sql_path):
|
||||
with open(sql_path, 'r') as fp:
|
||||
lines = fp.read().split(';')
|
||||
|
||||
with sqlite3.connect(db_path) as conn:
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
else:
|
||||
conn.execute(line)
|
||||
|
||||
def update_ccnet_sql(self, sql_path):
|
||||
dbname = os.path.splitext(os.path.basename(sql_path))[0]
|
||||
self.apply_sqls(self.ccnet_db.get_db(dbname), sql_path)
|
||||
|
||||
def update_seafile_sql(self, sql_path):
|
||||
self.apply_sqls(self.seafile_db, sql_path)
|
||||
|
||||
def update_seahub_sql(self, sql_path):
|
||||
self.apply_sqls(self.seahub_db, sql_path)
|
||||
|
||||
def update_seafevents_sql(self, sql_path):
|
||||
if self.is_pro:
|
||||
Utils.info('seafevents do not support sqlite3 database')
|
||||
|
||||
|
||||
class MySQLDBUpdater(DBUpdater):
|
||||
def __init__(self, version, ccnet_db_info, seafile_db_info, seahub_db_info):
|
||||
DBUpdater.__init__(self, version, 'mysql')
|
||||
self.ccnet_db_info = ccnet_db_info
|
||||
self.seafile_db_info = seafile_db_info
|
||||
self.seahub_db_info = seahub_db_info
|
||||
|
||||
def update_ccnet_sql(self, ccnet_sql):
|
||||
self.apply_sqls(self.ccnet_db_info, ccnet_sql)
|
||||
|
||||
def update_seafile_sql(self, seafile_sql):
|
||||
self.apply_sqls(self.seafile_db_info, seafile_sql)
|
||||
|
||||
def update_seahub_sql(self, seahub_sql):
|
||||
self.apply_sqls(self.seahub_db_info, seahub_sql)
|
||||
|
||||
def update_seafevents_sql(self, seafevents_sql):
|
||||
if self.is_pro:
|
||||
Utils.info('updating seafevents database...')
|
||||
self.apply_sqls(self.seahub_db_info, seafevents_sql)
|
||||
|
||||
def get_conn(self, info):
|
||||
kw = dict(
|
||||
user=info.username,
|
||||
passwd=info.password,
|
||||
db=info.db,
|
||||
)
|
||||
if info.unix_socket:
|
||||
kw['unix_socket'] = info.unix_socket
|
||||
else:
|
||||
kw['host'] = info.host
|
||||
kw['port'] = info.port
|
||||
try:
|
||||
conn = MySQLdb.connect(**kw)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
msg = str(e.args[1])
|
||||
else:
|
||||
msg = str(e)
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (info.db, msg))
|
||||
|
||||
return conn
|
||||
|
||||
def execute_sql(self, conn, sql):
|
||||
cursor = conn.cursor()
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
except Exception as e:
|
||||
msg = str(e)
|
||||
Utils.warning('Failed to execute sql: %s' % msg)
|
||||
|
||||
def apply_sqls(self, info, sql_path):
|
||||
with open(sql_path, 'r') as fp:
|
||||
lines = fp.read().split(';')
|
||||
|
||||
conn = self.get_conn(info)
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
else:
|
||||
self.execute_sql(conn, line)
|
||||
|
||||
|
||||
def main():
|
||||
skipdb = os.environ.get('SEAFILE_SKIP_DB_UPGRADE', '').lower()
|
||||
if skipdb in ('1', 'true', 'on'):
|
||||
print('Database upgrade skipped because SEAFILE_SKIP_DB_UPGRADE=%s' % skipdb)
|
||||
sys.exit()
|
||||
version = sys.argv[1]
|
||||
db_updater = DBUpdater.get_instance(version)
|
||||
db_updater.update_db()
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@@ -1,115 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
|
||||
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
|
||||
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
|
||||
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
|
||||
|
||||
echo
|
||||
echo "-------------------------------------------------------------"
|
||||
echo "This script would do the minor upgrade for you."
|
||||
echo "Press [ENTER] to contiune"
|
||||
echo "-------------------------------------------------------------"
|
||||
echo
|
||||
read dummy
|
||||
|
||||
media_dir=${INSTALLPATH}/seahub/media
|
||||
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
|
||||
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
|
||||
seafile_server_symlink=${TOPDIR}/seafile-server-latest
|
||||
seahub_data_dir=${TOPDIR}/seahub-data
|
||||
|
||||
function migrate_avatars() {
|
||||
echo
|
||||
echo "------------------------------"
|
||||
echo "migrating avatars ..."
|
||||
echo
|
||||
# move "media/avatars" directory outside
|
||||
if [[ ! -d ${dest_avatar_dir} ]]; then
|
||||
echo
|
||||
echo "Error: avatars directory \"${dest_avatar_dir}\" does not exist" 2>&1
|
||||
echo
|
||||
exit 1
|
||||
|
||||
elif [[ ! -L ${orig_avatar_dir} ]]; then
|
||||
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
|
||||
rm -rf "${orig_avatar_dir}"
|
||||
ln -s ../../../seahub-data/avatars "${media_dir}"
|
||||
fi
|
||||
echo
|
||||
echo "DONE"
|
||||
echo "------------------------------"
|
||||
echo
|
||||
}
|
||||
|
||||
function make_media_custom_symlink() {
|
||||
media_symlink=${INSTALLPATH}/seahub/media/custom
|
||||
if [[ -L "${media_symlink}" ]]; then
|
||||
return
|
||||
|
||||
elif [[ ! -e "${media_symlink}" ]]; then
|
||||
ln -s ../../../seahub-data/custom "${media_symlink}"
|
||||
return
|
||||
|
||||
|
||||
elif [[ -d "${media_symlink}" ]]; then
|
||||
cp -rf "${media_symlink}" "${seahub_data_dir}/"
|
||||
rm -rf "${media_symlink}"
|
||||
ln -s ../../../seahub-data/custom "${media_symlink}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function move_old_customdir_outside() {
|
||||
# find the path of the latest seafile server folder
|
||||
if [[ -L ${seafile_server_symlink} ]]; then
|
||||
latest_server=$(readlink -f "${seafile_server_symlink}")
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
old_customdir=${latest_server}/seahub/media/custom
|
||||
|
||||
# old customdir is already a symlink, do nothing
|
||||
if [[ -L "${old_customdir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# old customdir does not exist, do nothing
|
||||
if [[ ! -e "${old_customdir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# media/custom exist and is not a symlink
|
||||
cp -rf "${old_customdir}" "${seahub_data_dir}/"
|
||||
}
|
||||
|
||||
function update_latest_symlink() {
|
||||
# update the symlink seafile-server to the new server version
|
||||
echo
|
||||
echo "updating seafile-server-latest symbolic link to ${INSTALLPATH} ..."
|
||||
echo
|
||||
if ! rm -f "${seafile_server_symlink}"; then
|
||||
echo "Failed to remove ${seafile_server_symlink}"
|
||||
echo
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
|
||||
echo "Failed to update ${seafile_server_symlink} symbolic link."
|
||||
echo
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
migrate_avatars;
|
||||
|
||||
move_old_customdir_outside;
|
||||
make_media_custom_symlink;
|
||||
|
||||
update_latest_symlink;
|
||||
|
||||
|
||||
echo "DONE"
|
||||
echo "------------------------------"
|
||||
echo
|
@@ -1,58 +0,0 @@
|
||||
ALTER TABLE `file_tags_filetags` DROP FOREIGN KEY `file_tags_filetags_parent_folder_uuid_i_df56f09b_fk_tags_file`;
|
||||
ALTER TABLE `file_tags_filetags` DROP `parent_folder_uuid_id`;
|
||||
|
||||
|
||||
DROP TABLE drafts_reviewcomment;
|
||||
DROP TABLE drafts_reviewreviewer;
|
||||
DROP TABLE drafts_draftreview;
|
||||
DROP TABLE drafts_draft;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `drafts_draft` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`created_at` datetime(6) NOT NULL,
|
||||
`updated_at` datetime(6) NOT NULL,
|
||||
`username` varchar(255) NOT NULL,
|
||||
`origin_repo_id` varchar(36) NOT NULL,
|
||||
`origin_file_version` varchar(100) NOT NULL,
|
||||
`draft_file_path` varchar(1024) NOT NULL,
|
||||
`origin_file_uuid` char(32) NOT NULL,
|
||||
`publish_file_version` varchar(100) DEFAULT NULL,
|
||||
`status` varchar(20) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `drafts_draft_origin_file_uuid_id_f150319e_fk_tags_file` (`origin_file_uuid`),
|
||||
KEY `drafts_draft_created_at_e9f4523f` (`created_at`),
|
||||
KEY `drafts_draft_updated_at_0a144b05` (`updated_at`),
|
||||
KEY `drafts_draft_username_73e6738b` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `drafts_draftreviewer` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`reviewer` varchar(255) NOT NULL,
|
||||
`draft_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `drafts_draftreviewer_reviewer_e4c777ac` (`reviewer`),
|
||||
KEY `drafts_draftreviewer_draft_id_4ea59775_fk_drafts_draft_id` (`draft_id`),
|
||||
CONSTRAINT `drafts_draftreviewer_draft_id_4ea59775_fk_drafts_draft_id` FOREIGN KEY (`draft_id`) REFERENCES `drafts_draft` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `organizations_orgsettings` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`org_id` int(11) NOT NULL,
|
||||
`role` varchar(100) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `organizations_orgsettings_org_id_630f6843_uniq` (`org_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
DROP INDEX `profile_profile_contact_email_0975e4bf_uniq` ON `profile_profile`;
|
||||
ALTER TABLE `profile_profile` ADD CONSTRAINT `profile_profile_contact_email_0975e4bf_uniq` UNIQUE (`contact_email`);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `social_auth_usersocialauth` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`username` varchar(255) NOT NULL,
|
||||
`provider` varchar(32) NOT NULL,
|
||||
`uid` varchar(150) NOT NULL,
|
||||
`extra_data` longtext NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `social_auth_usersocialauth_provider_uid_e6b5e668_uniq` (`provider`,`uid`),
|
||||
KEY `social_auth_usersocialauth_username_3f06b5cf` (`username`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
@@ -1 +0,0 @@
|
||||
ALTER TABLE RepoInfo ADD COLUMN status INTEGER DEFAULT 0;
|
@@ -1,239 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
|
||||
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
|
||||
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
|
||||
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
|
||||
default_ccnet_conf_dir=${TOPDIR}/ccnet
|
||||
default_conf_dir=${TOPDIR}/conf
|
||||
default_pids_dir=${TOPDIR}/pids
|
||||
default_logs_dir=${TOPDIR}/logs
|
||||
seafile_server_symlink=${TOPDIR}/seafile-server-latest
|
||||
seahub_data_dir=${TOPDIR}/seahub-data
|
||||
seahub_settings_py=${TOPDIR}/seahub_settings.py
|
||||
|
||||
manage_py=${INSTALLPATH}/seahub/manage.py
|
||||
|
||||
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
|
||||
export SEAFILE_CENTRAL_CONF_DIR=${default_conf_dir}
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.6/site-packages:${INSTALLPATH}/seafile/lib64/python2.6/site-packages:${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
|
||||
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
|
||||
|
||||
prev_version=1.0
|
||||
current_version=1.1
|
||||
|
||||
echo
|
||||
echo "-------------------------------------------------------------"
|
||||
echo "This script would upgrade your seafile server from ${prev_version} to ${current_version}"
|
||||
echo "Press [ENTER] to contiune"
|
||||
echo "-------------------------------------------------------------"
|
||||
echo
|
||||
read dummy
|
||||
|
||||
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
|
||||
else
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function read_seafile_data_dir () {
|
||||
seafile_ini=${default_ccnet_conf_dir}/seafile.ini
|
||||
if [[ ! -f ${seafile_ini} ]]; then
|
||||
echo "${seafile_ini} not found. Now quit"
|
||||
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 ""
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
export SEAFILE_CONF_DIR=$seafile_data_dir
|
||||
}
|
||||
|
||||
function ensure_server_not_running() {
|
||||
# test whether seafile server has been stopped.
|
||||
if pgrep seaf-server 2>/dev/null 1>&2 ; then
|
||||
echo
|
||||
echo "seafile server is still running !"
|
||||
echo "stop it using scripts before upgrade."
|
||||
echo
|
||||
exit 1
|
||||
elif pgrep -f "${manage_py} run_gunicorn" 2>/dev/null 1>&2 \
|
||||
|| pgrep -f "seahub.wsgi:application" 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "seahub server is still running !"
|
||||
echo "stop it before upgrade."
|
||||
echo
|
||||
exit 1
|
||||
elif pgrep -f "${manage_py} runfcgi" 2>/dev/null 1>&2 ; then
|
||||
echo
|
||||
echo "seahub server is still running !"
|
||||
echo "stop it before upgrade."
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function migrate_avatars() {
|
||||
echo
|
||||
echo "migrating avatars ..."
|
||||
echo
|
||||
media_dir=${INSTALLPATH}/seahub/media
|
||||
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
|
||||
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
|
||||
|
||||
# move "media/avatars" directory outside
|
||||
if [[ ! -d ${dest_avatar_dir} ]]; then
|
||||
mkdir -p "${TOPDIR}/seahub-data"
|
||||
mv "${orig_avatar_dir}" "${dest_avatar_dir}" 2>/dev/null 1>&2
|
||||
ln -s ../../../seahub-data/avatars "${media_dir}"
|
||||
|
||||
elif [[ ! -L ${orig_avatar_dir} ]]; then
|
||||
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
|
||||
rm -rf "${orig_avatar_dir}"
|
||||
ln -s ../../../seahub-data/avatars "${media_dir}"
|
||||
fi
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
function update_database() {
|
||||
echo
|
||||
echo "Updating seafile/seahub database ..."
|
||||
echo
|
||||
|
||||
db_update_helper=${UPGRADE_DIR}/db_update_helper.py
|
||||
if ! $PYTHON "${db_update_helper}" 1.1.0; then
|
||||
echo
|
||||
echo "Failed to upgrade your database"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
function upgrade_seafile_server_latest_symlink() {
|
||||
# update the symlink seafile-server to the new server version
|
||||
if [[ -L "${seafile_server_symlink}" || ! -e "${seafile_server_symlink}" ]]; then
|
||||
echo
|
||||
printf "updating \033[33m${seafile_server_symlink}\033[m symbolic link to \033[33m${INSTALLPATH}\033[m ...\n\n"
|
||||
echo
|
||||
if ! rm -f "${seafile_server_symlink}"; then
|
||||
echo "Failed to remove ${seafile_server_symlink}"
|
||||
echo
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
|
||||
echo "Failed to update ${seafile_server_symlink} symbolic link."
|
||||
echo
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function make_media_custom_symlink() {
|
||||
media_symlink=${INSTALLPATH}/seahub/media/custom
|
||||
if [[ -L "${media_symlink}" ]]; then
|
||||
return
|
||||
|
||||
elif [[ ! -e "${media_symlink}" ]]; then
|
||||
ln -s ../../../seahub-data/custom "${media_symlink}"
|
||||
return
|
||||
|
||||
|
||||
elif [[ -d "${media_symlink}" ]]; then
|
||||
cp -rf "${media_symlink}" "${seahub_data_dir}/"
|
||||
rm -rf "${media_symlink}"
|
||||
ln -s ../../../seahub-data/custom "${media_symlink}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function move_old_customdir_outside() {
|
||||
# find the path of the latest seafile server folder
|
||||
if [[ -L ${seafile_server_symlink} ]]; then
|
||||
latest_server=$(readlink -f "${seafile_server_symlink}")
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
old_customdir=${latest_server}/seahub/media/custom
|
||||
|
||||
# old customdir is already a symlink, do nothing
|
||||
if [[ -L "${old_customdir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# old customdir does not exist, do nothing
|
||||
if [[ ! -e "${old_customdir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# media/custom exist and is not a symlink
|
||||
cp -rf "${old_customdir}" "${seahub_data_dir}/"
|
||||
}
|
||||
|
||||
function add_gunicorn_conf() {
|
||||
gunicorn_conf=${default_conf_dir}/gunicorn.conf
|
||||
if ! $(cat > ${gunicorn_conf} <<EOF
|
||||
import os
|
||||
|
||||
daemon = True
|
||||
workers = 5
|
||||
|
||||
# default localhost:8000
|
||||
bind = "127.0.0.1:8000"
|
||||
|
||||
# Pid
|
||||
pids_dir = '$default_pids_dir'
|
||||
pidfile = os.path.join(pids_dir, 'seahub.pid')
|
||||
|
||||
# for file upload, we need a longer timeout value (default is only 30s, too short)
|
||||
timeout = 1200
|
||||
|
||||
limit_request_line = 8190
|
||||
EOF
|
||||
); then
|
||||
echo "failed to generate gunicorn.conf";
|
||||
fi
|
||||
}
|
||||
|
||||
#################
|
||||
# The main execution flow of the script
|
||||
################
|
||||
|
||||
check_python_executable;
|
||||
read_seafile_data_dir;
|
||||
ensure_server_not_running;
|
||||
|
||||
update_database;
|
||||
migrate_avatars;
|
||||
|
||||
move_old_customdir_outside;
|
||||
make_media_custom_symlink;
|
||||
upgrade_seafile_server_latest_symlink;
|
||||
|
||||
add_gunicorn_conf;
|
||||
|
||||
echo
|
||||
echo "-----------------------------------------------------------------"
|
||||
echo "Upgraded your seafile server successfully."
|
||||
echo "-----------------------------------------------------------------"
|
||||
echo
|
@@ -1,239 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f "$0") # haiwen/seafile-server-1.3.0/upgrade/upgrade_xx_xx.sh
|
||||
UPGRADE_DIR=$(dirname "$SCRIPT") # haiwen/seafile-server-1.3.0/upgrade/
|
||||
INSTALLPATH=$(dirname "$UPGRADE_DIR") # haiwen/seafile-server-1.3.0/
|
||||
TOPDIR=$(dirname "${INSTALLPATH}") # haiwen/
|
||||
default_ccnet_conf_dir=${TOPDIR}/ccnet
|
||||
default_conf_dir=${TOPDIR}/conf
|
||||
default_pids_dir=${TOPDIR}/pids
|
||||
default_logs_dir=${TOPDIR}/logs
|
||||
seafile_server_symlink=${TOPDIR}/seafile-server-latest
|
||||
seahub_data_dir=${TOPDIR}/seahub-data
|
||||
seahub_settings_py=${TOPDIR}/seahub_settings.py
|
||||
|
||||
manage_py=${INSTALLPATH}/seahub/manage.py
|
||||
|
||||
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
|
||||
export SEAFILE_CENTRAL_CONF_DIR=${default_conf_dir}
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.6/site-packages:${INSTALLPATH}/seafile/lib64/python2.6/site-packages:${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
|
||||
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
|
||||
|
||||
prev_version=1.1
|
||||
current_version=1.2
|
||||
|
||||
echo
|
||||
echo "-------------------------------------------------------------"
|
||||
echo "This script would upgrade your seafile server from ${prev_version} to ${current_version}"
|
||||
echo "Press [ENTER] to contiune"
|
||||
echo "-------------------------------------------------------------"
|
||||
echo
|
||||
read dummy
|
||||
|
||||
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
|
||||
else
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function read_seafile_data_dir () {
|
||||
seafile_ini=${default_ccnet_conf_dir}/seafile.ini
|
||||
if [[ ! -f ${seafile_ini} ]]; then
|
||||
echo "${seafile_ini} not found. Now quit"
|
||||
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 ""
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
export SEAFILE_CONF_DIR=$seafile_data_dir
|
||||
}
|
||||
|
||||
function ensure_server_not_running() {
|
||||
# test whether seafile server has been stopped.
|
||||
if pgrep seaf-server 2>/dev/null 1>&2 ; then
|
||||
echo
|
||||
echo "seafile server is still running !"
|
||||
echo "stop it using scripts before upgrade."
|
||||
echo
|
||||
exit 1
|
||||
elif pgrep -f "${manage_py} run_gunicorn" 2>/dev/null 1>&2 \
|
||||
|| pgrep -f "seahub.wsgi:application" 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "seahub server is still running !"
|
||||
echo "stop it before upgrade."
|
||||
echo
|
||||
exit 1
|
||||
elif pgrep -f "${manage_py} runfcgi" 2>/dev/null 1>&2 ; then
|
||||
echo
|
||||
echo "seahub server is still running !"
|
||||
echo "stop it before upgrade."
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function migrate_avatars() {
|
||||
echo
|
||||
echo "migrating avatars ..."
|
||||
echo
|
||||
media_dir=${INSTALLPATH}/seahub/media
|
||||
orig_avatar_dir=${INSTALLPATH}/seahub/media/avatars
|
||||
dest_avatar_dir=${TOPDIR}/seahub-data/avatars
|
||||
|
||||
# move "media/avatars" directory outside
|
||||
if [[ ! -d ${dest_avatar_dir} ]]; then
|
||||
mkdir -p "${TOPDIR}/seahub-data"
|
||||
mv "${orig_avatar_dir}" "${dest_avatar_dir}" 2>/dev/null 1>&2
|
||||
ln -s ../../../seahub-data/avatars "${media_dir}"
|
||||
|
||||
elif [[ ! -L ${orig_avatar_dir} ]]; then
|
||||
mv "${orig_avatar_dir}"/* "${dest_avatar_dir}" 2>/dev/null 1>&2
|
||||
rm -rf "${orig_avatar_dir}"
|
||||
ln -s ../../../seahub-data/avatars "${media_dir}"
|
||||
fi
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
function update_database() {
|
||||
echo
|
||||
echo "Updating seafile/seahub database ..."
|
||||
echo
|
||||
|
||||
db_update_helper=${UPGRADE_DIR}/db_update_helper.py
|
||||
if ! $PYTHON "${db_update_helper}" 1.2.0; then
|
||||
echo
|
||||
echo "Failed to upgrade your database"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
function upgrade_seafile_server_latest_symlink() {
|
||||
# update the symlink seafile-server to the new server version
|
||||
if [[ -L "${seafile_server_symlink}" || ! -e "${seafile_server_symlink}" ]]; then
|
||||
echo
|
||||
printf "updating \033[33m${seafile_server_symlink}\033[m symbolic link to \033[33m${INSTALLPATH}\033[m ...\n\n"
|
||||
echo
|
||||
if ! rm -f "${seafile_server_symlink}"; then
|
||||
echo "Failed to remove ${seafile_server_symlink}"
|
||||
echo
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if ! ln -s "$(basename ${INSTALLPATH})" "${seafile_server_symlink}"; then
|
||||
echo "Failed to update ${seafile_server_symlink} symbolic link."
|
||||
echo
|
||||
exit 1;
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function make_media_custom_symlink() {
|
||||
media_symlink=${INSTALLPATH}/seahub/media/custom
|
||||
if [[ -L "${media_symlink}" ]]; then
|
||||
return
|
||||
|
||||
elif [[ ! -e "${media_symlink}" ]]; then
|
||||
ln -s ../../../seahub-data/custom "${media_symlink}"
|
||||
return
|
||||
|
||||
|
||||
elif [[ -d "${media_symlink}" ]]; then
|
||||
cp -rf "${media_symlink}" "${seahub_data_dir}/"
|
||||
rm -rf "${media_symlink}"
|
||||
ln -s ../../../seahub-data/custom "${media_symlink}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
function move_old_customdir_outside() {
|
||||
# find the path of the latest seafile server folder
|
||||
if [[ -L ${seafile_server_symlink} ]]; then
|
||||
latest_server=$(readlink -f "${seafile_server_symlink}")
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
old_customdir=${latest_server}/seahub/media/custom
|
||||
|
||||
# old customdir is already a symlink, do nothing
|
||||
if [[ -L "${old_customdir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# old customdir does not exist, do nothing
|
||||
if [[ ! -e "${old_customdir}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
# media/custom exist and is not a symlink
|
||||
cp -rf "${old_customdir}" "${seahub_data_dir}/"
|
||||
}
|
||||
|
||||
function add_gunicorn_conf() {
|
||||
gunicorn_conf=${default_conf_dir}/gunicorn.conf
|
||||
if ! $(cat > ${gunicorn_conf} <<EOF
|
||||
import os
|
||||
|
||||
daemon = True
|
||||
workers = 5
|
||||
|
||||
# default localhost:8000
|
||||
bind = "127.0.0.1:8000"
|
||||
|
||||
# Pid
|
||||
pids_dir = '$default_pids_dir'
|
||||
pidfile = os.path.join(pids_dir, 'seahub.pid')
|
||||
|
||||
# for file upload, we need a longer timeout value (default is only 30s, too short)
|
||||
timeout = 1200
|
||||
|
||||
limit_request_line = 8190
|
||||
EOF
|
||||
); then
|
||||
echo "failed to generate gunicorn.conf";
|
||||
fi
|
||||
}
|
||||
|
||||
#################
|
||||
# The main execution flow of the script
|
||||
################
|
||||
|
||||
check_python_executable;
|
||||
read_seafile_data_dir;
|
||||
ensure_server_not_running;
|
||||
|
||||
update_database;
|
||||
migrate_avatars;
|
||||
|
||||
move_old_customdir_outside;
|
||||
make_media_custom_symlink;
|
||||
upgrade_seafile_server_latest_symlink;
|
||||
|
||||
add_gunicorn_conf;
|
||||
|
||||
echo
|
||||
echo "-----------------------------------------------------------------"
|
||||
echo "Upgraded your seafile server successfully."
|
||||
echo "-----------------------------------------------------------------"
|
||||
echo
|
@@ -1,53 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
INSTALLPATH=$(dirname "${SCRIPT}")
|
||||
TOPDIR=$(dirname "${INSTALLPATH}")
|
||||
default_ccnet_conf_dir=${TOPDIR}/ccnet
|
||||
central_config_dir=${TOPDIR}/conf
|
||||
|
||||
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
|
||||
else
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function read_seafile_data_dir () {
|
||||
seafile_ini=${default_ccnet_conf_dir}/seafile.ini
|
||||
if [[ ! -f ${seafile_ini} ]]; then
|
||||
echo "${seafile_ini} not found. Now quit"
|
||||
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 ""
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
check_python_executable;
|
||||
read_seafile_data_dir;
|
||||
|
||||
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
|
||||
export SEAFILE_CONF_DIR=${seafile_data_dir}
|
||||
export SEAFILE_CENTRAL_CONF_DIR=${central_config_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
|
||||
exec "$PYTHON" "$manage_py" export_users
|
@@ -1,90 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo ""
|
||||
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
INSTALLPATH=$(dirname "${SCRIPT}")
|
||||
TOPDIR=$(dirname "${INSTALLPATH}")
|
||||
default_ccnet_conf_dir=${TOPDIR}/ccnet
|
||||
default_seafile_data_dir=${TOPDIR}/seafile-data
|
||||
default_conf_dir=${TOPDIR}/conf
|
||||
|
||||
migrate_to_ceph=${INSTALLPATH}/seafobj_migrate.py
|
||||
|
||||
script_name=$0
|
||||
function usage () {
|
||||
echo "usage : "
|
||||
echo "$(basename ${script_name}) ceph_seafile_central_conf_dir"
|
||||
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 "Install python 2.6+ before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function validate_ccnet_conf_dir () {
|
||||
if [[ ! -d ${default_ccnet_conf_dir} ]]; then
|
||||
echo "Error: there is no ccnet config directory."
|
||||
echo "Have you run setup-seafile.sh before this?"
|
||||
echo ""
|
||||
exit -1;
|
||||
fi
|
||||
}
|
||||
|
||||
function do_migrate_to_ceph () {
|
||||
validate_ccnet_conf_dir;
|
||||
|
||||
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
|
||||
export SEAFILE_CONF_DIR=${default_seafile_data_dir}
|
||||
export SEAFILE_CENTRAL_CONF_DIR=${default_conf_dir}
|
||||
export CEPH_SEAFILE_CENTRAL_CONF_DIR=${ceph_seafile_central_conf_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
|
||||
|
||||
$PYTHON ${migrate_to_ceph}
|
||||
}
|
||||
|
||||
check_python_executable;
|
||||
|
||||
if [ $# -gt 0 ];
|
||||
then
|
||||
for param in $@;
|
||||
do
|
||||
if [ ${param} = "-h" -o ${param} = "--help" ];
|
||||
then
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ $# -ne 1 ];
|
||||
then
|
||||
usage;
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
ceph_seafile_central_conf_dir="$1"
|
||||
do_migrate_to_ceph;
|
||||
|
||||
echo "Done."
|
@@ -11,14 +11,18 @@ function check_python_executable() {
|
||||
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
|
||||
else
|
||||
if !(python --version 2>&1 | grep "3\.[0-9]\.[0-9]") 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "The current version of python is not 3.x.x, please use Python 3.x.x ."
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PYTHON="python"$(python --version | cut -b 8-10)
|
||||
if !which $PYTHON 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of $PYTHON in PATH"
|
||||
echo "Install $PYTHON before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
@@ -46,8 +50,7 @@ read_seafile_data_dir;
|
||||
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
|
||||
export SEAFILE_CONF_DIR=${seafile_data_dir}
|
||||
export SEAFILE_CENTRAL_CONF_DIR=${central_config_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
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python3.6/site-packages:${INSTALLPATH}/seafile/lib64/python3.6/site-packages:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
|
||||
|
||||
manage_py=${INSTALLPATH}/seahub/manage.py
|
||||
exec "$PYTHON" "$manage_py" createsuperuser
|
||||
|
@@ -1,53 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is a wrapper shell script for the real seaf-cli command.
|
||||
# It prepares necessary environment variables and exec the real script.
|
||||
|
||||
# seafile cli client requires python 2.6 or 2.7
|
||||
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 "Install python 2.6+ before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_python_executable
|
||||
|
||||
# seafile cli client requires the argparse module
|
||||
if ! $PYTHON -c 'import argparse' 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Python argparse module is required"
|
||||
echo "see [https://pypi.python.org/pypi/argparse]"
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT=$(readlink -f "$0")
|
||||
INSTALLPATH=$(dirname "${SCRIPT}")
|
||||
|
||||
SEAFILE_BIN_DIR=${INSTALLPATH}/bin
|
||||
SEAFILE_LIB_DIR=${INSTALLPATH}/lib:${INSTALLPATH}/lib64
|
||||
SEAFILE_PYTHON_PATH=${INSTALLPATH}/lib/python2.6/site-packages:${INSTALLPATH}/lib64/python2.6/site-packages:${INSTALLPATH}/lib/python2.7/site-packages:${INSTALLPATH}/lib64/python2.7/site-packages
|
||||
|
||||
SEAF_CLI=${SEAFILE_BIN_DIR}/seaf-cli.py
|
||||
|
||||
PATH=${SEAFILE_BIN_DIR}:${PATH} \
|
||||
PYTHONPATH=${SEAFILE_PYTHON_PATH}:${PYTHONPATH} \
|
||||
SEAFILE_LD_LIBRARY_PATH=${SEAFILE_LIB_DIR}:${LD_LIBRARY_PATH} \
|
||||
exec $PYTHON ${SEAF_CLI} "$@"
|
@@ -23,7 +23,7 @@ gunicorn_conf=${TOPDIR}/conf/gunicorn.conf
|
||||
pidfile=${TOPDIR}/pids/seahub.pid
|
||||
errorlog=${TOPDIR}/logs/gunicorn_error.log
|
||||
accesslog=${TOPDIR}/logs/gunicorn_access.log
|
||||
gunicorn_exe=${INSTALLPATH}/seahub/thirdpart/gunicorn
|
||||
gunicorn_exe=${INSTALLPATH}/seahub/thirdpart/bin/gunicorn
|
||||
|
||||
script_name=$0
|
||||
function usage () {
|
||||
@@ -51,14 +51,18 @@ function check_python_executable() {
|
||||
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
|
||||
else
|
||||
if !(python --version 2>&1 | grep "3\.[0-9]\.[0-9]") 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "The current version of python is not 3.x.x, please use Python 3.x.x ."
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PYTHON="python"$(python --version | cut -b 8-10)
|
||||
if !which $PYTHON 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of $PYTHON in PATH"
|
||||
echo "Install $PYTHON before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
@@ -211,8 +215,8 @@ function prepare_env() {
|
||||
export CCNET_CONF_DIR=${default_ccnet_conf_dir}
|
||||
export SEAFILE_CONF_DIR=${seafile_data_dir}
|
||||
export SEAFILE_CENTRAL_CONF_DIR=${central_config_dir}
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.6/site-packages:${INSTALLPATH}/seafile/lib64/python2.6/site-packages:${INSTALLPATH}/seahub:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python2.7/site-packages:${INSTALLPATH}/seafile/lib64/python2.7/site-packages:$PYTHONPATH
|
||||
export PYTHONPATH=${INSTALLPATH}/seafile/lib/python3.6/site-packages:${INSTALLPATH}/seafile/lib64/python3.6/site-packages:${INSTALLPATH}/seahub:${INSTALLPATH}/seahub/thirdpart:$PYTHONPATH
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -230,9 +234,9 @@ function clear_sessions () {
|
||||
function stop_seahub () {
|
||||
if [[ -f ${pidfile} ]]; then
|
||||
echo "Stopping seahub ..."
|
||||
pkill -9 -f "thirdpart/gunicorn"
|
||||
pkill -9 -f "thirdpart/bin/gunicorn"
|
||||
sleep 1
|
||||
if pgrep -f "thirdpart/gunicorn" 2>/dev/null 1>&2 ; then
|
||||
if pgrep -f "thirdpart/bin/gunicorn" 2>/dev/null 1>&2 ; then
|
||||
echo 'Failed to stop seahub.'
|
||||
exit 1
|
||||
fi
|
||||
|
@@ -16,8 +16,7 @@ import warnings
|
||||
import socket
|
||||
from configparser import ConfigParser
|
||||
|
||||
import MySQLdb
|
||||
|
||||
import pymysql
|
||||
|
||||
try:
|
||||
import readline # pylint: disable=W0611
|
||||
@@ -343,10 +342,8 @@ class EnvManager(object):
|
||||
|
||||
os.path.join(install_path, 'seahub', 'thirdpart'),
|
||||
|
||||
os.path.join(install_path, 'seafile/lib/python2.6/site-packages'),
|
||||
os.path.join(install_path, 'seafile/lib64/python2.6/site-packages'),
|
||||
os.path.join(install_path, 'seafile/lib/python2.7/site-packages'),
|
||||
os.path.join(install_path, 'seafile/lib64/python2.7/site-packages'),
|
||||
os.path.join(install_path, 'seafile/lib/python3.6/site-packages'),
|
||||
os.path.join(install_path, 'seafile/lib64/python3.6/site-packages'),
|
||||
]
|
||||
|
||||
for path in extra_python_path:
|
||||
@@ -471,7 +468,7 @@ Please choose a way to initialize seafile databases:
|
||||
def check_mysql_server(self, host, port):
|
||||
print('\nverifying mysql server running ... ', end=' ')
|
||||
try:
|
||||
dummy = MySQLdb.connect(host=host, port=port)
|
||||
dummy = pymysql.connect(host=host, port=port)
|
||||
except Exception:
|
||||
print()
|
||||
raise InvalidAnswer('Failed to connect to mysql server at "%s:%s"' \
|
||||
@@ -487,9 +484,9 @@ Please choose a way to initialize seafile databases:
|
||||
passwd=password)
|
||||
|
||||
try:
|
||||
conn = MySQLdb.connect(**kwargs)
|
||||
conn = pymysql.connect(**kwargs)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
raise InvalidAnswer('Failed to connect to mysql server using user "%s" and password "***": %s' \
|
||||
% (user, e.args[1]))
|
||||
else:
|
||||
@@ -501,13 +498,13 @@ Please choose a way to initialize seafile databases:
|
||||
|
||||
def create_seahub_admin(self):
|
||||
try:
|
||||
conn = MySQLdb.connect(host=self.mysql_host,
|
||||
conn = pymysql.connect(host=self.mysql_host,
|
||||
port=self.mysql_port,
|
||||
user=self.seafile_mysql_user,
|
||||
passwd=self.seafile_mysql_password,
|
||||
db=self.ccnet_db_name)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (self.ccnet_db_name, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (self.ccnet_db_name, e))
|
||||
@@ -519,7 +516,7 @@ CREATE TABLE IF NOT EXISTS EmailUser (id INTEGER NOT NULL PRIMARY KEY AUTO_INCRE
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to create ccnet user table: %s' % e.args[1])
|
||||
else:
|
||||
Utils.error('Failed to create ccnet user table: %s' % e)
|
||||
@@ -530,7 +527,7 @@ CREATE TABLE IF NOT EXISTS EmailUser (id INTEGER NOT NULL PRIMARY KEY AUTO_INCRE
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to create admin user: %s' % e.args[1])
|
||||
else:
|
||||
Utils.error('Failed to create admin user: %s' % e)
|
||||
@@ -591,7 +588,7 @@ class NewDBConfigurator(AbstractDBConfigurator):
|
||||
cursor.execute(sql)
|
||||
return cursor.fetchall()[0][0]
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to check mysql user %s@%s: %s' % \
|
||||
(user, self.seafile_mysql_userhost, e.args[1]))
|
||||
else:
|
||||
@@ -654,7 +651,7 @@ class NewDBConfigurator(AbstractDBConfigurator):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to create mysql user {}@{}: {}'.format(self.seafile_mysql_user, self.seafile_mysql_userhost, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to create mysql user {}@{}: {}'.format(self.seafile_mysql_user, self.seafile_mysql_userhost, e))
|
||||
@@ -670,7 +667,7 @@ class NewDBConfigurator(AbstractDBConfigurator):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to create database %s: %s' % (db_name, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to create database %s: %s' % (db_name, e))
|
||||
@@ -688,7 +685,7 @@ class NewDBConfigurator(AbstractDBConfigurator):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to grant permission of database %s: %s' % (db_name, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to grant permission of database %s: %s' % (db_name, e))
|
||||
@@ -760,7 +757,7 @@ class ExistingDBConfigurator(AbstractDBConfigurator):
|
||||
|
||||
print('\nverifying user "%s" access to database %s ... ' % (user, db_name), end=' ')
|
||||
try:
|
||||
conn = MySQLdb.connect(host=self.mysql_host,
|
||||
conn = pymysql.connect(host=self.mysql_host,
|
||||
port=self.mysql_port,
|
||||
user=user,
|
||||
passwd=password,
|
||||
@@ -770,7 +767,7 @@ class ExistingDBConfigurator(AbstractDBConfigurator):
|
||||
cursor.execute('show tables')
|
||||
cursor.close()
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
raise InvalidAnswer('Failed to access database %s using user "%s" and password "***": %s' \
|
||||
% (db_name, user, e.args[1]))
|
||||
else:
|
||||
@@ -832,7 +829,7 @@ class CcnetConfigurator(AbstractConfigurator):
|
||||
config.add_section(db_section)
|
||||
config.set(db_section, 'ENGINE', 'mysql')
|
||||
config.set(db_section, 'HOST', db_config.mysql_host)
|
||||
config.set(db_section, 'PORT', db_config.mysql_port)
|
||||
config.set(db_section, 'PORT', str(db_config.mysql_port))
|
||||
config.set(db_section, 'USER', db_config.seafile_mysql_user)
|
||||
config.set(db_section, 'PASSWD', db_config.seafile_mysql_password)
|
||||
config.set(db_section, 'DB', db_config.ccnet_db_name)
|
||||
@@ -886,13 +883,13 @@ class CcnetConfigurator(AbstractConfigurator):
|
||||
print('----------------------------------------')
|
||||
|
||||
try:
|
||||
conn = MySQLdb.connect(host=db_config.mysql_host,
|
||||
conn = pymysql.connect(host=db_config.mysql_host,
|
||||
port=db_config.mysql_port,
|
||||
user=db_config.seafile_mysql_user,
|
||||
passwd=db_config.seafile_mysql_password,
|
||||
db=db_config.ccnet_db_name)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (db_config.ccnet_db_name, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (db_config.ccnet_db_name, e))
|
||||
@@ -908,7 +905,7 @@ class CcnetConfigurator(AbstractConfigurator):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to init ccnet database: %s' % e.args[1])
|
||||
else:
|
||||
Utils.error('Failed to init ccnet database: %s' % e)
|
||||
@@ -963,7 +960,7 @@ class SeafileConfigurator(AbstractConfigurator):
|
||||
config.add_section(db_section)
|
||||
config.set(db_section, 'type', 'mysql')
|
||||
config.set(db_section, 'host', db_config.mysql_host)
|
||||
config.set(db_section, 'port', db_config.mysql_port)
|
||||
config.set(db_section, 'port', str(db_config.mysql_port))
|
||||
config.set(db_section, 'user', db_config.seafile_mysql_user)
|
||||
config.set(db_section, 'password', db_config.seafile_mysql_password)
|
||||
config.set(db_section, 'db_name', db_config.seafile_db_name)
|
||||
@@ -1023,13 +1020,13 @@ class SeafileConfigurator(AbstractConfigurator):
|
||||
print('----------------------------------------')
|
||||
|
||||
try:
|
||||
conn = MySQLdb.connect(host=db_config.mysql_host,
|
||||
conn = pymysql.connect(host=db_config.mysql_host,
|
||||
port=db_config.mysql_port,
|
||||
user=db_config.seafile_mysql_user,
|
||||
passwd=db_config.seafile_mysql_password,
|
||||
db=db_config.seafile_db_name)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (db_config.seafile_db_name, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (db_config.seafile_db_name, e))
|
||||
@@ -1045,7 +1042,7 @@ class SeafileConfigurator(AbstractConfigurator):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to init seafile database: %s' % e.args[1])
|
||||
else:
|
||||
Utils.error('Failed to init seafile database: %s' % e)
|
||||
@@ -1157,13 +1154,13 @@ class SeahubConfigurator(AbstractConfigurator):
|
||||
print('----------------------------------------')
|
||||
|
||||
try:
|
||||
conn = MySQLdb.connect(host=db_config.mysql_host,
|
||||
conn = pymysql.connect(host=db_config.mysql_host,
|
||||
port=db_config.mysql_port,
|
||||
user=db_config.seafile_mysql_user,
|
||||
passwd=db_config.seafile_mysql_password,
|
||||
db=db_config.seahub_db_name)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (db_config.seahub_db_name, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to connect to mysql database %s: %s' % (db_config.seahub_db_name, e))
|
||||
@@ -1179,7 +1176,7 @@ class SeahubConfigurator(AbstractConfigurator):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception as e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to init seahub database: %s' % e.args[1])
|
||||
else:
|
||||
Utils.error('Failed to init seahub database: %s' % e)
|
||||
@@ -1506,7 +1503,7 @@ def main():
|
||||
|
||||
if need_pause:
|
||||
Utils.welcome()
|
||||
warnings.filterwarnings('ignore', category=MySQLdb.Warning)
|
||||
warnings.filterwarnings('ignore', category=pymysql.Warning)
|
||||
|
||||
env_mgr.check_pre_condiction()
|
||||
|
||||
|
@@ -23,57 +23,27 @@ function check_python_executable() {
|
||||
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
|
||||
else
|
||||
if !(python --version 2>&1 | grep "3\.[0-9]\.[0-9]") 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "The current version of python is not 3.x.x, please use Python 3.x.x ."
|
||||
echo
|
||||
err_and_quit
|
||||
fi
|
||||
|
||||
PYTHON="python"$(python --version | cut -b 8-10)
|
||||
if !which $PYTHON 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of $PYTHON in PATH"
|
||||
echo "Install $PYTHON before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
err_and_quit
|
||||
fi
|
||||
}
|
||||
|
||||
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. Now quit."
|
||||
err_and_quit;
|
||||
fi
|
||||
|
||||
if [[ $PYTHON == "python2.6" ]]; then
|
||||
py26="2.6"
|
||||
fi
|
||||
|
||||
hint='\nOn Debian/Ubuntu:\n\nsudo apt-get install python-mysqldb\n\nOn CentOS/RHEL:\n\nsudo yum install MySQL-python'
|
||||
check_python_module MySQLdb python-mysqldb "${hint}"
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
|
@@ -95,17 +95,21 @@ function check_python_executable() {
|
||||
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
|
||||
else
|
||||
if !(python --version 2>&1 | grep "3\.[0-9]\.[0-9]") 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of version 2.7 or above in PATH"
|
||||
echo "Install python 2.7+ before continue."
|
||||
echo "The current version of python is not 3.x.x, please use Python 3.x.x ."
|
||||
echo
|
||||
err_and_quit
|
||||
fi
|
||||
|
||||
PYTHON="python"$(python --version | cut -b 8-10)
|
||||
if !which $PYTHON 2>/dev/null 1>&2; then
|
||||
echo
|
||||
echo "Can't find a python executable of $PYTHON in PATH"
|
||||
echo "Install $PYTHON before continue."
|
||||
echo "Or if you installed it in a non-standard PATH, set the PYTHON enviroment varirable to it"
|
||||
echo
|
||||
exit 1
|
||||
err_and_quit
|
||||
fi
|
||||
|
||||
echo "Find python: $PYTHON"
|
||||
@@ -132,21 +136,7 @@ function check_python_module () {
|
||||
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
|
||||
check_python_module sqlite3 python-sqlite3
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,7 @@ import sys
|
||||
|
||||
def usage():
|
||||
msg = 'usage: %s <seahub db>' % os.path.basename(sys.argv[0])
|
||||
print msg
|
||||
print(msg)
|
||||
|
||||
def main():
|
||||
seahub_db = sys.argv[1]
|
||||
|
@@ -2,14 +2,14 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
import ConfigParser
|
||||
import configparser
|
||||
import glob
|
||||
|
||||
HAS_MYSQLDB = True
|
||||
HAS_PYMYSQL = True
|
||||
try:
|
||||
import MySQLdb
|
||||
import pymysql
|
||||
except ImportError:
|
||||
HAS_MYSQLDB = False
|
||||
HAS_PYMYSQL = False
|
||||
|
||||
HAS_SQLITE3 = True
|
||||
try:
|
||||
@@ -41,15 +41,15 @@ class Utils(object):
|
||||
|
||||
@staticmethod
|
||||
def info(msg):
|
||||
print Utils.highlight('[INFO] ') + msg
|
||||
print(Utils.highlight('[INFO] ') + msg)
|
||||
|
||||
@staticmethod
|
||||
def warning(msg):
|
||||
print Utils.highlight('[WARNING] ') + msg
|
||||
print(Utils.highlight('[WARNING] ') + msg)
|
||||
|
||||
@staticmethod
|
||||
def error(msg):
|
||||
print Utils.highlight('[ERROR] ') + msg
|
||||
print(Utils.highlight('[ERROR] ') + msg)
|
||||
sys.exit(1)
|
||||
|
||||
@staticmethod
|
||||
@@ -57,7 +57,7 @@ class Utils(object):
|
||||
if not os.path.exists(config_path):
|
||||
Utils.error('Config path %s doesn\'t exist, stop db upgrade' %
|
||||
config_path)
|
||||
cp = ConfigParser.ConfigParser(defaults)
|
||||
cp = configparser.ConfigParser(defaults)
|
||||
cp.read(config_path)
|
||||
return cp
|
||||
|
||||
@@ -87,8 +87,8 @@ class DBUpdater(object):
|
||||
|
||||
if ccnet_db_info and seafile_db_info and seahub_db_info:
|
||||
Utils.info('You are using MySQL')
|
||||
if not HAS_MYSQLDB:
|
||||
Utils.error('Python MySQLdb module is not found')
|
||||
if not HAS_PYMYSQL:
|
||||
Utils.error('Python pymysql module is not found')
|
||||
updater = MySQLDBUpdater(version, ccnet_db_info, seafile_db_info, seahub_db_info)
|
||||
|
||||
elif (ccnet_db_info is None) and (seafile_db_info is None) and (seahub_db_info is None):
|
||||
@@ -162,7 +162,7 @@ class DBUpdater(object):
|
||||
password = config.get(db_section, 'PASSWD')
|
||||
db = config.get(db_section, 'DB')
|
||||
unix_socket = config.get(db_section, 'UNIX_SOCKET')
|
||||
except ConfigParser.NoOptionError, e:
|
||||
except configparser.NoOptionError as e:
|
||||
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
||||
@@ -198,7 +198,7 @@ class DBUpdater(object):
|
||||
password = config.get(db_section, 'password')
|
||||
db = config.get(db_section, 'db_name')
|
||||
unix_socket = config.get(db_section, 'unix_socket')
|
||||
except ConfigParser.NoOptionError, e:
|
||||
except configparser.NoOptionError as e:
|
||||
Utils.error('Database config in seafile.conf is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db, unix_socket)
|
||||
@@ -211,7 +211,7 @@ class DBUpdater(object):
|
||||
sys.path.insert(0, env_mgr.central_config_dir)
|
||||
try:
|
||||
import seahub_settings # pylint: disable=F0401
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
Utils.error('Failed to import seahub_settings.py: %s' % e)
|
||||
|
||||
if not hasattr(seahub_settings, 'DATABASES'):
|
||||
@@ -336,9 +336,9 @@ class MySQLDBUpdater(DBUpdater):
|
||||
kw['host'] = info.host
|
||||
kw['port'] = info.port
|
||||
try:
|
||||
conn = MySQLdb.connect(**kw)
|
||||
except Exception, e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
conn = pymysql.connect(**kw)
|
||||
except Exception as e:
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
msg = str(e.args[1])
|
||||
else:
|
||||
msg = str(e)
|
||||
@@ -351,7 +351,7 @@ class MySQLDBUpdater(DBUpdater):
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
conn.commit()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
msg = str(e)
|
||||
Utils.warning('Failed to execute sql: %s' % msg)
|
||||
|
||||
@@ -372,7 +372,7 @@ class MySQLDBUpdater(DBUpdater):
|
||||
def main():
|
||||
skipdb = os.environ.get('SEAFILE_SKIP_DB_UPGRADE', '').lower()
|
||||
if skipdb in ('1', 'true', 'on'):
|
||||
print 'Database upgrade skipped because SEAFILE_SKIP_DB_UPGRADE=%s' % skipdb
|
||||
print('Database upgrade skipped because SEAFILE_SKIP_DB_UPGRADE=%s' % skipdb)
|
||||
sys.exit()
|
||||
version = sys.argv[1]
|
||||
db_updater = DBUpdater.get_instance(version)
|
||||
|
@@ -3,15 +3,15 @@
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import ConfigParser
|
||||
import configparser
|
||||
import getpass
|
||||
from collections import namedtuple
|
||||
|
||||
try:
|
||||
import MySQLdb
|
||||
HAS_MYSQLDB = True
|
||||
import pymysql
|
||||
HAS_PYMYSQL = True
|
||||
except ImportError:
|
||||
HAS_MYSQLDB = False
|
||||
HAS_PYMYSQL = False
|
||||
|
||||
MySQLDBInfo = namedtuple('MySQLDBInfo', 'host port username password db')
|
||||
|
||||
@@ -36,16 +36,16 @@ class Utils(object):
|
||||
|
||||
@staticmethod
|
||||
def info(msg):
|
||||
print Utils.highlight('[INFO] ') + msg
|
||||
print(Utils.highlight('[INFO] ') + msg)
|
||||
|
||||
@staticmethod
|
||||
def error(msg):
|
||||
print Utils.highlight('[ERROR] ') + msg
|
||||
print(Utils.highlight('[ERROR] ') + msg)
|
||||
sys.exit(1)
|
||||
|
||||
@staticmethod
|
||||
def read_config(config_path, defaults):
|
||||
cp = ConfigParser.ConfigParser(defaults)
|
||||
cp = configparser.ConfigParser(defaults)
|
||||
cp.read(config_path)
|
||||
return cp
|
||||
|
||||
@@ -72,7 +72,7 @@ def get_ccnet_mysql_info():
|
||||
username = config.get(db_section, 'USER')
|
||||
password = config.get(db_section, 'PASSWD')
|
||||
db = config.get(db_section, 'DB')
|
||||
except ConfigParser.NoOptionError, e:
|
||||
except configparser.NoOptionError as e:
|
||||
Utils.error('Database config in ccnet.conf is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db)
|
||||
@@ -100,7 +100,7 @@ def get_seafile_mysql_info():
|
||||
username = config.get(db_section, 'user')
|
||||
password = config.get(db_section, 'password')
|
||||
db = config.get(db_section, 'db_name')
|
||||
except ConfigParser.NoOptionError, e:
|
||||
except configparser.NoOptionError as e:
|
||||
Utils.error('Database config in seafile.conf is invalid: %s' % e)
|
||||
|
||||
info = MySQLDBInfo(host, port, username, password, db)
|
||||
@@ -110,7 +110,7 @@ def get_seahub_mysql_info():
|
||||
sys.path.insert(0, env_mgr.top_dir)
|
||||
try:
|
||||
import seahub_settings# pylint: disable=F0401
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
Utils.error('Failed to import seahub_settings.py: %s' % e)
|
||||
|
||||
if not hasattr(seahub_settings, 'DATABASES'):
|
||||
@@ -153,8 +153,8 @@ def ask_root_password(port):
|
||||
if password:
|
||||
try:
|
||||
return check_mysql_user('root', password, port)
|
||||
except InvalidAnswer, e:
|
||||
print '\n%s\n' % e
|
||||
except InvalidAnswer as e:
|
||||
print('\n%s\n' % e)
|
||||
continue
|
||||
|
||||
class InvalidAnswer(Exception):
|
||||
@@ -166,23 +166,23 @@ class InvalidAnswer(Exception):
|
||||
return self.msg
|
||||
|
||||
def check_mysql_user(user, password, port):
|
||||
print '\nverifying password of root user %s ... ' % user,
|
||||
print('\nverifying password of root user %s ... ' % user, end=' ')
|
||||
kwargs = dict(host='localhost',
|
||||
port=port,
|
||||
user=user,
|
||||
passwd=password)
|
||||
|
||||
try:
|
||||
conn = MySQLdb.connect(**kwargs)
|
||||
except Exception, e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
conn = pymysql.connect(**kwargs)
|
||||
except Exception as e:
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
raise InvalidAnswer('Failed to connect to mysql server using user "%s" and password "***": %s'
|
||||
% (user, e.args[1]))
|
||||
else:
|
||||
raise InvalidAnswer('Failed to connect to mysql server using user "%s" and password "***": %s'
|
||||
% (user, e))
|
||||
|
||||
print 'done'
|
||||
print('done')
|
||||
return conn
|
||||
|
||||
def apply_fix(root_conn, user, dbs):
|
||||
@@ -209,8 +209,8 @@ def grant_db_permission(conn, user, db):
|
||||
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except Exception, e:
|
||||
if isinstance(e, MySQLdb.OperationalError):
|
||||
except Exception as e:
|
||||
if isinstance(e, pymysql.err.OperationalError):
|
||||
Utils.error('Failed to grant permission of database %s: %s' % (db, e.args[1]))
|
||||
else:
|
||||
Utils.error('Failed to grant permission of database %s: %s' % (db, e))
|
||||
@@ -225,8 +225,8 @@ def main():
|
||||
if dbinfos[0].username == 'root':
|
||||
return
|
||||
|
||||
if not HAS_MYSQLDB:
|
||||
Utils.error('Python MySQLdb module is not found')
|
||||
if not HAS_PYMYSQL:
|
||||
Utils.error('Python pymysql module is not found')
|
||||
root_conn = ask_root_password(dbinfos[0].port)
|
||||
apply_fix(root_conn, dbinfos[0].username, [info.db for info in dbinfos])
|
||||
|
||||
|
Reference in New Issue
Block a user