From 6d7cd198bbd9a90a6002779b8668fc0c8f81f794 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 11 May 2018 11:00:06 +0100 Subject: [PATCH] Template support for mongodb --- src/freedombone-template | 81 ++++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/src/freedombone-template b/src/freedombone-template index bf09f156..e39df783 100755 --- a/src/freedombone-template +++ b/src/freedombone-template @@ -55,22 +55,22 @@ function show_help { echo $'Creates a new app script which can then be filled in' echo '' echo '' - echo $' -h --help Show help' - echo $' -a --app [name] Name of the application' - echo $' -n --name [name] Your name' - echo $' -e --email [address] Your email address' - echo $' -r --repo [url] Git repo url for the app' - echo $' -c --commit [hash] Git commit' - echo $' --port [number] Port number for the app' - echo $' --portinternal [number] Internal port between a daemon and the web server' - echo $' --node [yes|no] Is this a nodejs app?' - echo $' --nodeapp [package] Specify a nodejs package to install' - echo $' -o --onion [yes|no] Is this app only available on an onion address?' - echo $' -p --php [yes|no] Is this a PHP app?' - echo $' -s --daemon [yes|no] Add a daemon' - echo $' -d --database [mariadb|postgresql] Type of database' - echo $' -w --web [yes|no] Whether there is a web user interface (default is yes)' - echo $' --dir [directory] Where to install to' + echo $' -h --help Show help' + echo $' -a --app [name] Name of the application' + echo $' -n --name [name] Your name' + echo $' -e --email [address] Your email address' + echo $' -r --repo [url] Git repo url for the app' + echo $' -c --commit [hash] Git commit' + echo $' --port [number] Port number for the app' + echo $' --portinternal [number] Internal port between a daemon and the web server' + echo $' --node [yes|no] Is this a nodejs app?' + echo $' --nodeapp [package] Specify a nodejs package to install' + echo $' -o --onion [yes|no] Is this app only available on an onion address?' + echo $' -p --php [yes|no] Is this a PHP app?' + echo $' -s --daemon [yes|no] Add a daemon' + echo $' -d --database [mariadb|postgresql|mongodb] Type of database' + echo $' -w --web [yes|no] Whether there is a web user interface (default is yes)' + echo $' --dir [directory] Where to install to' echo '' exit 0 } @@ -322,7 +322,7 @@ echo '' echo " \"\${PROJECT_NAME}-pass\" -u \"\$curr_username\" -a ${app_name} -p \"\$new_user_password\"" echo '}' -if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* ]]; then +if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* || "$database_type" == "mongo"* ]]; then echo '' echo "function ${app_name}_create_database {" echo " if [ -f \$IMAGE_PASSWORD_FILE ]; then" @@ -336,9 +336,13 @@ if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database echo ' return' echo ' fi' echo '' - if [[ "$database_type" != "postgres"* ]]; then + if [[ "$database_type" = "mysql" || "$database_type" = "mariadb" ]]; then echo " create_database ${app_name} \"\$${app_name_upper}_ADMIN_PASSWORD\" \$MY_USERNAME" - else + fi + if [[ "$database_type" = "mongo"* ]]; then + echo " create_database_mongodb ${app_name} \"\$${app_name_upper}_ADMIN_PASSWORD\" \$MY_USERNAME" + fi + if [[ "$database_type" == "postgres"* ]]; then echo ' systemctl restart postgresql' echo " run_system_query_postgresql \"CREATE USER peertube WITH PASSWORD '\$${app_name_upper}_ADMIN_PASSWORD';\"" echo " run_system_query_postgresql \"CREATE DATABASE ${app_name} OWNER ${app_name};\"" @@ -430,6 +434,11 @@ if [[ "$database_type" == "postgres"* ]]; then echo " backup_database_to_usb ${app_name}" echo '' fi +if [[ "$database_type" == "mongo"* ]]; then + echo ' USE_MONGODB=1' + echo " backup_database_to_usb ${app_name}" + echo '' +fi if [ $app_webui ]; then echo ' restart_site' fi @@ -481,6 +490,16 @@ if [[ "$database_type" == "postgres"* ]]; then echo ' fi' echo '' fi +if [[ "$database_type" == "mongo"* ]]; then + echo " ${app_name}_create_database" + echo '' + echo ' USE_MONGODB=1' + echo " restore_database ${app_name}" + echo " if [ -d \$temp_restore_dir ]; then" + echo " rm -rf \$temp_restore_dir" + echo ' fi' + echo '' +fi echo " restore_directory_from_usb \$temp_restore_dir ${app_name}" echo " if [ -d \$temp_restore_dir ]; then" echo " if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then" @@ -539,6 +558,11 @@ if [[ "$database_type" == "postgres"* ]]; then echo " backup_database_to_friend ${app_name}" echo '' fi +if [[ "$database_type" == "mongo"* ]]; then + echo ' USE_MONGODB=1' + echo " backup_database_to_friend ${app_name}" + echo '' +fi if [ $app_daemon ]; then echo '' echo " systemctl start ${app_name}" @@ -592,6 +616,16 @@ if [[ "$database_type" == "postgres"* ]]; then echo ' fi' echo '' fi +if [[ "$database_type" == "mongo"* ]]; then + echo " ${app_name}_create_database" + echo '' + echo ' USE_MONGODB=1' + echo " restore_database_from_friend ${app_name}" + echo " if [ -d \"\$temp_restore_dir\" ]; then" + echo " rm -rf \$temp_restore_dir" + echo ' fi' + echo '' +fi echo " restore_directory_from_friend \$temp_restore_dir ${app_name}" echo " if [ -d \$temp_restore_dir ]; then" echo " if [ -d \"\$temp_restore_dir\$${app_name}_dir\" ]; then" @@ -655,6 +689,9 @@ fi if [[ "$database_type" == "postgres"* ]]; then echo " drop_database_postgresql ${app_name}" fi +if [[ "$database_type" == "mongo"* ]]; then + echo " drop_database_mongodb ${app_name}" +fi echo " remove_onion_service ${app_name} \"\${${app_name_upper}_ONION_PORT}\"" echo " if grep -q \"${app_name}\" /etc/crontab; then" echo " sed -i \"/${app_name}/d\" /etc/crontab" @@ -683,6 +720,10 @@ if [[ "$database_type" == "postgres"* ]]; then echo ' install_postgresql' echo '' fi +if [[ "$database_type" == "mongo"* ]]; then + echo ' install_mongodb' + echo '' +fi if [[ "$app_node" == 'yes' ]]; then echo " install_nodejs ${app_name}" fi @@ -748,7 +789,7 @@ if [ $app_webui ]; then echo " chown -R www-data:www-data \"/var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs\"" fi -if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* ]]; then +if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* || "$database_type" == "mongo"* ]]; then echo '' echo " ${app_name}_create_database" fi