Browse Source

Template support for mongodb

Bob Mottram 6 years ago
parent
commit
6d7cd198bb
1 changed files with 61 additions and 20 deletions
  1. 61
    20
      src/freedombone-template

+ 61
- 20
src/freedombone-template View File

55
     echo $'Creates a new app script which can then be filled in'
55
     echo $'Creates a new app script which can then be filled in'
56
     echo ''
56
     echo ''
57
     echo ''
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
     echo ''
74
     echo ''
75
     exit 0
75
     exit 0
76
 }
76
 }
322
 echo "    \"\${PROJECT_NAME}-pass\" -u \"\$curr_username\" -a ${app_name} -p \"\$new_user_password\""
322
 echo "    \"\${PROJECT_NAME}-pass\" -u \"\$curr_username\" -a ${app_name} -p \"\$new_user_password\""
323
 echo '}'
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
     echo ''
326
     echo ''
327
     echo "function ${app_name}_create_database {"
327
     echo "function ${app_name}_create_database {"
328
     echo "    if [ -f \$IMAGE_PASSWORD_FILE ]; then"
328
     echo "    if [ -f \$IMAGE_PASSWORD_FILE ]; then"
336
     echo '        return'
336
     echo '        return'
337
     echo '    fi'
337
     echo '    fi'
338
     echo ''
338
     echo ''
339
-    if [[ "$database_type" != "postgres"* ]]; then
339
+    if [[ "$database_type" = "mysql" || "$database_type" = "mariadb" ]]; then
340
         echo "    create_database ${app_name} \"\$${app_name_upper}_ADMIN_PASSWORD\" \$MY_USERNAME"
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
         echo '    systemctl restart postgresql'
346
         echo '    systemctl restart postgresql'
343
         echo "    run_system_query_postgresql \"CREATE USER peertube WITH PASSWORD '\$${app_name_upper}_ADMIN_PASSWORD';\""
347
         echo "    run_system_query_postgresql \"CREATE USER peertube WITH PASSWORD '\$${app_name_upper}_ADMIN_PASSWORD';\""
344
         echo "    run_system_query_postgresql \"CREATE DATABASE ${app_name} OWNER ${app_name};\""
348
         echo "    run_system_query_postgresql \"CREATE DATABASE ${app_name} OWNER ${app_name};\""
430
     echo "    backup_database_to_usb ${app_name}"
434
     echo "    backup_database_to_usb ${app_name}"
431
     echo ''
435
     echo ''
432
 fi
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
 if [ $app_webui ]; then
442
 if [ $app_webui ]; then
434
     echo '    restart_site'
443
     echo '    restart_site'
435
 fi
444
 fi
481
     echo '    fi'
490
     echo '    fi'
482
     echo ''
491
     echo ''
483
 fi
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
 echo "    restore_directory_from_usb \$temp_restore_dir ${app_name}"
503
 echo "    restore_directory_from_usb \$temp_restore_dir ${app_name}"
485
 echo "    if [ -d \$temp_restore_dir ]; then"
504
 echo "    if [ -d \$temp_restore_dir ]; then"
486
 echo "        if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then"
505
 echo "        if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then"
539
     echo "    backup_database_to_friend ${app_name}"
558
     echo "    backup_database_to_friend ${app_name}"
540
     echo ''
559
     echo ''
541
 fi
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
 if [ $app_daemon ]; then
566
 if [ $app_daemon ]; then
543
     echo ''
567
     echo ''
544
     echo "    systemctl start ${app_name}"
568
     echo "    systemctl start ${app_name}"
592
     echo '    fi'
616
     echo '    fi'
593
     echo ''
617
     echo ''
594
 fi
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
 echo "    restore_directory_from_friend \$temp_restore_dir ${app_name}"
629
 echo "    restore_directory_from_friend \$temp_restore_dir ${app_name}"
596
 echo "    if [ -d \$temp_restore_dir ]; then"
630
 echo "    if [ -d \$temp_restore_dir ]; then"
597
 echo "        if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then"
631
 echo "        if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then"
655
 if [[ "$database_type" == "postgres"* ]]; then
689
 if [[ "$database_type" == "postgres"* ]]; then
656
     echo "    drop_database_postgresql ${app_name}"
690
     echo "    drop_database_postgresql ${app_name}"
657
 fi
691
 fi
692
+if [[ "$database_type" == "mongo"* ]]; then
693
+    echo "    drop_database_mongodb ${app_name}"
694
+fi
658
 echo "    remove_onion_service ${app_name} \"\${${app_name_upper}_ONION_PORT}\""
695
 echo "    remove_onion_service ${app_name} \"\${${app_name_upper}_ONION_PORT}\""
659
 echo "    if grep -q \"${app_name}\" /etc/crontab; then"
696
 echo "    if grep -q \"${app_name}\" /etc/crontab; then"
660
 echo "        sed -i \"/${app_name}/d\" /etc/crontab"
697
 echo "        sed -i \"/${app_name}/d\" /etc/crontab"
683
     echo '    install_postgresql'
720
     echo '    install_postgresql'
684
     echo ''
721
     echo ''
685
 fi
722
 fi
723
+if [[ "$database_type" == "mongo"* ]]; then
724
+    echo '    install_mongodb'
725
+    echo ''
726
+fi
686
 if [[ "$app_node" == 'yes' ]]; then
727
 if [[ "$app_node" == 'yes' ]]; then
687
     echo "    install_nodejs ${app_name}"
728
     echo "    install_nodejs ${app_name}"
688
 fi
729
 fi
748
     echo "    chown -R www-data:www-data \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
789
     echo "    chown -R www-data:www-data \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\""
749
 fi
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
     echo ''
793
     echo ''
753
     echo "    ${app_name}_create_database"
794
     echo "    ${app_name}_create_database"
754
 fi
795
 fi