Browse Source

Ajouter la fonction GENERATE_DB

magikcypress 8 years ago
parent
commit
dd78dad684
1 changed files with 15 additions and 0 deletions
  1. 15 0
      scripts/.fonctions

+ 15 - 0
scripts/.fonctions

@@ -59,6 +59,21 @@ ALL_QUIET () {	# Redirige la sortie standard et d'erreur dans /dev/null
 	eval "$@" > /dev/null 2>&1
 }
 
+#=================================================
+# Create a database and a dedicated user in the name of the app
+#=================================================
+GENERATE_DB () {	
+	# $1 = Database name
+	# Generates a random password.
+	db_user=$1
+	db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
+	CHECK_VAR "$db_pwd" "db_pwd empty"
+	# Uses '$ app' as user name and database
+	# Initializes the database and stores the mysql password.
+	ynh_mysql_create_db "$db_user" "$db_user" $db_pwd
+	ynh_app_setting_set $app mysqlpwd $db_pwd
+}
+
 #=================================================
 # SETUP
 #=================================================