pma.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. #
  3. # phpmyadmin-fixer
  4. #
  5. # Fixes for phpmyadmin (configuration storage and some extended features)
  6. #
  7. # Original Version by Pavel Galkin (https://skurudo.ru)
  8. # https://github.com/skurudo/phpmyadmin-fixer
  9. #
  10. # Changed some lines to fit to Hestia Configuration.
  11. #
  12. PASS=$(gen_pass)
  13. #ubuntu phpmyadmin path
  14. pmapath="/etc/phpmyadmin/conf.d/01-localhost.php"
  15. echo "<?php " >> $pmapath
  16. echo "\$cfg['Servers'][\$i]['host'] = 'localhost';" >> $pmapath
  17. echo "\$cfg['Servers'][\$i]['port'] = '3306';" >> $pmapath
  18. echo "\$cfg['Servers'][\$i]['favorite'] = 'pma__favorite';" >> $pmapath
  19. echo "\$cfg['Servers'][\$i]['usergroups'] = 'pma__usergroups';" >> $pmapath
  20. echo "\$cfg['Servers'][\$i]['central_columns'] = 'pma__central_columns';" >> $pmapath
  21. echo "\$cfg['Servers'][\$i]['designer_settings'] = 'pma__designer_settings';" >> $pmapath
  22. echo "\$cfg['Servers'][\$i]['export_templates'] = 'pma__export_templates';" >> $pmapath
  23. echo "\$cfg['Servers'][\$i]['savedsearches'] = 'pma__savedsearches';" >> $pmapath
  24. echo "\$cfg['Servers'][\$i]['navigationhiding'] = 'pma__navigationhiding';" >> $pmapath
  25. echo "\$cfg['Servers'][\$i]['users'] = 'pma__users';" >> $pmapath
  26. echo "\$cfg['Servers'][\$i]['usergroups'] = 'pma__usergroups';" >> $pmapath
  27. echo "\$cfg['Servers'][\$i]['pmadb'] = 'phpmyadmin';" >> $pmapath
  28. echo "\$cfg['Servers'][\$i]['controluser'] = 'pma';" >> $pmapath
  29. echo "\$cfg['Servers'][\$i]['controlpass'] = '$PASS';" >> $pmapath
  30. echo "\$cfg['Servers'][\$i]['bookmarktable'] = 'pma__bookmark';" >> $pmapath
  31. echo "\$cfg['Servers'][\$i]['relation'] = 'pma__relation';" >> $pmapath
  32. echo "\$cfg['Servers'][\$i]['userconfig'] = 'pma__userconfig';" >> $pmapath
  33. echo "\$cfg['Servers'][\$i]['table_info'] = 'pma__table_info';" >> $pmapath
  34. echo "\$cfg['Servers'][\$i]['column_info'] = 'pma__column_info';" >> $pmapath
  35. echo "\$cfg['Servers'][\$i]['history'] = 'pma__history';" >> $pmapath
  36. echo "\$cfg['Servers'][\$i]['recent'] = 'pma__recent';" >> $pmapath
  37. echo "\$cfg['Servers'][\$i]['table_uiprefs'] = 'pma__table_uiprefs';" >> $pmapath
  38. echo "\$cfg['Servers'][\$i]['tracking'] = 'pma__tracking';" >> $pmapath
  39. echo "\$cfg['Servers'][\$i]['table_coords'] = 'pma__table_coords';" >> $pmapath
  40. echo "\$cfg['Servers'][\$i]['pdf_pages'] = 'pma__pdf_pages';" >> $pmapath
  41. echo "\$cfg['Servers'][\$i]['designer_coords'] = 'pma__designer_coords';" >> $pmapath
  42. echo "\$cfg['Servers'][\$i]['hide_db'] = 'information_schema';" >> $pmapath
  43. #SOME WORK with DATABASE (table / user)
  44. PMADB=phpmyadmin
  45. PMAUSER=pma
  46. #DROP USER and TABLE
  47. #mysql -uroot <<MYSQL_PMA1
  48. #DROP USER '$PMAUSER'@'localhost';
  49. #DROP DATABASE $PMADB;
  50. #FLUSH PRIVILEGES;
  51. #MYSQL_PMA1
  52. #CREATE PMA USER
  53. if [ -f '/usr/bin/mariadb' ]; then
  54. mysql_server="mariadb"
  55. else
  56. mysql_server="mysql"
  57. fi
  58. mysql_out=$(mktemp)
  59. $mysql -e 'SELECT VERSION()' > $mysql_out
  60. mysql_ver=$(cat $mysql_out | tail -n1 | cut -f 1 -d -)
  61. mysql_ver_sub=$(echo $mysql_ver | cut -d '.' -f1)
  62. mysql_ver_sub_sub=$(echo $mysql_ver | cut -d '.' -f2)
  63. if [ "$mysql" = "mysql" ] && [ "$mysql_ver_sub" -ge 8 ]; then
  64. query="CREATE USER '$PMAUSER'@'localhost' IDENTIFIED BY '$PASS';"
  65. $mysql_server -uroot -e "$query" > /dev/null
  66. query="CREATE DATABASE $PMADB;"
  67. $mysql_server -uroot -e "$query" > /dev/null
  68. query="GRANT USAGE ON $PMADB.* TO '$PMAUSER'@'localhost';"
  69. $mysql_server -uroot -e "$query" > /dev/null
  70. query="GRANT ALL PRIVILEGES ON $PMADB.* TO '$PMAUSER'@'localhost';"
  71. $mysql_server -uroot -e "$query" > /dev/null
  72. query="FLUSH PRIVILEGES;"
  73. $mysql_server -uroot -e "$query" > /dev/null
  74. else
  75. query="CREATE USER '$PMAUSER'@'localhost' IDENTIFIED BY '$PASS';"
  76. $mysql_server -uroot -e "$query" > /dev/null
  77. query="CREATE DATABASE $PMADB;"
  78. $mysql_server -uroot -e "$query" > /dev/null
  79. query="GRANT USAGE ON $PMADB.* TO '$PMAUSER'@'localhost' IDENTIFIED BY '$PASS';"
  80. $mysql_server -uroot -e "$query" > /dev/null
  81. query="GRANT ALL PRIVILEGES ON $PMADB.* TO '$PMAUSER'@'localhost';"
  82. $mysql_server -uroot -e "$query" > /dev/null
  83. query="FLUSH PRIVILEGES;"
  84. $mysql_server -uroot -e "$query" > /dev/null
  85. fi
  86. #MYSQL DB and TABLES ADDITION
  87. $mysql_server -uroot < "$HESTIA_INSTALL_DIR/phpmyadmin/create_tables.sql"