Init script can run on rom command line

This commit is contained in:
Laurent Destailleur 2012-10-05 23:20:18 +02:00
parent 6873e93b7f
commit e5cd2c1941

View File

@ -1,13 +1,16 @@
#!/bin/sh #!/bin/sh
#------------------------------------------------------ #------------------------------------------------------
# Script to purge and init a database with demo values. # Script to purge and init a database with demo values.
# Note: "dialog" tool need to be available. # Note: "dialog" tool need to be available if no parameter provided.
#
# WARNING: This script erase all data of database
# with data into dump file
# #
# Regis Houssin - regis@dolibarr.fr # Regis Houssin - regis@dolibarr.fr
# Laurent Destailleur - eldy@users.sourceforge.net # Laurent Destailleur - eldy@users.sourceforge.net
#------------------------------------------------------ #------------------------------------------------------
# WARNING: This script erase all data of database # Usage: initdemo.sh
# with data into dump file # usage: initdemo.sh mysqldump_dolibarr_x.x.x.sql database port login pass
#------------------------------------------------------ #------------------------------------------------------
@ -17,8 +20,6 @@ then
export mydir="." export mydir="."
fi fi
export id=`id -u`; export id=`id -u`;
export dumpfile=`ls $mydir/mysqldump_dolibarr_*.sql | sort | tail -n 1`
export dumpfile=`basename $dumpfile`
# ----------------------------- check if root # ----------------------------- check if root
@ -28,6 +29,21 @@ then
exit exit
fi fi
# ----------------------------- command line params
dumpfile=$1;
base=$2;
port=$3;
admin=$4;
passwd=$5;
# ----------------------------- if no params on command line
if [ "x$passwd" = "x" ]
then
export dumpfile=`ls $mydir/mysqldump_dolibarr_*.sql | sort | tail -n 1`
export dumpfile=`basename $dumpfile`
# ----------------------------- input file # ----------------------------- input file
DIALOG=${DIALOG=dialog} DIALOG=${DIALOG=dialog}
DIALOG="$DIALOG --ascii-lines" DIALOG="$DIALOG --ascii-lines"
@ -145,6 +161,9 @@ case $? in
255) exit;; 255) exit;;
esac esac
fi
# ---------------------------- run sql file # ---------------------------- run sql file
if [ "x$passwd" != "x" ] if [ "x$passwd" != "x" ]
then then
@ -154,6 +173,12 @@ fi
#mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile #mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
echo "mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile" echo "mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile"
mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
export res=$?
echo "Dolibarr data demo has been loaded." if [ "x$res" = "x0" ]
then
echo "Success, file successfully loaded."
else
echo "Error, load failed."
fi
echo echo