#!/bin/bash # # seafile-server-installer/seafile-ce_uberspace # # Copyright 2015, Alexander Jackson # # 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 . # # #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 < ${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 < ~/bin/seafile <<'ENDOFILE' #!/bin/bash # Short-Description: Seafile server # Description: Start Seafile server ### END INIT INFO # Author: Alexander Jackson # # 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 < "${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 <> ${DEST_SETTINGS_PY} </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 <