Last active
October 2, 2021 11:51
-
-
Save srehaider/88900295973d3b1aa567f8794b524ed0 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
#It is written on the basis of Instructions given here(http://git.27o.de/dataserver/about/) and I have tested it on ubuntu server 16.04. | |
#Before running this script get full information about inputs required to run this script | |
#SQL server ROOT password: | |
# is password which will be used as root password for MySQL server | |
#password for Zotero databases: | |
# This password will be used for all databases which are required for zotero dataserver | |
#Web access address: | |
# Address where you will access your server if you are installing it on a server you can use servers ip address to access it or a domain name which is pointing to it. | |
#Port: | |
# Port on which you will access your dataserver as it uses https protocol so default port is 443 if you want to access it on an other port which is available enter it. | |
#salt for user passwords: | |
# This salt will be embedded with user passwords before encrypting it to enhance security. You will have to use it during user creation on server. | |
#API super user name: | |
# Super username to access APIs | |
#API super user password: | |
# Superuser password to access APIs | |
#AWS secret key: | |
# This key is used to sync attachments with storage server. Storage server address and key is provided to client by server then client uploads attachment on storage server using this key. | |
#checking if script is ran as root or not | |
if [ "$EUID" -ne 0 ] | |
then echo 'Please run as root!' | |
exit | |
fi | |
# Ask the user for required inputs | |
echo 'Note: Do not use "zotero" as credential it cause some unknown problems.' | |
read -p 'Enter MySQL server ROOT password: ' sqlRootPassword | |
read -p 'Enter password for Zotero databases: ' zoteroDbPassword | |
printf 'Enter web/IP address where you will access it.\n' | |
printf 'Examples:\n\t127.0.0.1\n\texample.com\n\tsub.example.com\n' | |
read -p 'Enter web/IP address: ' webAdress | |
printf 'Enter port where you want to access it.\n' | |
read -p 'Default HTTPS port is 443 : ' port | |
read -p 'Enter salt for user passwords: ' salt | |
read -p 'Enter API super user name: ' suName | |
read -p 'Enter API super user password: ' suPassword | |
read -p 'Enter AWS secret key: ' awsKey | |
#install packages | |
echo 'Installing required packages' | |
apt-get update | |
debconf-set-selections <<< "mysql-server mysql-server/root_password password $sqlRootPassword" | |
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $sqlRootPassword" | |
apt-get -y install mysql-server | |
apt-get install apache2 libapache2-mod-php memcached zend-framework php-cli php-memcached php-mysql php-curl uwsgi uwsgi-plugin-psgi libplack-perl libdigest-hmac-perl libjson-xs-perl libfile-util-perl libapache2-mod-uwsgi git gnutls-bin runit libswitch-perl php-mbstring php-simplexml | |
#Create DIRECTORIES | |
echo 'Creating required directories' | |
mkdir -p /srv/zotero/{dataserver,zss,storage}/ /srv/zotero/log/{download,upload,error,api-errors,sync-errors} /etc/sv/zotero-download/log /etc/sv/zotero-upload/log /etc/sv/zotero-error/log | |
#Download dataserver Source Code | |
echo 'Cloning dataserver repository' | |
git clone git://git.27o.de/dataserver /srv/zotero/dataserver | |
#Commenting three lines which doesn't have correct syntax according to php7 and it doesn't have any impact on working | |
echo 'Commenting lines with incorect syntax' | |
sed -i '508,510 s/^/\/\//' /srv/zotero/dataserver/controllers/ApiController.php | |
#Prepare directory rights | |
echo 'Preparing directory rights' | |
chown www-data: /srv/zotero/log/{sync-errors,api-errors}/ | |
chown www-data:www-data /srv/zotero/dataserver/tmp /srv/zotero/storage | |
#Zend Linking | |
echo 'Linking Zend framework work with zotero dataserver' | |
cd /srv/zotero/dataserver/include | |
rm -r Zend | |
ln -s /usr/share/php/libzend-framework-php/Zend | |
#Apache2 Configuration | |
echo 'Enabling rewrite and ssl mode for apache2' | |
a2enmod ssl | |
a2enmod rewrite | |
# SSL Certificate Creation | |
echo 'Creating self-signed ssl certificates' | |
certtool -p --sec-param high --outfile /etc/apache2/zotero.key | |
certtool -s --load-privkey /etc/apache2/zotero.key --outfile /etc/apache2/zotero.cert | |
# Creating Virtual Host File | |
echo 'Creating VirtualHost file for zotero dataserver' | |
cat << EOF > /etc/apache2/sites-available/zotero.conf | |
<VirtualHost *:$port> | |
DocumentRoot /srv/zotero/dataserver/htdocs | |
SSLEngine on | |
SSLCertificateFile /etc/apache2/zotero.cert | |
SSLCertificateKeyFile /etc/apache2/zotero.key | |
<Location /zotero/> | |
SetHandler uwsgi-handler | |
uWSGISocket /var/run/uwsgi/app/zss/socket | |
uWSGImodifier1 5 | |
</Location> | |
<Directory "/srv/zotero/dataserver/htdocs/"> | |
Options FollowSymLinks MultiViews | |
AllowOverride All | |
Require all granted | |
Require all granted | |
</Directory> | |
php_value short_open_tag 1 | |
ErrorLog /srv/zotero/log/error.log | |
CustomLog /srv/zotero/log/access.log common | |
</VirtualHost> | |
EOF | |
# Registering Virtual Host File | |
echo 'Loading VirtualHost file of zotero dataserver' | |
a2ensite zotero.conf | |
# Editing .htaccess File | |
echo 'Editing /srv/zotero/dataserver/htdocs/.htaccess file' | |
sed -i -e 's/RewriteCond %{SCRIPT_FILENAME} !-d/RewriteCond %{SCRIPT_FILENAME} !-d\nRewriteCond %{REQUEST_URI} !^\/zotero/g' /srv/zotero/dataserver/htdocs/.htaccess | |
#MySQL Configuration | |
echo 'Configuring MySQL' | |
cat << EOF > /etc/mysql/conf.d/zotero.cnf | |
[mysqld] | |
character-set-server = utf8 | |
collation-server = utf8_general_ci | |
event-scheduler = ON | |
sql-mode = STRICT_ALL_TABLES | |
default-time-zone = '+0:00' | |
EOF | |
# Setting up Database | |
cd /srv/zotero/dataserver/misc/ | |
# Script to setup databases | |
echo 'Setting up databases' | |
sed -i -e "s/-pPW/-p$sqlRootPassword/g" /srv/zotero/dataserver/misc/setup_db | |
sed -i -e "s/foobar/$zoteroDbPassword/g" /srv/zotero/dataserver/misc/setup_db | |
./setup_db | |
#Dataserver Configuration | |
echo 'Configuring zotero dataserver settings' | |
cat << EOF > /srv/zotero/dataserver/include/config/dbconnect.inc.php | |
<? | |
function Zotero_dbConnectAuth(\$db) { | |
\$charset = ''; | |
if (\$db == 'master') { | |
\$host = 'localhost'; | |
\$port = 3306; | |
\$db = 'zotero_master'; | |
\$user = 'zotero'; | |
\$pass = '$zoteroDbPassword'; | |
} | |
else if (\$db == 'shard') { | |
\$host = false; | |
\$port = false; | |
\$db = false; | |
\$user = 'zotero'; | |
\$pass = '$zoteroDbPassword'; | |
} | |
else if (\$db == 'id1') { | |
\$host = 'localhost'; | |
\$port = 3306; | |
\$db = 'zotero_ids'; | |
\$user = 'zotero'; | |
\$pass = '$zoteroDbPassword'; | |
} | |
else if (\$db == 'id2') { | |
\$host = 'localhost'; | |
\$port = 3306; | |
\$db = 'zotero_ids'; | |
\$user = 'zotero'; | |
\$pass = '$zoteroDbPassword'; | |
} | |
else { | |
throw new Exception("Invalid db '\$db'"); | |
} | |
return array( | |
'host'=>\$host, | |
'port'=>\$port, | |
'db'=>\$db, | |
'user'=>\$user, | |
'pass'=>\$pass, | |
'charset'=>\$charset | |
); | |
} | |
?> | |
EOF | |
cat << EOF > /srv/zotero/dataserver/include/config/config.inc.php | |
<? | |
class Z_CONFIG { | |
public static \$API_ENABLED = true; | |
public static \$SYNC_ENABLED = true; | |
public static \$PROCESSORS_ENABLED = true; | |
public static \$MAINTENANCE_MESSAGE = 'Server updates in progress. Please try again in a few minutes.'; | |
public static \$TESTING_SITE = false; | |
public static \$DEV_SITE = false; | |
public static \$DEBUG_LOG = false; | |
public static \$BASE_URI = 'http://zotero.org/'; | |
public static \$API_BASE_URI = 'https://$webAdress:$port/';//address where you will access it | |
public static \$WWW_BASE_URI = ''; | |
public static \$SYNC_DOMAIN = 'sync'; | |
public static \$AUTH_SALT = '$salt';//add some salt that will be embeded with password before encrypting it and it will be used during user password setting. | |
public static \$API_SUPER_USERNAME = '$suName'; | |
public static \$API_SUPER_PASSWORD = '$suPassword'; | |
public static \$AWS_ACCESS_KEY = ''; | |
public static \$AWS_SECRET_KEY = '$awsKey'; //this key should be similar to key in ZSS.pm file | |
public static \$S3_BUCKET = 'zotero'; | |
public static \$S3_ENDPOINT = '$webAdress:$port'; | |
public static \$S3_USE_SSL = true; | |
public static \$S3_VALIDATE_SSL = false; | |
public static \$URI_PREFIX_DOMAIN_MAP = array( | |
'/sync/' => 'sync' | |
); | |
public static \$MEMCACHED_ENABLED = true; | |
public static \$MEMCACHED_SERVERS = array( | |
'localhost:11211' | |
); | |
public static \$TRANSLATION_SERVERS = array( | |
"translation1.localdomain:1969" | |
); | |
public static \$CITATION_SERVERS = array( | |
"citeserver1.localdomain:8080", "citeserver2.localdomain:8080" | |
); | |
public static \$ATTACHMENT_SERVER_HOSTS = array("files1.localdomain", "files2.localdomain"); | |
public static \$ATTACHMENT_SERVER_DYNAMIC_PORT = 80; | |
public static \$ATTACHMENT_SERVER_STATIC_PORT = 81; | |
public static \$ATTACHMENT_SERVER_URL = "https://files.example.net"; | |
public static \$ATTACHMENT_SERVER_DOCROOT = "/var/www/attachments/"; | |
public static \$STATSD_ENABLED = false; | |
public static \$STATSD_PREFIX = ""; | |
public static \$STATSD_HOST = "monitor.localdomain"; | |
public static \$STATSD_PORT = 8125; | |
public static \$LOG_TO_SCRIBE = false; | |
public static \$LOG_ADDRESS = ''; | |
public static \$LOG_PORT = 1463; | |
public static \$LOG_TIMEZONE = 'US/Eastern'; | |
public static \$LOG_TARGET_DEFAULT = 'errors'; | |
public static \$PROCESSOR_PORT_DOWNLOAD = 3455; | |
public static \$PROCESSOR_PORT_UPLOAD = 3456; | |
public static \$PROCESSOR_PORT_ERROR = 3457; | |
public static \$PROCESSOR_LOG_TARGET_DOWNLOAD = 'sync-processor-download'; | |
public static \$PROCESSOR_LOG_TARGET_UPLOAD = 'sync-processor-upload'; | |
public static \$PROCESSOR_LOG_TARGET_ERROR = 'sync-processor-error'; | |
public static \$SYNC_DOWNLOAD_SMALLEST_FIRST = false; | |
public static \$SYNC_UPLOAD_SMALLEST_FIRST = false; | |
// Set some things manually for running via command line | |
public static \$CLI_PHP_PATH = '/usr/bin/php'; | |
public static \$CLI_DOCUMENT_ROOT = "/srv/zotero/dataserver/"; | |
public static \$SYNC_ERROR_PATH = '/srv/zotero/log/sync-errors/'; | |
public static \$API_ERROR_PATH = '/srv/zotero/log/api-errors/'; | |
public static \$CACHE_VERSION_ATOM_ENTRY = 1; | |
public static \$CACHE_VERSION_BIB = 1; | |
public static \$CACHE_VERSION_ITEM_DATA = 1; | |
} | |
?> | |
EOF | |
#php Configuration | |
# Replace "short_open_tag = Off" with "short_open_tag = On" | |
echo 'Enabling php short_open_tag for cli use' | |
sed -i -e 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/7.0/cli/php.ini | |
#Creating Processor daemons Using runit | |
echo 'Creating Processor daemons Using runit' | |
cat << EOF > /etc/sv/zotero-download/run | |
#!/bin/sh | |
cd /srv/zotero/dataserver/processor/download | |
exec 2>&1 | |
exec chpst -u www-data:www-data php daemon.php | |
EOF | |
cat << EOF > /etc/sv/zotero-upload/run | |
#!/bin/sh | |
cd /srv/zotero/dataserver/processor/upload | |
exec 2>&1 | |
exec chpst -u www-data:www-data php daemon.php | |
EOF | |
cat << EOF > /etc/sv/zotero-error/run | |
#!/bin/sh | |
cd /srv/zotero/dataserver/processor/error | |
exec 2>&1 | |
exec chpst -u www-data:www-data php daemon.php | |
EOF | |
cat << EOF > /etc/sv/zotero-download/log/run | |
#!/bin/sh | |
exec svlogd /srv/zotero/log/download | |
EOF | |
cat << EOF > /etc/sv/zotero-upload/log/run | |
#!/bin/sh | |
exec svlogd /srv/zotero/log/upload | |
EOF | |
cat << EOF > /etc/sv/zotero-error/log/run | |
#!/bin/sh | |
exec svlogd /srv/zotero/log/error | |
EOF | |
#Fixing file permissions | |
echo 'Fixing file permissions' | |
chmod 744 /etc/sv/zotero-download/run /etc/sv/zotero-upload/run /etc/sv/zotero-error/run /etc/sv/zotero-download/log/run /etc/sv/zotero-upload/log/run /etc/sv/zotero-error/log/run | |
#Creating File links to run daemons | |
echo 'Creating File links to run daemons' | |
ln -s /etc/sv/zotero-download /etc/service/ | |
ln -s /etc/sv/zotero-upload /etc/service/ | |
ln -s /etc/sv/zotero-error /etc/service/ | |
#Configuring ZSS | |
echo 'Cloning zss repository to /srv/zotero/zss' | |
git clone git://git.27o.de/zss /srv/zotero/zss | |
echo 'Configuring ZSS' | |
sed -i -e 's/path\/to\/ZSS.pm/srv\/zotero\/zss\//g' /srv/zotero/zss/zss.psgi | |
sed -i -e "s/yoursecretkey/$awsKey/g" /srv/zotero/zss/ZSS.pm | |
sed -i -e 's/path\/to/srv\/zotero/g' /srv/zotero/zss/ZSS.pm | |
#Configure uwsgi | |
echo 'Configure uwsgi to launch zss' | |
cat << EOF > /etc/uwsgi/apps-available/zss.yaml | |
uwsgi: | |
plugin: psgi | |
psgi: /srv/zotero/zss/zss.psgi | |
EOF | |
ln -s /etc/uwsgi/apps-available/zss.yaml /etc/uwsgi/apps-enabled/ | |
echo 'Zotero dataserver installation Completed' | |
read -n1 -t10 -rsp 'System is going to reboot in 10 seconds or press any key to reboot now...'; | |
printf '\nRebooting...' | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment