From: Jean-Marc Pigeon (Delson) Date: Mon, 23 Jun 2025 23:09:10 +0000 (-0400) Subject: Working on shell script crdb.sh X-Git-Tag: tag-0.9~6 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=cc6135655231282a9a2b12965dbc2e11e3b0a96c;p=jmp%2Fmailleur Working on shell script crdb.sh --- diff --git a/support/crdb.sh b/support/crdb.sh index 6cae01c..a694c2f 100755 --- a/support/crdb.sh +++ b/support/crdb.sh @@ -1,5 +1,6 @@ #! /bin/sh #------------------------------------------------------------- +#$1 working directory #procedure to create the clement data-base the first #time the application is installed. #------------------------------------------------------------- @@ -23,30 +24,47 @@ cd $1 LOG=/etc/$APPNAME/dbinst.log USER=`id -nu` #building data_base +( +echo "#------------------------------------------" +date +/bin/echo "creating $DB_TYPE:$DB_NAME data-base" >> $LOG +) >> $LOG + case "$DB_TYPE" in "TO_BE_DEFINED" ) echo "Data base type is NOT set within mailleur.conf" exit 1 ;; "MYSQL" ) - SQL="mysqld" - /etc/rc.d/init.d/mysqld stop - #grabbing temporary control on the MySQL daemo - /usr/bin/mysqld_safe -u root --skip-grant-tables >> $LOG 2>&1 - sleep 5 #give time to daemon to start - ( - echo "CREATE TABLE user_bck AS (SELECT * FROM user);" - echo "UPDATE user SET Password=NULL WHERE User='root' AND Host='localhost';" - ) | mysql -u root mysql >> $LOG - ( - echo "Shutdown mysqld skip-grant-tables mode" - /usr/bin/mysqladmin -u root shutdown - echo "starting mysqld daemon" - /etc/rc.d/init.d/mysqld start - ) >> $LOG + SQL="/usr/bin/mariadb" + /etc/rc.d/init.d/mysqld status + if [ $? != 0 ] ; then + echo "MySQL serveur NOT found up and running (exiting!)" + exit 1 + fi + if [ ! -z "$DB_PORT" ] ; then + SQLPORT="-P $DB_PORT" + fi + SQLHOST="-h localhost"; + if [ ! -z "$DB_HOST" ] ; then + SQLHOST="-h $DB_HOST" + fi + if [ "$USER" = "root" ] ; then + chown $APPNAME $LOG + ( + CREATE DATABASE '$APPNAME'; + CREATE USER '$APPNAME'@'localhost'; + GRANT ALL PRIVILEGES ON '$APPNAME'.* TO '$APPNAME'@'localhost'; + FLUSH PRIVILEGES; + ) | $SQL $SQLHOST $SQLPORT >> $LOG + /bin/echo "data-base is now created" >> $LOG + fi + ;; + "*" ) + #undefined database type at that stage? ;; "POSTGRESQL" ) - SQL="psql -q" + SQL="/usr/bin/psql -q" /etc/rc.d/init.d/postgresql status if [ $? != 0 ] ; then echo "Postgresql serveur NOT found up and running (exiting!)" @@ -58,7 +76,6 @@ case "$DB_TYPE" in if [ ! -z "$DB_HOST" ] ; then SQLHOST="-h $DB_HOST" fi - /bin/echo "creating $DB_TYPE:$DB_NAME data-base" >> $LOG if [ "$USER" = "root" ] ; then chown $APPNAME $LOG /bin/su - -m postgres >> $LOG << !EOT diff --git a/support/starting.sh b/support/starting.sh index acfa406..3babce6 100755 --- a/support/starting.sh +++ b/support/starting.sh @@ -116,7 +116,7 @@ do_mkdb() case "$DB_TYPE" in "MYSQL" | \ "POSTGRESQL" ) - /usr/lib/$APPNAME/support/crdb.sh "/" + /usr/lib/$APPNAME/support/crdb.sh "/tmp" if [ $? != 0 ] ; then exit -1 fi