Skip to content

Commit

Permalink
Merge pull request #5 from kamansoft/ll/dev
Browse files Browse the repository at this point in the history
adding mariadb super user creation functionality
  • Loading branch information
lemyskaman authored Nov 9, 2022
2 parents c505b83 + 5b2473b commit f42ccfa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lemptool
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ show_help() {
echo " Usage example:"
echo " $ ./lemptool --mariadb-user-db-create=user password"
echo ""
echo " --mariadb-superuser-create Creates a new Mariadb superuser. and gran all rights"
echo " Usage example:"
echo " $ ./lemptool --mariadb-superuser-create=user password"
echo ""
echo " -p= --php-install= Installs a php version on system together with "
echo " dependencies for laravel development,it also"
echo " installs composer."
Expand Down Expand Up @@ -150,6 +154,11 @@ for i in "$@"; do
add_argument "${i#*=}"
shift # past arg
;;
--mariadb-superuser-create=*)
add_script "add_mdb_superuser"
add_argument "${i#*=}"
shift # past arg
;;
-p=* | --php-install=*)
add_script "install_php"
add_argument "${i#*=}"
Expand Down
38 changes: 38 additions & 0 deletions lemptool_scripts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,45 @@ install_phpmyadmin() {

}

add_mdb_superuser(){
validate_sudo
validate_mariadb


MDB_USERNAME=""
MDB_PASSWORD=""
MDB_HOST="%"
if [ -z "$1" ]; then
echo "Please type the username to add"
read -r MDB_USERNAME
else
MDB_USERNAME="$1"
fi

if [ -z "$2" ]; then
echo "Please type the password for $MDB_USERNAME"
read -r MDB_PASSWORD
else
MDB_PASSWORD="$2"
fi

if [ -n "$3" ]; then
MDB_HOST="$3"
fi



#CREATE_USER_QUERY="CREATE USER '$MDB_USERNAME'@'%' IDENTIFIED BY '$MDB_PASSWORD';GRANT USAGE ON *.* TO '$MDB_USERNAME'@'%' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;CREATE DATABASE IF NOT EXISTS $MDB_USERNAME; GRANT ALL PRIVILEGES ON $MDB_USERNAME.* TO '$MDB_USERNAME'@'%'; "
CREATE_USER_QUERY="CREATE USER IF NOT EXISTS '$MDB_USERNAME'@'%' IDENTIFIED BY '$MDB_PASSWORD';GRANT ALL PRIVILEGES ON *.* TO '$MDB_USERNAME'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;FLUSH PRIVILEGES;"
if echo "$CREATE_USER_QUERY" | mysql ; then
echo "SUPER User $MDB_USERNAME @ $MDB_HOST created "
return 0
else
echo "Error creating user $MDB_USERNAME"
return 1
fi

}
add_mdb_user_with_db(){

validate_sudo
Expand Down

0 comments on commit f42ccfa

Please sign in to comment.