freedombone-app-turtl 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # turtl app
  12. #
  13. # http://portallinux.es/instalacion-servidor-turtl-debian-8
  14. # http://framacloud.org/cultiver-son-jardin/installation-de-turtl/
  15. #
  16. # License
  17. # =======
  18. #
  19. # Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net>
  20. #
  21. # This program is free software: you can redistribute it and/or modify
  22. # it under the terms of the GNU Affero General Public License as published by
  23. # the Free Software Foundation, either version 3 of the License, or
  24. # (at your option) any later version.
  25. #
  26. # This program is distributed in the hope that it will be useful,
  27. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. # GNU Affero General Public License for more details.
  30. #
  31. # You should have received a copy of the GNU Affero General Public License
  32. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. VARIANTS="full full-vim writer"
  34. IN_DEFAULT_INSTALL=0
  35. SHOW_ON_ABOUT=1
  36. TURTL_DOMAIN_NAME=
  37. TURTL_CODE=
  38. TURTL_ONION_PORT=8107
  39. TURTL_PORT=8181
  40. TURTL_REPO="https://github.com/turtl/api.git"
  41. TURTL_COMMIT='53e00a5583f52de8f86ef380fe11c176b5738dcf'
  42. TURTL_ADMIN_PASSWORD=
  43. TURTL_STORAGE_LIMIT_MB=100
  44. TURTL_BASE_DIR=/etc/turtl
  45. # part of a hack to enable/disable signups
  46. TURTL_SIGNUP_STRING='Signup a new user'
  47. turtl_users_file=$TURTL_BASE_DIR/api/controllers/users.lisp
  48. turtl_variables=(ONION_ONLY
  49. DEFAULT_DOMAIN_NAME
  50. TURTL_DOMAIN_NAME
  51. TURTL_CODE
  52. TURTL_STORAGE_LIMIT_MB
  53. DDNS_PROVIDER
  54. MY_EMAIL_ADDRESS
  55. MY_USERNAME)
  56. function logging_on_turtl {
  57. echo -n ''
  58. }
  59. function logging_off_turtl {
  60. echo -n ''
  61. }
  62. function change_password_turtl {
  63. echo -n ''
  64. # change_username="$1"
  65. # new_user_password="$2"
  66. }
  67. function remove_user_turtl {
  68. echo -n ''
  69. # remove_username="$1"
  70. }
  71. function add_user_turtl {
  72. # new_username="$1"
  73. # new_user_password="$2"
  74. echo '0'
  75. }
  76. function install_interactive_turtl {
  77. if [ ! "$ONION_ONLY" ]; then
  78. ONION_ONLY='no'
  79. fi
  80. if [[ $ONION_ONLY != "no" ]]; then
  81. TURTL_DOMAIN_NAME='notes.local'
  82. write_config_param "TURTL_DOMAIN_NAME" "$TURTL_DOMAIN_NAME"
  83. else
  84. function_check interactive_site_details
  85. interactive_site_details "turtl" "TURTL_DOMAIN_NAME" "TURTL_CODE"
  86. fi
  87. APP_INSTALLED=1
  88. }
  89. function turtl_disable_registrations {
  90. if grep -q "$TURTL_SIGNUP_STRING" $turtl_users_file; then
  91. if [ -f $turtl_users_file ]; then
  92. cp $turtl_users_file $TURTL_BASE_DIR/.users.lisp
  93. sed -i '/(route (:post "\/users") (req res)/,/(send-json res user))))/{//!d}' $turtl_users_file
  94. sed -i 's|(send-json res user))))|())|g' $turtl_users_file
  95. chown -R turtl:turtl $TURTL_BASE_DIR
  96. systemctl restart turtl
  97. fi
  98. fi
  99. }
  100. function turtl_enable_registrations {
  101. if ! grep -q "$TURTL_SIGNUP_STRING" $turtl_users_file; then
  102. if [ -f $TURTL_BASE_DIR/.users.lisp ]; then
  103. cp $TURTL_BASE_DIR/.users.lisp $turtl_users_file
  104. rm $TURTL_BASE_DIR/.users.lisp
  105. chown -R turtl:turtl $TURTL_BASE_DIR
  106. systemctl restart turtl
  107. fi
  108. fi
  109. }
  110. function configure_interactive_turtl_signups {
  111. # This implements a hack which removes or adds the function needed
  112. # to sign up new users. It should eventually be removed once that
  113. # capability exists within the api
  114. dialog --title $"Allow new turtl signups" \
  115. --backtitle $"Freedombone Control Panel" \
  116. --defaultno \
  117. --yesno $"\\nAllow registration of new users?" 10 60
  118. sel=$?
  119. case $sel in
  120. 0)
  121. turtl_enable_registrations
  122. dialog --title $"Allow new turtl signups" \
  123. --msgbox $"New turtl user registrations are now allowed" 6 60
  124. return;;
  125. 1)
  126. turtl_disable_registrations
  127. dialog --title $"Disable new turtl signups" \
  128. --msgbox $"New turtl user registrations are now disabled" 6 60
  129. return;;
  130. 255) return;;
  131. esac
  132. }
  133. function configure_interactive_turtl_storage {
  134. data=$(mktemp 2>/dev/null)
  135. dialog --title $"Change storage limit" \
  136. --backtitle $"Freedombone Control Panel" \
  137. --inputbox $"Enter a storage limit in megabytes." 8 75 "$TURTL_STORAGE_LIMIT_MB" 2>"$data"
  138. sel=$?
  139. case $sel in
  140. 0)
  141. STORAGE=$(<"$data")
  142. if [ ${#STORAGE} -gt 0 ]; then
  143. TURTL_STORAGE_LIMIT_MB=$STORAGE
  144. sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* ${TURTL_STORAGE_LIMIT_MB})|g" $TURTL_BASE_DIR/api/config/config.lisp
  145. systemctl restart turtl
  146. dialog --title $"Change storage limit" \
  147. --msgbox $"Storage limit changed to ${TURTL_STORAGE_LIMIT_MB}M" 6 50
  148. fi
  149. ;;
  150. esac
  151. rm -f "$data"
  152. }
  153. function configure_interactive_turtl {
  154. data=$(mktemp 2>/dev/null)
  155. dialog --backtitle $"Freedombone Control Panel" \
  156. --title $"turtl app settings" \
  157. --radiolist $"Choose an operation:" 12 70 3 \
  158. 1 $"Enable/disable new user registrations" off \
  159. 2 $"Change storage limit" off \
  160. 3 $"Exit" on 2> "$data"
  161. sel=$?
  162. case $sel in
  163. 1) rm -f "$data"
  164. exit 1;;
  165. 255) rm -f "$data"
  166. exit 1;;
  167. esac
  168. case $(cat "$data") in
  169. 1) configure_interactive_turtl_signups;;
  170. 2) configure_interactive_turtl_storage;;
  171. 3) rm -f "$data"
  172. return;;
  173. esac
  174. rm -f "$data"
  175. }
  176. function reconfigure_turtl {
  177. if [ -d $TURTL_BASE_DIR/data ]; then
  178. rm -rf $TURTL_BASE_DIR/data/*
  179. fi
  180. }
  181. function upgrade_turtl {
  182. CURR_TURTL_COMMIT=$(get_completion_param "turtl commit")
  183. if [[ "$CURR_TURTL_COMMIT" == "$TURTL_COMMIT" ]]; then
  184. return
  185. fi
  186. read_config_param "TURTL_DOMAIN_NAME"
  187. function_check set_repo_commit
  188. set_repo_commit $TURTL_BASE_DIR/api "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
  189. # this is used as a crude way of disabling signups and so
  190. # should be superceded in future
  191. if [ -f $TURTL_BASE_DIR/.users.lisp ]; then
  192. turtl_disable_registrations
  193. fi
  194. systemctl restart turtl
  195. nginx_dissite $TURTL_DOMAIN_NAME
  196. chown -R turtl:turtl $TURTL_BASE_DIR
  197. nginx_ensite $TURTL_DOMAIN_NAME
  198. }
  199. function backup_local_turtl {
  200. read_config_param "TURTL_DOMAIN_NAME"
  201. source_directory=$TURTL_BASE_DIR
  202. if [ -d $source_directory ]; then
  203. dest_directory=turtl
  204. function_check suspend_site
  205. suspend_site ${TURTL_DOMAIN_NAME}
  206. function_check backup_directory_to_usb
  207. backup_directory_to_usb $source_directory $dest_directory
  208. function_check restart_site
  209. restart_site
  210. fi
  211. source_directory=/var/lib/rethinkdb
  212. if [ -d $source_directory ]; then
  213. dest_directory=rethinkdb
  214. function_check suspend_site
  215. suspend_site ${TURTL_DOMAIN_NAME}
  216. function_check backup_directory_to_usb
  217. backup_directory_to_usb $source_directory $dest_directory
  218. function_check restart_site
  219. restart_site
  220. fi
  221. }
  222. function restore_local_turtl {
  223. read_config_param "TURTL_DOMAIN_NAME"
  224. if [ $TURTL_DOMAIN_NAME ]; then
  225. temp_restore_dir=/root/tempturtl
  226. restore_directory_from_usb $temp_restore_dir turtl
  227. if [ -d ${temp_restore_dir}/etc/turtl ]; then
  228. cp -r ${temp_restore_dir}/etc/turtl/* /etc/turtl/
  229. else
  230. cp -r ${temp_restore_dir}/* /etc/turtl/
  231. fi
  232. # shellcheck disable=SC2181
  233. if [ ! "$?" = "0" ]; then
  234. set_user_permissions
  235. backup_unmount_drive
  236. exit 36723
  237. fi
  238. rm -rf ${temp_restore_dir}
  239. chown -R turtl:turtl $TURTL_BASE_DIR
  240. temp_restore_dir=/root/temprethinkdb
  241. restore_directory_from_usb $temp_restore_dir rethinkdb
  242. if [ -d ${temp_restore_dir}/var/lib/rethinkdb ]; then
  243. cp -r ${temp_restore_dir}/var/lib/rethinkdb/* /var/lib/rethinkdb/
  244. else
  245. cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
  246. fi
  247. # shellcheck disable=SC2181
  248. if [ ! "$?" = "0" ]; then
  249. set_user_permissions
  250. backup_unmount_drive
  251. exit 378324
  252. fi
  253. rm -rf ${temp_restore_dir}
  254. fi
  255. }
  256. function backup_remote_turtl {
  257. read_config_param "TURTL_DOMAIN_NAME"
  258. if [ $TURTL_DOMAIN_NAME ]; then
  259. temp_backup_dir=$TURTL_BASE_DIR
  260. if [ -d $temp_backup_dir ]; then
  261. echo $"Backing up turtl"
  262. backup_directory_to_friend $temp_backup_dir turtl
  263. echo $"Backup of turtl complete"
  264. else
  265. echo $"turtl domain specified but not found in $temp_backup_dir"
  266. exit 68725
  267. fi
  268. temp_backup_dir=/var/lib/rethinkdb
  269. if [ -d $temp_backup_dir ]; then
  270. echo $"Backing up rethinkdb"
  271. backup_directory_to_friend $temp_backup_dir rethinkdb
  272. echo $"Backup of rethinkdb complete"
  273. fi
  274. fi
  275. }
  276. function restore_remote_turtl {
  277. read_config_param "TURTL_DOMAIN_NAME"
  278. if [ $TURTL_DOMAIN_NAME ]; then
  279. temp_restore_dir=/root/tempturtl
  280. mkdir $temp_restore_dir
  281. function_check restore_directory_from_friend
  282. restore_directory_from_friend $temp_restore_dir turtl
  283. if [ -d ${temp_restore_dir}/etc/turtl ]; then
  284. cp -r ${temp_restore_dir}/etc/turtl/* /etc/turtl/
  285. else
  286. cp -r ${temp_restore_dir}/* /etc/turtl/
  287. fi
  288. # shellcheck disable=SC2181
  289. if [ ! "$?" = "0" ]; then
  290. if [ -d /etc/turtl_previous ]; then
  291. mv /etc/turtl_previous $TURTL_BASE_DIR
  292. fi
  293. set_user_permissions
  294. exit 37823
  295. fi
  296. rm -rf ${temp_restore_dir}
  297. temp_restore_dir=/root/temprethinkdb
  298. mkdir $temp_restore_dir
  299. function_check restore_directory_from_friend
  300. restore_directory_from_friend $temp_restore_dir rethinkdb
  301. if [ -d ${temp_restore_dir}/var/lib/rethinkdb ]; then
  302. cp -r ${temp_restore_dir}/var/lib/rethinkdb/* /var/lib/rethinkdb/
  303. else
  304. cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
  305. fi
  306. # shellcheck disable=SC2181
  307. if [ ! "$?" = "0" ]; then
  308. set_user_permissions
  309. exit 26783
  310. fi
  311. rm -rf ${temp_restore_dir}
  312. fi
  313. }
  314. function remove_turtl {
  315. if [ ! -d $TURTL_BASE_DIR ]; then
  316. return
  317. fi
  318. systemctl stop turtl
  319. systemctl disable turtl
  320. rm /etc/systemd/system/turtl.service
  321. systemctl daemon-reload
  322. remove_rethinkdb
  323. remove_app turtl
  324. remove_completion_param install_turtl
  325. sed -i '/turtl/d' "$COMPLETION_FILE"
  326. nginx_dissite $TURTL_DOMAIN_NAME
  327. if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
  328. rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
  329. fi
  330. remove_certs $TURTL_DOMAIN_NAME
  331. function_check remove_onion_service
  332. remove_onion_service turtl ${TURTL_ONION_PORT}
  333. function_check remove_ddns_domain
  334. remove_ddns_domain $TURTL_DOMAIN_NAME
  335. rm -rf /etc/rethinkdb
  336. rm -rf /var/lib/rethinkdb
  337. rm -rf $TURTL_BASE_DIR
  338. groupdel -f turtl
  339. userdel -r turtl
  340. }
  341. function turtl_setup {
  342. PIDFILE=${PIDFILE:-nil}
  343. BINDADDR=${BINDADDR:-0.0.0.0}
  344. BINDPORT=${BINDPORT:-8181}
  345. PROD_ERR_HANDLING=${PROD_ERR_HANDLING:-t}
  346. if [[ $ONION_ONLY == 'no' ]]; then
  347. FQDN=${FQDN:-$TURTL_DOMAIN_NAME}
  348. SITE_URL=${SITE_URL:-https://$TURTL_DOMAIN_NAME}
  349. else
  350. FQDN=${FQDN:-$TURTL_ONION_HOSTNAME}
  351. SITE_URL=${SITE_URL:-http://$TURTL_ONION_HOSTNAME}
  352. fi
  353. ADMIN_EMAIL=${ADMIN_EMAIL:-$MY_EMAIL_ADDRESS}
  354. EMAIL_FROM=${EMAIL_FROM:-noreply@$DEFAULT_DOMAIN_NAME}
  355. SMTP_USER=${SMTP_USER:-}
  356. SMTP_PASS=${SMTP_PASS:-}
  357. DISPLAY_ERRORS=${DISPLAY_ERRORS:-t}
  358. DEFAULT_STORAGE_LIMIT=${DEFAULT_STORAGE_LIMIT:-100}
  359. STORAGE_INVITE_CREDIT=${STORAGE_INVITE_CREDIT:-25}
  360. if [[ $ONION_ONLY == 'no' ]]; then
  361. LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-https://$TURTL_DOMAIN_NAME}
  362. else
  363. LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-http://$TURTL_ONION_HOSTNAME}
  364. fi
  365. LOCAL_UPLOAD_PATH=${LOCAL_UPLOAD_PATH:-"$TURTL_BASE_DIR/data"}
  366. AWS_S3_TOKEN=${AWS_S3_TOKEN:-(:token ''
  367. :secret ''
  368. :bucket ''
  369. :endpoint 'https://s3.amazonaws.com')}
  370. # generates the config-file
  371. cat << __ENDCONFIG__ > $TURTL_BASE_DIR/api/config/config.lisp
  372. (in-package :turtl)
  373. (defparameter *root* (asdf:system-relative-pathname :turtl #P""))
  374. (defparameter *pid-file* "${PIDFILE}")
  375. (defvar *server-bind* "${BINDADDR}")
  376. (defvar *server-port* ${BINDPORT})
  377. (defvar *db-name* "turtl")
  378. (defvar *db-host* "127.0.0.1")
  379. (defvar *db-port* 28015)
  380. (defvar *production-error-handling* ${PROD_ERR_HANDLING})
  381. (defvar *enable-hsts-header* nil)
  382. (defvar *site-url* "${SITE_URL}")
  383. (defvar *api-path* "")
  384. (defvar *admin-email* "${ADMIN_EMAIL}")
  385. (defvar *email-from* "${EMAIL_FROM}")
  386. (defvar *email-user* "${SMTP_USER}")
  387. (defvar *email-pass* "${SMTP_PASS}")
  388. (defvar *display-errors* ${DISPLAY_ERRORS})
  389. (defparameter *default-storage-limit* ${DEFAULT_STORAGE_LIMIT})
  390. (defparameter *storage-invite-credit* ${STORAGE_INVITE_CREDIT})
  391. (vom:config :turtl :info)
  392. (defvar *local-upload* "${LOCAL_UPLOAD_PATH}")
  393. (defvar *local-upload-url* "${LOCAL_UPLOAD_URL}")
  394. (defvar *amazon-s3* "${AWS_S3_TOKEN}")
  395. __ENDCONFIG__
  396. cat $TURTL_BASE_DIR/api/config/config.footer >> $TURTL_BASE_DIR/api/config/config.lisp
  397. # start the turtl server
  398. systemctl restart rethinkdb
  399. if [ ! -f $TURTL_BASE_DIR/quicklisp/setup.lisp ]; then
  400. echo $"$TURTL_BASE_DIR/quicklisp/setup.lisp was not found"
  401. exit 6238234
  402. fi
  403. { echo '[Unit]';
  404. echo 'Description=Note taking service';
  405. echo 'Documentation=http://turtl.it';
  406. echo 'Requires=network.target';
  407. echo 'Requires=rethinkdb.service';
  408. echo 'After=network.target';
  409. echo 'After=rethinkdb.service';
  410. echo '';
  411. echo '[Service]';
  412. echo 'Type=simple';
  413. echo 'User=turtl';
  414. echo "WorkingDirectory=$TURTL_BASE_DIR/api/"; } > /etc/systemd/system/turtl.service
  415. if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
  416. echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
  417. else
  418. if [[ "$check_architecture" != *"arm"* ]]; then
  419. echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
  420. else
  421. echo "ExecStart=$TURTL_BASE_DIR/ccl/armcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
  422. fi
  423. fi
  424. { echo '';
  425. echo '[Install]';
  426. echo 'WantedBy=multi-user.target'; } >> /etc/systemd/system/turtl.service
  427. chmod +x /etc/systemd/system/turtl.service
  428. chown -R turtl:turtl $TURTL_BASE_DIR
  429. systemctl enable turtl
  430. systemctl daemon-reload
  431. systemctl start turtl
  432. }
  433. function install_turtl_api {
  434. # https://github.com/ArthurGarnier/turtl-docker
  435. apt-get -yq install wget libterm-readline-perl-perl gcc libuv1-dev
  436. if [ ! -d $TURTL_BASE_DIR ]; then
  437. mkdir -p $TURTL_BASE_DIR
  438. fi
  439. cd "$TURTL_BASE_DIR" || exit 745726542
  440. mkdir cd $TURTL_BASE_DIR/data
  441. check_architecture=$(uname -a)
  442. # Install ccl
  443. if [[ "$check_architecture" != *"arm"* ]]; then
  444. wget -P $TURTL_BASE_DIR/ ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxx86.tar.gz
  445. mkdir -p $TURTL_BASE_DIR/ccl
  446. tar xvzf $TURTL_BASE_DIR/ccl-1.11-linuxx86.tar.gz -C $TURTL_BASE_DIR/ccl --strip-components=1
  447. else
  448. wget -P $TURTL_BASE_DIR/ ftp://ftp.clozure.com/pub/release/1.11/ccl-1.11-linuxarm.tar.gz
  449. mkdir -p $TURTL_BASE_DIR/ccl
  450. tar xvzf $TURTL_BASE_DIR/ccl-1.11-linuxarm.tar.gz -C $TURTL_BASE_DIR/ccl --strip-components=1
  451. fi
  452. # install quicklisp
  453. cat << __ENDCONFIG__ > $TURTL_BASE_DIR/quicklisp_install
  454. (load (compile-file "asdf.lisp"))
  455. (load (compile-file "quicklisp.lisp"))
  456. (quicklisp-quickstart:install)
  457. (ql:system-apropos "vecto")
  458. (ql:quickload "alexandria")
  459. (ql:quickload "babel")
  460. (ql:quickload "blackbird")
  461. (ql:quickload "bordeaux-threads")
  462. (ql:quickload "cffi")
  463. (ql:quickload "chipz")
  464. (ql:quickload "chunga")
  465. (ql:quickload "cl-annot")
  466. (ql:quickload "cl-async")
  467. (ql:quickload "cl-async-future")
  468. (ql:quickload "cl-base64")
  469. (ql:quickload "cl-fad")
  470. (ql:quickload "cl-libuv")
  471. (ql:quickload "cl-mongo-id")
  472. (ql:quickload "cl-ppcre")
  473. (ql:quickload "cl-rethinkdb")
  474. (ql:quickload "cl-smtp")
  475. (ql:quickload "cl+ssl")
  476. (ql:quickload "cl-syntax")
  477. (ql:quickload "cl-utilities")
  478. (ql:quickload "cl-vectors")
  479. (ql:quickload "do-urlencode")
  480. (ql:quickload "drakma")
  481. (ql:quickload "drakma-async")
  482. (ql:quickload "event-glue")
  483. (ql:quickload "fast-http")
  484. (ql:quickload "fast-io")
  485. (ql:quickload "flexi-streams")
  486. (ql:quickload "ironclad")
  487. (ql:quickload "jonathan")
  488. (ql:quickload "local-time")
  489. (ql:quickload "md5")
  490. (ql:quickload "named-readtables")
  491. (ql:quickload "nibbles")
  492. (ql:quickload "proc-parse")
  493. (ql:quickload "puri")
  494. (ql:quickload "quri")
  495. (ql:quickload "salza2")
  496. (ql:quickload "secure-random")
  497. (ql:quickload "smart-buffer")
  498. (ql:quickload "split-sequence")
  499. (ql:quickload "static-vectors")
  500. (ql:quickload "trivial-backtrace")
  501. (ql:quickload "trivial-features")
  502. (ql:quickload "trivial-garbage")
  503. (ql:quickload "trivial-gray-streams")
  504. (ql:quickload "trivial-types")
  505. (ql:quickload "usocket")
  506. (ql:quickload "vecto")
  507. (ql:quickload "vom")
  508. (ql:quickload "wookie")
  509. (ql:quickload "xmls")
  510. (ql:quickload "xsubseq")
  511. (ql:quickload "yason")
  512. (ql:quickload "zpb-ttf")
  513. (ql:quickload "zpng")
  514. (ql:add-to-init-file)
  515. (ccl::quit)
  516. __ENDCONFIG__
  517. if [ ! -f asdf.lisp ]; then
  518. wget https://common-lisp.net/project/asdf/asdf.lisp
  519. fi
  520. if [ ! -f quicklisp.lisp ]; then
  521. wget https://beta.quicklisp.org/quicklisp.lisp
  522. fi
  523. if [ -d $TURTL_BASE_DIR ]; then
  524. chown -R turtl:turtl $TURTL_BASE_DIR
  525. fi
  526. adduser --disabled-login --home=$TURTL_BASE_DIR --gecos 'turtl' turtl
  527. if [ ! -d $TURTL_BASE_DIR ]; then
  528. echo $"$TURTL_BASE_DIR directory not created"
  529. exit 263493
  530. fi
  531. groupadd turtl
  532. chown -R turtl:turtl $TURTL_BASE_DIR
  533. if [[ "$check_architecture" != *"arm"* ]]; then
  534. if [[ "$check_architecture" == *"64"* ]]; then
  535. su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/lx86cl64" - turtl
  536. else
  537. su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/lx86cl" - turtl
  538. fi
  539. else
  540. su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/larmcl" - turtl
  541. fi
  542. rm $TURTL_BASE_DIR/quicklisp_install
  543. install_rethinkdb
  544. echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
  545. chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
  546. # install turtl API
  547. cd "$TURTL_BASE_DIR/" || exit 6428462
  548. if [ -d /repos/turtl ]; then
  549. mkdir $TURTL_BASE_DIR/api
  550. cp -r -p /repos/turtl/. $TURTL_BASE_DIR/api
  551. cd "$TURTL_BASE_DIR/api" || exit 57141845
  552. git pull
  553. else
  554. git clone $TURTL_REPO $TURTL_BASE_DIR/api
  555. fi
  556. cd "$TURTL_BASE_DIR/api" || exit 35814614
  557. git checkout $TURTL_COMMIT -b $TURTL_COMMIT
  558. set_completion_param "turtl commit" "$TURTL_COMMIT"
  559. cd "$TURTL_BASE_DIR/quicklisp/local-projects" || exit 43618941415
  560. git clone git://github.com/orthecreedence/cl-hash-util
  561. if [[ "$check_architecture" != *"arm"* ]]; then
  562. if [[ "$check_architecture" == *"64"* ]]; then
  563. su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp" - turtl
  564. else
  565. su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/lx86cl -l $TURTL_BASE_DIR/quicklisp/setup.lisp" - turtl
  566. fi
  567. else
  568. su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/larmcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp" - turtl
  569. fi
  570. # config
  571. { echo '(defvar *enabled-cors-resources* "resource://turtl-at-lyonbros-dot-com"';
  572. echo ' "When set, will enable CORS for resource:// origins if they match the given';
  573. echo ' string. Entries should be comma separated (this string is passed verbatim in';
  574. echo ' the Access-Control-Allow-Origin header).")';
  575. echo '(defparameter *public-actions*';
  576. echo " \`((:post . ,(concatenate 'string *api-path* \"/users\"))";
  577. echo " (:post . ,(concatenate 'string *api-path* \"/log/error\"))";
  578. echo ' (:post . "/cla/sign")';
  579. echo ' (:get . "/ping")';
  580. echo ' (:get . "/admin")';
  581. echo " (:get . ,(cl-ppcre:create-scanner (concatenate 'string *api-path* \"/invites/codes/([0-9a-f-]+)\"))))";
  582. echo " \"A list of public resources/actions that do not require authentication.\")";
  583. echo "(defvar *analytics* '(:enabled t";
  584. echo ' :db "analytics"))'; } > "$TURTL_BASE_DIR/api/config/config.footer"
  585. cp $TURTL_BASE_DIR/asdf.lisp $TURTL_BASE_DIR/api
  586. echo '(load (compile-file "asdf.lisp"))' > $TURTL_BASE_DIR/api/launch.lisp
  587. echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" >> $TURTL_BASE_DIR/api/launch.lisp
  588. echo '(load "start")' >> $TURTL_BASE_DIR/api/launch.lisp
  589. TURTL_ONION_HOSTNAME=$(add_onion_service turtl 80 ${TURTL_ONION_PORT})
  590. turtl_setup
  591. }
  592. function install_turtl_nginx {
  593. turtl_nginx_site=/etc/nginx/sites-available/$TURTL_DOMAIN_NAME
  594. if [[ $ONION_ONLY == "no" ]]; then
  595. function_check nginx_http_redirect
  596. nginx_http_redirect $TURTL_DOMAIN_NAME
  597. { echo 'server {';
  598. echo ' listen 443 ssl;';
  599. echo ' #listen [::]:443 ssl;';
  600. echo " server_name ${TURTL_DOMAIN_NAME};";
  601. echo '';
  602. echo ' # Security'; } >> "$turtl_nginx_site"
  603. function_check nginx_ssl
  604. nginx_ssl $TURTL_DOMAIN_NAME
  605. function_check nginx_security_options
  606. nginx_security_options $TURTL_DOMAIN_NAME
  607. { echo ' add_header Strict-Transport-Security max-age=15768000;';
  608. echo '';
  609. echo ' # Logs';
  610. echo ' access_log /dev/null;';
  611. echo ' error_log /dev/null;';
  612. echo '';
  613. echo ' location / {'; } >> "$turtl_nginx_site"
  614. function_check nginx_limits
  615. nginx_limits $TURTL_DOMAIN_NAME '15m'
  616. { echo " proxy_pass http://localhost:${TURTL_PORT}/;";
  617. echo " proxy_set_header Host \$host;";
  618. echo ' proxy_buffering off;';
  619. echo ' }';
  620. echo '}'; } >> "$turtl_nginx_site"
  621. else
  622. echo -n '' > $turtl_nginx_site
  623. fi
  624. { echo 'server {';
  625. echo " listen 127.0.0.1:${TURTL_ONION_PORT};";
  626. echo " server_name ${TURTL_ONION_HOSTNAME};";
  627. echo ''; } >> $turtl_nginx_site
  628. function_check nginx_security_options
  629. nginx_security_options $TURTL_DOMAIN_NAME
  630. { echo '';
  631. echo ' # Logs';
  632. echo ' access_log /dev/null;';
  633. echo ' error_log /dev/null;';
  634. echo '';
  635. echo ' location / {'; } >> $turtl_nginx_site
  636. function_check nginx_limits
  637. nginx_limits $TURTL_DOMAIN_NAME '15m'
  638. { echo " proxy_pass http://localhost:${TURTL_PORT}/;";
  639. echo " proxy_set_header Host \$host;";
  640. echo ' proxy_buffering off;';
  641. echo ' }';
  642. echo '}'; } >> $turtl_nginx_site
  643. function_check add_ddns_domain
  644. add_ddns_domain $TURTL_DOMAIN_NAME
  645. set_completion_param "turtl domain" "$TURTL_DOMAIN_NAME"
  646. function_check create_site_certificate
  647. create_site_certificate $TURTL_DOMAIN_NAME 'yes'
  648. function_check nginx_ensite
  649. nginx_ensite $TURTL_DOMAIN_NAME
  650. systemctl restart nginx
  651. }
  652. function install_turtl {
  653. install_turtl_api
  654. install_turtl_nginx
  655. APP_INSTALLED=1
  656. }