2016-12-15 21:20:12 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# turtl app
|
|
|
|
#
|
|
|
|
# http://portallinux.es/instalacion-servidor-turtl-debian-8
|
|
|
|
# http://framacloud.org/cultiver-son-jardin/installation-de-turtl/
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
VARIANTS="full full-vim writer"
|
|
|
|
|
|
|
|
IN_DEFAULT_INSTALL=0
|
|
|
|
SHOW_ON_ABOUT=1
|
|
|
|
|
|
|
|
TURTL_DOMAIN_NAME=
|
|
|
|
TURTL_CODE=
|
|
|
|
TURTL_ONION_PORT=8107
|
2016-12-16 00:11:43 +01:00
|
|
|
TURTL_API_ONION_PORT=8108
|
2016-12-15 21:20:12 +01:00
|
|
|
TURTL_PORT=8181
|
2016-12-16 00:11:43 +01:00
|
|
|
TURTL_API_REPO="https://github.com/turtl/api.git"
|
|
|
|
TURTL_API_COMMIT='53e00a5583f52de8f86ef380fe11c176b5738dcf'
|
|
|
|
TURTL_REPO="https://github.com/turtl/js.git"
|
|
|
|
TURTL_COMMIT='61923ffb47d95d172f80d14c76aa032a4d5f5d6d'
|
2016-12-15 21:20:12 +01:00
|
|
|
TURTL_ADMIN_PASSWORD=
|
|
|
|
TURTL_STORAGE_LIMIT_MB=100
|
|
|
|
|
|
|
|
LIBUV_VERSION='1.9.1'
|
|
|
|
LIBUV_HASH='e83953782c916d7822ef0b94e8115ce5756fab5300cca173f0de5f5b0e0ae928'
|
|
|
|
|
|
|
|
turtl_variables=(ONION_ONLY
|
|
|
|
DEFAULT_DOMAIN_NAME
|
|
|
|
TURTL_DOMAIN_NAME
|
|
|
|
TURTL_CODE
|
|
|
|
TURTL_STORAGE_LIMIT_MB
|
|
|
|
DDNS_PROVIDER
|
|
|
|
MY_EMAIL_ADDRESS
|
|
|
|
MY_USERNAME)
|
|
|
|
|
|
|
|
function change_password_turtl {
|
|
|
|
change_username="$1"
|
|
|
|
new_user_password="$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_user_turtl {
|
|
|
|
remove_username="$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_user_turtl {
|
|
|
|
new_username="$1"
|
|
|
|
new_user_password="$2"
|
|
|
|
echo '0'
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_interactive_turtl {
|
|
|
|
if [ ! $ONION_ONLY ]; then
|
|
|
|
ONION_ONLY='no'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $ONION_ONLY != "no" ]]; then
|
|
|
|
TURTL_DOMAIN_NAME='notes.local'
|
|
|
|
write_config_param "TURTL_DOMAIN_NAME" "$TURTL_DOMAIN_NAME"
|
|
|
|
else
|
|
|
|
function_check interactive_site_details
|
|
|
|
interactive_site_details "turtl" "TURTL_DOMAIN_NAME" "TURTL_CODE"
|
|
|
|
fi
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|
|
|
|
|
|
|
|
function configure_interactive_turtl {
|
|
|
|
data=$(tempfile 2>/dev/null)
|
|
|
|
trap "rm -f $data" 0 1 2 5 15
|
|
|
|
dialog --title $"Change storage limit" \
|
|
|
|
--backtitle $"Freedombone Control Panel" \
|
|
|
|
--inputbox $"Enter a storage limit in megabytes." 8 75 "$TURTL_STORAGE_LIMIT_MB" 2>$data
|
|
|
|
sel=$?
|
|
|
|
case $sel in
|
|
|
|
0)
|
|
|
|
STORAGE=$(<$data)
|
|
|
|
if [ ${#STORAGE} -gt 0 ]; then
|
|
|
|
TURTL_STORAGE_LIMIT_MB=$STORAGE
|
2016-12-16 00:11:43 +01:00
|
|
|
sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* $TURTL_STORAGE_LIMIT_MB|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
2016-12-15 21:20:12 +01:00
|
|
|
systemctl restart turtl
|
|
|
|
dialog --title $"Change storage limit" \
|
|
|
|
--msgbox $"Storage limit changed to ${TURTL_STORAGE_LIMIT_MB}M" 6 50
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function reconfigure_turtl {
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/htdocs/data ]; then
|
|
|
|
rm -rf /var/www/${TURTL_DOMAIN_NAME}/htdocs/data/*
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_turtl {
|
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
|
|
|
|
install_libuv
|
|
|
|
|
|
|
|
function_check set_repo_commit
|
|
|
|
set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
|
2016-12-16 00:11:43 +01:00
|
|
|
set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl api commit" "$TURTL_API_COMMIT" $TURTL_API_REPO
|
2016-12-17 17:17:19 +01:00
|
|
|
nginx_dissite $TURTL_DOMAIN_NAME
|
|
|
|
cd /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
npm install
|
|
|
|
make minify
|
|
|
|
nginx_ensite $TURTL_DOMAIN_NAME
|
2016-12-15 21:20:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_local_turtl {
|
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
source_directory=/var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
dest_directory=turtl
|
|
|
|
function_check suspend_site
|
|
|
|
suspend_site ${TURTL_DOMAIN_NAME}
|
|
|
|
|
|
|
|
function_check backup_directory_to_usb
|
|
|
|
backup_directory_to_usb $source_directory $dest_directory
|
|
|
|
|
|
|
|
function_check restart_site
|
|
|
|
restart_site
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_local_turtl {
|
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
if [ $TURTL_DOMAIN_NAME ]; then
|
|
|
|
temp_restore_dir=/root/tempturtl
|
|
|
|
restore_directory_from_usb $temp_restore_dir turtl
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/htdocs ]; then
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
|
|
rm -rf /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
|
|
fi
|
|
|
|
mv /var/www/${TURTL_DOMAIN_NAME}/htdocs /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
|
|
fi
|
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
|
|
|
|
cp -r ${temp_source_dir} /var/www/${TURTL_DOMAIN_NAME}/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
|
|
mv /var/www/${TURTL_DOMAIN_NAME}/previous /var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
|
|
fi
|
|
|
|
set_user_permissions
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 36723
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
|
|
|
chown -R turtl:turtl /var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_turtl {
|
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
if [ $TURTL_DOMAIN_NAME ]; then
|
|
|
|
temp_backup_dir=/var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
|
|
if [ -d $temp_backup_dir ]; then
|
|
|
|
echo $"Backing up turtl"
|
|
|
|
backup_directory_to_friend $temp_backup_dir turtl
|
|
|
|
echo $"Backup of turtl complete"
|
|
|
|
else
|
|
|
|
echo $"turtl domain specified but not found in $temp_backup_dir"
|
|
|
|
exit 68725
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_remote_turtl {
|
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
if [ $TURTL_DOMAIN_NAME ]; then
|
|
|
|
temp_restore_dir=/root/tempturtl
|
|
|
|
mkdir $temp_restore_dir
|
|
|
|
function_check restore_directory_from_friend
|
|
|
|
restore_directory_from_friend $temp_restore_dir turtl
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/htdocs ]; then
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
|
|
rm -rf /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
|
|
fi
|
|
|
|
mv /var/www/${TURTL_DOMAIN_NAME}/htdocs /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
|
|
fi
|
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
|
|
|
|
cp -r ${temp_source_dir} /var/www/${TURTL_DOMAIN_NAME}/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
|
|
mv /var/www/${TURTL_DOMAIN_NAME}/previous /var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
|
|
fi
|
|
|
|
exit 37823
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
function remove_turtl_old {
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ${#TURTL_DOMAIN_NAME} -eq 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
read_config_param "MY_USERNAME"
|
|
|
|
echo "Removing $TURTL_DOMAIN_NAME"
|
|
|
|
if [ -f /etc/systemd/system/turtl.service ]; then
|
|
|
|
systemctl stop turtl
|
|
|
|
systemctl disable turtl
|
|
|
|
rm /etc/systemd/system/turtl.service
|
|
|
|
fi
|
|
|
|
nginx_dissite $TURTL_DOMAIN_NAME
|
|
|
|
remove_certs $TURTL_DOMAIN_NAME
|
|
|
|
if [ -d /var/www/$TURTL_DOMAIN_NAME ]; then
|
|
|
|
rm -rf /var/www/$TURTL_DOMAIN_NAME
|
|
|
|
fi
|
|
|
|
if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
|
|
|
|
rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
|
|
|
|
fi
|
|
|
|
function_check remove_onion_service
|
|
|
|
remove_onion_service turtl ${TURTL_ONION_PORT}
|
2016-12-16 00:11:43 +01:00
|
|
|
remove_onion_service turtlapi ${TURTL_API_ONION_PORT}
|
2016-12-15 21:20:12 +01:00
|
|
|
remove_app turtl
|
|
|
|
remove_completion_param install_turtl
|
|
|
|
sed -i '/turtl/d' $COMPLETION_FILE
|
|
|
|
deluser --remove-all-files turtl
|
|
|
|
remove_nodejs turtl
|
|
|
|
|
|
|
|
remove_rethinkdb
|
2016-12-17 17:17:19 +01:00
|
|
|
remove_common_lisp
|
2016-12-15 21:20:12 +01:00
|
|
|
|
|
|
|
function_check remove_ddns_domain
|
|
|
|
remove_ddns_domain $TURTL_DOMAIN_NAME
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
function remove_turtl {
|
|
|
|
if [ ! -d /opt/api ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
systemctl stop turtl
|
|
|
|
systemctl disable turtl
|
|
|
|
rm /etc/systemd/system/turtl.service
|
2016-12-18 01:05:34 +01:00
|
|
|
apt-get -y remove rethinkdb
|
2016-12-18 00:48:20 +01:00
|
|
|
remove_app turtl
|
|
|
|
remove_completion_param install_turtl
|
|
|
|
sed -i '/turtl/d' $COMPLETION_FILE
|
2016-12-18 01:05:34 +01:00
|
|
|
rm $INSTALL_DIR/quicklisp.lisp
|
2016-12-18 10:50:00 +01:00
|
|
|
rm $INSTALL_DIR/asdf.lisp
|
2016-12-18 01:05:34 +01:00
|
|
|
rm -rf /etc/rethinkdb
|
|
|
|
rm -rf /var/lib/rethinkdb
|
2016-12-18 00:48:20 +01:00
|
|
|
rm -rf /root/quicklisp
|
|
|
|
rm -rf /opt/ccl
|
|
|
|
rm -rf /opt/api
|
|
|
|
}
|
|
|
|
|
2016-12-15 21:20:12 +01:00
|
|
|
function install_libuv {
|
2016-12-17 17:17:19 +01:00
|
|
|
if [ ! -d /usr/local/src ]; then
|
|
|
|
mkdir -p /usr/local/src
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
|
2016-12-17 17:17:19 +01:00
|
|
|
cd /usr/local/src
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
|
|
|
|
wget http://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz
|
|
|
|
fi
|
|
|
|
if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
|
|
|
|
echo $"Couldn't download libuv ${LIBUV_VERSION}"
|
|
|
|
exit 728235
|
|
|
|
fi
|
|
|
|
hashstr=$(sha256sum libuv-v${LIBUV_VERSION}.tar.gz | awk -F ' ' '{print $1}')
|
|
|
|
if [[ "$hashstr" != "$LIBUV_HASH" ]]; then
|
|
|
|
rm libuv-v${LIBUV_VERSION}.tar.gz
|
|
|
|
echo $"libuv hash does not match. Expected $LIBUV_HASH but found $hashstr"
|
|
|
|
exit 27685
|
|
|
|
fi
|
2016-12-17 17:17:19 +01:00
|
|
|
if [ ! -d /usr/local/src/libuv-v${LIBUV_VERSION} ]; then
|
2016-12-15 21:20:12 +01:00
|
|
|
tar -xf libuv-v${LIBUV_VERSION}.tar.gz
|
|
|
|
fi
|
2016-12-17 17:17:19 +01:00
|
|
|
if [ ! -d /usr/local/src/libuv-v${LIBUV_VERSION} ]; then
|
2016-12-15 21:20:12 +01:00
|
|
|
rm libuv-v${LIBUV_VERSION}.tar.gz
|
|
|
|
echo $'libuv could not be extracted'
|
|
|
|
exit 72754
|
|
|
|
fi
|
2016-12-17 17:17:19 +01:00
|
|
|
cd /usr/local/src/libuv-v${LIBUV_VERSION}
|
2016-12-15 21:20:12 +01:00
|
|
|
sh autogen.sh
|
|
|
|
./configure
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
function install_turtl_old {
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ! $TURTL_DOMAIN_NAME ]; then
|
|
|
|
echo $'No domain name was given for turtl'
|
|
|
|
exit 47823
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f $IMAGE_PASSWORD_FILE ]; then
|
|
|
|
TURTL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
|
|
else
|
|
|
|
if [ ! $TURTL_ADMIN_PASSWORD ]; then
|
|
|
|
TURTL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get -yq install git wget curl libtool subversion gcc make automake
|
|
|
|
|
2016-12-17 17:17:19 +01:00
|
|
|
if [ ! -d /usr/local/src ]; then
|
|
|
|
mkdir -p /usr/local/src
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
|
2016-12-16 00:11:43 +01:00
|
|
|
if [ -d /var/www/$TURTL_DOMAIN_NAME ]; then
|
|
|
|
rm -rf /var/www/$TURTL_DOMAIN_NAME
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
2016-12-16 00:11:43 +01:00
|
|
|
mkdir /var/www/$TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
# get the app
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs ]; then
|
|
|
|
function_check git_clone
|
|
|
|
git_clone $TURTL_REPO /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs ]; then
|
|
|
|
echo $'Unable to clone turtl repo'
|
|
|
|
exit 367292
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-12-16 00:11:43 +01:00
|
|
|
# get the api
|
|
|
|
if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs/api ]; then
|
|
|
|
git_clone $TURTL_API_REPO /var/www/$TURTL_DOMAIN_NAME/htdocs/api
|
|
|
|
if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs/api ]; then
|
|
|
|
echo $'Unable to clone turtl api repo'
|
|
|
|
exit 473843
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check that default config files exist
|
|
|
|
if [ ! -f /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.default.lisp ]; then
|
|
|
|
echo $'No default turtl api config found'
|
2016-12-15 21:20:12 +01:00
|
|
|
exit 825328
|
|
|
|
fi
|
2016-12-16 00:18:21 +01:00
|
|
|
if [ ! -f /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js.default ]; then
|
2016-12-16 00:11:43 +01:00
|
|
|
echo $'No default turtl config found'
|
|
|
|
exit 783524
|
|
|
|
fi
|
|
|
|
|
|
|
|
# directory where uploads are stored
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs/data ]; then
|
|
|
|
mkdir -p /var/www/$TURTL_DOMAIN_NAME/htdocs/data
|
|
|
|
fi
|
2016-12-16 00:11:43 +01:00
|
|
|
|
|
|
|
# create config files
|
|
|
|
cp /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.default.lisp /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
cp /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js.default /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js
|
|
|
|
|
|
|
|
# app config file settings
|
|
|
|
sed -i "s|api_url.*|api_url: 'https://api.${TURTL_DOMAIN_NAME}'|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js
|
|
|
|
sed -i "s|site_url.*|api_url: 'https://${TURTL_DOMAIN_NAME}'|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js
|
|
|
|
|
|
|
|
# api config file settings
|
|
|
|
sed -i "s|defvar *admin-email* \".*|defvar *admin-email* \"$MY_EMAIL_ADDRESS\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|defvar *email-from* \".*|defvar *email-from* \"noreply@$DEFAULT_DOMAIN_NAME\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|defvar *site-url* \".*|defvar *site-url* \"https://$TURTL_DOMAIN_NAME\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|defvar *analytics* '(:enabled.*|defvar *analytics* '(:enabled f|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i 's|http://turtl.dev:8181|https://$TURTL_DOMAIN_NAME|g' /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|defvar *local-upload*.*|defvar *local-upload* \"/var/www/$TURTL_DOMAIN_NAME/htdocs/data\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|defvar *local-upload-url*.*|defvar *local-upload-url* \"https://api.${TURTL_DOMAIN_NAME}\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i 's|defparameter *storage-invite-credit*.*|defparameter *storage-invite-credit* 0|g' /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* $TURTL_STORAGE_LIMIT_MB|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
2016-12-15 21:20:12 +01:00
|
|
|
|
|
|
|
cd /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
git checkout $TURTL_COMMIT -b $TURTL_COMMIT
|
|
|
|
set_completion_param "turtl commit" "$TURTL_COMMIT"
|
|
|
|
|
2016-12-16 00:11:43 +01:00
|
|
|
cd /var/www/$TURTL_DOMAIN_NAME/htdocs/api
|
|
|
|
git checkout $TURTL_API_COMMIT -b $TURTL_API_COMMIT
|
|
|
|
set_completion_param "turtl api commit" "$TURTL_API_COMMIT"
|
2016-12-15 21:20:12 +01:00
|
|
|
|
2016-12-17 17:17:19 +01:00
|
|
|
function_check install_libuv
|
2016-12-15 21:20:12 +01:00
|
|
|
install_libuv
|
2016-12-17 17:17:19 +01:00
|
|
|
|
|
|
|
function_check install_rethinkdb
|
2016-12-15 21:20:12 +01:00
|
|
|
install_rethinkdb
|
2016-12-17 17:17:19 +01:00
|
|
|
|
|
|
|
function_check install_common_lisp
|
2016-12-15 21:20:12 +01:00
|
|
|
install_common_lisp
|
2016-12-17 17:17:19 +01:00
|
|
|
|
|
|
|
function_check install_quicklisp
|
2016-12-15 21:20:12 +01:00
|
|
|
install_quicklisp
|
|
|
|
|
|
|
|
function_check install_nodejs
|
|
|
|
install_nodejs turtl
|
|
|
|
|
|
|
|
function_check add_ddns_domain
|
|
|
|
add_ddns_domain $TURTL_DOMAIN_NAME
|
|
|
|
|
2016-12-17 18:41:17 +01:00
|
|
|
sed -i 's|CCL_DEFAULT_DIRECTORY=.*|CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl|g' /usr/bin/ccl
|
|
|
|
sed -i 's|CCL_DEFAULT_DIRECTORY=.*|CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl|g' /usr/bin/ccl64
|
2016-12-17 17:17:19 +01:00
|
|
|
|
|
|
|
adduser --disabled-login --home=/var/www/$TURTL_DOMAIN_NAME/htdocs --gecos 'turtl' turtl
|
2016-12-17 18:41:17 +01:00
|
|
|
|
|
|
|
cp /usr/local/src/asdf.lisp /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
cp /usr/local/src/quicklisp.lisp /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
echo '(load (compile-file "asdf.lisp"))' > /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(load (compile-file "quicklisp.lisp"))' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
2016-12-17 19:08:28 +01:00
|
|
|
echo '(quicklisp-quickstart:install)' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
echo '(ql:system-apropos "vecto")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "alexandria")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "babel")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "blackbird")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "bordeaux-threads")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cffi")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "chipz")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "chunga")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-annot")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-async")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-async-future")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-base64")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-fad")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-libuv")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-mongo-id")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-ppcre")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-rethinkdb")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-smtp")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl+ssl")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-syntax")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-utilities")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "cl-vectors")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "do-urlencode")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "drakma")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "drakma-async")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "event-glue")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "fast-http")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "fast-io")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "flexi-streams")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "ironclad")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "jonathan")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "local-time")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "md5")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "named-readtables")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "nibbles")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "proc-parse")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "puri")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "quri")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "salza2")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "secure-random")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "smart-buffer")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "split-sequence")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "static-vectors")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "trivial-backtrace")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "trivial-features")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "trivial-garbage")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "trivial-gray-streams")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "trivial-types")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "usocket")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "vecto")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "vom")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "wookie")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "xmls")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "xsubseq")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "yason")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "zpb-ttf")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
|
|
|
echo '(ql:quickload "zpng")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
2016-12-17 19:08:28 +01:00
|
|
|
echo '(ql:add-to-init-file)' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp
|
2016-12-17 18:41:17 +01:00
|
|
|
|
2016-12-17 17:17:19 +01:00
|
|
|
chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
|
2016-12-17 18:41:17 +01:00
|
|
|
|
2016-12-17 17:17:19 +01:00
|
|
|
check_architecture=$(uname -a)
|
|
|
|
if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
|
2016-12-17 18:41:17 +01:00
|
|
|
su -c '/usr/bin/ccl64 --load install.lisp --eval "(quit)"' - turtl
|
2016-12-17 17:17:19 +01:00
|
|
|
else
|
2016-12-17 18:41:17 +01:00
|
|
|
su -c '/usr/bin/ccl --load install.lisp --eval "(quit)"' - turtl
|
2016-12-17 17:17:19 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" > /var/www/$TURTL_DOMAIN_NAME/htdocs/api/launch.lisp
|
|
|
|
echo '(load "start")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/api/launch.lisp
|
|
|
|
|
|
|
|
cd /var/www/$TURTL_DOMAIN_NAME/htdocs/quicklisp/local-projects
|
|
|
|
git clone git://github.com/orthecreedence/cl-hash-util
|
|
|
|
git clone git://github.com/orthecreedence/vom
|
|
|
|
git clone git://github.com/orthecreedence/cl-async
|
|
|
|
git clone git://github.com/orthecreedence/cffi
|
|
|
|
git clone git://github.com/orthecreedence/wookie
|
|
|
|
git clone git://github.com/orthecreedence/cl-rethinkdb
|
|
|
|
git clone git://github.com/orthecreedence/cl-libuv
|
|
|
|
git clone git://github.com/orthecreedence/drakma-async
|
|
|
|
git clone https://github.com/Inaimathi/cl-cwd.git
|
|
|
|
|
|
|
|
echo '#-quicklisp' > /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
|
|
|
|
echo '(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
|
|
|
|
echo ' (when (probe-file quicklisp-init)' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
|
|
|
|
echo ' (load quicklisp-init)))' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
|
2016-12-17 18:41:17 +01:00
|
|
|
echo '(cwd "~/api")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
|
|
|
|
echo '(load "~/api/launch")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
|
2016-12-17 17:17:19 +01:00
|
|
|
|
2016-12-16 00:11:43 +01:00
|
|
|
chmod a+w /var/www/$TURTL_DOMAIN_NAME/htdocs
|
2016-12-15 21:20:12 +01:00
|
|
|
chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
|
2016-12-17 17:17:19 +01:00
|
|
|
# install the app
|
|
|
|
cd /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
npm install
|
|
|
|
make minify
|
|
|
|
if [ ! -f /var/www/$TURTL_DOMAIN_NAME/htdocs/index.html ]; then
|
|
|
|
echo $'Failed to install turtl app'
|
|
|
|
exit 823652
|
|
|
|
fi
|
|
|
|
|
|
|
|
chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
|
|
|
2016-12-15 21:20:12 +01:00
|
|
|
echo '[Unit]' > /etc/systemd/system/turtl.service
|
|
|
|
echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Requires=network.target' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Requires=rethinkdb.service' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'After=network.target' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'After=rethinkdb.service' >> /etc/systemd/system/turtl.service
|
|
|
|
echo '' >> /etc/systemd/system/turtl.service
|
|
|
|
echo '[Service]' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Type=simple' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'User=turtl' >> /etc/systemd/system/turtl.service
|
2016-12-18 00:48:20 +01:00
|
|
|
echo 'Group=turtl' >> /etc/systemd/system/turtl.service
|
2016-12-16 00:11:43 +01:00
|
|
|
echo "WorkingDirectory=/var/www/$TURTL_DOMAIN_NAME/htdocs/api/" >> /etc/systemd/system/turtl.service
|
2016-12-15 21:20:12 +01:00
|
|
|
check_architecture=$(uname -a)
|
|
|
|
if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
|
2016-12-18 00:48:20 +01:00
|
|
|
echo "ExecStart=/usr/bin/ccl64 -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service
|
2016-12-15 21:20:12 +01:00
|
|
|
else
|
2016-12-18 00:48:20 +01:00
|
|
|
echo "ExecStart=/usr/bin/ccl -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
echo '' >> /etc/systemd/system/turtl.service
|
|
|
|
echo '[Install]' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/turtl.service
|
|
|
|
chmod +x /etc/systemd/system/turtl.service
|
|
|
|
|
2016-12-16 00:11:43 +01:00
|
|
|
TURTL_ONION_HOSTNAME=$(add_onion_service turtl 80 ${TURTL_ONION_PORT})
|
|
|
|
TURTL_API_ONION_HOSTNAME=$(add_onion_service turtlapi 80 ${TURTL_API_ONION_PORT})
|
|
|
|
|
2016-12-15 21:20:12 +01:00
|
|
|
turtl_nginx_site=/etc/nginx/sites-available/$TURTL_DOMAIN_NAME
|
|
|
|
if [[ $ONION_ONLY == "no" ]]; then
|
|
|
|
function_check nginx_http_redirect
|
|
|
|
nginx_http_redirect $TURTL_DOMAIN_NAME
|
|
|
|
echo 'server {' >> $turtl_nginx_site
|
|
|
|
echo ' listen 443 ssl;' >> $turtl_nginx_site
|
|
|
|
echo ' listen [::]:443 ssl;' >> $turtl_nginx_site
|
2016-12-16 00:11:43 +01:00
|
|
|
echo " server_name api.${TURTL_DOMAIN_NAME};" >> $turtl_nginx_site
|
2016-12-15 21:20:12 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Security' >> $turtl_nginx_site
|
|
|
|
function_check nginx_ssl
|
|
|
|
nginx_ssl $TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Logs' >> $turtl_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Root' >> $turtl_nginx_site
|
2016-12-16 00:11:43 +01:00
|
|
|
echo " root /var/www/$TURTL_DOMAIN_NAME/htdocs/api;" >> $turtl_nginx_site
|
2016-12-15 21:20:12 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' location / {' >> $turtl_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $TURTL_DOMAIN_NAME '15m'
|
|
|
|
echo " proxy_pass http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
|
|
|
|
echo ' proxy_set_header Host $host;' >> $turtl_nginx_site
|
|
|
|
echo ' proxy_buffering off;' >> $turtl_nginx_site
|
|
|
|
echo ' }' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo '}' >> $turtl_nginx_site
|
2016-12-16 00:11:43 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo 'server {' >> $turtl_nginx_site
|
|
|
|
echo ' listen 443 ssl;' >> $turtl_nginx_site
|
|
|
|
echo ' listen [::]:443 ssl;' >> $turtl_nginx_site
|
|
|
|
echo " server_name ${TURTL_DOMAIN_NAME};" >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' index index.html;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Security' >> $turtl_nginx_site
|
|
|
|
function_check nginx_ssl
|
|
|
|
nginx_ssl $TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
echo ' add_header Strict-Transport-Security max-age=15768000;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Logs' >> $turtl_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Root' >> $turtl_nginx_site
|
|
|
|
echo " root /var/www/$TURTL_DOMAIN_NAME/htdocs;" >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' location / {' >> $turtl_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $TURTL_DOMAIN_NAME '15m'
|
|
|
|
echo ' }' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo '}' >> $turtl_nginx_site
|
2016-12-15 21:20:12 +01:00
|
|
|
else
|
|
|
|
echo -n '' > $turtl_nginx_site
|
|
|
|
fi
|
|
|
|
echo 'server {' >> $turtl_nginx_site
|
2016-12-16 00:11:43 +01:00
|
|
|
echo " listen 127.0.0.1:${TURTL_API_ONION_PORT};" >> $turtl_nginx_site
|
|
|
|
echo " server_name ${TURTL_API_ONION_HOSTNAME};" >> $turtl_nginx_site
|
2016-12-15 21:20:12 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Logs' >> $turtl_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Root' >> $turtl_nginx_site
|
2016-12-16 00:11:43 +01:00
|
|
|
echo " root /var/www/$TURTL_DOMAIN_NAME/htdocs/api;" >> $turtl_nginx_site
|
2016-12-15 21:20:12 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' location / {' >> $turtl_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $TURTL_DOMAIN_NAME '15m'
|
|
|
|
echo " proxy_pass http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
|
|
|
|
echo ' proxy_set_header Host $host;' >> $turtl_nginx_site
|
|
|
|
echo ' proxy_buffering off;' >> $turtl_nginx_site
|
|
|
|
echo ' }' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo '}' >> $turtl_nginx_site
|
2016-12-16 00:11:43 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo 'server {' >> $turtl_nginx_site
|
|
|
|
echo " listen 127.0.0.1:$TURTL_ONION_PORT default_server;" >> $turtl_nginx_site
|
|
|
|
echo " server_name $TURTL_ONION_HOSTNAME;" >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' index index.html;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
function_check nginx_disable_sniffing
|
|
|
|
nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Logs' >> $turtl_nginx_site
|
|
|
|
echo ' access_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo ' error_log /dev/null;' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Root' >> $turtl_nginx_site
|
|
|
|
echo " root /var/www/$TURTL_DOMAIN_NAME/htdocs;" >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' location / {' >> $turtl_nginx_site
|
|
|
|
function_check nginx_limits
|
|
|
|
nginx_limits $TURTL_DOMAIN_NAME '15m'
|
|
|
|
echo ' }' >> $turtl_nginx_site
|
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo '}' >> $turtl_nginx_site
|
2016-12-15 21:20:12 +01:00
|
|
|
|
|
|
|
function_check create_site_certificate
|
|
|
|
create_site_certificate $TURTL_DOMAIN_NAME 'yes'
|
|
|
|
|
|
|
|
if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt ]; then
|
|
|
|
mv /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
|
|
|
|
fi
|
|
|
|
|
|
|
|
function_check nginx_ensite
|
|
|
|
nginx_ensite $TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
if [[ $ONION_ONLY != 'no' ]]; then
|
2016-12-16 00:11:43 +01:00
|
|
|
sed -i "s|https://${TURTL_DOMAIN_NAME}|http://${TURTL_ONION_HOSTNAME}|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|https://api.${TURTL_DOMAIN_NAME}|http://${TURTL_API_ONION_HOSTNAME}|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/api/config/config.lisp
|
|
|
|
sed -i "s|https://${TURTL_DOMAIN_NAME}|http://${TURTL_ONION_HOSTNAME}|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js
|
|
|
|
sed -i "s|https://api.${TURTL_DOMAIN_NAME}|http://${TURTL_API_ONION_HOSTNAME}|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.js
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
${PROJECT_NAME}-pass -u $MY_USERNAME -a turtl -p "$TURTL_ADMIN_PASSWORD"
|
|
|
|
|
|
|
|
function_check add_ddns_domain
|
|
|
|
add_ddns_domain $TURTL_DOMAIN_NAME
|
|
|
|
|
|
|
|
set_completion_param "turtl domain" "$TURTL_DOMAIN_NAME"
|
|
|
|
|
|
|
|
systemctl enable turtl
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start turtl
|
|
|
|
systemctl restart nginx
|
|
|
|
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
function turtl_setup {
|
|
|
|
PIDFILE=${PIDFILE:-nil}
|
|
|
|
BINDADDR=${BINDADDR:-0.0.0.0}
|
|
|
|
BINDPORT=${BINDPORT:-8181}
|
|
|
|
PROD_ERR_HANDLING=${PROD_ERR_HANDLING:-t}
|
|
|
|
FQDN=${FQDN:-turtl.local}
|
|
|
|
SITE_URL=${SITE_URL:-http://turtl.local}
|
|
|
|
ADMIN_EMAIL=${ADMIN_EMAIL:-$MY_USERNAME@$DEFAULT_DOMAIN_NAME}
|
|
|
|
EMAIL_FROM=${EMAIL_FROM:-noreply@$DEFAULT_DOMAIN_NAME}
|
|
|
|
SMTP_USER=${SMTP_USER:-}
|
|
|
|
SMTP_PASS=${SMTP_PASS:-}
|
|
|
|
DISPLAY_ERRORS=${DISPLAY_ERRORS:-t}
|
|
|
|
DEFAULT_STORAGE_LIMIT=${DEFAULT_STORAGE_LIMIT:-100}
|
|
|
|
STORAGE_INVITE_CREDIT=${STORAGE_INVITE_CREDIT:-25}
|
|
|
|
LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-http://turtl.local}
|
|
|
|
LOCAL_UPLOAD_PATH=${LOCAL_UPLOAD_PATH:-"/opt/api/uploads"}
|
|
|
|
AWS_S3_TOKEN=${AWS_S3_TOKEN:-(:token ''
|
|
|
|
:secret ''
|
|
|
|
:bucket ''
|
|
|
|
:endpoint 'https://s3.amazonaws.com')}
|
|
|
|
|
|
|
|
# generates the config-file
|
|
|
|
cat << __ENDCONFIG__ > /opt/api/config/config.lisp
|
|
|
|
(in-package :turtl)
|
|
|
|
(defparameter *root* (asdf:system-relative-pathname :turtl #P""))
|
|
|
|
(defparameter *pid-file* "${PIDFILE}")
|
|
|
|
(defvar *server-bind* "${BINDADDR}")
|
|
|
|
(defvar *server-port* ${BINDPORT})
|
|
|
|
(defvar *db-name* "turtl")
|
|
|
|
(defvar *db-host* "127.0.0.1")
|
|
|
|
(defvar *db-port* 28015)
|
|
|
|
(defvar *production-error-handling* ${PROD_ERR_HANDLING})
|
|
|
|
(defvar *enable-hsts-header* nil)
|
|
|
|
(defvar *site-url* "${SITE_URL}")
|
|
|
|
(defvar *api-path* "")
|
|
|
|
(defvar *admin-email* "${ADMIN_EMAIL}")
|
|
|
|
(defvar *email-from* "${EMAIL_FROM}")
|
|
|
|
(defvar *email-user* "${SMTP_USER}")
|
|
|
|
(defvar *email-pass* "${SMTP_PASS}")
|
|
|
|
(defvar *display-errors* ${DISPLAY_ERRORS})
|
|
|
|
(defparameter *default-storage-limit* ${DEFAULT_STORAGE_LIMIT})
|
|
|
|
(defparameter *storage-invite-credit* ${STORAGE_INVITE_CREDIT})
|
|
|
|
(vom:config :turtl :info)
|
|
|
|
(defvar *local-upload* "${LOCAL_UPLOAD_PATH}")
|
|
|
|
(defvar *local-upload-url* "${LOCAL_UPLOAD_URL}")
|
|
|
|
(defvar *amazon-s3* "${AWS_S3_TOKEN}")
|
|
|
|
__ENDCONFIG__
|
|
|
|
|
|
|
|
cat /opt/api/config/config.footer >> /opt/api/config/config.lisp
|
|
|
|
|
|
|
|
# start the turtl server
|
|
|
|
systemctl restart rethinkdb
|
|
|
|
|
|
|
|
echo '[Unit]' > /etc/systemd/system/turtl.service
|
|
|
|
echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Requires=network.target' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Requires=rethinkdb.service' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'After=network.target' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'After=rethinkdb.service' >> /etc/systemd/system/turtl.service
|
|
|
|
echo '' >> /etc/systemd/system/turtl.service
|
|
|
|
echo '[Service]' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'Type=simple' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'User=root' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'WorkingDirectory=/opt/api/' >> /etc/systemd/system/turtl.service
|
|
|
|
|
|
|
|
if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
|
|
|
|
echo "ExecStart=/opt/ccl/lx86cl64 -l /root/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
|
|
|
|
else
|
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
|
|
|
echo "ExecStart=/opt/ccl/lx86cl -l /root/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
|
|
|
|
else
|
|
|
|
echo "ExecStart=/opt/ccl/larmcl -l /root/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo '' >> /etc/systemd/system/turtl.service
|
|
|
|
echo '[Install]' >> /etc/systemd/system/turtl.service
|
|
|
|
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/turtl.service
|
|
|
|
chmod +x /etc/systemd/system/turtl.service
|
|
|
|
|
|
|
|
systemctl enable turtl
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start turtl
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:50:56 +01:00
|
|
|
function install_turtl_api {
|
2016-12-18 00:48:20 +01:00
|
|
|
# https://github.com/ArthurGarnier/turtl-docker
|
|
|
|
apt-get -yq install wget libterm-readline-perl-perl gcc libuv1-dev
|
|
|
|
|
|
|
|
if [ ! -d $INSTALL_DIR ]; then
|
|
|
|
mkdir -p $INSTALL_DIR
|
|
|
|
fi
|
|
|
|
cd $INSTALL_DIR
|
|
|
|
check_architecture=$(uname -a)
|
|
|
|
|
|
|
|
# Install ccl
|
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
|
|
|
wget -P /opt/ ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxx86.tar.gz
|
|
|
|
mkdir -p /opt/ccl
|
|
|
|
tar xvzf /opt/ccl-1.11-linuxx86.tar.gz -C /opt/ccl --strip-components=1
|
|
|
|
else
|
|
|
|
wget -P /opt/ ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxarm.tar.gz
|
|
|
|
mkdir -p /opt/ccl
|
|
|
|
tar xvzf /opt/ccl-1.11-linuxarm.tar.gz -C /opt/ccl --strip-components=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# install quicklisp
|
|
|
|
cat << __ENDCONFIG__ > $INSTALL_DIR/quicklisp_install
|
2016-12-18 10:50:00 +01:00
|
|
|
(load (compile-file "asdf.lisp"))
|
|
|
|
(load (compile-file "quicklisp.lisp"))
|
2016-12-18 00:48:20 +01:00
|
|
|
(quicklisp-quickstart:install)
|
|
|
|
(ql:system-apropos "vecto")
|
|
|
|
(ql:quickload "alexandria")
|
|
|
|
(ql:quickload "babel")
|
|
|
|
(ql:quickload "blackbird")
|
|
|
|
(ql:quickload "bordeaux-threads")
|
|
|
|
(ql:quickload "cffi")
|
|
|
|
(ql:quickload "chipz")
|
|
|
|
(ql:quickload "chunga")
|
|
|
|
(ql:quickload "cl-annot")
|
|
|
|
(ql:quickload "cl-async")
|
|
|
|
(ql:quickload "cl-async-future")
|
|
|
|
(ql:quickload "cl-base64")
|
|
|
|
(ql:quickload "cl-fad")
|
|
|
|
(ql:quickload "cl-libuv")
|
|
|
|
(ql:quickload "cl-mongo-id")
|
|
|
|
(ql:quickload "cl-ppcre")
|
|
|
|
(ql:quickload "cl-rethinkdb")
|
|
|
|
(ql:quickload "cl-smtp")
|
|
|
|
(ql:quickload "cl+ssl")
|
|
|
|
(ql:quickload "cl-syntax")
|
|
|
|
(ql:quickload "cl-utilities")
|
|
|
|
(ql:quickload "cl-vectors")
|
|
|
|
(ql:quickload "do-urlencode")
|
|
|
|
(ql:quickload "drakma")
|
|
|
|
(ql:quickload "drakma-async")
|
|
|
|
(ql:quickload "event-glue")
|
|
|
|
(ql:quickload "fast-http")
|
|
|
|
(ql:quickload "fast-io")
|
|
|
|
(ql:quickload "flexi-streams")
|
|
|
|
(ql:quickload "ironclad")
|
|
|
|
(ql:quickload "jonathan")
|
|
|
|
(ql:quickload "local-time")
|
|
|
|
(ql:quickload "md5")
|
|
|
|
(ql:quickload "named-readtables")
|
|
|
|
(ql:quickload "nibbles")
|
|
|
|
(ql:quickload "proc-parse")
|
|
|
|
(ql:quickload "puri")
|
|
|
|
(ql:quickload "quri")
|
|
|
|
(ql:quickload "salza2")
|
|
|
|
(ql:quickload "secure-random")
|
|
|
|
(ql:quickload "smart-buffer")
|
|
|
|
(ql:quickload "split-sequence")
|
|
|
|
(ql:quickload "static-vectors")
|
|
|
|
(ql:quickload "trivial-backtrace")
|
|
|
|
(ql:quickload "trivial-features")
|
|
|
|
(ql:quickload "trivial-garbage")
|
|
|
|
(ql:quickload "trivial-gray-streams")
|
|
|
|
(ql:quickload "trivial-types")
|
|
|
|
(ql:quickload "usocket")
|
|
|
|
(ql:quickload "vecto")
|
|
|
|
(ql:quickload "vom")
|
|
|
|
(ql:quickload "wookie")
|
|
|
|
(ql:quickload "xmls")
|
|
|
|
(ql:quickload "xsubseq")
|
|
|
|
(ql:quickload "yason")
|
|
|
|
(ql:quickload "zpb-ttf")
|
|
|
|
(ql:quickload "zpng")
|
|
|
|
(ql:add-to-init-file)
|
|
|
|
(quit)
|
2016-12-18 11:43:45 +01:00
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
__ENDCONFIG__
|
|
|
|
|
2016-12-18 10:50:00 +01:00
|
|
|
if [ ! -f asdf.lisp ]; then
|
|
|
|
wget https://common-lisp.net/project/asdf/asdf.lisp
|
|
|
|
fi
|
|
|
|
if [ ! -f quicklisp.lisp ]; then
|
|
|
|
wget https://beta.quicklisp.org/quicklisp.lisp
|
|
|
|
fi
|
2016-12-18 00:48:20 +01:00
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
|
|
|
if [[ "$check_architecture" == *"64"* ]]; then
|
2016-12-18 11:23:57 +01:00
|
|
|
cat $INSTALL_DIR/quicklisp_install | /opt/ccl/lx86cl64
|
2016-12-18 00:48:20 +01:00
|
|
|
else
|
2016-12-18 11:23:57 +01:00
|
|
|
cat $INSTALL_DIR/quicklisp_install | /opt/ccl/lx86cl
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
|
|
|
else
|
2016-12-18 11:23:57 +01:00
|
|
|
cat $INSTALL_DIR/quicklisp_install | /opt/ccl/larmcl
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
|
|
|
rm $INSTALL_DIR/quicklisp_install
|
|
|
|
|
|
|
|
install_rethinkdb
|
|
|
|
|
|
|
|
# install turtl API
|
|
|
|
cd /opt/
|
|
|
|
git clone $TURTL_API_REPO /opt/api
|
|
|
|
cd /opt/api
|
|
|
|
git checkout $TURTL_API_COMMIT -b $TURTL_API_COMMIT
|
|
|
|
cd /root/quicklisp/local-projects
|
|
|
|
git clone git://github.com/orthecreedence/cl-hash-util
|
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
|
|
|
if [[ "$check_architecture" == *"64"* ]]; then
|
|
|
|
/opt/ccl/lx86cl64 -l /root/quicklisp/setup.lisp
|
|
|
|
else
|
|
|
|
/opt/ccl/lx86cl -l /root/quicklisp/setup.lisp
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
/opt/ccl/larmcl -l /root/quicklisp/setup.lisp
|
|
|
|
fi
|
|
|
|
|
|
|
|
# config
|
|
|
|
echo '(defvar *enabled-cors-resources* "resource://turtl-at-lyonbros-dot-com"' > /opt/api/config/config.footer
|
|
|
|
echo ' "When set, will enable CORS for resource:// origins if they match the given' >> /opt/api/config/config.footer
|
|
|
|
echo ' string. Entries should be comma separated (this string is passed verbatim in' >> /opt/api/config/config.footer
|
|
|
|
echo ' the Access-Control-Allow-Origin header).")' >> /opt/api/config/config.footer
|
|
|
|
echo '(defparameter *public-actions*' >> /opt/api/config/config.footer
|
|
|
|
echo " \`((:post . ,(concatenate 'string *api-path* \"/users\"))" >> /opt/api/config/config.footer
|
|
|
|
echo " (:post . ,(concatenate 'string *api-path* \"/log/error\"))" >> /opt/api/config/config.footer
|
|
|
|
echo ' (:post . "/cla/sign")' >> /opt/api/config/config.footer
|
|
|
|
echo ' (:get . "/ping")' >> /opt/api/config/config.footer
|
|
|
|
echo ' (:get . "/admin")' >> /opt/api/config/config.footer
|
|
|
|
echo " (:get . ,(cl-ppcre:create-scanner (concatenate 'string *api-path* \"/invites/codes/([0-9a-f-]+)\"))))" >> /opt/api/config/config.footer
|
|
|
|
echo " \"A list of public resources/actions that do not require authentication.\")" >> /opt/api/config/config.footer
|
|
|
|
echo "(defvar *analytics* '(:enabled t" >> /opt/api/config/config.footer
|
|
|
|
echo ' :db "analytics"))' >> /opt/api/config/config.footer
|
|
|
|
|
2016-12-18 11:07:44 +01:00
|
|
|
cp $INSTALL_DIR/asdf.lisp /opt/api
|
|
|
|
echo '(load (compile-file "asdf.lisp"))' > /opt/api/launch.lisp
|
|
|
|
echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" >> /opt/api/launch.lisp
|
2016-12-18 00:48:20 +01:00
|
|
|
echo '(load "start")' >> /opt/api/launch.lisp
|
|
|
|
|
|
|
|
turtl_setup
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:50:56 +01:00
|
|
|
function install_turtl_app {
|
2016-12-18 00:48:20 +01:00
|
|
|
echo -n ''
|
|
|
|
}
|
|
|
|
|
2016-12-18 00:50:56 +01:00
|
|
|
function install_turtl {
|
|
|
|
install_turtl_api
|
|
|
|
install_turtl_app
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
#systemctl restart nginx
|
|
|
|
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|