Przeglądaj źródła

Upgrade ghost install to 1.x type

Bob Mottram 7 lat temu
rodzic
commit
3609e4c952
1 zmienionych plików z 39 dodań i 240 usunięć
  1. 39
    240
      src/freedombone-app-ghost

+ 39
- 240
src/freedombone-app-ghost Wyświetl plik

@@ -38,9 +38,6 @@ GHOST_DOMAIN_NAME=
38 38
 GHOST_CODE=
39 39
 GHOST_ONION_PORT=8104
40 40
 GHOST_PORT=2368
41
-GHOST_VERSION='1.0.2'
42
-GHOST_HASH='c703ffe27539ec4d369631db18720574ca963b5449ace1f255c3f90739ff9a99'
43
-GHOST_DOWNLOAD_URL="https://github.com/TryGhost/Ghost/releases/download/${GHOST_VERSION}/Ghost-${GHOST_VERSION}.zip"
44 41
 
45 42
 ghost_variables=(GHOST_DOMAIN_NAME
46 43
                  GHOST_CODE
@@ -58,18 +55,29 @@ function logging_off_ghost {
58 55
 }
59 56
 
60 57
 function ghost_replace_jquery {
61
-    sed -i "s|code.jquery.com/jquery-${previous_jquery_version}.min.js|$GHOST_DOMAIN_NAME/jquery-${jquery_version}.js|g" content/themes/casper/default.hbs
62
-    sed -i "s|code.jquery.com/jquery-${previous_jquery_version}.min.js|$GHOST_DOMAIN_NAME/jquery-${jquery_version}.js|g" core/server/data/migration/fixtures/004/01-move-jquery-with-alert.js
63
-    sed -i "s|code.jquery.com/jquery-${previous_jquery_version}.min.js|$GHOST_DOMAIN_NAME/jquery-${jquery_version}.js|g" node_modules/gscan/app/tpl/layouts/default.hbs
58
+    curr_domain="https://$GHOST_DOMAIN_NAME"
59
+    if [[ "$ONION_ONLY" != 'no' ]]; then
60
+        curr_domain="http://$GHOST_ONION_HOSTNAME"
61
+    fi
62
+
63
+    sed -i "s|src=\"https://code.jquery.com/jquery-.*|src=\"$curr_domain/jquery-${jquery_version}.js\"|g" current/content/themes/casper/default.hbs
64
+    sed -i "s|src=\"https://code.jquery.com/jquery-.*|src=\"$curr_domain/jquery-${jquery_version}.js\"></script>|g" current/node_modules/gscan/app/tpl/layouts/default.hbs
65
+    sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
66
+    sed -i "s|https://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
67
+
68
+    find ./ -type f -exec sed -i -e 's|https://code.jquery.com|$curr_domain|g' {} \;
69
+    find ./ -type f -exec sed -i -e 's|http://code.jquery.com|$curr_domain|g' {} \;
64 70
 }
65 71
 
66 72
 function ghost_remove_offsite_links {
67
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
73
+    curr_domain="$GHOST_DOMAIN_NAME"
74
+    if [[ "$ONION_ONLY" != 'no' ]]; then
75
+        curr_domain="$GHOST_ONION_HOSTNAME"
76
+    fi
68 77
 
69 78
     # remove google font links
70
-    # Note that the privacy options in config.js aren't sufficient to remove Google's tentacles
71
-    sed -i "s/fonts.googleapis.com/$GHOST_DOMAIN_NAME/g" content/themes/casper/default.hbs
72
-    sed -i "s/fonts.googleapis.com/$GHOST_DOMAIN_NAME/g" core/server/apps/amp/lib/views/amp.hbs
79
+    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
80
+    find ./ -type f -exec sed -i -e 's/fonts.googleapis.com/$curr_domain/g' {} \;
73 81
 
74 82
     # copy jquery locally
75 83
     previous_jquery_version='1.12.0'
@@ -166,52 +174,11 @@ function upgrade_ghost {
166 174
     if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
167 175
         return
168 176
     fi
169
-
170
-    if ! grep -q "ghost version:" $COMPLETION_FILE; then
171
-        CURR_GHOST_VERSION=${GHOST_VERSION}b
172
-    else
173
-        CURR_GHOST_VERSION=$(get_completion_param "ghost version")
174
-    fi
175
-
176
-    if [[ "$GHOST_VERSION" == "$CURR_GHOST_VERSION" ]]; then
177
-        return
178
-    fi
179
-
180
-    read_config_param "GHOST_DOMAIN_NAME"
181
-
182
-    GHOST_PATH=/var/www/$GHOST_DOMAIN_NAME/htdocs
183
-
184
-    cd $GHOST_PATH
185
-    if [ ! -f Ghost-${GHOST_VERSION}.zip ]; then
186
-        wget ${GHOST_DOWNLOAD_URL}
187
-    fi
188
-    if [ ! -f Ghost-${GHOST_VERSION}.zip ]; then
189
-        echo $'Unable to download ghost'
190
-        exit 367245
191
-    fi
192
-
193
-    # check the hash
194
-    hash=$(sha256sum Ghost-${GHOST_VERSION}.zip | awk -F ' ' '{print $1}')
195
-    if [[ "$hash" != "$GHOST_HASH" ]]; then
196
-        echo $'ghost hash does not match'
197
-        exit 729856
198
-    fi
199
-
200
-    unzip -o Ghost-${GHOST_VERSION}.zip
201
-    if [ ! -f $GHOST_PATH/index.js ]; then
202
-        echo $'ghost failed to unzip'
203
-        exit 63835
204
-    fi
205
-
206
-    sed -i "/sqlite/d" $GHOST_PATH/package.json
207
-    npm install --production
208
-
209
-    chown -R ghost: $GHOST_PATH/
177
+    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
178
+    /usr/local/bin/ghost update
210 179
     ghost_replace_services
211
-    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
212
-
213 180
     ghost_remove_offsite_links
214
-    sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
181
+    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
215 182
     systemctl restart ghost
216 183
 }
217 184
 
@@ -223,10 +190,10 @@ function backup_local_ghost {
223 190
 
224 191
     ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
225 192
     if [ -d $ghost_path ]; then
226
-        function_check backup_database_to_usb
227
-        backup_database_to_usb ghost
228
-
193
+        suspend_site ${GHOST_DOMAIN_NAME}
194
+        systemctl stop ghost
229 195
         backup_directory_to_usb $ghost_path ghostcontent
196
+        systemctl start ghost
230 197
         restart_site
231 198
     fi
232 199
 }
@@ -237,14 +204,9 @@ function restore_local_ghost {
237 204
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
238 205
     fi
239 206
     if [ $GHOST_DOMAIN_NAME ]; then
207
+        suspend_site ${GHOST_DOMAIN_NAME}
240 208
         systemctl stop ghost
241 209
 
242
-        function_check ghost_create_database
243
-        ghost_create_database
244
-
245
-        function_check restore_database
246
-        restore_database ghost ${GHOST_DOMAIN_NAME}
247
-
248 210
         temp_restore_dir=/root/tempghostcontent
249 211
         function_check restore_directory_from_usb
250 212
         restore_directory_from_usb $temp_restore_dir ghostcontent
@@ -254,32 +216,6 @@ function restore_local_ghost {
254 216
             rm -rf $temp_restore_dir
255 217
         fi
256 218
 
257
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
258
-        ghost_config=/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.js
259
-        sed -i "s|password :.*|password : '${MARIADB_PASSWORD}',|g" $ghost_config
260
-        MARIADB_PASSWORD=
261
-
262
-        # install any missing packages
263
-        cd /var/www/${GHOST_DOMAIN_NAME}/htdocs
264
-        if [ ! -d /var/www/${GHOST_DOMAIN_NAME}/htdocs/node_modules/intl ]; then
265
-            npm install passport-http-bearer@1.0.1
266
-            npm install amperize@0.3.4
267
-            npm install bcryptjs@2.4.3
268
-            npm install knex@0.12.9
269
-            npm install bookshelf@0.10.2
270
-            npm install cookie-session@1.2.0
271
-            npm install ghost-gql@0.0.6
272
-            npm install intl@1.2.5
273
-            npm install sanitize-html@1.14.1
274
-            npm install showdown-ghost@0.3.6
275
-            npm install superagent@3.5.2
276
-            npm install mysql@2.1.1
277
-        fi
278
-        if [ ! -d /var/www/${GHOST_DOMAIN_NAME}/htdocs/node_modules/debug ]; then
279
-            npm install debug@2.6.8
280
-            npm install nconf@0.8.4
281
-        fi
282
-
283 219
         systemctl start ghost
284 220
         restart_site
285 221
     fi
@@ -294,7 +230,6 @@ function backup_remote_ghost {
294 230
     temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
295 231
     if [ -d $temp_backup_dir ]; then
296 232
         suspend_site ${GHOST_DOMAIN_NAME}
297
-        backup_database_to_friend ghost
298 233
         backup_directory_to_friend $temp_backup_dir ghostcontent
299 234
         restart_site
300 235
     else
@@ -308,53 +243,21 @@ function restore_remote_ghost {
308 243
     if grep -q "ghost domain" $COMPLETION_FILE; then
309 244
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
310 245
     fi
246
+    suspend_site ${GHOST_DOMAIN_NAME}
311 247
 
312 248
     systemctl stop ghost
313 249
 
314
-    function_check get_mariadb_password
315
-    get_mariadb_password
316
-
317
-    function_check restore_database_from_friend
318
-
319
-    function_check ghost_create_database
320
-    ghost_create_database
321
-
322
-    restore_database_from_friend ghost
323
-
324 250
     temp_restore_dir=/root/tempghostcontent
325 251
     function_check restore_directory_from_friend
326 252
     restore_directory_from_friend $temp_restore_dir ghostcontent
327 253
     if [ -d $temp_restore_dir ]; then
328 254
         cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
329
-        chown -R ghost:ghost /var/www/$GHOST_DOMAIN_NAME/htdocs/content
255
+        chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
330 256
         rm -rf $temp_restore_dir
331 257
     fi
332 258
 
333
-    MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
334
-    ghost_config=/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.js
335
-    sed -i "s|password :.*|password : '${MARIADB_PASSWORD}',|g" $ghost_config
336
-    MARIADB_PASSWORD=
337
-
338
-    # install any missing packages
339
-    if [ ! -d /var/www/${GHOST_DOMAIN_NAME}/htdocs/node_modules/intl ]; then
340
-        cd /var/www/${GHOST_DOMAIN_NAME}/htdocs
341
-        npm install passport-http-bearer@1.0.1
342
-        npm install amperize@0.3.4
343
-        npm install bcryptjs@2.4.3
344
-        npm install knex@0.12.9
345
-        npm install bookshelf@0.10.2
346
-        npm install cookie-session@1.2.0
347
-        npm install ghost-gql@0.0.6
348
-        npm install intl@1.2.5
349
-        npm install sanitize-html@1.14.1
350
-        npm install showdown-ghost@0.3.6
351
-        npm install superagent@3.5.2
352
-        npm install mysql@2.1.1
353
-    fi
354
-
355 259
     systemctl start ghost
356 260
     restart_site
357
-    chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs/
358 261
 }
359 262
 
360 263
 function remove_ghost {
@@ -370,9 +273,6 @@ function remove_ghost {
370 273
     function_check remove_nodejs
371 274
     remove_nodejs ghost
372 275
 
373
-    drop_database ghost
374
-    remove_backup_database_local ghost
375
-
376 276
     read_config_param "GHOST_DOMAIN_NAME"
377 277
     nginx_dissite $GHOST_DOMAIN_NAME
378 278
     remove_certs ${GHOST_DOMAIN_NAME}
@@ -397,70 +297,6 @@ function remove_ghost {
397 297
     remove_ddns_domain $GHOST_DOMAIN_NAME
398 298
 }
399 299
 
400
-function ghost_create_config {
401
-    ghost_config=/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.js
402
-
403
-    function_check get_mariadb_password
404
-    get_mariadb_password
405
-
406
-    echo "var path = require('path')," > $ghost_config
407
-    echo '    config;' >> $ghost_config
408
-    echo '' >> $ghost_config
409
-    echo 'config = {' >> $ghost_config
410
-    echo '    production: {' >> $ghost_config
411
-    echo '        // This needs to be http and NOT https' >> $ghost_config
412
-    echo "        url: 'http://${GHOST_DOMAIN_NAME}'," >> $ghost_config
413
-    echo '        mail: {' >> $ghost_config
414
-    echo "            transport: 'SMTP'," >> $ghost_config
415
-    echo '            options: {' >> $ghost_config
416
-    echo "                service: 'Sendmail'," >> $ghost_config
417
-    echo '            }' >> $ghost_config
418
-    echo '        },' >> $ghost_config
419
-    echo '        database: {' >> $ghost_config
420
-    echo "            client: 'mysql'," >> $ghost_config
421
-    echo '            connection: {' >> $ghost_config
422
-    echo "                host     : '127.0.0.1'," >> $ghost_config
423
-    echo "                user     : 'root'," >> $ghost_config
424
-    echo "                password : '${MARIADB_PASSWORD}'," >> $ghost_config
425
-    echo "                database : 'ghost'," >> $ghost_config
426
-    echo "                charset  : 'utf8'" >> $ghost_config
427
-    echo '            }' >> $ghost_config
428
-    echo '        },' >> $ghost_config
429
-    echo '' >> $ghost_config
430
-    echo '        server: {' >> $ghost_config
431
-    echo "            host: '127.0.0.1'," >> $ghost_config
432
-    echo "            port: '${GHOST_PORT}'" >> $ghost_config
433
-    echo '        },' >> $ghost_config
434
-    echo '        privacy: {' >> $ghost_config
435
-    echo '            useTinfoil: true,' >> $ghost_config
436
-    echo '        },' >> $ghost_config
437
-    echo '        logging: false' >> $ghost_config
438
-    echo '    }' >> $ghost_config
439
-    echo '};' >> $ghost_config
440
-    echo '' >> $ghost_config
441
-    echo 'module.exports = config;' >> $ghost_config
442
-    chmod 700 $ghost_config
443
-}
444
-
445
-function ghost_create_database {
446
-    if [ -f ${IMAGE_PASSWORD_FILE} ]; then
447
-        GIT_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
448
-    else
449
-        if [ ! ${GIT_ADMIN_PASSWORD} ]; then
450
-            GIT_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
451
-        fi
452
-    fi
453
-    if [ ! $GIT_ADMIN_PASSWORD ]; then
454
-        return
455
-    fi
456
-
457
-    function_check get_mariadb_password
458
-    get_mariadb_password
459
-
460
-    function_check create_database
461
-    create_database ghost "$GHOST_ADMIN_PASSWORD"
462
-}
463
-
464 300
 function install_ghost {
465 301
     if [ ! $ONION_ONLY ]; then
466 302
         ONION_ONLY='no'
@@ -478,35 +314,11 @@ function install_ghost {
478 314
         mkdir -p /var/www/$GHOST_DOMAIN_NAME/htdocs
479 315
     fi
480 316
     cd /var/www/$GHOST_DOMAIN_NAME/htdocs
481
-    if [ ! -f Ghost-${GHOST_VERSION}.zip ]; then
482
-        wget ${GHOST_DOWNLOAD_URL}
483
-    fi
484
-    if [ ! -f Ghost-${GHOST_VERSION}.zip ]; then
485
-        echo $'Unable to download ghost'
486
-        rm -rf /var/www/$GHOST_DOMAIN_NAME
487
-        exit 63892
488
-    fi
489
-
490
-    # check the hash
491
-    hash=$(sha256sum Ghost-${GHOST_VERSION}.zip | awk -F ' ' '{print $1}')
492
-    if [[ "$hash" != "$GHOST_HASH" ]]; then
493
-        echo $'ghost hash does not match'
494
-        exit 729856
495
-    fi
496
-
497
-    unzip -o Ghost-${GHOST_VERSION}.zip
498
-    if [ ! -f /var/www/${GHOST_DOMAIN_NAME}/htdocs/index.js ]; then
499
-        echo $'ghost failed to unzip'
500
-        rm -rf /var/www/$GHOST_DOMAIN_NAME
501
-        exit 63835
502
-    fi
503 317
 
504 318
     function_check install_nodejs
505 319
     install_nodejs ghost
506 320
 
507
-    sed -i "/sqlite/d" /var/www/${GHOST_DOMAIN_NAME}/htdocs/package.json
508
-
509
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
321
+    # Some dependencies of ghost
510 322
     npm install -g jison@0.4.13 --save
511 323
     npm install moment-timezone@0.5.13
512 324
     npm install express@4.15.3
@@ -561,43 +373,39 @@ function install_ghost {
561 373
     npm install debug@2.6.8
562 374
     npm install nconf@0.8.4
563 375
 
564
-    npm install --production
376
+    npm install -g knex-migrator
377
+    knex-migrator init
565 378
 
566
-    function_check install_mariadb
567
-    install_mariadb
568
-
569
-    function_check get_mariadb_password
570
-    get_mariadb_password
571
-
572
-    function_check ghost_create_database
573
-    ghost_create_database
574
-
575
-    ghost_create_config
379
+    # now install ghost itself
380
+    npm install -g ghost-cli
381
+    ghost install local
576 382
 
577 383
     adduser --system --home=/var/www/${GHOST_DOMAIN_NAME}/htdocs/ --group ghost
578
-    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
579 384
 
580 385
     echo '[Unit]' > /etc/systemd/system/ghost.service
581 386
     echo 'Description=Ghost Blog' >> /etc/systemd/system/ghost.service
582 387
     echo 'After=syslog.target' >> /etc/systemd/system/ghost.service
583 388
     echo 'After=network.target' >> /etc/systemd/system/ghost.service
584
-    echo 'After=mysqld.service' >> /etc/systemd/system/ghost.service
585 389
     echo '' >> /etc/systemd/system/ghost.service
586 390
     echo '[Service]' >> /etc/systemd/system/ghost.service
587 391
     echo 'Type=simple' >> /etc/systemd/system/ghost.service
588 392
     echo 'User=ghost' >> /etc/systemd/system/ghost.service
589 393
     echo 'Group=ghost' >> /etc/systemd/system/ghost.service
590 394
     echo "WorkingDirectory=/var/www/${GHOST_DOMAIN_NAME}/htdocs" >> /etc/systemd/system/ghost.service
591
-    echo "ExecStart=/usr/local/bin/node /var/www/${GHOST_DOMAIN_NAME}/htdocs/index.js" >> /etc/systemd/system/ghost.service
395
+    echo "ExecStart=/usr/local/bin/ghost run" >> /etc/systemd/system/ghost.service
396
+    echo "ExecStop=/usr/local/bin/ghost stop" >> /etc/systemd/system/ghost.service
397
+    echo "ExecRestart=/usr/local/bin/ghost restart" >> /etc/systemd/system/ghost.service
592 398
     echo 'Restart=always' >> /etc/systemd/system/ghost.service
593 399
     echo 'RestartSec=60' >> /etc/systemd/system/ghost.service
594
-    echo "Environment=NODE_ENV=production PORT=${GHOST_PORT}" >> /etc/systemd/system/ghost.service
400
+    echo "Environment=NODE_ENV=development PORT=${GHOST_PORT}" >> /etc/systemd/system/ghost.service
595 401
     echo '' >> /etc/systemd/system/ghost.service
596 402
     echo '[Install]' >> /etc/systemd/system/ghost.service
597 403
     echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ghost.service
598 404
 
599 405
     ghost_remove_offsite_links
600 406
 
407
+    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
408
+
601 409
     systemctl enable ghost
602 410
     systemctl daemon-reload
603 411
     systemctl start ghost
@@ -678,15 +486,6 @@ function install_ghost {
678 486
     function_check create_site_certificate
679 487
     create_site_certificate $GHOST_DOMAIN_NAME 'yes'
680 488
 
681
-    function_check configure_php
682
-    configure_php
683
-
684
-    if [[ $ONION_ONLY != 'no' ]]; then
685
-        sed -i "s|url: .*|url: 'http://${GHOST_ONION_HOSTNAME}',|g" /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.js
686
-        systemctl restart mariadb
687
-        systemctl restart ghost
688
-    fi
689
-
690 489
     ghost_replace_services
691 490
 
692 491
     function_check nginx_ensite