Browse Source

More turtl config

Bob Mottram 8 years ago
parent
commit
85f6db39a3
2 changed files with 120 additions and 39 deletions
  1. 68
    22
      src/freedombone-app-turtl
  2. 52
    17
      src/freedombone-utils-lisp

+ 68
- 22
src/freedombone-app-turtl View File

@@ -126,6 +126,11 @@ function upgrade_turtl {
126 126
     function_check set_repo_commit
127 127
     set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
128 128
     set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl api commit" "$TURTL_API_COMMIT" $TURTL_API_REPO
129
+    nginx_dissite $TURTL_DOMAIN_NAME
130
+    cd /var/www/$TURTL_DOMAIN_NAME/htdocs
131
+    npm install
132
+    make minify
133
+    nginx_ensite $TURTL_DOMAIN_NAME
129 134
 }
130 135
 
131 136
 function backup_local_turtl {
@@ -240,17 +245,18 @@ function remove_turtl {
240 245
     remove_nodejs turtl
241 246
 
242 247
     remove_rethinkdb
248
+    remove_common_lisp
243 249
 
244 250
     function_check remove_ddns_domain
245 251
     remove_ddns_domain $TURTL_DOMAIN_NAME
246 252
 }
247 253
 
248 254
 function install_libuv {
249
-    if [ ! -d $INSTALL_DIR ]; then
250
-        mkdir -p $INSTALL_DIR
255
+    if [ ! -d /usr/local/src ]; then
256
+        mkdir -p /usr/local/src
251 257
     fi
252 258
 
253
-    cd $INSTALL_DIR
259
+    cd /usr/local/src
254 260
     if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
255 261
         wget http://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz
256 262
     fi
@@ -264,15 +270,15 @@ function install_libuv {
264 270
         echo $"libuv hash does not match. Expected $LIBUV_HASH but found $hashstr"
265 271
         exit 27685
266 272
     fi
267
-    if [ ! -d $INSTALL_DIR/libuv-v${LIBUV_VERSION} ]; then
273
+    if [ ! -d /usr/local/src/libuv-v${LIBUV_VERSION} ]; then
268 274
         tar -xf libuv-v${LIBUV_VERSION}.tar.gz
269 275
     fi
270
-    if [ ! -d $INSTALL_DIR/libuv-v${LIBUV_VERSION} ]; then
276
+    if [ ! -d /usr/local/src/libuv-v${LIBUV_VERSION} ]; then
271 277
         rm libuv-v${LIBUV_VERSION}.tar.gz
272 278
         echo $'libuv could not be extracted'
273 279
         exit 72754
274 280
     fi
275
-    cd $INSTALL_DIR/libuv-v${LIBUV_VERSION}
281
+    cd /usr/local/src/libuv-v${LIBUV_VERSION}
276 282
     sh autogen.sh
277 283
     ./configure
278 284
     make
@@ -294,10 +300,9 @@ function install_turtl {
294 300
     fi
295 301
 
296 302
     apt-get -yq install git wget curl libtool subversion gcc make automake
297
-    apt-get -yq install cl-cffi cl-quicklisp libuv1-dev build-essential
298 303
 
299
-    if [ ! -d $INSTALL_DIR ]; then
300
-        mkdir -p $INSTALL_DIR
304
+    if [ ! -d /usr/local/src ]; then
305
+        mkdir -p /usr/local/src
301 306
     fi
302 307
 
303 308
     if [ -d /var/www/$TURTL_DOMAIN_NAME ]; then
@@ -366,9 +371,16 @@ function install_turtl {
366 371
     git checkout $TURTL_API_COMMIT -b $TURTL_API_COMMIT
367 372
     set_completion_param "turtl api commit" "$TURTL_API_COMMIT"
368 373
 
374
+    function_check install_libuv
369 375
     install_libuv
376
+
377
+    function_check install_rethinkdb
370 378
     install_rethinkdb
379
+
380
+    function_check install_common_lisp
371 381
     install_common_lisp
382
+
383
+    function_check install_quicklisp
372 384
     install_quicklisp
373 385
 
374 386
     function_check install_nodejs
@@ -377,10 +389,54 @@ function install_turtl {
377 389
     function_check add_ddns_domain
378 390
     add_ddns_domain $TURTL_DOMAIN_NAME
379 391
 
380
-    adduser --system --home=/var/www/$TURTL_DOMAIN_NAME/htdocs/ --group turtl
392
+    cp -r $INSTALL_DIR/lisp/* /var/www/$TURTL_DOMAIN_NAME/htdocs
393
+    sed -i 's|CCL_DEFAULT_DIRECTORY=.*|CCL_DEFAULT_DIRECTORY=$HOME/ccl|g' /var/www/$TURTL_DOMAIN_NAME/htdocs/ccl/scripts/ccl
394
+    sed -i 's|CCL_DEFAULT_DIRECTORY=.*|CCL_DEFAULT_DIRECTORY=$HOME/ccl|g' /var/www/$TURTL_DOMAIN_NAME/htdocs/ccl/scripts/ccl64
395
+
396
+    adduser --disabled-login --home=/var/www/$TURTL_DOMAIN_NAME/htdocs --gecos 'turtl' turtl
397
+    chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
398
+    check_architecture=$(uname -a)
399
+    if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
400
+        su -c '$HOME/ccl/scripts/ccl --load install.lisp --eval "(quit)"' - turtl
401
+    else
402
+        su -c '$HOME/ccl/scripts/ccl64 --load install.lisp --eval "(quit)"' - turtl
403
+    fi
404
+
405
+    echo "(pushnew \"./\" asdf:*central-registry* :test #'equal)" > /var/www/$TURTL_DOMAIN_NAME/htdocs/api/launch.lisp
406
+    echo '(load "start")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/api/launch.lisp
407
+
408
+    cd /var/www/$TURTL_DOMAIN_NAME/htdocs/quicklisp/local-projects
409
+    git clone git://github.com/orthecreedence/cl-hash-util
410
+    git clone git://github.com/orthecreedence/vom
411
+    git clone git://github.com/orthecreedence/cl-async
412
+    git clone git://github.com/orthecreedence/cffi
413
+    git clone git://github.com/orthecreedence/wookie
414
+    git clone git://github.com/orthecreedence/cl-rethinkdb
415
+    git clone git://github.com/orthecreedence/cl-libuv
416
+    git clone git://github.com/orthecreedence/drakma-async
417
+    git clone https://github.com/Inaimathi/cl-cwd.git
418
+
419
+    echo '#-quicklisp' > /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
420
+    echo '(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
421
+    echo '  (when (probe-file quicklisp-init)' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
422
+    echo '    (load quicklisp-init)))' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
423
+    echo '(cwd "$HOME/api")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
424
+    echo '(load "$HOME/api/launch")' >> /var/www/$TURTL_DOMAIN_NAME/htdocs/.ccl-init.lisp
425
+
381 426
     chmod a+w /var/www/$TURTL_DOMAIN_NAME/htdocs
382 427
     chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
383 428
 
429
+    # install the app
430
+    cd /var/www/$TURTL_DOMAIN_NAME/htdocs
431
+    npm install
432
+    make minify
433
+    if [ ! -f /var/www/$TURTL_DOMAIN_NAME/htdocs/index.html ]; then
434
+        echo $'Failed to install turtl app'
435
+        exit 823652
436
+    fi
437
+
438
+    chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
439
+
384 440
     echo '[Unit]' > /etc/systemd/system/turtl.service
385 441
     echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
386 442
     echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
@@ -395,9 +451,9 @@ function install_turtl {
395 451
     echo "WorkingDirectory=/var/www/$TURTL_DOMAIN_NAME/htdocs/api/" >> /etc/systemd/system/turtl.service
396 452
     check_architecture=$(uname -a)
397 453
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
398
-        echo 'ExecStart=/usr/bin/ccl64 -Q -b --load start.lisp' >> /etc/systemd/system/turtl.service
454
+        echo "ExecStart=/var/www/$TURTL_DOMAIN_NAME/htdocs/ccl/scripts/ccl64 -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service
399 455
     else
400
-        echo 'ExecStart=/usr/bin/ccl -Q -b --load start.lisp' >> /etc/systemd/system/turtl.service
456
+        echo "ExecStart=/var/www/$TURTL_DOMAIN_NAME/htdocs/ccl/scripts/ccl -Q -b --load start.lisp" >> /etc/systemd/system/turtl.service
401 457
     fi
402 458
     echo '' >> /etc/systemd/system/turtl.service
403 459
     echo '[Install]' >> /etc/systemd/system/turtl.service
@@ -440,7 +496,6 @@ function install_turtl {
440 496
         echo '    proxy_buffering   off;' >> $turtl_nginx_site
441 497
         echo '  }' >> $turtl_nginx_site
442 498
         echo '' >> $turtl_nginx_site
443
-        nginx_keybase $TURTL_DOMAIN_NAME
444 499
         echo '}' >> $turtl_nginx_site
445 500
         echo '' >> $turtl_nginx_site
446 501
         echo 'server {' >> $turtl_nginx_site
@@ -471,7 +526,6 @@ function install_turtl {
471 526
         nginx_limits $TURTL_DOMAIN_NAME '15m'
472 527
         echo '  }' >> $turtl_nginx_site
473 528
         echo '' >> $turtl_nginx_site
474
-        nginx_keybase $TURTL_DOMAIN_NAME
475 529
         echo '}' >> $turtl_nginx_site
476 530
     else
477 531
         echo -n '' > $turtl_nginx_site
@@ -498,7 +552,6 @@ function install_turtl {
498 552
     echo '    proxy_buffering   off;' >> $turtl_nginx_site
499 553
     echo '  }' >> $turtl_nginx_site
500 554
     echo '' >> $turtl_nginx_site
501
-    nginx_keybase $TURTL_DOMAIN_NAME
502 555
     echo '}' >> $turtl_nginx_site
503 556
     echo '' >> $turtl_nginx_site
504 557
     echo 'server {' >> $turtl_nginx_site
@@ -522,7 +575,6 @@ function install_turtl {
522 575
     nginx_limits $TURTL_DOMAIN_NAME '15m'
523 576
     echo '  }' >> $turtl_nginx_site
524 577
     echo '' >> $turtl_nginx_site
525
-    nginx_keybase $TURTL_DOMAIN_NAME
526 578
     echo '}' >> $turtl_nginx_site
527 579
 
528 580
     function_check create_site_certificate
@@ -531,12 +583,6 @@ function install_turtl {
531 583
     if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt ]; then
532 584
         mv /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
533 585
     fi
534
-    if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem ]; then
535
-        chown turtl:turtl /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
536
-    fi
537
-    if [ -f /etc/ssl/private/${TURTL_DOMAIN_NAME}.key ]; then
538
-        chown turtl:turtl /etc/ssl/private/${TURTL_DOMAIN_NAME}.key
539
-    fi
540 586
 
541 587
     function_check nginx_ensite
542 588
     nginx_ensite $TURTL_DOMAIN_NAME

+ 52
- 17
src/freedombone-utils-lisp View File

@@ -32,11 +32,16 @@ COMMON_LISP_VERSION='1.11'
32 32
 
33 33
 function install_common_lisp {
34 34
     # http://ccl.clozure.com
35
-    if [ ! -d $INSTALL_DIR/lisp ]; then
36
-        mkdir -p $INSTALL_DIR/lisp
35
+    lisp_base=/usr/local/src
36
+    if [ $1 ]; then
37
+        lisp_base=$1
37 38
     fi
38 39
 
39
-    cd $INSTALL_DIR/lisp
40
+    if [ ! -d $lisp_base ]; then
41
+        mkdir -p $lisp_base
42
+    fi
43
+
44
+    cd $lisp_base
40 45
 
41 46
     check_architecture=$(uname -a)
42 47
     if [[ "$check_architecture" == *"arm"* ]]; then
@@ -45,25 +50,48 @@ function install_common_lisp {
45 50
         svn co http://svn.clozure.com/publicsvn/openmcl/release/${COMMON_LISP_VERSION}/linuxx86/ccl
46 51
     fi
47 52
 
48
-    if [ ! -d $INSTALL_DIR/lisp/ccl/scripts ]; then
53
+    if [ ! -d $lisp_base/ccl/scripts ]; then
49 54
         echo $'Unable to clone ccl repo'
50 55
         exit 728245
51 56
     fi
52
-    if [ ! -f $INSTALL_DIR/lisp/ccl/scripts/ccl ]; then
57
+    if [ ! -f $lisp_base/ccl/scripts/ccl ]; then
53 58
         echo $'ccl not found'
54 59
         exit 5825422
55 60
     fi
56
-    cp $INSTALL_DIR/lisp/ccl/scripts/ccl /usr/bin
57
-    if [ -f $INSTALL_DIR/lisp/ccl/scripts/ccl64 ]; then
58
-        cp $INSTALL_DIR/lisp/ccl/scripts/ccl64 /usr/bin
61
+    cp $lisp_base/ccl/scripts/ccl /usr/bin
62
+    sed -i 's|CCL_DEFAULT_DIRECTORY=.*|CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl|g' /usr/bin/ccl
63
+    if [ -f $lisp_base/ccl/scripts/ccl64 ]; then
64
+        cp $lisp_base/ccl/scripts/ccl64 /usr/bin
65
+        sed -i 's|CCL_DEFAULT_DIRECTORY=.*|CCL_DEFAULT_DIRECTORY=/usr/local/src/ccl|g' /usr/bin/ccl64
66
+    fi
67
+}
68
+
69
+function remove_common_lisp {
70
+    if [ -f /usr/bin/ccl ]; then
71
+        rm /usr/bin/ccl
72
+    fi
73
+
74
+    if [ -f /usr/bin/ccl64 ]; then
75
+        rm /usr/bin/ccl64
76
+    fi
77
+
78
+    if [ -d /usr/local/src/ccl ]; then
79
+        rm -rf /usr/local/src/ccl
80
+    fi
81
+    if [ -d $INSTALL_DIR/lisp ]; then
82
+        rm -rf $INSTALL_DIR/lisp
59 83
     fi
60 84
 }
61 85
 
62 86
 function install_quicklisp {
63
-    if [ ! -d $INSTALL_DIR/lisp ]; then
64
-        mkdir -p $INSTALL_DIR/lisp
87
+    quicklisp_base=/usr/local/src
88
+    if [ $1 ]; then
89
+        quicklisp_base=$1
90
+    fi
91
+    if [ ! -d $quicklisp_base ]; then
92
+        mkdir -p $quicklisp_base
65 93
     fi
66
-    cd $INSTALL_DIR/lisp
94
+    cd $quicklisp_base
67 95
     if [ ! -f asdf.lisp ]; then
68 96
         wget https://common-lisp.net/project/asdf/asdf.lisp
69 97
     fi
@@ -79,17 +107,24 @@ function install_quicklisp {
79 107
         exit 80253
80 108
     fi
81 109
 
82
-    echo '(quicklisp-quickstart:install)' > install.lisp
110
+    echo '(load (compile-file "asdf.lisp"))' > install.lisp
111
+    echo '(load (compile-file "quicklisp.lisp"))' >> install.lisp
112
+    echo '(quicklisp-quickstart:install)' >> install.lisp
83 113
     echo '(ql:add-to-init-file)' >> install.lisp
84
-    echo '(load (compile-file "asdf.lisp"))' >> install.lisp
85 114
 
86 115
     check_architecture=$(uname -a)
87 116
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
88
-        ccl64 --load quicklisp.lisp
89
-        ccl64 --load install.lisp
117
+        if [ ! $2 ]; then
118
+            ccl64 --load install.lisp
119
+        else
120
+            su -c 'ccl64 --load install.lisp' - $2
121
+        fi
90 122
     else
91
-        ccl --load quicklisp.lisp
92
-        ccl --load install.lisp
123
+        if [ ! $2 ]; then
124
+            ccl --load install.lisp
125
+        else
126
+            su -c 'ccl --load install.lisp' - $2
127
+        fi
93 128
     fi
94 129
 }
95 130