diff --git a/src/freedombone-app-turtl b/src/freedombone-app-turtl index 40a28d20..89a19b78 100755 --- a/src/freedombone-app-turtl +++ b/src/freedombone-app-turtl @@ -215,7 +215,7 @@ function restore_remote_turtl { fi } -function remove_turtl { +function remove_turtl_old { if [ ${#TURTL_DOMAIN_NAME} -eq 0 ]; then return fi @@ -251,6 +251,21 @@ function remove_turtl { remove_ddns_domain $TURTL_DOMAIN_NAME } +function remove_turtl { + if [ ! -d /opt/api ]; then + return + fi + systemctl stop turtl + systemctl disable turtl + rm /etc/systemd/system/turtl.service + remove_app turtl + remove_completion_param install_turtl + sed -i '/turtl/d' $COMPLETION_FILE + rm -rf /root/quicklisp + rm -rf /opt/ccl + rm -rf /opt/api +} + function install_libuv { if [ ! -d /usr/local/src ]; then mkdir -p /usr/local/src @@ -285,7 +300,7 @@ function install_libuv { make install } -function install_turtl { +function install_turtl_old { if [ ! $TURTL_DOMAIN_NAME ]; then echo $'No domain name was given for turtl' exit 47823 @@ -399,6 +414,65 @@ function install_turtl { 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 echo '(quicklisp-quickstart:install)' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp + + + 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 echo '(ql:add-to-init-file)' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/install.lisp chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs @@ -456,12 +530,13 @@ function install_turtl { echo '[Service]' >> /etc/systemd/system/turtl.service echo 'Type=simple' >> /etc/systemd/system/turtl.service echo 'User=turtl' >> /etc/systemd/system/turtl.service + echo 'Group=turtl' >> /etc/systemd/system/turtl.service echo "WorkingDirectory=/var/www/$TURTL_DOMAIN_NAME/htdocs/api/" >> /etc/systemd/system/turtl.service check_architecture=$(uname -a) if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then - echo "ExecStart=/var/www/$TURTL_DOMAIN_NAME/htdocs/ccl/scripts/ccl64 -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service + echo "ExecStart=/usr/bin/ccl64 -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service else - echo "ExecStart=/var/www/$TURTL_DOMAIN_NAME/htdocs/ccl/scripts/ccl -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service + echo "ExecStart=/usr/bin/ccl -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service fi echo '' >> /etc/systemd/system/turtl.service echo '[Install]' >> /etc/systemd/system/turtl.service @@ -616,3 +691,239 @@ function install_turtl { APP_INSTALLED=1 } + +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 +} + +function install_tutl_api { + # 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 +(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) +__ENDCONFIG__ + + wget https://beta.quicklisp.org/quicklisp.lisp + if [[ "$check_architecture" != *"arm"* ]]; then + if [[ "$check_architecture" == *"64"* ]]; then + cat $INSTALL_DIR/quicklisp_install | /opt/ccl/lx86cl64 --load /quicklisp.lisp + else + cat $INSTALL_DIR/quicklisp_install | /opt/ccl/lx86cl --load /quicklisp.lisp + fi + else + cat $INSTALL_DIR/quicklisp_install | /opt/ccl/larmcl --load /quicklisp.lisp + 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 + + echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" > /opt/api/launch.lisp + echo '(load "start")' >> /opt/api/launch.lisp + + turtl_setup +} + +function install_tutl_app { + echo -n '' +} + +function install_tutl { + install_tutl_api + install_tutl_app + + #systemctl restart nginx + + APP_INSTALLED=1 +} diff --git a/src/freedombone-utils-database b/src/freedombone-utils-database index 525d06a0..c5285dc5 100755 --- a/src/freedombone-utils-database +++ b/src/freedombone-utils-database @@ -300,19 +300,19 @@ function install_rethinkdb { apt-get update apt-get -yq install rethinkdb - echo '# runuser=rethinkdb' > /etc/rethinkdb/instances.d/default.conf - echo '# rungroup=rethinkdb' >> /etc/rethinkdb/instances.d/default.conf + echo 'runuser=rethinkdb' > /etc/rethinkdb/instances.d/default.conf + echo 'rungroup=rethinkdb' >> /etc/rethinkdb/instances.d/default.conf echo '# pid-file=/var/run/rethinkdb/rethinkdb.pid' >> /etc/rethinkdb/instances.d/default.conf echo '# directory=/var/lib/rethinkdb/default' >> /etc/rethinkdb/instances.d/default.conf - echo 'log-file=/var/log/rethinkdb' >> /etc/rethinkdb/instances.d/default.conf - echo '# bind=127.0.0.1' >> /etc/rethinkdb/instances.d/default.conf + echo '# log-file=/var/log/rethinkdb' >> /etc/rethinkdb/instances.d/default.conf + echo 'bind=127.0.0.1' >> /etc/rethinkdb/instances.d/default.conf echo '# canonical-address=' >> /etc/rethinkdb/instances.d/default.conf echo '# driver-port=28015' >> /etc/rethinkdb/instances.d/default.conf echo '# cluster-port=29015' >> /etc/rethinkdb/instances.d/default.conf echo '# join=example.com:29015' >> /etc/rethinkdb/instances.d/default.conf echo '# port-offset=0' >> /etc/rethinkdb/instances.d/default.conf echo '# reql-http-proxy=socks5://example.com:1080' >> /etc/rethinkdb/instances.d/default.conf - echo '# http-port=8080' >> /etc/rethinkdb/instances.d/default.conf + echo '# http-port=8091' >> /etc/rethinkdb/instances.d/default.conf echo '# no-http-admin' >> /etc/rethinkdb/instances.d/default.conf echo '# cores=2' >> /etc/rethinkdb/instances.d/default.conf echo '# cache-size=1024' >> /etc/rethinkdb/instances.d/default.conf