]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Working on shell script crdb.sh
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 23 Jun 2025 23:09:10 +0000 (19:09 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 23 Jun 2025 23:09:10 +0000 (19:09 -0400)
support/crdb.sh
support/starting.sh

index 6cae01c30f52859c94556aa9ab747328f97c44d9..a694c2f60579a0412bf2e414d87fb4b327aab7cd 100755 (executable)
@@ -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
index acfa4064424dd83a39164baa12941bdf74ca8811..3babce65f8ede0c7bcc9bff143792aeca2ad6e1d 100755 (executable)
@@ -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