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,122 +29,140 @@ then
exit exit
fi fi
# ----------------------------- input file
DIALOG=${DIALOG=dialog} # ----------------------------- command line params
DIALOG="$DIALOG --ascii-lines" dumpfile=$1;
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$ base=$2;
trap "rm -f $fichtemp" 0 1 2 5 15 port=$3;
$DIALOG --title "Init Dolibarr with demo values" --clear \ 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
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 --inputbox "Input dump file :" 16 55 $dumpfile 2> $fichtemp
valret=$? valret=$?
case $valret in case $valret in
0) 0)
dumpfile=`cat $fichtemp`;; dumpfile=`cat $fichtemp`;;
1) 1)
exit;; exit;;
255) 255)
exit;; exit;;
esac esac
# ----------------------------- database name # ----------------------------- database name
DIALOG=${DIALOG=dialog} DIALOG=${DIALOG=dialog}
DIALOG="$DIALOG --ascii-lines" DIALOG="$DIALOG --ascii-lines"
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$ fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15 trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --title "Init Dolibarr with demo values" --clear \ $DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Mysql database name :" 16 55 dolibarrdemo 2> $fichtemp --inputbox "Mysql database name :" 16 55 dolibarrdemo 2> $fichtemp
valret=$? valret=$?
case $valret in case $valret in
0) 0)
base=`cat $fichtemp`;; base=`cat $fichtemp`;;
1) 1)
exit;; exit;;
255) 255)
exit;; exit;;
esac esac
# ---------------------------- database port # ---------------------------- database port
DIALOG=${DIALOG=dialog} DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$ fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15 trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --title "Init Dolibarr with demo values" --clear \ $DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Mysql port (ex: 3306):" 16 55 3306 2> $fichtemp --inputbox "Mysql port (ex: 3306):" 16 55 3306 2> $fichtemp
valret=$? valret=$?
case $valret in case $valret in
0) 0)
port=`cat $fichtemp`;; port=`cat $fichtemp`;;
1) 1)
exit;; exit;;
255) 255)
exit;; exit;;
esac esac
# ---------------------------- compte admin mysql # ---------------------------- compte admin mysql
DIALOG=${DIALOG=dialog} DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$ fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15 trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --title "Init Dolibarr with demo values" --clear \ $DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Mysql root login (ex: root):" 16 55 root 2> $fichtemp --inputbox "Mysql root login (ex: root):" 16 55 root 2> $fichtemp
valret=$? valret=$?
case $valret in case $valret in
0) 0)
admin=`cat $fichtemp`;; admin=`cat $fichtemp`;;
1) 1)
exit;; exit;;
255) 255)
exit;; exit;;
esac esac
# ---------------------------- mot de passe admin mysql # ---------------------------- mot de passe admin mysql
DIALOG=${DIALOG=dialog} DIALOG=${DIALOG=dialog}
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$ fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
trap "rm -f $fichtemp" 0 1 2 5 15 trap "rm -f $fichtemp" 0 1 2 5 15
$DIALOG --title "Init Dolibarr with demo values" --clear \ $DIALOG --title "Init Dolibarr with demo values" --clear \
--inputbox "Password for Mysql root login :" 16 55 2> $fichtemp --inputbox "Password for Mysql root login :" 16 55 2> $fichtemp
valret=$? valret=$?
case $valret in case $valret in
0) 0)
passwd=`cat $fichtemp`;; passwd=`cat $fichtemp`;;
1) 1)
exit;; exit;;
255) 255)
exit;; exit;;
esac esac
# ---------------------------- chemin d'acces du repertoire documents # ---------------------------- chemin d'acces du repertoire documents
#DIALOG=${DIALOG=dialog} #DIALOG=${DIALOG=dialog}
#fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$ #fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
#trap "rm -f $fichtemp" 0 1 2 5 15 #trap "rm -f $fichtemp" 0 1 2 5 15
#$DIALOG --title "Init Dolibarr with demo values" --clear \ #$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 # --inputbox "Full path to documents directory (ex: /var/www/dolibarr/documents)- no / at end :" 16 55 2> $fichtemp
#valret=$? #valret=$?
#case $valret in #case $valret in
# 0) # 0)
#docs=`cat $fichtemp`;; #docs=`cat $fichtemp`;;
# 1) # 1)
#exit;; #exit;;
# 255) # 255)
#exit;; #exit;;
#esac #esac
# ---------------------------- confirmation # ---------------------------- confirmation
DIALOG=${DIALOG=dialog} DIALOG=${DIALOG=dialog}
$DIALOG --title "Init Dolibarr with demo values" --clear \ $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 --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 case $? in
0) echo "Ok, start process...";; 0) echo "Ok, start process...";;
1) exit;; 1) exit;;
255) exit;; 255) exit;;
esac esac
fi
# ---------------------------- run sql file # ---------------------------- run sql file
if [ "x$passwd" != "x" ] if [ "x$passwd" != "x" ]
@ -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