From cfaee39e706e2998f023d4693aa49ed29ae7fd27 Mon Sep 17 00:00:00 2001 From: Benedikt Koeppel Date: Sat, 18 Feb 2012 21:02:26 +0100 Subject: [PATCH] new type 'mysql_database' installs a database on an existing mysql_server remotely --- conf/type/__mysql_database/gencode-remote | 48 ++++++++++++++++++ conf/type/__mysql_database/man.text | 49 +++++++++++++++++++ conf/type/__mysql_database/parameter/optional | 3 ++ 3 files changed, 100 insertions(+) create mode 100755 conf/type/__mysql_database/gencode-remote create mode 100644 conf/type/__mysql_database/man.text create mode 100644 conf/type/__mysql_database/parameter/optional diff --git a/conf/type/__mysql_database/gencode-remote b/conf/type/__mysql_database/gencode-remote new file mode 100755 index 00000000..fdfb1501 --- /dev/null +++ b/conf/type/__mysql_database/gencode-remote @@ -0,0 +1,48 @@ +#!/bin/sh +# +# 2012 Benedikt Koeppel (code@benediktkoeppel.ch) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +# if --database was specified +if [ -f "$__object/parameter/database" ]; then + database="$(cat "$__object/parameter/database")" +else # otherwise use the object id as database name + database="$__object_id" +fi + +mysql -u root -p <<-EOF + CREATE DATABASE IF NOT EXISTS $database +EOF + +# if --user was specified +if [ -f "$__object/parameter/user" ]; then + user="$(cat "$__object/parameter/user")" + + # if --password was specified + if [ -f "$__object/parameter/password" ]; then + password="$(cat "$__object/parameter/password")" + mysql -u root -p <<-EOF + GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost' IDENTIFIED BY '$password'; + EOF + else + mysql -u root -p <<-EOF + GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost'; + EOF + fi +fi diff --git a/conf/type/__mysql_database/man.text b/conf/type/__mysql_database/man.text new file mode 100644 index 00000000..3c66eeab --- /dev/null +++ b/conf/type/__mysql_database/man.text @@ -0,0 +1,49 @@ +cdist-type__mysql_database(7) +============================= +Benedikt Koeppel + + +NAME +---- +cdist-type__mysql_database - Manage a MySQL database + + +DESCRIPTION +----------- +This cdist type allows you to install a MySQL database. + + +REQUIRED PARAMETERS +------------------- +None. + +OPTIONAL PARAMETERS +------------------- +database:: + The name of the database to install + defaults to the object id + +user:: + A user that should have access to the database + +password:: + The password for the user who manages the database + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +__mysql_database "cdist" --database "cdist" --user "myuser" --password "mypwd" +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2012 Benedikt Koeppel. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/conf/type/__mysql_database/parameter/optional b/conf/type/__mysql_database/parameter/optional new file mode 100644 index 00000000..ac60a873 --- /dev/null +++ b/conf/type/__mysql_database/parameter/optional @@ -0,0 +1,3 @@ +database +user +password