]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Added script to create db
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 18 Jun 2025 13:40:07 +0000 (09:40 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 18 Jun 2025 13:40:07 +0000 (09:40 -0400)
conf/mailleur.conf
mailleur.spec.in
support/crdb.sh [new file with mode: 0755]
support/starting.sh [changed mode: 0644->0755]

index cc8622f27685b72f9c97559f4519b0fc2fe3096b..0d6e1e0e7d820eeb004f42b18a3c32bd1ab84af1 100644 (file)
@@ -30,7 +30,7 @@ CA_KEY_CLT="./certs/localhost-key.pem"
 CA_VERIFY_CLT=0        #to check PEER/server remote certificate
 #------------------------------------------------
 #Configured for Postgresql database
-#DB_TYPE can be either POSTGRES,MYSQL
+#DB_TYPE can be either POSTGRESQL,MYSQL
 DB_TYPE=TO_BE_DEFINED
 DB_NAME=mailleur
 DB_HOST=localhost
index d17a9e12bba5560cbf394d63c53325624ed05c76..7ba6786c84f2c5fba30d4c894304833a1c081e93 100644 (file)
@@ -39,6 +39,7 @@ search about email exchange within time and transaction context.
 %attr(0755,%{name},mail) %{_sbindir}/sorter
 %attr(0754,root,root) %{_libdir}/%{name}/shell/*.sh
 %attr(0754,root,root) %{_libdir}/%{name}/support/starting.sh
+%attr(0754,root,root) %{_libdir}/%{name}/support/crdb.sh
 %attr(0755,%{name},mail) %dir %{spooldir}/%{name}/{queue,in.log,out.log}
 #-----------------------------------------------------------------------------
 
@@ -148,7 +149,7 @@ Obsoletes   :       %{name}-mysql           <= %{version}-%{release}
 %post                  postgresql
 if [ "$1" = 1 ]; then
   sed -i                                       \
-       -e "s/DB_TO_BE_DEFINED/POSTGRES/"       \
+       -e "s/DB_TO_BE_DEFINED/POSTGRESQL/"     \
        %{_sysconfdir}/%{name}/%{name}.conf
   fi
 
diff --git a/support/crdb.sh b/support/crdb.sh
new file mode 100755 (executable)
index 0000000..cf406be
--- /dev/null
@@ -0,0 +1,56 @@
+#! /bin/sh
+#-------------------------------------------------------------
+#procedure to create the clement data-base the first
+#time the application is installed.
+#-------------------------------------------------------------
+#loading the variable value
+. /etc/mailleur/mailleur.conf
+#-------------------------------------------------------------
+
+#setting the Variable
+#first the Data-base type
+if [ -z "$DB_TYPE" ] ; then
+  DB_TYPE=POSTGRESQL;
+  fi
+
+#Then the data-base name
+if [ -z "$DB_NAME" ] ; then
+  DB_NAME=$APPNAME;
+  fi
+#-------------------------------------------------------------
+#moving to the right directory
+cd $1
+LOG=/etc/$APPNAME/dbinst.log
+USER=`id -nu`
+#building data_base
+case "$DB_TYPE" in 
+  "MYSQL"      )
+    ;;
+  "POSTGRESQL" )
+    SQL="psql -q"
+    if [ ! -z "$DB_PORT" ] ; then
+      SQLPORT="-p $DB_PORT"
+      fi
+    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
+        echo "CREATE ROLE $APPNAME WITH LOGIN CREATEDB SUPERUSER" |    \
+                $SQL $SQLHOST $SQLPORT template1
+        echo "CREATE ROLE apache WITH LOGIN" |                         \
+                $SQL $SQLHOST $SQLPORT template1
+        echo "CREATE ROLE dovecot WITH LOGIN" |                        \
+                $SQL $SQLHOST $SQLPORT template1
+         /usr/bin/createdb -T template0 -E $DB_LANG -O                         \
+                       $APPNAME $SQLHOST $SQLPORT $DB_NAME
+!EOT
+      /bin/echo "data-base is now created" >> $LOG
+      fi
+    ;;
+  "*"          )
+    #undefined database type at that stage?
+    ;;
+  esac
old mode 100644 (file)
new mode 100755 (executable)
index 9de26be..a90c1db
@@ -7,8 +7,8 @@ OS=$1           #set the OS Type
 #Hard coded variables
 APPNAME=mailleur
 #===============================================================
-#----------------------------------------------------------------------
 #reporting a big trouble
+#----------------------------------------------------------------------
 sh_failure()
 
 {
@@ -30,7 +30,6 @@ case "$OS" in
 }
 #----------------------------------------------------------------------
 #procedure to check if the config is properly done
-#you MUST AT LEAST, specify the Data Base type to be used by clement.
 #----------------------------------------------------------------------
 chk_config()
 
@@ -42,8 +41,54 @@ if      [ -z "$DB_TYPE" -o "$DB_TYPE" = "DB_TO_BE_DEFINED" ] ; then
   echo -e "\tAborting start, Exiting at once"
   exit -1;
   fi
+#----------------------------------------------------------------------
+#building application data-base
+#----------------------------------------------------------------------
+do_mkdb()
+
+{
+case "$DB_TYPE" in
+  "MYSQL"              )
+    ;;
+  "POSTGRESQL"         )
+    /usr/lib/$APPNAME/support/crdb.sh "/"
+    ;;
+  "TO_BE_DEFINED"      )
+    echo "You must install $APPNAME with a DB flavor (ex: $APPNAME-pgsql, $APPNAME-mysql)"
+    echo "Exiting now"
+    exit -2;
+    ;;
+  "*"                  )
+    echo "Unexpectd DB_TYPE variable within /etc/sysconfig/$APPNAME, please check"
+    echo "Exiting now"
+    exit -3;
+    ;;
+  esac
+}
 }
+#----------------------------------------------------------------------
+#setting local mailleur configuration
+#----------------------------------------------------------------------
+do_mkconf()
 
+{
+if [ ! -f /etc/$APPNAME/config.done ] ; then
+  do_mkdb ;
+  case "$OS" in 
+    osukiss    )
+      ;;
+    sysvinit   )
+      ;;
+    systemd    )
+      ;;
+    *          )
+      echo "sh_mkconf: Unexpected OS=$OS, exiting!"
+      exit 1
+      ;;
+    esac
+  date > /etc/$APPNAME/config.done
+fi
+}
 #===============================================================
 #main script
 #----------------------------------------------------------------------
@@ -53,5 +98,6 @@ if      [ -z "$DB_TYPE" -o "$DB_TYPE" = "DB_TO_BE_DEFINED" ] ; then
 [ -f /etc/sysconfig/$APPNAME ] && . /etc/sysconfig/$APPNAME
 
 chk_config $1;
+do_mkconf $1;
 exit 0;
 #---------------------------------------------------------------