mirror of
https://github.com/haiwen/seafile-server-installer-cn.git
synced 2025-12-25 17:02:46 +00:00
476 lines
16 KiB
Bash
476 lines
16 KiB
Bash
#!/bin/bash
|
|
#
|
|
# seafile-server-installer/seafile-ce_uberspace
|
|
#
|
|
# Copyright 2015, Alexander Jackson <alexander.jackson@seafile.de>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
#
|
|
#set -x
|
|
# -------------------------------------------
|
|
# Vars
|
|
# -------------------------------------------
|
|
SEAFILE_ADMIN=admin@seafile.local
|
|
SEAFILE_USER=seafile
|
|
WHOAMI=$(whoami)
|
|
HOSTNAME=$(hostname -f)
|
|
SERVER_NAME=$(echo ${WHOAMI}$(hostname -s) | cut -c -16)
|
|
|
|
|
|
# -------------------------------------------
|
|
# Seafile Server Community Edition on Uberspace
|
|
# -------------------------------------------
|
|
clear
|
|
cat <<EOF
|
|
This script installs the community edition of the Seafile Server on Uberspace
|
|
-----------------------------------------------------------------
|
|
This installer is meant to run on a fresh Uberspace.
|
|
If you run it on a production server things can and
|
|
probably will go terrible wrong and you will loose valuable
|
|
data!
|
|
For questions or suggestions please contact me at
|
|
alexander.jackson@seafile.de
|
|
-----------------------------------------------------------------
|
|
Hit return to proceed or CTRL-C to abort.
|
|
EOF
|
|
read dummy
|
|
clear
|
|
|
|
|
|
# -------------------------------------------
|
|
# Abort if directory ${HOME}/seafile/ exists
|
|
# -------------------------------------------
|
|
if [[ -d "${HOME}/seafile/" ]] ;
|
|
then
|
|
echo " Aborting because directory ${HOME}/seafile/ already exist" ; exit 1
|
|
fi
|
|
|
|
|
|
# -------------------------------------------
|
|
# Python requirements
|
|
# -------------------------------------------
|
|
cd
|
|
mkdir -p ~/bin ~/lib/python2.7
|
|
easy_install-2.7 simplejson
|
|
curl --silent http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz | tar -xzf -
|
|
cd Imaging-1.1.7
|
|
perl -pi -e 's|/usr/lib|/usr/lib64|g' setup.py
|
|
python2.7 setup.py install
|
|
rm -rf Imaging-1.1.7
|
|
|
|
|
|
# -------------------------------------------
|
|
# Setup Seafile
|
|
# -------------------------------------------
|
|
mkdir -p ~/seafile/installed/
|
|
cd ~/seafile/
|
|
wget https://download.seafile.com.de/seafile-server_latest_x86-64.tar.gz
|
|
tar xzf seafile-server_latest_x86-64.tar.gz
|
|
SEAFILE_VERSION=$(basename ~/seafile/seafile-server-* | awk -F'-' ' { print $3 }')
|
|
mv seafile-server_latest_x86-64.tar.gz installed/seafile-server_${SEAFILE_VERSION}_x86-64.tar.gz
|
|
|
|
|
|
# -------------------------------------------
|
|
# Seafile DB
|
|
# -------------------------------------------
|
|
MYSQL=$(which mysql)
|
|
DB_CCNET=${WHOAMI}_ccnet
|
|
DB_SEAFILE=${WHOAMI}_seafile
|
|
DB_SEAHUB=${WHOAMI}_seahub
|
|
DB_CHARSET=utf8
|
|
|
|
# Datenbanken erstellen
|
|
for i in ${DB_CCNET} ${DB_SEAFILE} ${DB_SEAHUB} ; do
|
|
${MYSQL} -e "CREATE DATABASE IF NOT EXISTS \`${i}\` character set = '${DB_CHARSET}';" ;
|
|
done
|
|
|
|
mysql ${DB_SEAHUB} < ~/seafile/seafile-server-${SEAFILE_VERSION}/seahub/sql/mysql.sql
|
|
|
|
# -------------------------------------------
|
|
# Get free ports
|
|
# -------------------------------------------
|
|
START_PORT=61100
|
|
END_PORT=65535
|
|
INCREMENT=1
|
|
PORT=${START_PORT}
|
|
PORT_LIST=free_ports.txt
|
|
|
|
# Empty port list
|
|
echo -n > ${PORT_LIST}
|
|
|
|
COUNT=1
|
|
while [ ${COUNT} -le 5 ]; do
|
|
ISFREE=$(netstat -tapln | grep ${PORT})
|
|
while [[ -n "${ISFREE}" ]]; do
|
|
PORT=$[PORT+INCREMENT]
|
|
ISFREE=$(netstat -tapln | grep ${PORT});
|
|
if [ ${COUNT} > ${END_PORT} ]; then
|
|
echo "Not enough free ports available. Aborting installation!" ; exit 1
|
|
fi
|
|
done
|
|
|
|
# Write free port to file
|
|
echo -n "${PORT} " >> ${PORT_LIST}
|
|
|
|
# Increment search port
|
|
PORT=$(( PORT+1 ))
|
|
|
|
# Increment loop counter
|
|
(( COUNT++ ))
|
|
done
|
|
|
|
# Import free ports to vars
|
|
read SEAHUB_PORT FILESERVER_PORT SERVER_PORT SEAFILE_SERVER_PORT SEAFDAV_PORT< ${PORT_LIST}
|
|
|
|
# Delete port list
|
|
rm ${PORT_LIST}
|
|
|
|
|
|
# -------------------------------------------
|
|
# Apache htaccess
|
|
# -------------------------------------------
|
|
cat > ~/html/.htaccess <<"EOF"
|
|
RewriteEngine on
|
|
|
|
# Redirect to https
|
|
RewriteCond %{HTTPS} !=on
|
|
RewriteCond %{ENV:HTTPS} !=on
|
|
RewriteRule ^(.*)$ https://WHOAMI.HOSTNAME/$1 [L,R=301]
|
|
|
|
# Port of seafile httpserver (compare ~/haiwen/seafile-data/seafile.conf)
|
|
RewriteRule ^seafhttp/(.*)$ http://localhost:FILESERVER_PORT/$1 [QSA,P,L]
|
|
|
|
RewriteRule ^/(seafmedia.*)$ /$1 [QSA,L,PT]
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteRule ^(.*)$ /fcgi-bin/seahub/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
|
EOF
|
|
|
|
# Set seahub port
|
|
eval sed -i 's/WHOAMI/${WHOAMI}/' ~/html/.htaccess
|
|
eval sed -i 's/HOSTNAME/${HOSTNAME}/' ~/html/.htaccess
|
|
eval sed -i 's/FILESERVER_PORT/${FILESERVER_PORT}/' ~/html/.htaccess
|
|
|
|
|
|
# -------------------------------------------
|
|
# Create Seahub FastCGI script
|
|
# -------------------------------------------
|
|
cat > ~/fcgi-bin/seahub <<EOF
|
|
#!/usr/bin/env python2.7
|
|
import sys, os, site
|
|
|
|
# directory of seafile installation
|
|
seafile_directory = '${HOME}/seafile'
|
|
|
|
# Add a custom Python path.
|
|
sys.path.insert(0, seafile_directory + '/seafile-server-latest/seahub')
|
|
|
|
# Set environment variables (compare ~/haiwen/seafile-server-latest/seahub.sh)
|
|
os.environ['CCNET_CONF_DIR'] = seafile_directory + '/ccnet'
|
|
os.environ['SEAHUB_LOG_DIR'] = seafile_directory + '/logs'
|
|
os.environ['SEAFILE_CONF_DIR'] = seafile_directory + '/seafile-data'
|
|
|
|
# Load required python modules (compare ~/seafile-server-latest/seahub.sh)
|
|
site.addsitedir(seafile_directory + '/seafile-server-latest/seafile/lib/python2.6/site-packages')
|
|
site.addsitedir(seafile_directory + '/seafile-server-latest/seafile/lib64/python2.6/site-packages')
|
|
site.addsitedir(seafile_directory + '/seafile-server-latest/seahub/thirdpart')
|
|
site.addsitedir(seafile_directory + '/seafile-server-latest/seafile/lib/python2.7/site-packages')
|
|
site.addsitedir(seafile_directory + '/seafile-server-latest/seafile/lib64/python2.7/site-packages')
|
|
|
|
# Switch to the directory of your project.
|
|
os.chdir(seafile_directory + '/seafile-server-latest/seahub')
|
|
|
|
# Set the DJANGO_SETTINGS_MODULE environment variable.
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'seahub.settings'
|
|
|
|
from django.core.servers.fastcgi import runfastcgi
|
|
runfastcgi(method='threaded', daemonize='false')
|
|
EOF
|
|
|
|
chmod 755 ~/fcgi-bin/seahub
|
|
|
|
# -------------------------------------------
|
|
# Seafile start script
|
|
# -------------------------------------------
|
|
cat > ~/bin/seafile <<'ENDOFILE'
|
|
#!/bin/bash
|
|
# Short-Description: Seafile server
|
|
# Description: Start Seafile server
|
|
### END INIT INFO
|
|
# Author: Alexander Jackson <alexander.jackson@seafile.de>
|
|
#
|
|
# Change the value of "seafile_dir" to your path of seafile installation
|
|
seafile_dir=~/seafile
|
|
script_path=${seafile_dir}/seafile-server-latest
|
|
seafile_init_log=${seafile_dir}/logs/seafile.init.log
|
|
|
|
case "$1" in
|
|
start)
|
|
${script_path}/seafile.sh start >> ${seafile_init_log}
|
|
;;
|
|
restart)
|
|
${script_path}/seafile.sh restart >> ${seafile_init_log}
|
|
;;
|
|
stop)
|
|
${script_path}/seafile.sh $1 >> ${seafile_init_log} && \
|
|
ps aux | grep seahub | grep -v grep | awk '{ print $2 }' | while read line; do kill $line ; done
|
|
;;
|
|
*)
|
|
echo "Usage: seafile {start|stop|restart}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
ENDOFILE
|
|
|
|
chmod +x ~/bin/seafile
|
|
|
|
|
|
# -------------------------------------------
|
|
# Go to ${HOME}/seafile/seafile-server-${SEAFILE_VERSION}
|
|
# -------------------------------------------
|
|
cd ${HOME}/seafile/seafile-server-${SEAFILE_VERSION}/
|
|
|
|
|
|
# -------------------------------------------
|
|
# Vars - Don't touch these unless you really know what you are doing!
|
|
# -------------------------------------------
|
|
INSTALLPATH=${HOME}/seafile/seafile-server-${SEAFILE_VERSION}
|
|
TOPDIR=$(dirname "${INSTALLPATH}")
|
|
SRC_DOCS_DIR=${INSTALLPATH}/seafile/docs/
|
|
SEAHUB_SECRET_KEYGEN=${INSTALLPATH}/seahub/tools/secret_key_generator.py
|
|
DEFAULT_CCNET_CONF_DIR=${TOPDIR}/ccnet
|
|
DEFAULT_SEAFILE_DATA_DIR=${TOPDIR}/seafile-data
|
|
DEFAULT_SEAHUB_DB=${TOPDIR}/seahub.db
|
|
DEFAULT_CONF_DIR=${TOPDIR}/conf
|
|
SEAFILE_DATA_DIR=${TOPDIR}/seafile-data
|
|
LIBRARY_TEMPLATE_DIR=${SEAFILE_DATA_DIR}/library-template
|
|
DEST_SETTINGS_PY=${TOPDIR}/seahub_settings.py
|
|
CCNET_INIT=${INSTALLPATH}/seafile/bin/ccnet-init
|
|
SEAF_SERVER_INIT=${INSTALLPATH}/seafile/bin/seaf-server-init
|
|
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
|
|
|
|
|
|
# -------------------------------------------
|
|
# Create ccnet conf
|
|
# -------------------------------------------
|
|
export SEAFILE_LD_LIBRARY_PATH=${INSTALLPATH}/seafile/lib/:${INSTALLPATH}/seafile/lib64:${LD_LIBRARY_PATH}
|
|
LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH "${CCNET_INIT}" -c "${DEFAULT_CCNET_CONF_DIR}" \
|
|
--name "${SERVER_NAME}" --port "${SERVER_PORT}" --host "${HOSTNAME}"
|
|
|
|
# Fix service url
|
|
eval "sed -i 's/^SERVICE_URL.*/SERVICE_URL = https:\/\/${WHOAMI}.${HOSTNAME}/' ${DEFAULT_CCNET_CONF_DIR}/ccnet.conf"
|
|
|
|
|
|
# -------------------------------------------
|
|
# Create seafile conf
|
|
# -------------------------------------------
|
|
LD_LIBRARY_PATH=$SEAFILE_LD_LIBRARY_PATH ${SEAF_SERVER_INIT} --seafile-dir "${SEAFILE_DATA_DIR}" \
|
|
--port ${SEAFILE_SERVER_PORT} --fileserver-port ${FILESERVER_PORT}
|
|
|
|
|
|
# -------------------------------------------
|
|
# Write seafile.ini
|
|
# -------------------------------------------
|
|
echo "${SEAFILE_DATA_DIR}" > "${DEFAULT_CCNET_CONF_DIR}/seafile.ini"
|
|
|
|
|
|
# -------------------------------------------
|
|
# Configure Seafile WebDAV Server(SeafDAV)
|
|
# -------------------------------------------
|
|
mkdir -p ${DEFAULT_CONF_DIR}
|
|
cat > ${DEFAULT_CONF_DIR}/seafdav.conf <<EOF
|
|
[WEBDAV]
|
|
enabled = true
|
|
port = ${SEAFDAV_PORT}
|
|
fastcgi = true
|
|
share_name = /seafdav
|
|
EOF
|
|
|
|
|
|
# -------------------------------------------
|
|
# generate seahub_settings.py
|
|
# -------------------------------------------
|
|
key=$(python "${SEAHUB_SECRET_KEYGEN}")
|
|
echo "SECRET_KEY = \"${key}\"" > "${DEST_SETTINGS_PY}"
|
|
|
|
|
|
# -------------------------------------------
|
|
# prepare avatar directory
|
|
# -------------------------------------------
|
|
mkdir -p "${TOPDIR}/seahub-data"
|
|
mv "${ORIG_AVATAR_DIR}" "${DEST_AVATAR_DIR}"
|
|
ln -s ../../../seahub-data/avatars ${MEDIA_DIR}
|
|
|
|
|
|
# -------------------------------------------
|
|
# create logs directory
|
|
# -------------------------------------------
|
|
mkdir -p "${TOPDIR}/logs"
|
|
|
|
|
|
# -------------------------------------------
|
|
# Create symlink for current server version
|
|
# -------------------------------------------
|
|
ln -s $(basename ${INSTALLPATH}) ${SEAFILE_SERVER_SYMLINK}
|
|
|
|
|
|
# Fix permissions
|
|
chmod 0600 "$DEST_SETTINGS_PY"
|
|
chmod 0700 "$DEFAULT_CCNET_CONF_DIR"
|
|
chmod 0700 "$SEAFILE_DATA_DIR"
|
|
chmod 0700 "$DEFAULT_CONF_DIR"
|
|
|
|
|
|
# -------------------------------------------
|
|
# copy user manuals to library template
|
|
# -------------------------------------------
|
|
mkdir -p ${LIBRARY_TEMPLATE_DIR}
|
|
cp -f ${SRC_DOCS_DIR}/*.doc ${LIBRARY_TEMPLATE_DIR}
|
|
|
|
|
|
# -------------------------------------------
|
|
# Configuring ccnet.conf
|
|
# -------------------------------------------
|
|
SEAFILESQLPW=$(grep password $HOME/.my.cnf | awk -F'=' {'print $2'} | awk -F' ' {'print $1'})
|
|
|
|
cat >> ${DEFAULT_CCNET_CONF_DIR}/ccnet.conf <<EOF
|
|
[Database]
|
|
ENGINE = mysql
|
|
HOST = 127.0.0.1
|
|
PORT = 3306
|
|
USER = ${WHOAMI}
|
|
PASSWD = ${SEAFILESQLPW}
|
|
DB = ${DB_CCNET}
|
|
CONNECTION_CHARSET = utf8
|
|
EOF
|
|
|
|
|
|
# -------------------------------------------
|
|
# Configuring seahub_settings.py
|
|
# -------------------------------------------
|
|
cat >> ${DEST_SETTINGS_PY} <<EOF
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.mysql',
|
|
'NAME': '${DB_SEAHUB}',
|
|
'USER': '${WHOAMI}',
|
|
'PASSWORD': '${SEAFILESQLPW}',
|
|
'HOST': '127.0.0.1',
|
|
'PORT': '3306',
|
|
'OPTIONS': {
|
|
'init_command': 'SET storage_engine=INNODB',
|
|
}
|
|
}
|
|
}
|
|
EMAIL_USE_TLS = False
|
|
EMAIL_HOST = 'localhost'
|
|
EMAIL_HOST_USER = ''
|
|
EMAIL_HOST_PASSWORD = ''
|
|
EMAIL_PORT = '25'
|
|
DEFAULT_FROM_EMAIL = 'seafile@${HOSTNAME}'
|
|
SERVER_EMAIL = 'EMAIL_HOST_USER'
|
|
TIME_ZONE = 'Europe/Berlin'
|
|
SITE_BASE = 'https://${WHOAMI}.${HOSTNAME}'
|
|
SITE_NAME = 'Seafile Server'
|
|
SITE_TITLE = 'Seafile Server'
|
|
SITE_ROOT = '/'
|
|
USE_PDFJS = True
|
|
ENABLE_SIGNUP = False
|
|
ACTIVATE_AFTER_REGISTRATION = False
|
|
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER = True
|
|
SEND_EMAIL_ON_RESETTING_USER_PASSWD = True
|
|
CLOUD_MODE = False
|
|
FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024
|
|
SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2
|
|
SESSION_SAVE_EVERY_REQUEST = False
|
|
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
|
|
FILE_SERVER_ROOT = 'https://${WHOAMI}.${HOSTNAME}/seafhttp'
|
|
DEBUG = True
|
|
EOF
|
|
|
|
|
|
# -------------------------------------------
|
|
# Backup check_init_admin.py befor applying changes
|
|
# -------------------------------------------
|
|
cp ${INSTALLPATH}/check_init_admin.py ${INSTALLPATH}/check_init_admin.py.backup
|
|
|
|
|
|
# -------------------------------------------
|
|
# Set admin credentials in check_init_admin.py
|
|
# -------------------------------------------
|
|
SEAFILE_ADMIN_PW=$(dd if=/dev/urandom bs=1 count=14 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev)
|
|
eval "sed -i 's/= ask_admin_email()/= \"${SEAFILE_ADMIN}\"/' ${INSTALLPATH}/check_init_admin.py"
|
|
eval "sed -i 's/= ask_admin_password()/= \"${SEAFILE_ADMIN_PW}\"/' ${INSTALLPATH}/check_init_admin.py"
|
|
|
|
|
|
# -------------------------------------------
|
|
# Start and stop Seafile eco system. This generates the initial admin user.
|
|
# -------------------------------------------
|
|
${TOPDIR}/seafile-server-${SEAFILE_VERSION}/seafile.sh start
|
|
${TOPDIR}/seafile-server-${SEAFILE_VERSION}/seahub.sh start ${SEAHUB_PORT}
|
|
${TOPDIR}/seafile-server-${SEAFILE_VERSION}/seahub.sh stop
|
|
|
|
|
|
# -------------------------------------------
|
|
# Restore original check_init_admin.py
|
|
# -------------------------------------------
|
|
mv ${INSTALLPATH}/check_init_admin.py.backup ${INSTALLPATH}/check_init_admin.py
|
|
|
|
|
|
# -------------------------------------------
|
|
# Final report
|
|
# -------------------------------------------
|
|
cat > ~/seafile/seafile-ce_uberspace.log <<EOF
|
|
Your Seafile server is installed
|
|
-----------------------------------------------------------------
|
|
Server Name: ${SERVER_NAME}
|
|
Server Address: https://${WHOAMI}.${HOSTNAME}
|
|
Seafile Admin: ${SEAFILE_ADMIN}
|
|
Admin Password: ${SEAFILE_ADMIN_PW}
|
|
Seafile Data Dir: ${SEAFILE_DATA_DIR}
|
|
|
|
SEAHUB_PORT: $SEAHUB_PORT
|
|
FILESERVER_PORT: $FILESERVER_PORT
|
|
SERVER_PORT: $SERVER_PORT
|
|
SEAFILE_SERVER_PORT: $SEAFILE_SERVER_PORT
|
|
SEAFDAV_PORT: $SEAFDAV_PORT
|
|
|
|
This report is also saved to ~/seafile/seafile-ce_uberspace.log
|
|
Next you should manually complete the following steps
|
|
-----------------------------------------------------------------
|
|
1) Setup mail in ~/seafile/seahub_settings.py
|
|
|
|
Optional steps
|
|
-----------------------------------------------------------------
|
|
1) Check seahub_settings.py and customize it to fit your needs. Consult
|
|
http://manual.seafile.com/config/seahub_settings_py.html for possible switches.
|
|
2) Implement a backup routine for your Seafile server.
|
|
|
|
-----------------------------------------------------------------
|
|
For free community support visit: https://forum.seafile-server.org
|
|
For paid commercial support visit: https://seafile.com.de
|
|
|
|
Contribute
|
|
-----------------------------------------------------------------
|
|
Contact alexander.jackson@seafile.de for bugs or suggestions about this installer.
|
|
|
|
EOF
|
|
|
|
chmod 600 ~/seafile/seafile-ce_uberspace.log
|
|
|
|
less ~/seafile/seafile-ce_uberspace.log
|