2017-07-28 12:35:26 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-08-11 14:34:22 +02:00
|
|
|
set -eu
|
|
|
|
|
2017-07-28 12:35:26 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE FAILURE OF THE SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2017-09-22 13:53:04 +02:00
|
|
|
|
2017-07-28 12:35:26 +02:00
|
|
|
path=$YNH_APP_ARG_PATH
|
2017-09-22 13:53:04 +02:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-07-28 12:35:26 +02:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK THE DEBIAN'S CODENAME
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
codename=$(lsb_release -a 2>/dev/null | grep Codename | cut -f 2)
|
|
|
|
test -z "$codename" && (ynh_die "codename empty")
|
|
|
|
if [ $codename != 'jessie' ]
|
|
|
|
then
|
|
|
|
ynh_die "Sorry, it can only be installed on Debian Jessie"
|
|
|
|
fi
|
|
|
|
archi=$(uname -m)
|
|
|
|
pwd=$(pwd)
|
2017-09-22 13:53:04 +02:00
|
|
|
wwwhome=~www-data
|
2017-07-28 12:35:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
port=$(ynh_find_port 8181) # Cherche un port libre.
|
|
|
|
|
|
|
|
# Store infos in YunoHost config
|
2017-09-22 13:53:04 +02:00
|
|
|
ynh_app_setting_set $app port $port
|
2017-07-28 12:35:26 +02:00
|
|
|
ynh_app_setting_set $app path ${path}
|
2017-09-22 13:53:04 +02:00
|
|
|
ynh_app_setting_set $app domain ${domain}
|
2017-07-28 12:35:26 +02:00
|
|
|
ynh_app_setting_set $app is_public ${is_public}
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DEPENDENCIES
|
|
|
|
#=================================================
|
2017-09-22 13:53:04 +02:00
|
|
|
# Activate backports sources.list
|
|
|
|
cp -a "../conf/turtl.list" "/etc/apt/sources.list.d/$app.list"
|
|
|
|
cp -a "../conf/turtl-preferences" "/etc/apt/preferences.d/00TurtlPinning"
|
|
|
|
if [ $archi == "armv7l" ]
|
|
|
|
then
|
2017-10-27 08:53:58 +02:00
|
|
|
gpg --list-keys 7638D0442B90D010 > /dev/null 2>&1
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
gpg --keyserver pgpkeys.mit.edu --recv-key 7638D0442B90D010
|
|
|
|
fi
|
|
|
|
gpg --list-keys 8B48AD6246925553 > /dev/null 2>&1
|
|
|
|
if [ $? != 0 ]
|
|
|
|
then
|
|
|
|
gpg --keyserver pgpkeys.mit.edu --recv-key 8B48AD6246925553
|
|
|
|
fi
|
|
|
|
if [ $(apt-key finger | grep "7638 D044 2B90 D010" -c) == 0 ]
|
|
|
|
then
|
|
|
|
gpg -a --export 7638D0442B90D010 | apt-key add -
|
|
|
|
fi
|
|
|
|
if [ $(apt-key finger | grep "8B48 AD62 4692 5553" -c) == 0 ]
|
|
|
|
then
|
|
|
|
gpg -a --export 8B48AD6246925553 | apt-key add -
|
|
|
|
fi
|
2017-09-22 13:53:04 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $archi == "armv7l" ]
|
|
|
|
then
|
|
|
|
# Install RethinkDB
|
|
|
|
dpkg -i ../conf/rethinkdb_2.3.6_armhf.deb
|
|
|
|
else
|
|
|
|
# Activate RethinkDB sources.list
|
|
|
|
release=$(lsb_release -cs)
|
|
|
|
echo "deb http://download.rethinkdb.com/apt $release main" | tee /etc/apt/sources.list.d/rethinkdb.list
|
|
|
|
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | apt-key add -
|
|
|
|
ynh_package_update
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install dependencies
|
|
|
|
ynh_package_update
|
|
|
|
ynh_install_app_dependencies wget git build-essential rethinkdb libuv1-dev python-pip
|
|
|
|
|
|
|
|
|
2017-07-28 12:35:26 +02:00
|
|
|
# Install Clozure Common Lisp
|
|
|
|
cd /opt
|
|
|
|
if [ $archi == "armv7l" ]
|
|
|
|
then
|
|
|
|
wget -q ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxarm.tar.gz
|
|
|
|
tar xf ccl-1.11-linuxarm.tar.gz
|
|
|
|
else
|
|
|
|
wget -q ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxx86.tar.gz
|
|
|
|
tar xf ccl-1.11-linuxx86.tar.gz
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd ccl
|
|
|
|
if [ $(grep -c "flags.* lm .*" /proc/cpuinfo) -eq 0 ]
|
|
|
|
then
|
|
|
|
cp scripts/ccl /usr/bin/ccl
|
|
|
|
else
|
|
|
|
cp scripts/ccl64 /usr/bin/ccl
|
|
|
|
fi
|
|
|
|
sed -e "s@CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl@CCL_DEFAULT_DIRECTORY=/opt/ccl@" -i /usr/bin/ccl
|
|
|
|
|
2017-09-22 13:53:04 +02:00
|
|
|
# Install QuickLisp
|
2017-07-28 12:35:26 +02:00
|
|
|
cd $pwd
|
2017-09-22 13:53:04 +02:00
|
|
|
cp -a ../conf/ccl-init.lisp $wwwhome/.ccl-init.lisp
|
|
|
|
cp -a ../conf/quicklisp.lisp /tmp/quicklisp.lisp
|
|
|
|
cp -a ../conf/quicklisp.lisp.asc /tmp/quicklisp.lisp.asc
|
2017-07-28 12:35:26 +02:00
|
|
|
|
2017-09-22 13:53:04 +02:00
|
|
|
mkdir $wwwhome/quicklisp $wwwhome/.cache/
|
|
|
|
chown www-data: $wwwhome/quicklisp $wwwhome/.cache/ $wwwhome/.ccl-init.lisp
|
2017-07-28 12:35:26 +02:00
|
|
|
|
|
|
|
gpg --keyserver pgpkeys.mit.edu --recv-key 307965AB028B5FF7
|
|
|
|
gpg --verify /tmp/quicklisp.lisp.asc /tmp/quicklisp.lisp
|
|
|
|
|
|
|
|
su -c 'echo -e "(quicklisp-quickstart:install)\n(quit)" | ccl --load /tmp/quicklisp.lisp' -s /bin/bash www-data
|
|
|
|
|
2017-09-22 13:53:04 +02:00
|
|
|
echo "(pushnew \"./\" asdf :*central-registry* :test #'equal)" >> $wwwhome/.ccl-init.lisp
|
2017-07-28 12:35:26 +02:00
|
|
|
|
|
|
|
rm -f /tmp/quicklisp /tmp/quicklisp.lisp.asc
|
|
|
|
|
2017-09-22 13:53:04 +02:00
|
|
|
# Configure RethinkDB
|
2017-07-28 12:35:26 +02:00
|
|
|
echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
|
|
|
|
service rethinkdb restart
|
|
|
|
|
|
|
|
# Install RethinkDB tools (needed for backup)
|
|
|
|
pip install rethinkdb
|
|
|
|
|
|
|
|
# Install Turtl
|
2017-09-22 13:53:04 +02:00
|
|
|
cd $wwwhome
|
2017-07-28 12:35:26 +02:00
|
|
|
mkdir turtl/data -p
|
|
|
|
cd turtl
|
|
|
|
git clone https://github.com/turtl/api.git
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CONFIGURE TURTL
|
|
|
|
#=================================================
|
|
|
|
cd api
|
|
|
|
|
|
|
|
# Copions le modèle de fichier de configuration
|
|
|
|
cp config/config.default.lisp config/config.lisp
|
|
|
|
|
|
|
|
# Modifie la configuration de turtl
|
|
|
|
sed -e "s@\*server-port\* 8181@*server-port* $port@" \
|
|
|
|
-e "s@\*server-bind\* nil@*server-bind* \"127.0.0.1\"@" \
|
|
|
|
-e "s@\*production-error-handling\* nil@*production-error-handling* t@" \
|
|
|
|
-e "s@\*site-url\* \"http://turtl.dev:8181\"@*site-url* \"https://$domain\"@" \
|
|
|
|
-e "s@\*smtp-host\* nil@*smtp-host* \"localhost\"@" \
|
|
|
|
-e "s@\*display-errors\* t@*display-errors* nil@" \
|
2017-09-22 13:53:04 +02:00
|
|
|
-e "s@\*local-upload\* nil@*local-upload* \"$wwwhome/turtl/data\"@" \
|
2017-07-28 12:35:26 +02:00
|
|
|
-e "s@\*local-upload-url\* nil@*local-upload-url* \"https://$domain\"@" \
|
|
|
|
-i config/config.lisp
|
|
|
|
|
|
|
|
if [ $path != '/' ]
|
|
|
|
then
|
|
|
|
sed -e "s@\*api-path\* \"\"@\*api-path\* \"$path\"@" -i config/config.lisp
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOG HANDLING
|
|
|
|
#=================================================
|
|
|
|
cd $pwd
|
2017-09-22 13:53:04 +02:00
|
|
|
cp "../conf/rsyslogd.conf" "/etc/rsyslog.d/$app.conf"
|
|
|
|
service rsyslog restart
|
|
|
|
mkdir /var/log/turtl/ -p
|
|
|
|
cp "../conf/logrotate.conf" "/etc/logrotate.d/$app"
|
2017-07-28 12:35:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENABLE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
# Add service to Yunohost monitoring
|
2017-09-22 13:53:04 +02:00
|
|
|
cp "../conf/turtl.service" "/etc/systemd/system/$app.service"
|
|
|
|
systemctl daemon-reload
|
|
|
|
yunohost service add turtl --log "/var/log/turtl/$app.log"
|
|
|
|
yunohost service start turtl
|
2017-07-28 12:35:26 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX
|
|
|
|
#=================================================
|
|
|
|
# Copy Nginx conf
|
2017-09-22 13:53:04 +02:00
|
|
|
cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2017-07-28 12:35:26 +02:00
|
|
|
|
|
|
|
# Change variables in Nginx configuration
|
|
|
|
if [ $is_public -eq 1 ];
|
|
|
|
then
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "$path"
|
|
|
|
fi
|
2017-09-22 13:53:04 +02:00
|
|
|
sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf
|
2017-07-28 12:35:26 +02:00
|
|
|
|
2017-09-22 13:53:04 +02:00
|
|
|
# Reload Nginx
|
|
|
|
service nginx reload
|