diff --git a/.gitignore b/.gitignore index 3f05f5a..065d6f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ err.log out.log +mys.log *.sql .DS_Store diff --git a/commands/mys_cpdb b/commands/mys_cpdb deleted file mode 100755 index 2f6819a..0000000 --- a/commands/mys_cpdb +++ /dev/null @@ -1,17 +0,0 @@ -#! /bin/bash -. ~/.config/mys.conf - -file=$1 -db=$2 - -copydb() { - mysql -u ${MYS_NAME} --password=${MYS_PASS} ${db} < $file; -} - -copydb > out.log 2> err.log - -if [ $? -eq 0 ]; then - printf -- "\e[32mSuccessfully copied ${file} into ${db}!\e[39m\n" -else - printf -- "\e[31mOops! Something wasn't right, please check the mys_helper err.log\e[39m" -fi \ No newline at end of file diff --git a/commands/mys_ddb b/commands/mys_ddb deleted file mode 100755 index 7151482..0000000 --- a/commands/mys_ddb +++ /dev/null @@ -1,16 +0,0 @@ -#! /bin/bash -. ~/.config/mys.conf - -db=$1 - -dropdb() { - mysql -u ${MYS_NAME} --password=${MYS_PASS} -e "drop database ${db};" -} - -dropdb > out.log 2> err.log - -if [ $? -eq 0 ]; then - printf -- "\e[32mSuccessfully dropped ${db}!\e[39m\n" -else - printf -- "\e[31mOops! Something wasn't right, please check the mys_helper err.log\e[39m" -fi \ No newline at end of file diff --git a/commands/mys_mkdb b/commands/mys_mkdb deleted file mode 100755 index da0bf5d..0000000 --- a/commands/mys_mkdb +++ /dev/null @@ -1,16 +0,0 @@ -#! /bin/bash -. ~/.config/mys.conf - -db=$1 - -makedb() { - mysql -u ${MYS_NAME} --password=${MYS_PASS} -e "create database ${db};" -} - -makedb > out.log 2> err.log - -if [ $? -eq 0 ]; then - printf -- "\e[32mSuccessfully created ${db}!\e[39m\n" -else - printf -- "\e[31mOops! Something wasn't right, please check the mys_helper err.log\e[39m" -fi \ No newline at end of file diff --git a/mys b/mys index ec5147d..fa459a1 100755 --- a/mys +++ b/mys @@ -3,7 +3,7 @@ # ----- # if this is your first time here, please run `mys -h` for more info. -version=0.1.1 +version=0.1.2 main() { CFG=~/.config/mys.conf @@ -34,15 +34,15 @@ main() { ;; "mkdb") printf -- "\e[1;32mCreating a fresh db with name: \e[42;90m ${args[1]} \e[0m\n" - . ./commands/mys_mkdb ${args[1]} + mkdb ${args[1]} ;; "ddb") printf -- "\e[1;32mDropping ${args[1]}\e[0m\n" - . ./commands/mys_ddb ${args[1]} + ddb ${args[1]} ;; "cpdb") printf -- "\e[1;32mCopying ${args[1]} into ${args[2]}\e[0m\n" - . ./commands/mys_cpdb ${args[1]} ${args[2]} + cpdb ${args[1]} ${args[2]} ;; *) printf -- "\e[91mSorry, mys doesn't recognise that command. (${args[0]})\n" @@ -50,6 +50,56 @@ main() { esac } +# functions +initconfig() { + . ~/.config/mys.conf +} + +mkdb() { + initconfig + + db=$1 + + mysql -u ${MYS_NAME} --password=${MYS_PASS} -e "create database ${db};" > mys.log 2>&1 + + if [ $? -eq 0 ]; then + printf -- "\e[32mSuccessfully created ${db}!\e[39m\n" + else + printf -- "\e[31mOops! Something wasn't right, please check the mys.log\e[39m" + fi +} + +ddb() { + initconfig + + db=$1 + + mysql -u ${MYS_NAME} --password=${MYS_PASS} -e "drop database ${db};" > mys.log 2>&1 + + if [ $? -eq 0 ]; then + printf -- "\e[32mSuccessfully dropped ${db}!\e[39m\n" + else + printf -- "\e[31mOops! Something wasn't right, please check the mys.log\e[39m" + fi +} + +cpdb() { + initconfig + + file=$1 + db=$2 + + mysql -u ${MYS_NAME} --password=${MYS_PASS} ${db} < ${file} > mys.log 2>&1 + + if [ $? -eq 0 ]; then + printf -- "\e[32mSuccessfully copied ${file} into ${db}!\e[39m\n" + else + printf -- "\e[31mOops! Something wasn't right, please check the mys.log\e[39m" + fi +} + +# endfunction + # Check if a config file exists configexists() { if [ ! -e ~/.config/mys.conf ]