summaryrefslogtreecommitdiffstats
path: root/satellit_installer/includes/10-handle_mysql.inc
diff options
context:
space:
mode:
authorSimon Rettberg2014-12-11 15:22:51 +0100
committerSimon Rettberg2014-12-11 15:22:51 +0100
commitcbf10febc6e51952b960364f207b055b15c590c7 (patch)
treeed079a90cf32b8ca1abd86ff5476374e846042e8 /satellit_installer/includes/10-handle_mysql.inc
parent[SSPS] gpg_import subroutine moved (diff)
downloadsetup-scripts-cbf10febc6e51952b960364f207b055b15c590c7.tar.gz
setup-scripts-cbf10febc6e51952b960364f207b055b15c590c7.tar.xz
setup-scripts-cbf10febc6e51952b960364f207b055b15c590c7.zip
[SSPS] Add perror handling to mysql functions
Diffstat (limited to 'satellit_installer/includes/10-handle_mysql.inc')
-rw-r--r--satellit_installer/includes/10-handle_mysql.inc64
1 files changed, 29 insertions, 35 deletions
diff --git a/satellit_installer/includes/10-handle_mysql.inc b/satellit_installer/includes/10-handle_mysql.inc
index 5191d08..1038892 100644
--- a/satellit_installer/includes/10-handle_mysql.inc
+++ b/satellit_installer/includes/10-handle_mysql.inc
@@ -6,75 +6,69 @@ preset_mysql_root() {
}
mysql_add_db() {
- echo -n "# Creating mysql database $1..."
+ echo "# Creating mysql database $1..."
echo "create database $1;" | mysql -u root -p"$MYSQL_ROOT_PASS"
ERR=$?
if [ "$ERR" -ne 0 ]; then
- echo
- echo "# Could not create mysql database $1!"
- # Fehlerbehandlung?
- else
- echo "ok."
+ perror "Could not create mysql database $1!"
fi
}
mysql_delete_db() {
# $1 database; $2 password
- echo -n "# Deleting mysql database $1..."
- echo "drop database if exists $1;" | mysql -u root -p${2}
+ echo "# Deleting mysql database $1..."
+ echo "drop database if exists $1;" | mysql -u root -p"${2}"
ERR=$?
if [ "$ERR" -ne 0 ]; then
- echo "# Could not delete mysql user $1!"
- # Fehlerbehandlung?
- else
- echo "ok."
+ perror "Could not delete mysql user $1!"
fi
}
mysql_add_user() {
# $1=user, $2=database, $3=privileges, $4=password
- local TEMPFILE=$(mktemp "$BASEDIR"/temp/mysql_useradd_XXXXX.sql)
- echo -n "# Adding user $1 for database $2, privileges $3..."
- echo "CREATE USER $1@'localhost' IDENTIFIED BY '$4';" > "$TEMPFILE"
- echo "GRANT $3 ON $2.* TO '$1'@'localhost';" >> "$TEMPFILE"
+ echo "# Adding user $1 for database $2, privileges $3..."
+ mysql -u root -p"$MYSQL_ROOT_PASS" <<-CMDS
+ CREATE USER '$1'@'localhost' IDENTIFIED BY '$4';
+ GRANT $3 ON $2.* TO '$1'@'localhost';
+ CMDS
- mysql -u root -p"$MYSQL_ROOT_PASS" < "$TEMPFILE"
ERR=$?
if [ "$ERR" -ne 0 ]; then
- echo
- echo "# Could not add mysql user $1!"
- # Fehlerbehandlung?
- else
- echo "ok."
+ perror "Could not add mysql user!"
+ fi
+}
+
+mysql_add_privs() {
+ # $1=user, $2=database, $3=privileges
+ echo "# Adding privileges $3 for user $1 on database $2..."
+ mysql -u root -p"$MYSQL_ROOT_PASS" <<-CMDS
+ GRANT $3 ON $2.* TO '$1'@'localhost';
+ CMDS
+
+ ERR=$?
+ if [ "$ERR" -ne 0 ]; then
+ perror "Could not add privs!"
fi
- rm -f "$TEMPFILE"
}
mysql_delete_user() {
# $1: mysql user, $2 password
- echo -n "# Deleting mysql user $1..."
+ echo "# Deleting mysql user $1..."
echo "drop user $1@localhost;" | mysql -u root -p${2}
ERR=$?
if [ "$ERR" -ne 0 ]; then
- echo "# Could not delete mysql user $1!"
- # Fehlerbehandlung?
- else
- echo "ok."
+ perror "Could not delete mysql user $1!"
fi
}
mysql_import_dump() {
# $1: dump file, $2: database
- echo -n "# Importing sql dump file $1..."
+ echo "# Importing sql dump file $1..."
mysql -u root -p"$MYSQL_ROOT_PASS" -h localhost "$2" < "$1"
ERR=$?
if [ "$ERR" -ne 0 ]; then
- echo
- echo
- echo "# Could not import sql dump file $1!"
- # Fehlerbehandlung?
- else
- echo "ok."
+ perror "Could not import sql dump file $1!"
fi
}
+