-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server] Add upgrade script for 6.0.0.
- Loading branch information
Showing
3 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
ALTER TABLE api2_tokenv2 ADD COLUMN wiped_at DATETIME DEFAULT NULL; | ||
ALTER TABLE api2_tokenv2 ADD COLUMN created_at DATETIME NOT NULL; | ||
|
||
CREATE TABLE IF NOT EXISTS `base_filecomment` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`repo_id` varchar(36) NOT NULL, | ||
`parent_path` longtext NOT NULL, | ||
`repo_id_parent_path_md5` varchar(100) NOT NULL, | ||
`item_name` longtext NOT NULL, | ||
`author` varchar(255) NOT NULL, | ||
`comment` longtext NOT NULL, | ||
`created_at` datetime NOT NULL, | ||
`updated_at` datetime NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `base_filecomment_9a8c79bf` (`repo_id`), | ||
KEY `base_filecomment_c5bf47d4` (`repo_id_parent_path_md5`), | ||
KEY `base_filecomment_02bd92fa` (`author`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `termsandconditions_termsandconditions` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`slug` varchar(50) NOT NULL, | ||
`name` longtext NOT NULL, | ||
`version_number` decimal(6,2) NOT NULL, | ||
`text` longtext, | ||
`info` longtext, | ||
`date_active` datetime DEFAULT NULL, | ||
`date_created` datetime NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `termsandconditions_termsandconditions_2dbcba41` (`slug`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `termsandconditions_usertermsandconditions` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`username` varchar(255) NOT NULL, | ||
`ip_address` char(39) DEFAULT NULL, | ||
`date_accepted` datetime NOT NULL, | ||
`terms_id` int(11) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `termsandconditions_usertermsandcon_username_f4ab54cafa29322_uniq` (`username`,`terms_id`), | ||
KEY `e4da106203f3f13ff96409b55de6f515` (`terms_id`), | ||
CONSTRAINT `e4da106203f3f13ff96409b55de6f515` FOREIGN KEY (`terms_id`) REFERENCES `termsandconditions_termsandconditions` (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `two_factor_totpdevice` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`user` varchar(255) NOT NULL, | ||
`name` varchar(64) NOT NULL, | ||
`confirmed` tinyint(1) NOT NULL, | ||
`key` varchar(80) NOT NULL, | ||
`step` smallint(5) unsigned NOT NULL, | ||
`t0` bigint(20) NOT NULL, | ||
`digits` smallint(5) unsigned NOT NULL, | ||
`tolerance` smallint(5) unsigned NOT NULL, | ||
`drift` smallint(6) NOT NULL, | ||
`last_t` bigint(20) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `user` (`user`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `two_factor_phonedevice` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`user` varchar(255) NOT NULL, | ||
`name` varchar(64) NOT NULL, | ||
`confirmed` tinyint(1) NOT NULL, | ||
`number` varchar(40) NOT NULL, | ||
`key` varchar(40) NOT NULL, | ||
`method` varchar(4) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `user` (`user`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `two_factor_staticdevice` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`user` varchar(255) NOT NULL, | ||
`name` varchar(64) NOT NULL, | ||
`confirmed` tinyint(1) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `user` (`user`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `two_factor_statictoken` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`token` varchar(16) NOT NULL, | ||
`device_id` int(11) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `two_fac_device_id_55a7b345293a7c6c_fk_two_factor_staticdevice_id` (`device_id`), | ||
KEY `two_factor_statictoken_94a08da1` (`token`), | ||
CONSTRAINT `two_fac_device_id_55a7b345293a7c6c_fk_two_factor_staticdevice_id` FOREIGN KEY (`device_id`) REFERENCES `two_factor_staticdevice` (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE IF NOT EXISTS `invitations_invitation` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`token` varchar(40) NOT NULL, | ||
`inviter` varchar(255) NOT NULL, | ||
`accepter` varchar(255) NOT NULL, | ||
`invite_time` datetime NOT NULL, | ||
`accept_time` datetime DEFAULT NULL, | ||
`invite_type` varchar(20) NOT NULL, | ||
`expire_time` datetime NOT NULL, | ||
PRIMARY KEY (`id`), | ||
KEY `invitations_invitation_d5dd16f8` (`inviter`), | ||
KEY `invitations_invitation_token_1961fbb98c05e5fd_uniq` (`token`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
CREATE TABLE IF NOT EXISTS "base_filecomment" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "repo_id" varchar(36) NOT NULL, "parent_path" text NOT NULL, "repo_id_parent_path_md5" varchar(100) NOT NULL, "item_name" text NOT NULL, "author" varchar(255) NOT NULL, "comment" text NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL); | ||
CREATE INDEX IF NOT EXISTS "base_filecomment_02bd92fa" ON "base_filecomment" ("author"); | ||
CREATE INDEX IF NOT EXISTS "base_filecomment_9a8c79bf" ON "base_filecomment" ("repo_id"); | ||
CREATE INDEX IF NOT EXISTS "base_filecomment_c5bf47d4" ON "base_filecomment" ("repo_id_parent_path_md5"); | ||
|
||
CREATE TABLE IF NOT EXISTS "termsandconditions_termsandconditions" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "slug" varchar(50) NOT NULL, "name" text NOT NULL, "version_number" decimal NOT NULL, "text" text NULL, "info" text NULL, "date_active" datetime NULL, "date_created" datetime NOT NULL); | ||
CREATE INDEX IF NOT EXISTS "termsandconditions_termsandconditions_2dbcba41" ON "termsandconditions_termsandconditions" ("slug"); | ||
|
||
CREATE TABLE IF NOT EXISTS "termsandconditions_usertermsandconditions" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "username" varchar(255) NOT NULL, "ip_address" char(39) NULL, "date_accepted" datetime NOT NULL, "terms_id" integer NOT NULL REFERENCES "termsandconditions_termsandconditions" ("id"), UNIQUE ("username", "terms_id")); | ||
CREATE INDEX IF NOT EXISTS "termsandconditions_usertermsandconditions_2ab34720" ON "termsandconditions_usertermsandconditions" ("terms_id"); | ||
|
||
CREATE TABLE IF NOT EXISTS "two_factor_phonedevice" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "user" varchar(255) NOT NULL UNIQUE, "name" varchar(64) NOT NULL, "confirmed" bool NOT NULL, "number" varchar(40) NOT NULL, "key" varchar(40) NOT NULL, "method" varchar(4) NOT NULL); | ||
CREATE TABLE IF NOT EXISTS "two_factor_staticdevice" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "user" varchar(255) NOT NULL UNIQUE, "name" varchar(64) NOT NULL, "confirmed" bool NOT NULL); | ||
CREATE TABLE IF NOT EXISTS "two_factor_statictoken" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "token" varchar(16) NOT NULL, "device_id" integer NOT NULL REFERENCES "two_factor_staticdevice" ("id")); | ||
CREATE TABLE IF NOT EXISTS "two_factor_totpdevice" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "user" varchar(255) NOT NULL UNIQUE, "name" varchar(64) NOT NULL, "confirmed" bool NOT NULL, "key" varchar(80) NOT NULL, "step" smallint unsigned NOT NULL, "t0" bigint NOT NULL, "digits" smallint unsigned NOT NULL, "tolerance" smallint unsigned NOT NULL, "drift" smallint NOT NULL, "last_t" bigint NOT NULL); | ||
CREATE INDEX IF NOT EXISTS "two_factor_statictoken_94a08da1" ON "two_factor_statictoken" ("token"); | ||
CREATE INDEX IF NOT EXISTS "two_factor_statictoken_9379346c" ON "two_factor_statictoken" ("device_id"); | ||
|
||
CREATE TABLE IF NOT EXISTS "invitations_invitation" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "token" varchar(40) NOT NULL, "inviter" varchar(255) NOT NULL, "accepter" varchar(255) NOT NULL, "invite_time" datetime NOT NULL, "accept_time" datetime NULL, "invite_type" varchar(20) NOT NULL, "expire_time" datetime NOT NULL); | ||
CREATE INDEX IF NOT EXISTS "invitations_invitation_94a08da1" ON "invitations_invitation" ("token"); | ||
CREATE INDEX IF NOT EXISTS "invitations_invitation_d5dd16f8" ON "invitations_invitation" ("inviter"); | ||
|
||
ALTER TABLE api2_tokenv2 ADD COLUMN wiped_at datetime DEFAULT NULL; | ||
ALTER TABLE api2_tokenv2 ADD COLUMN created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
#!/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 | ||
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=5.1 | ||
current_version=6.0 | ||
|
||
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}" 6.0.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}/" | ||
} | ||
|
||
################# | ||
# 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; | ||
|
||
echo | ||
echo "-----------------------------------------------------------------" | ||
echo "Upgraded your seafile server successfully." | ||
echo "-----------------------------------------------------------------" | ||
echo |