Skip to content

Commit

Permalink
Fix: Script to load demo works with sudo and all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 6, 2011
1 parent 6cf20da commit f46c148
Show file tree
Hide file tree
Showing 3 changed files with 5,310 additions and 14 deletions.
52 changes: 38 additions & 14 deletions dev/initdata/initdemo.sh
@@ -1,32 +1,56 @@
#!/bin/sh
#!/bin/bash
#------------------------------------------------------
# Script to purge and init a database with demo values.
# Note: "dialog" tool need to be available.
#
# Regis Houssin - regis@dolibarr.fr
# Regis Houssin - regis@dolibarr.fr
# Laurent Destailleur - eldy@users.sourceforge.net
#------------------------------------------------------
# WARNING: This script erase all data of database
# with data into initdemo.sql
# with data into dump file
#------------------------------------------------------

export mydir=`echo "$_" | sed -e 's/initdemo.sh//'`;

export dumpfile="mysqldump_dolibarr_3.0.0.sql"
export mydir=`echo "$0" | sed -e 's/initdemo.sh//'`;
if [ "x$mydir" = "x" ]
then
export mydir="."
fi
export id=`id -u`;


# ----------------------------- check if root
if [ "x$id" != "x0" -a "x$id" != "x1001" ]
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)
base=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac

# ----------------------------- database name
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 "Mysql database name :" 16 51 dolibarrdemo 2> $fichtemp
--inputbox "Mysql database name :" 16 55 dolibarrdemo 2> $fichtemp
valret=$?
case $valret in
0)
Expand All @@ -42,7 +66,7 @@ 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 51 3306 2> $fichtemp
--inputbox "Mysql port (ex: 3306):" 16 55 3306 2> $fichtemp

valret=$?

Expand All @@ -60,7 +84,7 @@ 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 root login (ex: root):" 16 51 root 2> $fichtemp
--inputbox "Mysql root login (ex: root):" 16 55 root 2> $fichtemp

valret=$?

Expand All @@ -78,7 +102,7 @@ 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 "Password for Mysql root login :" 16 51 2> $fichtemp
--inputbox "Password for Mysql root login :" 16 55 2> $fichtemp

valret=$?

Expand All @@ -96,7 +120,7 @@ esac
#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 51 2> $fichtemp
# --inputbox "Full path to documents directory (ex: /var/www/dolibarr/documents)- no / at end :" 16 55 2> $fichtemp

#valret=$?

Expand All @@ -112,7 +136,7 @@ esac
# ---------------------------- confirmation
DIALOG=${DIALOG=dialog}
$DIALOG --title "Init Dolibarr with demo values" --clear \
--yesno "Do you confirm ? \n Mysql database : '$base' \n Mysql port : '$port' \n Mysql login: '$admin' \n Mysql password : '$passwd'" 15 40
--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

case $? in
0) echo "Ok, start process...";;
Expand All @@ -125,10 +149,10 @@ if [ "x$passwd" != "x" ]
then
export passwd="-p$passwd"
fi
#echo "mysql -P$port -u$admin $passwd $base < $mydir/initdemo.sql"
#mysql -P$port -u$admin $passwd $base < $mydir/initdemo.sql
echo "mysql -P$port $base < $mydir/initdemo.sql"
mysql -P$port -u$admin $passwd $base < $mydir/initdemo.sql
#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

echo "Dolibarr data demo has been loaded."
echo
File renamed without changes.

0 comments on commit f46c148

Please sign in to comment.