Files
debian-web-server/bin/mysql-db.sh
T
bachirandClaude Sonnet 5 7ff4df1173 Fix installer bugs: broken root checks, PHP version mismatches, dead paths
- Replace $EUID with $(id -u) for root checks across all bin/*.sh and
  install.sh: dash (Debian's /bin/sh) never sets $EUID, so the check was
  silently broken everywhere.
- lemp.sh: make apt-get upgrade non-interactive (--yes), align the Redis
  PHP module and php-fpm restart with $PHP_VERSION instead of a hardcoded
  8.1, and template the nginx PHP-FPM socket path via a PHP_FPM_SOCK
  placeholder substituted at install time.
- nginx-phpmyadmin.conf: fix docroot to match the actual phpMyAdmin
  symlink location created by lemp.sh.
- mysql-db.sh: inline the root check instead of sourcing the
  nonexistent bin/checkroot.sh.
- webhook.sh: fix chowm typo (chown).
- urbackup.sh: copy the systemd unit from assets/ instead of a relative
  path to a file that doesn't exist in the repo.
- _addUserSite.sh: fix invalid `$var=value` assignment and an empty
  if-block that was a POSIX sh syntax error.

Also carries over pending fixes to deploy-drupal.sh (drush now
invoked via vendor/bin/drush) and gitbarrerepos.sh (comment cleanup).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 09:28:08 +02:00

60 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
echo -e '
_ _ _ _
__| | |__ | | | |___ ___ _ _
/ _` | _ \ | |_| (_-</ -_) _|
\__,_|_.__/ \___//__/\___|_|
'
echo -e "Create new mysql db and user (you will be asked a db name and a password)"
if [ "$(id -u)" -ne 0 ]; then
echo "Please run as root"
exit
fi
sleep 3
# configure
echo -n "Please provide the mysql root passwd : "
read _root_mysql_passwd
mysql -u root -p$_root_mysql_passwd -e "show databases;"
echo -n "Enter new db name: "
read db_name
while [ "$db_name" = "" ]
do
read -p "enter a db name ? " db_name
if [ "$db_name" != "" ]; then
# TODO check if db already exists
# if id "$db_name" >/dev/null 2>&1; then
# echo "user $db_name alreday exists, you must provide a non existing user name."
# db=""
# else
read -p "is db name $db_name correcte [y|n] " validated
if [ "$validated" = "y" ]; then
break
else
db_name=""
fi
# fi
fi
done
# generate random password for new mysql user
_passwd="$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c16)"
# create new mysql user
mysql -u root -p$_root_mysql_passwd -e "CREATE DATABASE $db_name;"
mysql -u root -p$_root_mysql_passwd -e "CREATE USER '$db_name'@'localhost' IDENTIFIED BY '$_passwd';"
mysql -u root -p$_root_mysql_passwd -e "GRANT ALL ON $db_name.* TO '$db_name'@'localhost';"
mysql -u root -p$_root_mysql_passwd -e "show databases;"
echo "database and user : $db_name installed"
echo " please record your password $_passwd"
echo "press any key to continue."
read continu