reecriture fonction checkdb
This commit is contained in:
parent
e38d98b1a1
commit
69aef9fb9f
30
bin/postauto
30
bin/postauto
@ -5,19 +5,25 @@ source /home/$USER/autopost/common.sh
|
|||||||
# ========== FONCTIONS SCRIPT ==========
|
# ========== FONCTIONS SCRIPT ==========
|
||||||
|
|
||||||
checkdb() {
|
checkdb() {
|
||||||
if [ "$dbtype" = "sqlite" ]; then
|
if [ "$dbtype" = "sqlite" ]; then
|
||||||
if [ ! -f "$DB_FILE" ]; then
|
if [ ! -f "$DB_FILE" ]; then
|
||||||
echo "La base de données n'existe pas. Création..."
|
echo "La base de données SQLite n'existe pas. Création…"
|
||||||
do_createdb
|
do_createdb
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Vérifie si la table existe, sinon crée-la
|
|
||||||
exists=$(db_query "SHOW TABLES LIKE \`$MYSQL_TABLE\`;")
|
|
||||||
if [ -z "$exists" ]; then
|
|
||||||
echo "La table 'release' n'existe pas. Création..."
|
|
||||||
do_createdb
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Échapper _ et % pour LIKE
|
||||||
|
local pattern=${MYSQL_TABLE//_/\\_}
|
||||||
|
pattern=${pattern//%/\\%}
|
||||||
|
|
||||||
|
# Assure-toi que db_query utilise `mysql -N -B` pour ne pas avoir d'entêtes
|
||||||
|
local exists
|
||||||
|
exists=$(db_query "SHOW TABLES LIKE '${pattern}';" | tr -d '[:space:]')
|
||||||
|
|
||||||
|
if [ -z "$exists" ]; then
|
||||||
|
echo "La table '${MYSQL_TABLE}' n'existe pas. Création…"
|
||||||
|
do_createdb
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
do_start() {
|
do_start() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user