#!/bin/bash # # seafile-server-installer/seafile-server-ce-ubuntu-14-04-amd64 # # 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 . # # if [[ $HOME == "" ]]; then export HOME=/root fi if [[ $SEAFILE_DEBUG != "" ]]; then set -x fi set -e if [[ "$#" -ne 1 ]]; then echo "You must specif Seafile version to install" echo "Like: $0 4.4.2" exit 1 fi clear cat < /etc/nginx/sites-available/seafile.conf <<'EOF' server { listen 80; server_name ""; location / { fastcgi_pass 127.0.0.1:8000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; access_log /var/log/nginx/seahub.access.log; error_log /var/log/nginx/seahub.error.log; } location /seafhttp { rewrite ^/seafhttp(.*)$ $1 break; proxy_pass http://127.0.0.1:8082; client_max_body_size 0; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; } location /media { root /opt/seafile/seafile-server-latest/seahub; } location /seafdav { fastcgi_pass 127.0.0.1:8080; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; client_max_body_size 0; access_log /var/log/nginx/seafdav.access.log; error_log /var/log/nginx/seafdav.error.log; } } EOF ln -sf /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf service nginx restart # ------------------------------------------- # MariaDB # ------------------------------------------- if [[ -f "/root/.my.cnf" ]] ; then echo "MariaDB installed before, skip this part" else DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server SQLROOTPW=$(pwgen) mysqladmin -u root password $SQLROOTPW cat > /root/.my.cnf < /etc/init.d/seafile-server <<'EOF' #!/bin/bash ### BEGIN INIT INFO # Provides: seafile-server # Required-Start: $remote_fs $syslog mysql # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Seafile server # Description: Start Seafile server ### END INIT INFO # Author: Alexander Jackson # # Change the value of "user" to your linux user name user=seafile # Change the value of "seafile_dir" to your path of seafile installation seafile_dir=/opt/seafile script_path=${seafile_dir}/seafile-server-latest seafile_init_log=${seafile_dir}/logs/seafile.init.log seahub_init_log=${seafile_dir}/logs/seahub.init.log # Change the value of fastcgi to true if fastcgi is to be used fastcgi=true # Set the port of fastcgi, default is 8000. Change it if you need different. fastcgi_port=8000 case "$1" in start) sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log} if [ $fastcgi = true ]; then sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} else sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log} fi ;; restart) sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log} if [ $fastcgi = true ]; then sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log} else sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log} fi ;; stop) sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log} sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log} ;; *) echo "Usage: /etc/init.d/seafile-server {start|stop|restart}" exit 1 ;; esac EOF chmod +x /etc/init.d/seafile-server update-rc.d seafile-server defaults # ------------------------------------------- # Seafile # ------------------------------------------- adduser --system --gecos "${SEAFILE_USER}" ${SEAFILE_USER} --home /opt/seafile mkdir -p /opt/seafile/installed cd /opt/seafile/ if ! is_pro && [[ ! -e /opt/${SEAFILE_SERVER_PACKAGE} ]]; then curl -OL ${SEAFILE_SERVER_PACKAGE_URL} else cp /opt/${SEAFILE_SERVER_PACKAGE} . fi tar xzf ${SEAFILE_SERVER_PACKAGE} mv ${SEAFILE_SERVER_PACKAGE} installed # ------------------------------------------- # Seafile DB # ------------------------------------------- SQLSEAFILEPW=$(pwgen) cat > /opt/seafile/.my.cnf < "${DEFAULT_CCNET_CONF_DIR}/seafile.ini" # ------------------------------------------- # Configure Seafile WebDAV Server(SeafDAV) # ------------------------------------------- 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 # ------------------------------------------- cat >> ${DEFAULT_CONF_DIR}/ccnet.conf <> ${DEFAULT_CONF_DIR}/seafile.conf <> ${DEST_SETTINGS_PY} < ${seafile_dir}/aio_seafile-server.log<