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
|
|
|
|
|
2016-12-19 23:07:39 +01:00
|
|
|
TURTL_DOMAIN_NAME=
|
|
|
|
TURTL_CODE=
|
|
|
|
TURTL_ONION_PORT=8107
|
2016-12-15 21:20:12 +01:00
|
|
|
TURTL_PORT=8181
|
2016-12-19 23:07:39 +01:00
|
|
|
TURTL_REPO="https://github.com/turtl/api.git"
|
|
|
|
TURTL_COMMIT='53e00a5583f52de8f86ef380fe11c176b5738dcf'
|
2016-12-15 21:20:12 +01:00
|
|
|
TURTL_ADMIN_PASSWORD=
|
|
|
|
TURTL_STORAGE_LIMIT_MB=100
|
2016-12-18 13:51:03 +01:00
|
|
|
TURTL_BASE_DIR=/etc/turtl
|
2016-12-15 21:20:12 +01:00
|
|
|
|
|
|
|
turtl_variables=(ONION_ONLY
|
|
|
|
DEFAULT_DOMAIN_NAME
|
2016-12-19 23:07:39 +01:00
|
|
|
TURTL_DOMAIN_NAME
|
|
|
|
TURTL_CODE
|
2016-12-15 21:20:12 +01:00
|
|
|
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
|
2016-12-19 23:07:39 +01:00
|
|
|
TURTL_DOMAIN_NAME='notes.local'
|
|
|
|
write_config_param "TURTL_DOMAIN_NAME" "$TURTL_DOMAIN_NAME"
|
2016-12-15 21:20:12 +01:00
|
|
|
else
|
|
|
|
function_check interactive_site_details
|
2016-12-19 23:07:39 +01:00
|
|
|
interactive_site_details "turtl" "TURTL_DOMAIN_NAME" "TURTL_CODE"
|
2016-12-15 21:20:12 +01:00
|
|
|
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-18 20:24:38 +01:00
|
|
|
sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* ${TURTL_STORAGE_LIMIT_MB})|g" $TURTL_BASE_DIR/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 {
|
2016-12-19 22:50:37 +01:00
|
|
|
if [ -d $TURTL_BASE_DIR/data ]; then
|
|
|
|
rm -rf $TURTL_BASE_DIR/data/*
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function upgrade_turtl {
|
2016-12-19 23:07:39 +01:00
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
2016-12-15 21:20:12 +01:00
|
|
|
|
|
|
|
function_check set_repo_commit
|
2016-12-19 23:07:39 +01:00
|
|
|
set_repo_commit $TURTL_BASE_DIR/api "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
|
|
|
|
nginx_dissite $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
chown -R turtl:turtl $TURTL_BASE_DIR
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_ensite $TURTL_DOMAIN_NAME
|
2016-12-15 21:20:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function backup_local_turtl {
|
2016-12-19 23:07:39 +01:00
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
2016-12-19 22:50:37 +01:00
|
|
|
source_directory=$TURTL_BASE_DIR
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
dest_directory=turtl
|
|
|
|
function_check suspend_site
|
2016-12-19 23:07:39 +01:00
|
|
|
suspend_site ${TURTL_DOMAIN_NAME}
|
2016-12-15 21:20:12 +01:00
|
|
|
|
|
|
|
function_check backup_directory_to_usb
|
|
|
|
backup_directory_to_usb $source_directory $dest_directory
|
|
|
|
|
2016-12-18 16:34:18 +01:00
|
|
|
function_check restart_site
|
|
|
|
restart_site
|
|
|
|
fi
|
|
|
|
source_directory=/var/lib/rethinkdb
|
|
|
|
if [ -d $source_directory ]; then
|
|
|
|
dest_directory=rethinkdb
|
|
|
|
function_check suspend_site
|
2016-12-19 23:07:39 +01:00
|
|
|
suspend_site ${TURTL_DOMAIN_NAME}
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
function_check backup_directory_to_usb
|
|
|
|
backup_directory_to_usb $source_directory $dest_directory
|
|
|
|
|
2016-12-15 21:20:12 +01:00
|
|
|
function_check restart_site
|
|
|
|
restart_site
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_local_turtl {
|
2016-12-19 23:07:39 +01:00
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
if [ $TURTL_DOMAIN_NAME ]; then
|
2016-12-15 21:20:12 +01:00
|
|
|
temp_restore_dir=/root/tempturtl
|
|
|
|
restore_directory_from_usb $temp_restore_dir turtl
|
2016-12-19 22:50:37 +01:00
|
|
|
if [ -d $TURTL_BASE_DIR ]; then
|
|
|
|
if [ -d /etc/turtl_previous ]; then
|
|
|
|
rm -rf /etc/turtl_previous
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
2016-12-19 22:50:37 +01:00
|
|
|
mv $TURTL_BASE_DIR /etc/turtl_previous
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
2016-12-19 22:50:37 +01:00
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name turtl)
|
|
|
|
cp -r ${temp_source_dir} /etc/
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
2016-12-19 22:50:37 +01:00
|
|
|
if [ -d /etc/turtl_previous ]; then
|
|
|
|
mv /etc/turtl_previous $TURTL_BASE_DIR
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
set_user_permissions
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 36723
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
2016-12-19 22:50:37 +01:00
|
|
|
chown -R turtl:turtl $TURTL_BASE_DIR
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
temp_restore_dir=/root/temprethinkdb
|
|
|
|
restore_directory_from_usb $temp_restore_dir rethinkdb
|
|
|
|
if [ -d /var/lib/rethinkdb ]; then
|
|
|
|
if [ -d /var/lib/previous_rethinkdb ]; then
|
|
|
|
rm -rf /var/lib/previous_rethinkdb
|
|
|
|
fi
|
|
|
|
mv /var/lib/rethinkdb /var/lib/previous_rethinkdb
|
|
|
|
fi
|
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name rethinkdb)
|
|
|
|
cp -r ${temp_source_dir} /var/lib/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
if [ -d /var/lib/previous_rethinkdb ]; then
|
|
|
|
mv /var/lib/previous_rethinkdb /var/lib/rethinkdb
|
|
|
|
fi
|
|
|
|
set_user_permissions
|
|
|
|
backup_unmount_drive
|
|
|
|
exit 378324
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function backup_remote_turtl {
|
2016-12-19 23:07:39 +01:00
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
if [ $TURTL_DOMAIN_NAME ]; then
|
2016-12-19 22:50:37 +01:00
|
|
|
temp_backup_dir=$TURTL_BASE_DIR
|
2016-12-15 21:20:12 +01:00
|
|
|
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
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
temp_backup_dir=/var/lib/rethinkdb
|
|
|
|
if [ -d $temp_backup_dir ]; then
|
|
|
|
echo $"Backing up rethinkdb"
|
|
|
|
backup_directory_to_friend $temp_backup_dir rethinkdb
|
|
|
|
echo $"Backup of rethinkdb complete"
|
|
|
|
fi
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore_remote_turtl {
|
2016-12-19 23:07:39 +01:00
|
|
|
read_config_param "TURTL_DOMAIN_NAME"
|
|
|
|
if [ $TURTL_DOMAIN_NAME ]; then
|
2016-12-15 21:20:12 +01:00
|
|
|
temp_restore_dir=/root/tempturtl
|
|
|
|
mkdir $temp_restore_dir
|
|
|
|
function_check restore_directory_from_friend
|
|
|
|
restore_directory_from_friend $temp_restore_dir turtl
|
2016-12-19 22:50:37 +01:00
|
|
|
if [ -d $TURTL_BASE_DIR ]; then
|
|
|
|
if [ -d /etc/turtl_previous ]; then
|
|
|
|
rm -rf /etc/turtl_previous
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
2016-12-19 22:50:37 +01:00
|
|
|
mv $TURTL_BASE_DIR /etc/turtl_previous
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
2016-12-19 22:50:37 +01:00
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name turtl)
|
|
|
|
cp -r ${temp_source_dir} /etc/
|
2016-12-15 21:20:12 +01:00
|
|
|
if [ ! "$?" = "0" ]; then
|
2016-12-19 22:50:37 +01:00
|
|
|
if [ -d /etc/turtl_previous ]; then
|
|
|
|
mv /etc/turtl_previous $TURTL_BASE_DIR
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
|
|
|
exit 37823
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
|
|
|
|
2016-12-18 16:34:18 +01:00
|
|
|
temp_restore_dir=/root/temprethinkdb
|
|
|
|
mkdir $temp_restore_dir
|
|
|
|
function_check restore_directory_from_friend
|
|
|
|
restore_directory_from_friend $temp_restore_dir rethinkdb
|
|
|
|
if [ -d /var/lib/rethinkdb ]; then
|
|
|
|
if [ -d /var/lib/previous_rethinkdb ]; then
|
|
|
|
rm -rf /var/lib/previous_rethinkdb
|
|
|
|
fi
|
|
|
|
mv /var/lib/rethinkdb /var/lib/previous_rethinkdb
|
|
|
|
fi
|
|
|
|
temp_source_dir=$(find ${temp_restore_dir} -name rethinkdb)
|
|
|
|
cp -r ${temp_source_dir} /var/lib/
|
|
|
|
if [ ! "$?" = "0" ]; then
|
|
|
|
if [ -d /var/lib/previous_rethinkdb ]; then
|
|
|
|
mv /var/lib/previous_rethinkdb /var/lib/rethinkdb
|
|
|
|
fi
|
|
|
|
exit 26783
|
|
|
|
fi
|
|
|
|
rm -rf ${temp_restore_dir}
|
|
|
|
fi
|
2016-12-15 21:20:12 +01:00
|
|
|
}
|
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
function remove_turtl {
|
2016-12-18 13:51:03 +01:00
|
|
|
if [ ! -d $TURTL_BASE_DIR ]; then
|
2016-12-18 00:48:20 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
systemctl stop turtl
|
|
|
|
systemctl disable turtl
|
|
|
|
rm /etc/systemd/system/turtl.service
|
2016-12-18 16:34:18 +01:00
|
|
|
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 13:51:03 +01:00
|
|
|
deluser turtl
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_dissite $TURTL_DOMAIN_NAME
|
|
|
|
if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
|
|
|
|
rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
|
2016-12-15 21:20:12 +01:00
|
|
|
fi
|
2016-12-19 23:07:39 +01:00
|
|
|
remove_certs $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
function_check remove_onion_service
|
2016-12-19 23:31:20 +01:00
|
|
|
remove_onion_service turtl ${TURTL_ONION_PORT}
|
2016-12-18 16:34:18 +01:00
|
|
|
function_check remove_ddns_domain
|
2016-12-19 23:07:39 +01:00
|
|
|
remove_ddns_domain $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
rm -rf /etc/rethinkdb
|
|
|
|
rm -rf /var/lib/rethinkdb
|
|
|
|
rm -rf $TURTL_BASE_DIR
|
2016-12-15 21:20:12 +01:00
|
|
|
}
|
2016-12-18 00:48:20 +01:00
|
|
|
|
2016-12-18 16:34:18 +01:00
|
|
|
|
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}
|
2016-12-19 23:03:41 +01:00
|
|
|
if [[ $ONION_ONLY == 'no' ]]; then
|
2016-12-19 23:07:39 +01:00
|
|
|
FQDN=${FQDN:-$TURTL_DOMAIN_NAME}
|
|
|
|
SITE_URL=${SITE_URL:-https://$TURTL_DOMAIN_NAME}
|
2016-12-19 23:03:41 +01:00
|
|
|
else
|
2016-12-19 23:07:39 +01:00
|
|
|
FQDN=${FQDN:-$TURTL_ONION_HOSTNAME}
|
|
|
|
SITE_URL=${SITE_URL:-http://$TURTL_ONION_HOSTNAME}
|
2016-12-19 23:03:41 +01:00
|
|
|
fi
|
2016-12-18 00:48:20 +01:00
|
|
|
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}
|
2016-12-19 23:03:41 +01:00
|
|
|
if [[ $ONION_ONLY == 'no' ]]; then
|
2016-12-19 23:07:39 +01:00
|
|
|
LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-https://$TURTL_DOMAIN_NAME}
|
2016-12-19 23:03:41 +01:00
|
|
|
else
|
2016-12-19 23:07:39 +01:00
|
|
|
LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-http://$TURTL_ONION_HOSTNAME}
|
2016-12-19 23:03:41 +01:00
|
|
|
fi
|
2016-12-19 22:50:37 +01:00
|
|
|
LOCAL_UPLOAD_PATH=${LOCAL_UPLOAD_PATH:-"$TURTL_BASE_DIR/data"}
|
2016-12-18 00:48:20 +01:00
|
|
|
AWS_S3_TOKEN=${AWS_S3_TOKEN:-(:token ''
|
|
|
|
:secret ''
|
|
|
|
:bucket ''
|
|
|
|
:endpoint 'https://s3.amazonaws.com')}
|
|
|
|
|
|
|
|
# generates the config-file
|
2016-12-18 13:51:03 +01:00
|
|
|
cat << __ENDCONFIG__ > $TURTL_BASE_DIR/api/config/config.lisp
|
2016-12-18 00:48:20 +01:00
|
|
|
(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__
|
|
|
|
|
2016-12-18 13:51:03 +01:00
|
|
|
cat $TURTL_BASE_DIR/api/config/config.footer >> $TURTL_BASE_DIR/api/config/config.lisp
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
# 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
|
2016-12-18 13:51:03 +01:00
|
|
|
echo 'User=turtl' >> /etc/systemd/system/turtl.service
|
|
|
|
echo "WorkingDirectory=$TURTL_BASE_DIR/api/" >> /etc/systemd/system/turtl.service
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
|
2016-12-18 13:51:03 +01:00
|
|
|
echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
|
2016-12-18 00:48:20 +01:00
|
|
|
else
|
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
2016-12-18 13:51:03 +01:00
|
|
|
echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
|
2016-12-18 00:48:20 +01:00
|
|
|
else
|
2016-12-18 13:51:03 +01:00
|
|
|
echo "ExecStart=$TURTL_BASE_DIR/ccl/larmcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
|
2016-12-18 00:48:20 +01:00
|
|
|
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
|
|
|
|
|
2016-12-18 13:51:03 +01:00
|
|
|
chown -R turtl:turtl $TURTL_BASE_DIR
|
2016-12-18 00:48:20 +01:00
|
|
|
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
|
|
|
|
|
2016-12-18 13:51:03 +01:00
|
|
|
if [ ! -d $TURTL_BASE_DIR ]; then
|
|
|
|
mkdir -p $TURTL_BASE_DIR
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
2016-12-18 13:51:03 +01:00
|
|
|
cd $TURTL_BASE_DIR
|
2016-12-19 22:50:37 +01:00
|
|
|
mkdir cd $TURTL_BASE_DIR/data
|
2016-12-18 00:48:20 +01:00
|
|
|
check_architecture=$(uname -a)
|
|
|
|
|
|
|
|
# Install ccl
|
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
2016-12-18 13:51:03 +01:00
|
|
|
wget -P $TURTL_BASE_DIR/ ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxx86.tar.gz
|
|
|
|
mkdir -p $TURTL_BASE_DIR/ccl
|
|
|
|
tar xvzf $TURTL_BASE_DIR/ccl-1.11-linuxx86.tar.gz -C $TURTL_BASE_DIR/ccl --strip-components=1
|
2016-12-18 00:48:20 +01:00
|
|
|
else
|
2016-12-18 13:51:03 +01:00
|
|
|
wget -P $TURTL_BASE_DIR/ ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxarm.tar.gz
|
|
|
|
mkdir -p $TURTL_BASE_DIR/ccl
|
|
|
|
tar xvzf $TURTL_BASE_DIR/ccl-1.11-linuxarm.tar.gz -C $TURTL_BASE_DIR/ccl --strip-components=1
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# install quicklisp
|
2016-12-18 13:51:03 +01:00
|
|
|
cat << __ENDCONFIG__ > $TURTL_BASE_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)
|
2016-12-18 11:54:35 +01:00
|
|
|
(ccl::quit)
|
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 13:51:03 +01:00
|
|
|
|
|
|
|
adduser --disabled-login --home=$TURTL_BASE_DIR --gecos 'turtl' turtl
|
|
|
|
chown -R turtl:turtl $TURTL_BASE_DIR
|
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
|
|
|
if [[ "$check_architecture" == *"64"* ]]; then
|
2016-12-18 13:51:03 +01:00
|
|
|
su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/lx86cl64" - turtl
|
2016-12-18 00:48:20 +01:00
|
|
|
else
|
2016-12-18 13:51:03 +01:00
|
|
|
su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/lx86cl" - turtl
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
|
|
|
else
|
2016-12-18 13:51:03 +01:00
|
|
|
su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/larmcl" - turtl
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
2016-12-18 13:51:03 +01:00
|
|
|
rm $TURTL_BASE_DIR/quicklisp_install
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
install_rethinkdb
|
2016-12-19 21:07:15 +01:00
|
|
|
echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
|
|
|
|
chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
# install turtl API
|
2016-12-18 13:51:03 +01:00
|
|
|
cd $TURTL_BASE_DIR/
|
2016-12-19 23:07:39 +01:00
|
|
|
git clone $TURTL_REPO $TURTL_BASE_DIR/api
|
2016-12-18 13:51:03 +01:00
|
|
|
cd $TURTL_BASE_DIR/api
|
2016-12-19 23:07:39 +01:00
|
|
|
git checkout $TURTL_COMMIT -b $TURTL_COMMIT
|
|
|
|
set_completion_param "turtl commit" "$TURTL_COMMIT"
|
2016-12-18 16:34:18 +01:00
|
|
|
cd $TURTL_BASE_DIR/quicklisp/local-projects
|
2016-12-18 00:48:20 +01:00
|
|
|
git clone git://github.com/orthecreedence/cl-hash-util
|
|
|
|
if [[ "$check_architecture" != *"arm"* ]]; then
|
|
|
|
if [[ "$check_architecture" == *"64"* ]]; then
|
2016-12-18 13:51:03 +01:00
|
|
|
su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/lx86cl64 -l /root/quicklisp/setup.lisp" - turtl
|
2016-12-18 00:48:20 +01:00
|
|
|
else
|
2016-12-18 13:51:03 +01:00
|
|
|
su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/lx86cl -l /root/quicklisp/setup.lisp" - turtl
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
|
|
|
else
|
2016-12-18 13:51:03 +01:00
|
|
|
su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/larmcl -l /root/quicklisp/setup.lisp" - turtl
|
2016-12-18 00:48:20 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# config
|
2016-12-18 13:51:03 +01:00
|
|
|
echo '(defvar *enabled-cors-resources* "resource://turtl-at-lyonbros-dot-com"' > $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' "When set, will enable CORS for resource:// origins if they match the given' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' string. Entries should be comma separated (this string is passed verbatim in' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' the Access-Control-Allow-Origin header).")' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo '(defparameter *public-actions*' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo " \`((:post . ,(concatenate 'string *api-path* \"/users\"))" >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo " (:post . ,(concatenate 'string *api-path* \"/log/error\"))" >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' (:post . "/cla/sign")' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' (:get . "/ping")' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' (:get . "/admin")' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo " (:get . ,(cl-ppcre:create-scanner (concatenate 'string *api-path* \"/invites/codes/([0-9a-f-]+)\"))))" >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo " \"A list of public resources/actions that do not require authentication.\")" >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo "(defvar *analytics* '(:enabled t" >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
echo ' :db "analytics"))' >> $TURTL_BASE_DIR/api/config/config.footer
|
|
|
|
|
|
|
|
cp $TURTL_BASE_DIR/asdf.lisp $TURTL_BASE_DIR/api
|
|
|
|
echo '(load (compile-file "asdf.lisp"))' > $TURTL_BASE_DIR/api/launch.lisp
|
|
|
|
echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" >> $TURTL_BASE_DIR/api/launch.lisp
|
|
|
|
echo '(load "start")' >> $TURTL_BASE_DIR/api/launch.lisp
|
2016-12-18 00:48:20 +01:00
|
|
|
|
2016-12-19 23:31:20 +01:00
|
|
|
TURTL_ONION_HOSTNAME=$(add_onion_service turtl 80 ${TURTL_ONION_PORT})
|
2016-12-19 23:03:41 +01:00
|
|
|
|
2016-12-18 00:48:20 +01:00
|
|
|
turtl_setup
|
|
|
|
}
|
|
|
|
|
2016-12-19 22:50:37 +01:00
|
|
|
function install_turtl_nginx {
|
2016-12-19 23:07:39 +01:00
|
|
|
turtl_nginx_site=/etc/nginx/sites-available/$TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
if [[ $ONION_ONLY == "no" ]]; then
|
|
|
|
function_check nginx_http_redirect
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_http_redirect $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
echo 'server {' >> $turtl_nginx_site
|
|
|
|
echo ' listen 443 ssl;' >> $turtl_nginx_site
|
|
|
|
echo ' listen [::]:443 ssl;' >> $turtl_nginx_site
|
2016-12-19 23:07:39 +01:00
|
|
|
echo " server_name ${TURTL_DOMAIN_NAME};" >> $turtl_nginx_site
|
2016-12-18 16:34:18 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
echo ' # Security' >> $turtl_nginx_site
|
|
|
|
function_check nginx_ssl
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_ssl $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
function_check nginx_disable_sniffing
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
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 ' location / {' >> $turtl_nginx_site
|
|
|
|
function_check nginx_limits
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_limits $TURTL_DOMAIN_NAME '15m'
|
2016-12-18 16:34:18 +01:00
|
|
|
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
|
|
|
|
else
|
|
|
|
echo -n '' > $turtl_nginx_site
|
|
|
|
fi
|
|
|
|
echo 'server {' >> $turtl_nginx_site
|
2016-12-19 23:07:39 +01:00
|
|
|
echo " listen 127.0.0.1:${TURTL_ONION_PORT};" >> $turtl_nginx_site
|
|
|
|
echo " server_name ${TURTL_ONION_HOSTNAME};" >> $turtl_nginx_site
|
2016-12-18 16:34:18 +01:00
|
|
|
echo '' >> $turtl_nginx_site
|
|
|
|
function_check nginx_disable_sniffing
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
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 ' location / {' >> $turtl_nginx_site
|
|
|
|
function_check nginx_limits
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_limits $TURTL_DOMAIN_NAME '15m'
|
2016-12-18 16:34:18 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
function_check add_ddns_domain
|
2016-12-19 23:07:39 +01:00
|
|
|
add_ddns_domain $TURTL_DOMAIN_NAME
|
2016-12-19 00:05:42 +01:00
|
|
|
|
2016-12-19 23:07:39 +01:00
|
|
|
set_completion_param "turtl domain" "$TURTL_DOMAIN_NAME"
|
2016-12-18 16:54:20 +01:00
|
|
|
|
2016-12-18 16:34:18 +01:00
|
|
|
function_check create_site_certificate
|
2016-12-19 23:07:39 +01:00
|
|
|
create_site_certificate $TURTL_DOMAIN_NAME 'yes'
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
function_check nginx_ensite
|
2016-12-19 23:07:39 +01:00
|
|
|
nginx_ensite $TURTL_DOMAIN_NAME
|
2016-12-18 16:34:18 +01:00
|
|
|
|
|
|
|
systemctl restart nginx
|
2016-12-18 00:48:20 +01:00
|
|
|
}
|
|
|
|
|
2016-12-18 00:50:56 +01:00
|
|
|
function install_turtl {
|
|
|
|
install_turtl_api
|
2016-12-19 22:50:37 +01:00
|
|
|
install_turtl_nginx
|
2016-12-18 00:48:20 +01:00
|
|
|
|
|
|
|
APP_INSTALLED=1
|
|
|
|
}
|