Selaa lähdekoodia

Template support for mongodb

Bob Mottram 6 vuotta sitten
vanhempi
commit
6d7cd198bb
1 muutettua tiedostoa jossa 61 lisäystä ja 20 poistoa
  1. 61
    20
      src/freedombone-template

+ 61
- 20
src/freedombone-template Näytä tiedosto

@@ -55,22 +55,22 @@ function show_help {
55 55
     echo $'Creates a new app script which can then be filled in'
56 56
     echo ''
57 57
     echo ''
58
-    echo $'  -h --help                            Show help'
59
-    echo $'  -a --app [name]                      Name of the application'
60
-    echo $'  -n --name [name]                     Your name'
61
-    echo $'  -e --email [address]                 Your email address'
62
-    echo $'  -r --repo [url]                      Git repo url for the app'
63
-    echo $'  -c --commit [hash]                   Git commit'
64
-    echo $'     --port [number]                   Port number for the app'
65
-    echo $'     --portinternal [number]           Internal port between a daemon and the web server'
66
-    echo $'     --node [yes|no]                   Is this a nodejs app?'
67
-    echo $'     --nodeapp [package]               Specify a nodejs package to install'
68
-    echo $'  -o --onion [yes|no]                  Is this app only available on an onion address?'
69
-    echo $'  -p --php [yes|no]                    Is this a PHP app?'
70
-    echo $'  -s --daemon [yes|no]                 Add a daemon'
71
-    echo $'  -d --database [mariadb|postgresql]   Type of database'
72
-    echo $'  -w --web [yes|no]                    Whether there is a web user interface (default is yes)'
73
-    echo $'     --dir [directory]                 Where to install to'
58
+    echo $'  -h --help                                   Show help'
59
+    echo $'  -a --app [name]                             Name of the application'
60
+    echo $'  -n --name [name]                            Your name'
61
+    echo $'  -e --email [address]                        Your email address'
62
+    echo $'  -r --repo [url]                             Git repo url for the app'
63
+    echo $'  -c --commit [hash]                          Git commit'
64
+    echo $'     --port [number]                          Port number for the app'
65
+    echo $'     --portinternal [number]                  Internal port between a daemon and the web server'
66
+    echo $'     --node [yes|no]                          Is this a nodejs app?'
67
+    echo $'     --nodeapp [package]                      Specify a nodejs package to install'
68
+    echo $'  -o --onion [yes|no]                         Is this app only available on an onion address?'
69
+    echo $'  -p --php [yes|no]                           Is this a PHP app?'
70
+    echo $'  -s --daemon [yes|no]                        Add a daemon'
71
+    echo $'  -d --database [mariadb|postgresql|mongodb]  Type of database'
72
+    echo $'  -w --web [yes|no]                           Whether there is a web user interface (default is yes)'
73
+    echo $'     --dir [directory]                        Where to install to'
74 74
     echo ''
75 75
     exit 0
76 76
 }
@@ -322,7 +322,7 @@ echo ''
322 322
 echo "    \"\${PROJECT_NAME}-pass\" -u \"\$curr_username\" -a ${app_name} -p \"\$new_user_password\""
323 323
 echo '}'
324 324
 
325
-if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* ]]; then
325
+if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* || "$database_type" == "mongo"* ]]; then
326 326
     echo ''
327 327
     echo "function ${app_name}_create_database {"
328 328
     echo "    if [ -f \$IMAGE_PASSWORD_FILE ]; then"
@@ -336,9 +336,13 @@ if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database
336 336
     echo '        return'
337 337
     echo '    fi'
338 338
     echo ''
339
-    if [[ "$database_type" != "postgres"* ]]; then
339
+    if [[ "$database_type" = "mysql" || "$database_type" = "mariadb" ]]; then
340 340
         echo "    create_database ${app_name} \"\$${app_name_upper}_ADMIN_PASSWORD\" \$MY_USERNAME"
341
-    else
341
+    fi
342
+    if [[ "$database_type" = "mongo"* ]]; then
343
+        echo "    create_database_mongodb ${app_name} \"\$${app_name_upper}_ADMIN_PASSWORD\" \$MY_USERNAME"
344
+    fi
345
+    if [[ "$database_type" == "postgres"* ]]; then
342 346
         echo '    systemctl restart postgresql'
343 347
         echo "    run_system_query_postgresql \"CREATE USER peertube WITH PASSWORD '\$${app_name_upper}_ADMIN_PASSWORD';\""
344 348
         echo "    run_system_query_postgresql \"CREATE DATABASE ${app_name} OWNER ${app_name};\""
@@ -430,6 +434,11 @@ if [[ "$database_type" == "postgres"* ]]; then
430 434
     echo "    backup_database_to_usb ${app_name}"
431 435
     echo ''
432 436
 fi
437
+if [[ "$database_type" == "mongo"* ]]; then
438
+    echo '    USE_MONGODB=1'
439
+    echo "    backup_database_to_usb ${app_name}"
440
+    echo ''
441
+fi
433 442
 if [ $app_webui ]; then
434 443
     echo '    restart_site'
435 444
 fi
@@ -481,6 +490,16 @@ if [[ "$database_type" == "postgres"* ]]; then
481 490
     echo '    fi'
482 491
     echo ''
483 492
 fi
493
+if [[ "$database_type" == "mongo"* ]]; then
494
+    echo "    ${app_name}_create_database"
495
+    echo ''
496
+    echo '    USE_MONGODB=1'
497
+    echo "    restore_database ${app_name}"
498
+    echo "    if [ -d \$temp_restore_dir ]; then"
499
+    echo "        rm -rf \$temp_restore_dir"
500
+    echo '    fi'
501
+    echo ''
502
+fi
484 503
 echo "    restore_directory_from_usb \$temp_restore_dir ${app_name}"
485 504
 echo "    if [ -d \$temp_restore_dir ]; then"
486 505
 echo "        if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then"
@@ -539,6 +558,11 @@ if [[ "$database_type" == "postgres"* ]]; then
539 558
     echo "    backup_database_to_friend ${app_name}"
540 559
     echo ''
541 560
 fi
561
+if [[ "$database_type" == "mongo"* ]]; then
562
+    echo '    USE_MONGODB=1'
563
+    echo "    backup_database_to_friend ${app_name}"
564
+    echo ''
565
+fi
542 566
 if [ $app_daemon ]; then
543 567
     echo ''
544 568
     echo "    systemctl start ${app_name}"
@@ -592,6 +616,16 @@ if [[ "$database_type" == "postgres"* ]]; then
592 616
     echo '    fi'
593 617
     echo ''
594 618
 fi
619
+if [[ "$database_type" == "mongo"* ]]; then
620
+    echo "    ${app_name}_create_database"
621
+    echo ''
622
+    echo '    USE_MONGODB=1'
623
+    echo "    restore_database_from_friend ${app_name}"
624
+    echo "    if [ -d \"\$temp_restore_dir\" ]; then"
625
+    echo "        rm -rf \$temp_restore_dir"
626
+    echo '    fi'
627
+    echo ''
628
+fi
595 629
 echo "    restore_directory_from_friend \$temp_restore_dir ${app_name}"
596 630
 echo "    if [ -d \$temp_restore_dir ]; then"
597 631
 echo "        if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then"
@@ -655,6 +689,9 @@ fi
655 689
 if [[ "$database_type" == "postgres"* ]]; then
656 690
     echo "    drop_database_postgresql ${app_name}"
657 691
 fi
692
+if [[ "$database_type" == "mongo"* ]]; then
693
+    echo "    drop_database_mongodb ${app_name}"
694
+fi
658 695
 echo "    remove_onion_service ${app_name} \"\${${app_name_upper}_ONION_PORT}\""
659 696
 echo "    if grep -q \"${app_name}\" /etc/crontab; then"
660 697
 echo "        sed -i \"/${app_name}/d\" /etc/crontab"
@@ -683,6 +720,10 @@ if [[ "$database_type" == "postgres"* ]]; then
683 720
     echo '    install_postgresql'
684 721
     echo ''
685 722
 fi
723
+if [[ "$database_type" == "mongo"* ]]; then
724
+    echo '    install_mongodb'
725
+    echo ''
726
+fi
686 727
 if [[ "$app_node" == 'yes' ]]; then
687 728
     echo "    install_nodejs ${app_name}"
688 729
 fi
@@ -748,7 +789,7 @@ if [ $app_webui ]; then
748 789
     echo "    chown -R www-data:www-data \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
749 790
 fi
750 791
 
751
-if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"*  ]]; then
792
+if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* || "$database_type" == "mongo"*  ]]; then
752 793
     echo ''
753 794
     echo "    ${app_name}_create_database"
754 795
 fi