dolibarr/dev/initdata/initdemo.sh

159 lines
3.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2008-08-19 21:19:29 +02:00
#------------------------------------------------------
# Script to purge and init a database with demo values.
# Note: "dialog" tool need to be available.
#
# Regis Houssin - regis@dolibarr.fr
2008-08-19 21:11:11 +02:00
# Laurent Destailleur - eldy@users.sourceforge.net
2008-08-19 21:19:29 +02:00
#------------------------------------------------------
# WARNING: This script erase all data of database
# with data into dump file
2008-08-19 21:19:29 +02:00
#------------------------------------------------------
2008-08-19 21:11:11 +02:00
2011-07-18 20:31:53 +02:00
export dumpfile="mysqldump_dolibarr_3.1.0.sql"
export mydir=`echo "$0" | sed -e 's/initdemo.sh//'`;
if [ "x$mydir" = "x" ]
then
export mydir="."
fi
2008-12-28 06:22:00 +01:00
export id=`id -u`;
2008-10-08 01:04:12 +02:00
2008-12-28 06:22:00 +01:00
# ----------------------------- check if root
2010-02-14 14:59:00 +01:00
if [ "x$id" != "x0" -a "x$id" != "x1001" ]
2008-12-28 06:22:00 +01:00
then
echo "Script must be ran as root"
exit
fi
# ----------------------------- input file
DIALOG=${DIALOG=dialog}
DIALOG="$DIALOG --ascii-lines"
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Input dump file :" 16 55 $dumpfile 2> $fichtemp
valret=$?
case $valret in
0)
dumpfile=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2008-12-28 06:22:00 +01:00
# ----------------------------- database name
2008-08-19 21:01:31 +02:00
DIALOG=${DIALOG=dialog}
2008-08-19 21:11:11 +02:00
DIALOG="$DIALOG --ascii-lines"
2008-08-19 21:01:31 +02:00
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15
2008-10-08 01:04:12 +02:00
$DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Mysql database name :" 16 55 dolibarrdemo 2> $fichtemp
2008-08-19 21:01:31 +02:00
valret=$?
case $valret in
0)
base=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2008-12-28 06:22:00 +01:00
# ---------------------------- database port
DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Mysql port (ex: 3306):" 16 55 3306 2> $fichtemp
2008-12-28 06:22:00 +01:00
valret=$?
case $valret in
0)
port=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2008-08-19 21:01:31 +02:00
# ---------------------------- compte admin mysql
DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15
2008-10-08 01:04:12 +02:00
$DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Mysql root login (ex: root):" 16 55 root 2> $fichtemp
2008-08-19 21:01:31 +02:00
valret=$?
case $valret in
0)
admin=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2008-12-28 06:22:00 +01:00
2008-08-19 21:01:31 +02:00
# ---------------------------- mot de passe admin mysql
DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15
2008-10-08 01:04:12 +02:00
$DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Password for Mysql root login :" 16 55 2> $fichtemp
2008-08-19 21:01:31 +02:00
valret=$?
case $valret in
0)
passwd=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2008-12-28 06:22:00 +01:00
2009-08-04 09:25:41 +02:00
# ---------------------------- chemin d'acces du repertoire documents
2010-02-14 15:22:25 +01:00
#DIALOG=${DIALOG=dialog}
#fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
#trap "rm -f $fichtemp" 0 1 2 5 15
#$DIALOG --title "Init Dolibarr with demo values" --clear \
# --inputbox "Full path to documents directory (ex: /var/www/dolibarr/documents)- no / at end :" 16 55 2> $fichtemp
2010-02-14 15:22:25 +01:00
#valret=$?
#case $valret in
# 0)
#docs=`cat $fichtemp`;;
# 1)
#exit;;
# 255)
#exit;;
#esac
2008-12-28 06:22:00 +01:00
2008-08-19 21:01:31 +02:00
# ---------------------------- confirmation
DIALOG=${DIALOG=dialog}
2008-08-19 21:19:29 +02:00
$DIALOG --title "Init Dolibarr with demo values" --clear \
--yesno "Do you confirm ? \n Dump file : '$dumpfile' \n Dump dir : '$mydir' \n Mysql database : '$base' \n Mysql port : '$port' \n Mysql login: '$admin' \n Mysql password : '$passwd'" 15 55
2008-08-19 21:01:31 +02:00
case $? in
2008-08-19 21:19:29 +02:00
0) echo "Ok, start process...";;
2008-08-19 21:01:31 +02:00
1) exit;;
255) exit;;
esac
# ---------------------------- run sql file
2008-12-28 06:22:00 +01:00
if [ "x$passwd" != "x" ]
then
export passwd="-p$passwd"
fi
#echo "mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile"
#mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
echo "mysql -P$port $base < $mydir/$dumpfile"
mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
2008-10-08 01:04:12 +02:00
echo "Dolibarr data demo has been loaded."
echo