freedombone-app-turtl 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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 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 change_password_turtl {
  57. change_username="$1"
  58. new_user_password="$2"
  59. }
  60. function remove_user_turtl {
  61. remove_username="$1"
  62. }
  63. function add_user_turtl {
  64. new_username="$1"
  65. new_user_password="$2"
  66. echo '0'
  67. }
  68. function install_interactive_turtl {
  69. if [ ! $ONION_ONLY ]; then
  70. ONION_ONLY='no'
  71. fi
  72. if [[ $ONION_ONLY != "no" ]]; then
  73. TURTL_DOMAIN_NAME='notes.local'
  74. write_config_param "TURTL_DOMAIN_NAME" "$TURTL_DOMAIN_NAME"
  75. else
  76. function_check interactive_site_details
  77. interactive_site_details "turtl" "TURTL_DOMAIN_NAME" "TURTL_CODE"
  78. fi
  79. APP_INSTALLED=1
  80. }
  81. function turtl_disable_registrations {
  82. if grep "$TURTL_SIGNUP_STRING" $turtl_users_file; then
  83. if [ -f $turtl_users_file ]; then
  84. cp $turtl_users_file $TURTL_BASE_DIR/.users.lisp
  85. sed -i '/(route (:post "\/users") (req res)/,/(send-json res user))))/{//!d}' $turtl_users_file
  86. sed -i 's|(send-json res user))))|())|g' $turtl_users_file
  87. chown -R turtl:turtl $TURTL_BASE_DIR
  88. systemctl restart turtl
  89. fi
  90. fi
  91. }
  92. function turtl_enable_registrations {
  93. if ! grep "$TURTL_SIGNUP_STRING" $turtl_users_file; then
  94. if [ -f $TURTL_BASE_DIR/.users.lisp ]; then
  95. cp $TURTL_BASE_DIR/.users.lisp $turtl_users_file
  96. rm $TURTL_BASE_DIR/.users.lisp
  97. chown -R turtl:turtl $TURTL_BASE_DIR
  98. systemctl restart turtl
  99. fi
  100. fi
  101. }
  102. function configure_interactive_turtl_signups {
  103. # This implements a hack which removes or adds the function needed
  104. # to sign up new users. It should eventually be removed once that
  105. # capability exists within the api
  106. dialog --title $"Allow new turtl signups" \
  107. --backtitle $"Freedombone Control Panel" \
  108. --defaultno \
  109. --yesno $"\nAllow registration of new users?" 10 60
  110. sel=$?
  111. case $sel in
  112. 0)
  113. turtl_enable_registrations
  114. dialog --title $"Allow new turtl signups" \
  115. --msgbox $"New turtl user registrations are now allowed" 6 60
  116. return;;
  117. 1)
  118. turtl_disable_registrations
  119. dialog --title $"Disable new turtl signups" \
  120. --msgbox $"New turtl user registrations are now disabled" 6 60
  121. return;;
  122. 255) return;;
  123. esac
  124. }
  125. function configure_interactive_turtl_storage {
  126. data=$(tempfile 2>/dev/null)
  127. trap "rm -f $data" 0 1 2 5 15
  128. dialog --title $"Change storage limit" \
  129. --backtitle $"Freedombone Control Panel" \
  130. --inputbox $"Enter a storage limit in megabytes." 8 75 "$TURTL_STORAGE_LIMIT_MB" 2>$data
  131. sel=$?
  132. case $sel in
  133. 0)
  134. STORAGE=$(<$data)
  135. if [ ${#STORAGE} -gt 0 ]; then
  136. TURTL_STORAGE_LIMIT_MB=$STORAGE
  137. sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* ${TURTL_STORAGE_LIMIT_MB})|g" $TURTL_BASE_DIR/api/config/config.lisp
  138. systemctl restart turtl
  139. dialog --title $"Change storage limit" \
  140. --msgbox $"Storage limit changed to ${TURTL_STORAGE_LIMIT_MB}M" 6 50
  141. fi
  142. ;;
  143. esac
  144. }
  145. function configure_interactive_turtl {
  146. data=$(tempfile 2>/dev/null)
  147. trap "rm -f $data" 0 1 2 5 15
  148. dialog --backtitle $"Freedombone Control Panel" \
  149. --title $"turtl app settings" \
  150. --radiolist $"Choose an operation:" 12 70 3 \
  151. 1 $"Enable/disable new user registrations" off \
  152. 2 $"Change storage limit" off \
  153. 3 $"Exit" on 2> $data
  154. sel=$?
  155. case $sel in
  156. 1) exit 1;;
  157. 255) exit 1;;
  158. esac
  159. case $(cat $data) in
  160. 1) configure_interactive_turtl_signups;;
  161. 2) configure_interactive_turtl_storage;;
  162. 3) return;;
  163. esac
  164. }
  165. function reconfigure_turtl {
  166. if [ -d $TURTL_BASE_DIR/data ]; then
  167. rm -rf $TURTL_BASE_DIR/data/*
  168. fi
  169. }
  170. function upgrade_turtl {
  171. CURR_TURTL_COMMIT=$(get_completion_param "turtl commit")
  172. if [[ "$CURR_TURTL_COMMIT" == "$TURTL_COMMIT" ]]; then
  173. return
  174. fi
  175. read_config_param "TURTL_DOMAIN_NAME"
  176. function_check set_repo_commit
  177. set_repo_commit $TURTL_BASE_DIR/api "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
  178. # this is used as a crude way of disabling signups and so
  179. # should be superceded in future
  180. if [ -f $TURTL_BASE_DIR/.users.lisp ]; then
  181. turtl_disable_registrations
  182. fi
  183. systemctl restart turtl
  184. nginx_dissite $TURTL_DOMAIN_NAME
  185. chown -R turtl:turtl $TURTL_BASE_DIR
  186. nginx_ensite $TURTL_DOMAIN_NAME
  187. }
  188. function backup_local_turtl {
  189. read_config_param "TURTL_DOMAIN_NAME"
  190. source_directory=$TURTL_BASE_DIR
  191. if [ -d $source_directory ]; then
  192. dest_directory=turtl
  193. function_check suspend_site
  194. suspend_site ${TURTL_DOMAIN_NAME}
  195. function_check backup_directory_to_usb
  196. backup_directory_to_usb $source_directory $dest_directory
  197. function_check restart_site
  198. restart_site
  199. fi
  200. source_directory=/var/lib/rethinkdb
  201. if [ -d $source_directory ]; then
  202. dest_directory=rethinkdb
  203. function_check suspend_site
  204. suspend_site ${TURTL_DOMAIN_NAME}
  205. function_check backup_directory_to_usb
  206. backup_directory_to_usb $source_directory $dest_directory
  207. function_check restart_site
  208. restart_site
  209. fi
  210. }
  211. function restore_local_turtl {
  212. read_config_param "TURTL_DOMAIN_NAME"
  213. if [ $TURTL_DOMAIN_NAME ]; then
  214. temp_restore_dir=/root/tempturtl
  215. restore_directory_from_usb $temp_restore_dir turtl
  216. if [ -d $TURTL_BASE_DIR ]; then
  217. if [ -d /etc/turtl_previous ]; then
  218. rm -rf /etc/turtl_previous
  219. fi
  220. mv $TURTL_BASE_DIR /etc/turtl_previous
  221. fi
  222. temp_source_dir=$(find ${temp_restore_dir} -name turtl)
  223. cp -r ${temp_source_dir} /etc/
  224. if [ ! "$?" = "0" ]; then
  225. if [ -d /etc/turtl_previous ]; then
  226. mv /etc/turtl_previous $TURTL_BASE_DIR
  227. fi
  228. set_user_permissions
  229. backup_unmount_drive
  230. exit 36723
  231. fi
  232. rm -rf ${temp_restore_dir}
  233. chown -R turtl:turtl $TURTL_BASE_DIR
  234. temp_restore_dir=/root/temprethinkdb
  235. restore_directory_from_usb $temp_restore_dir rethinkdb
  236. if [ -d /var/lib/rethinkdb ]; then
  237. if [ -d /var/lib/previous_rethinkdb ]; then
  238. rm -rf /var/lib/previous_rethinkdb
  239. fi
  240. mv /var/lib/rethinkdb /var/lib/previous_rethinkdb
  241. fi
  242. temp_source_dir=$(find ${temp_restore_dir} -name rethinkdb)
  243. cp -r ${temp_source_dir} /var/lib/
  244. if [ ! "$?" = "0" ]; then
  245. if [ -d /var/lib/previous_rethinkdb ]; then
  246. mv /var/lib/previous_rethinkdb /var/lib/rethinkdb
  247. fi
  248. set_user_permissions
  249. backup_unmount_drive
  250. exit 378324
  251. fi
  252. rm -rf ${temp_restore_dir}
  253. fi
  254. }
  255. function backup_remote_turtl {
  256. read_config_param "TURTL_DOMAIN_NAME"
  257. if [ $TURTL_DOMAIN_NAME ]; then
  258. temp_backup_dir=$TURTL_BASE_DIR
  259. if [ -d $temp_backup_dir ]; then
  260. echo $"Backing up turtl"
  261. backup_directory_to_friend $temp_backup_dir turtl
  262. echo $"Backup of turtl complete"
  263. else
  264. echo $"turtl domain specified but not found in $temp_backup_dir"
  265. exit 68725
  266. fi
  267. temp_backup_dir=/var/lib/rethinkdb
  268. if [ -d $temp_backup_dir ]; then
  269. echo $"Backing up rethinkdb"
  270. backup_directory_to_friend $temp_backup_dir rethinkdb
  271. echo $"Backup of rethinkdb complete"
  272. fi
  273. fi
  274. }
  275. function restore_remote_turtl {
  276. read_config_param "TURTL_DOMAIN_NAME"
  277. if [ $TURTL_DOMAIN_NAME ]; then
  278. temp_restore_dir=/root/tempturtl
  279. mkdir $temp_restore_dir
  280. function_check restore_directory_from_friend
  281. restore_directory_from_friend $temp_restore_dir turtl
  282. if [ -d $TURTL_BASE_DIR ]; then
  283. if [ -d /etc/turtl_previous ]; then
  284. rm -rf /etc/turtl_previous
  285. fi
  286. mv $TURTL_BASE_DIR /etc/turtl_previous
  287. fi
  288. temp_source_dir=$(find ${temp_restore_dir} -name turtl)
  289. cp -r ${temp_source_dir} /etc/
  290. if [ ! "$?" = "0" ]; then
  291. if [ -d /etc/turtl_previous ]; then
  292. mv /etc/turtl_previous $TURTL_BASE_DIR
  293. fi
  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 /var/lib/rethinkdb ]; then
  302. if [ -d /var/lib/previous_rethinkdb ]; then
  303. rm -rf /var/lib/previous_rethinkdb
  304. fi
  305. mv /var/lib/rethinkdb /var/lib/previous_rethinkdb
  306. fi
  307. temp_source_dir=$(find ${temp_restore_dir} -name rethinkdb)
  308. cp -r ${temp_source_dir} /var/lib/
  309. if [ ! "$?" = "0" ]; then
  310. if [ -d /var/lib/previous_rethinkdb ]; then
  311. mv /var/lib/previous_rethinkdb /var/lib/rethinkdb
  312. fi
  313. exit 26783
  314. fi
  315. rm -rf ${temp_restore_dir}
  316. fi
  317. }
  318. function remove_turtl {
  319. if [ ! -d $TURTL_BASE_DIR ]; then
  320. return
  321. fi
  322. systemctl stop turtl
  323. systemctl disable turtl
  324. rm /etc/systemd/system/turtl.service
  325. systemctl daemon-reload
  326. remove_rethinkdb
  327. remove_app turtl
  328. remove_completion_param install_turtl
  329. sed -i '/turtl/d' $COMPLETION_FILE
  330. nginx_dissite $TURTL_DOMAIN_NAME
  331. if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
  332. rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
  333. fi
  334. remove_certs $TURTL_DOMAIN_NAME
  335. function_check remove_onion_service
  336. remove_onion_service turtl ${TURTL_ONION_PORT}
  337. function_check remove_ddns_domain
  338. remove_ddns_domain $TURTL_DOMAIN_NAME
  339. rm -rf /etc/rethinkdb
  340. rm -rf /var/lib/rethinkdb
  341. rm -rf $TURTL_BASE_DIR
  342. groupdel -f turtl
  343. userdel -r turtl
  344. }
  345. function turtl_setup {
  346. PIDFILE=${PIDFILE:-nil}
  347. BINDADDR=${BINDADDR:-0.0.0.0}
  348. BINDPORT=${BINDPORT:-8181}
  349. PROD_ERR_HANDLING=${PROD_ERR_HANDLING:-t}
  350. if [[ $ONION_ONLY == 'no' ]]; then
  351. FQDN=${FQDN:-$TURTL_DOMAIN_NAME}
  352. SITE_URL=${SITE_URL:-https://$TURTL_DOMAIN_NAME}
  353. else
  354. FQDN=${FQDN:-$TURTL_ONION_HOSTNAME}
  355. SITE_URL=${SITE_URL:-http://$TURTL_ONION_HOSTNAME}
  356. fi
  357. ADMIN_EMAIL=${ADMIN_EMAIL:-$MY_EMAIL_ADDRESS}
  358. EMAIL_FROM=${EMAIL_FROM:-noreply@$DEFAULT_DOMAIN_NAME}
  359. SMTP_USER=${SMTP_USER:-}
  360. SMTP_PASS=${SMTP_PASS:-}
  361. DISPLAY_ERRORS=${DISPLAY_ERRORS:-t}
  362. DEFAULT_STORAGE_LIMIT=${DEFAULT_STORAGE_LIMIT:-100}
  363. STORAGE_INVITE_CREDIT=${STORAGE_INVITE_CREDIT:-25}
  364. if [[ $ONION_ONLY == 'no' ]]; then
  365. LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-https://$TURTL_DOMAIN_NAME}
  366. else
  367. LOCAL_UPLOAD_URL=${LOCAL_UPLOAD_URL:-http://$TURTL_ONION_HOSTNAME}
  368. fi
  369. LOCAL_UPLOAD_PATH=${LOCAL_UPLOAD_PATH:-"$TURTL_BASE_DIR/data"}
  370. AWS_S3_TOKEN=${AWS_S3_TOKEN:-(:token ''
  371. :secret ''
  372. :bucket ''
  373. :endpoint 'https://s3.amazonaws.com')}
  374. # generates the config-file
  375. cat << __ENDCONFIG__ > $TURTL_BASE_DIR/api/config/config.lisp
  376. (in-package :turtl)
  377. (defparameter *root* (asdf:system-relative-pathname :turtl #P""))
  378. (defparameter *pid-file* "${PIDFILE}")
  379. (defvar *server-bind* "${BINDADDR}")
  380. (defvar *server-port* ${BINDPORT})
  381. (defvar *db-name* "turtl")
  382. (defvar *db-host* "127.0.0.1")
  383. (defvar *db-port* 28015)
  384. (defvar *production-error-handling* ${PROD_ERR_HANDLING})
  385. (defvar *enable-hsts-header* nil)
  386. (defvar *site-url* "${SITE_URL}")
  387. (defvar *api-path* "")
  388. (defvar *admin-email* "${ADMIN_EMAIL}")
  389. (defvar *email-from* "${EMAIL_FROM}")
  390. (defvar *email-user* "${SMTP_USER}")
  391. (defvar *email-pass* "${SMTP_PASS}")
  392. (defvar *display-errors* ${DISPLAY_ERRORS})
  393. (defparameter *default-storage-limit* ${DEFAULT_STORAGE_LIMIT})
  394. (defparameter *storage-invite-credit* ${STORAGE_INVITE_CREDIT})
  395. (vom:config :turtl :info)
  396. (defvar *local-upload* "${LOCAL_UPLOAD_PATH}")
  397. (defvar *local-upload-url* "${LOCAL_UPLOAD_URL}")
  398. (defvar *amazon-s3* "${AWS_S3_TOKEN}")
  399. __ENDCONFIG__
  400. cat $TURTL_BASE_DIR/api/config/config.footer >> $TURTL_BASE_DIR/api/config/config.lisp
  401. # start the turtl server
  402. systemctl restart rethinkdb
  403. echo '[Unit]' > /etc/systemd/system/turtl.service
  404. echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
  405. echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
  406. echo 'Requires=network.target' >> /etc/systemd/system/turtl.service
  407. echo 'Requires=rethinkdb.service' >> /etc/systemd/system/turtl.service
  408. echo 'After=network.target' >> /etc/systemd/system/turtl.service
  409. echo 'After=rethinkdb.service' >> /etc/systemd/system/turtl.service
  410. echo '' >> /etc/systemd/system/turtl.service
  411. echo '[Service]' >> /etc/systemd/system/turtl.service
  412. echo 'Type=simple' >> /etc/systemd/system/turtl.service
  413. echo 'User=turtl' >> /etc/systemd/system/turtl.service
  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/larmcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
  422. fi
  423. fi
  424. echo '' >> /etc/systemd/system/turtl.service
  425. echo '[Install]' >> /etc/systemd/system/turtl.service
  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
  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. adduser --disabled-login --home=$TURTL_BASE_DIR --gecos 'turtl' turtl
  524. if [ ! -d /home/turtl ]; then
  525. echo $"/home/turtl directory not created"
  526. exit 263493
  527. fi
  528. groupadd turtl
  529. chown -R turtl:turtl $TURTL_BASE_DIR
  530. if [[ "$check_architecture" != *"arm"* ]]; then
  531. if [[ "$check_architecture" == *"64"* ]]; then
  532. su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/lx86cl64" - turtl
  533. else
  534. su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/lx86cl" - turtl
  535. fi
  536. else
  537. su -c "cat $TURTL_BASE_DIR/quicklisp_install | $TURTL_BASE_DIR/ccl/larmcl" - turtl
  538. fi
  539. rm $TURTL_BASE_DIR/quicklisp_install
  540. install_rethinkdb
  541. echo "http-port=8091" > /etc/rethinkdb/instances.d/turtl.conf
  542. chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
  543. # install turtl API
  544. cd $TURTL_BASE_DIR/
  545. if [ -d /repos/turtl ]; then
  546. mkdir $TURTL_BASE_DIR/api
  547. cp -r -p /repos/turtl/. $TURTL_BASE_DIR/api
  548. cd $TURTL_BASE_DIR/api
  549. git pull
  550. else
  551. git clone $TURTL_REPO $TURTL_BASE_DIR/api
  552. fi
  553. cd $TURTL_BASE_DIR/api
  554. git checkout $TURTL_COMMIT -b $TURTL_COMMIT
  555. set_completion_param "turtl commit" "$TURTL_COMMIT"
  556. cd $TURTL_BASE_DIR/quicklisp/local-projects
  557. git clone git://github.com/orthecreedence/cl-hash-util
  558. if [[ "$check_architecture" != *"arm"* ]]; then
  559. if [[ "$check_architecture" == *"64"* ]]; then
  560. su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp" - turtl
  561. else
  562. su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/lx86cl -l $TURTL_BASE_DIR/quicklisp/setup.lisp" - turtl
  563. fi
  564. else
  565. su -c "cat '(ccl:quit)' | $TURTL_BASE_DIR/ccl/larmcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp" - turtl
  566. fi
  567. # config
  568. echo '(defvar *enabled-cors-resources* "resource://turtl-at-lyonbros-dot-com"' > $TURTL_BASE_DIR/api/config/config.footer
  569. echo ' "When set, will enable CORS for resource:// origins if they match the given' >> $TURTL_BASE_DIR/api/config/config.footer
  570. echo ' string. Entries should be comma separated (this string is passed verbatim in' >> $TURTL_BASE_DIR/api/config/config.footer
  571. echo ' the Access-Control-Allow-Origin header).")' >> $TURTL_BASE_DIR/api/config/config.footer
  572. echo '(defparameter *public-actions*' >> $TURTL_BASE_DIR/api/config/config.footer
  573. echo " \`((:post . ,(concatenate 'string *api-path* \"/users\"))" >> $TURTL_BASE_DIR/api/config/config.footer
  574. echo " (:post . ,(concatenate 'string *api-path* \"/log/error\"))" >> $TURTL_BASE_DIR/api/config/config.footer
  575. echo ' (:post . "/cla/sign")' >> $TURTL_BASE_DIR/api/config/config.footer
  576. echo ' (:get . "/ping")' >> $TURTL_BASE_DIR/api/config/config.footer
  577. echo ' (:get . "/admin")' >> $TURTL_BASE_DIR/api/config/config.footer
  578. echo " (:get . ,(cl-ppcre:create-scanner (concatenate 'string *api-path* \"/invites/codes/([0-9a-f-]+)\"))))" >> $TURTL_BASE_DIR/api/config/config.footer
  579. echo " \"A list of public resources/actions that do not require authentication.\")" >> $TURTL_BASE_DIR/api/config/config.footer
  580. echo "(defvar *analytics* '(:enabled t" >> $TURTL_BASE_DIR/api/config/config.footer
  581. echo ' :db "analytics"))' >> $TURTL_BASE_DIR/api/config/config.footer
  582. cp $TURTL_BASE_DIR/asdf.lisp $TURTL_BASE_DIR/api
  583. echo '(load (compile-file "asdf.lisp"))' > $TURTL_BASE_DIR/api/launch.lisp
  584. echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" >> $TURTL_BASE_DIR/api/launch.lisp
  585. echo '(load "start")' >> $TURTL_BASE_DIR/api/launch.lisp
  586. TURTL_ONION_HOSTNAME=$(add_onion_service turtl 80 ${TURTL_ONION_PORT})
  587. turtl_setup
  588. }
  589. function install_turtl_nginx {
  590. turtl_nginx_site=/etc/nginx/sites-available/$TURTL_DOMAIN_NAME
  591. if [[ $ONION_ONLY == "no" ]]; then
  592. function_check nginx_http_redirect
  593. nginx_http_redirect $TURTL_DOMAIN_NAME
  594. echo 'server {' >> $turtl_nginx_site
  595. echo ' listen 443 ssl;' >> $turtl_nginx_site
  596. echo ' listen [::]:443 ssl;' >> $turtl_nginx_site
  597. echo " server_name ${TURTL_DOMAIN_NAME};" >> $turtl_nginx_site
  598. echo '' >> $turtl_nginx_site
  599. echo ' # Security' >> $turtl_nginx_site
  600. function_check nginx_ssl
  601. nginx_ssl $TURTL_DOMAIN_NAME
  602. function_check nginx_disable_sniffing
  603. nginx_disable_sniffing $TURTL_DOMAIN_NAME
  604. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $turtl_nginx_site
  605. echo '' >> $turtl_nginx_site
  606. echo ' # Logs' >> $turtl_nginx_site
  607. echo ' access_log /dev/null;' >> $turtl_nginx_site
  608. echo ' error_log /dev/null;' >> $turtl_nginx_site
  609. echo '' >> $turtl_nginx_site
  610. echo ' location / {' >> $turtl_nginx_site
  611. function_check nginx_limits
  612. nginx_limits $TURTL_DOMAIN_NAME '15m'
  613. echo " proxy_pass http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
  614. echo ' proxy_set_header Host $host;' >> $turtl_nginx_site
  615. echo ' proxy_buffering off;' >> $turtl_nginx_site
  616. echo ' }' >> $turtl_nginx_site
  617. echo '}' >> $turtl_nginx_site
  618. else
  619. echo -n '' > $turtl_nginx_site
  620. fi
  621. echo 'server {' >> $turtl_nginx_site
  622. echo " listen 127.0.0.1:${TURTL_ONION_PORT};" >> $turtl_nginx_site
  623. echo " server_name ${TURTL_ONION_HOSTNAME};" >> $turtl_nginx_site
  624. echo '' >> $turtl_nginx_site
  625. function_check nginx_disable_sniffing
  626. nginx_disable_sniffing $TURTL_DOMAIN_NAME
  627. echo '' >> $turtl_nginx_site
  628. echo ' # Logs' >> $turtl_nginx_site
  629. echo ' access_log /dev/null;' >> $turtl_nginx_site
  630. echo ' error_log /dev/null;' >> $turtl_nginx_site
  631. echo '' >> $turtl_nginx_site
  632. echo ' location / {' >> $turtl_nginx_site
  633. function_check nginx_limits
  634. nginx_limits $TURTL_DOMAIN_NAME '15m'
  635. echo " proxy_pass http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
  636. echo ' proxy_set_header Host $host;' >> $turtl_nginx_site
  637. echo ' proxy_buffering off;' >> $turtl_nginx_site
  638. echo ' }' >> $turtl_nginx_site
  639. echo '}' >> $turtl_nginx_site
  640. function_check add_ddns_domain
  641. add_ddns_domain $TURTL_DOMAIN_NAME
  642. set_completion_param "turtl domain" "$TURTL_DOMAIN_NAME"
  643. function_check create_site_certificate
  644. create_site_certificate $TURTL_DOMAIN_NAME 'yes'
  645. function_check nginx_ensite
  646. nginx_ensite $TURTL_DOMAIN_NAME
  647. systemctl restart nginx
  648. }
  649. function install_turtl {
  650. install_turtl_api
  651. install_turtl_nginx
  652. APP_INSTALLED=1
  653. }