浏览代码

More turtl config

Bob Mottram 8 年前
父节点
当前提交
85f6db39a3
共有 2 个文件被更改,包括 120 次插入39 次删除
  1. 68
    22
      src/freedombone-app-turtl
  2. 52
    17
      src/freedombone-utils-lisp

+ 68
- 22
src/freedombone-app-turtl 查看文件

126
     function_check set_repo_commit
126
     function_check set_repo_commit
127
     set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
127
     set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
128
     set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl api commit" "$TURTL_API_COMMIT" $TURTL_API_REPO
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
 function backup_local_turtl {
136
 function backup_local_turtl {
240
     remove_nodejs turtl
245
     remove_nodejs turtl
241
 
246
 
242
     remove_rethinkdb
247
     remove_rethinkdb
248
+    remove_common_lisp
243
 
249
 
244
     function_check remove_ddns_domain
250
     function_check remove_ddns_domain
245
     remove_ddns_domain $TURTL_DOMAIN_NAME
251
     remove_ddns_domain $TURTL_DOMAIN_NAME
246
 }
252
 }
247
 
253
 
248
 function install_libuv {
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
     fi
257
     fi
252
 
258
 
253
-    cd $INSTALL_DIR
259
+    cd /usr/local/src
254
     if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
260
     if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
255
         wget http://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz
261
         wget http://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz
256
     fi
262
     fi
264
         echo $"libuv hash does not match. Expected $LIBUV_HASH but found $hashstr"
270
         echo $"libuv hash does not match. Expected $LIBUV_HASH but found $hashstr"
265
         exit 27685
271
         exit 27685
266
     fi
272
     fi
267
-    if [ ! -d $INSTALL_DIR/libuv-v${LIBUV_VERSION} ]; then
273
+    if [ ! -d /usr/local/src/libuv-v${LIBUV_VERSION} ]; then
268
         tar -xf libuv-v${LIBUV_VERSION}.tar.gz
274
         tar -xf libuv-v${LIBUV_VERSION}.tar.gz
269
     fi
275
     fi
270
-    if [ ! -d $INSTALL_DIR/libuv-v${LIBUV_VERSION} ]; then
276
+    if [ ! -d /usr/local/src/libuv-v${LIBUV_VERSION} ]; then
271
         rm libuv-v${LIBUV_VERSION}.tar.gz
277
         rm libuv-v${LIBUV_VERSION}.tar.gz
272
         echo $'libuv could not be extracted'
278
         echo $'libuv could not be extracted'
273
         exit 72754
279
         exit 72754
274
     fi
280
     fi
275
-    cd $INSTALL_DIR/libuv-v${LIBUV_VERSION}
281
+    cd /usr/local/src/libuv-v${LIBUV_VERSION}
276
     sh autogen.sh
282
     sh autogen.sh
277
     ./configure
283
     ./configure
278
     make
284
     make
294
     fi
300
     fi
295
 
301
 
296
     apt-get -yq install git wget curl libtool subversion gcc make automake
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
     fi
306
     fi
302
 
307
 
303
     if [ -d /var/www/$TURTL_DOMAIN_NAME ]; then
308
     if [ -d /var/www/$TURTL_DOMAIN_NAME ]; then
366
     git checkout $TURTL_API_COMMIT -b $TURTL_API_COMMIT
371
     git checkout $TURTL_API_COMMIT -b $TURTL_API_COMMIT
367
     set_completion_param "turtl api commit" "$TURTL_API_COMMIT"
372
     set_completion_param "turtl api commit" "$TURTL_API_COMMIT"
368
 
373
 
374
+    function_check install_libuv
369
     install_libuv
375
     install_libuv
376
+
377
+    function_check install_rethinkdb
370
     install_rethinkdb
378
     install_rethinkdb
379
+
380
+    function_check install_common_lisp
371
     install_common_lisp
381
     install_common_lisp
382
+
383
+    function_check install_quicklisp
372
     install_quicklisp
384
     install_quicklisp
373
 
385
 
374
     function_check install_nodejs
386
     function_check install_nodejs
377
     function_check add_ddns_domain
389
     function_check add_ddns_domain
378
     add_ddns_domain $TURTL_DOMAIN_NAME
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
     chmod a+w /var/www/$TURTL_DOMAIN_NAME/htdocs
426
     chmod a+w /var/www/$TURTL_DOMAIN_NAME/htdocs
382
     chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
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
     echo '[Unit]' > /etc/systemd/system/turtl.service
440
     echo '[Unit]' > /etc/systemd/system/turtl.service
385
     echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
441
     echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
386
     echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
442
     echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
395
     echo "WorkingDirectory=/var/www/$TURTL_DOMAIN_NAME/htdocs/api/" >> /etc/systemd/system/turtl.service
451
     echo "WorkingDirectory=/var/www/$TURTL_DOMAIN_NAME/htdocs/api/" >> /etc/systemd/system/turtl.service
396
     check_architecture=$(uname -a)
452
     check_architecture=$(uname -a)
397
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
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
     else
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
     fi
457
     fi
402
     echo '' >> /etc/systemd/system/turtl.service
458
     echo '' >> /etc/systemd/system/turtl.service
403
     echo '[Install]' >> /etc/systemd/system/turtl.service
459
     echo '[Install]' >> /etc/systemd/system/turtl.service
440
         echo '    proxy_buffering   off;' >> $turtl_nginx_site
496
         echo '    proxy_buffering   off;' >> $turtl_nginx_site
441
         echo '  }' >> $turtl_nginx_site
497
         echo '  }' >> $turtl_nginx_site
442
         echo '' >> $turtl_nginx_site
498
         echo '' >> $turtl_nginx_site
443
-        nginx_keybase $TURTL_DOMAIN_NAME
444
         echo '}' >> $turtl_nginx_site
499
         echo '}' >> $turtl_nginx_site
445
         echo '' >> $turtl_nginx_site
500
         echo '' >> $turtl_nginx_site
446
         echo 'server {' >> $turtl_nginx_site
501
         echo 'server {' >> $turtl_nginx_site
471
         nginx_limits $TURTL_DOMAIN_NAME '15m'
526
         nginx_limits $TURTL_DOMAIN_NAME '15m'
472
         echo '  }' >> $turtl_nginx_site
527
         echo '  }' >> $turtl_nginx_site
473
         echo '' >> $turtl_nginx_site
528
         echo '' >> $turtl_nginx_site
474
-        nginx_keybase $TURTL_DOMAIN_NAME
475
         echo '}' >> $turtl_nginx_site
529
         echo '}' >> $turtl_nginx_site
476
     else
530
     else
477
         echo -n '' > $turtl_nginx_site
531
         echo -n '' > $turtl_nginx_site
498
     echo '    proxy_buffering   off;' >> $turtl_nginx_site
552
     echo '    proxy_buffering   off;' >> $turtl_nginx_site
499
     echo '  }' >> $turtl_nginx_site
553
     echo '  }' >> $turtl_nginx_site
500
     echo '' >> $turtl_nginx_site
554
     echo '' >> $turtl_nginx_site
501
-    nginx_keybase $TURTL_DOMAIN_NAME
502
     echo '}' >> $turtl_nginx_site
555
     echo '}' >> $turtl_nginx_site
503
     echo '' >> $turtl_nginx_site
556
     echo '' >> $turtl_nginx_site
504
     echo 'server {' >> $turtl_nginx_site
557
     echo 'server {' >> $turtl_nginx_site
522
     nginx_limits $TURTL_DOMAIN_NAME '15m'
575
     nginx_limits $TURTL_DOMAIN_NAME '15m'
523
     echo '  }' >> $turtl_nginx_site
576
     echo '  }' >> $turtl_nginx_site
524
     echo '' >> $turtl_nginx_site
577
     echo '' >> $turtl_nginx_site
525
-    nginx_keybase $TURTL_DOMAIN_NAME
526
     echo '}' >> $turtl_nginx_site
578
     echo '}' >> $turtl_nginx_site
527
 
579
 
528
     function_check create_site_certificate
580
     function_check create_site_certificate
531
     if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt ]; then
583
     if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt ]; then
532
         mv /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
584
         mv /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
533
     fi
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
     function_check nginx_ensite
587
     function_check nginx_ensite
542
     nginx_ensite $TURTL_DOMAIN_NAME
588
     nginx_ensite $TURTL_DOMAIN_NAME

+ 52
- 17
src/freedombone-utils-lisp 查看文件

32
 
32
 
33
 function install_common_lisp {
33
 function install_common_lisp {
34
     # http://ccl.clozure.com
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
     fi
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
     check_architecture=$(uname -a)
46
     check_architecture=$(uname -a)
42
     if [[ "$check_architecture" == *"arm"* ]]; then
47
     if [[ "$check_architecture" == *"arm"* ]]; then
45
         svn co http://svn.clozure.com/publicsvn/openmcl/release/${COMMON_LISP_VERSION}/linuxx86/ccl
50
         svn co http://svn.clozure.com/publicsvn/openmcl/release/${COMMON_LISP_VERSION}/linuxx86/ccl
46
     fi
51
     fi
47
 
52
 
48
-    if [ ! -d $INSTALL_DIR/lisp/ccl/scripts ]; then
53
+    if [ ! -d $lisp_base/ccl/scripts ]; then
49
         echo $'Unable to clone ccl repo'
54
         echo $'Unable to clone ccl repo'
50
         exit 728245
55
         exit 728245
51
     fi
56
     fi
52
-    if [ ! -f $INSTALL_DIR/lisp/ccl/scripts/ccl ]; then
57
+    if [ ! -f $lisp_base/ccl/scripts/ccl ]; then
53
         echo $'ccl not found'
58
         echo $'ccl not found'
54
         exit 5825422
59
         exit 5825422
55
     fi
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
     fi
83
     fi
60
 }
84
 }
61
 
85
 
62
 function install_quicklisp {
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
     fi
93
     fi
66
-    cd $INSTALL_DIR/lisp
94
+    cd $quicklisp_base
67
     if [ ! -f asdf.lisp ]; then
95
     if [ ! -f asdf.lisp ]; then
68
         wget https://common-lisp.net/project/asdf/asdf.lisp
96
         wget https://common-lisp.net/project/asdf/asdf.lisp
69
     fi
97
     fi
79
         exit 80253
107
         exit 80253
80
     fi
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
     echo '(ql:add-to-init-file)' >> install.lisp
113
     echo '(ql:add-to-init-file)' >> install.lisp
84
-    echo '(load (compile-file "asdf.lisp"))' >> install.lisp
85
 
114
 
86
     check_architecture=$(uname -a)
115
     check_architecture=$(uname -a)
87
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
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
     else
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
     fi
128
     fi
94
 }
129
 }
95
 
130