dolibarr/dev/initdemo/initdemo.sh

247 lines
6.5 KiB
Bash
Raw Normal View History

2012-10-02 23:48:27 +02:00
#!/bin/sh
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 if no parameter provided.
#
# WARNING: This script erase all data of database
# with data into dump file
2008-08-19 21:19:29 +02:00
#
2018-10-27 14:43:12 +02:00
# Regis Houssin - regis.houssin@inodbox.com
2008-08-19 21:11:11 +02:00
# Laurent Destailleur - eldy@users.sourceforge.net
2008-08-19 21:19:29 +02:00
#------------------------------------------------------
2019-02-13 15:11:31 +01:00
# Usage: initdemo.sh confirm
# usage: initdemo.sh confirm mysqldump_dolibarr_x.x.x.sql database port login pass
2008-08-19 21:19:29 +02:00
#------------------------------------------------------
2008-08-19 21:11:11 +02:00
export mydir=`echo "$0" | sed -e 's/initdemo.sh//'`;
2016-07-30 14:05:39 +02:00
if [ "x$mydir" = 'x' -o "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
2008-08-19 21:01:31 +02:00
# ----------------------------- command line params
2019-02-13 15:11:31 +01:00
confirm=$1;
dumpfile=$2;
base=$3;
port=$4;
admin=$5;
passwd=$6;
# ----------------------------- check params
if [ "x$confirm" != "xconfirm" ]
then
echo "----- $0 -----"
echo "Usage: initdemo.sh confirm [mysqldump_dolibarr_x.x.x.sql database port login pass]"
exit
fi
2008-08-19 21:01:31 +02:00
2008-12-28 06:22:00 +01:00
# ----------------------------- if no params on command line
if [ "x$passwd" = "x" ]
then
2019-09-26 13:58:30 +02:00
export dumpfile=`ls -v $mydir/mysqldump_dolibarr_*.sql | 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
valret=$?
case $valret in
0)
dumpfile=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2020-09-17 12:05:52 +02:00
rm $fichtemp
# ----------------------------- 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 55 dolibarrdemo 2> $fichtemp
valret=$?
case $valret in
0)
base=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2020-09-17 12:05:52 +02:00
rm $fichtemp
# ---------------------------- 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
valret=$?
case $valret in
0)
port=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2020-09-17 12:05:52 +02:00
rm $fichtemp
# ---------------------------- compte admin mysql
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 \
2020-03-30 14:57:44 +02:00
--inputbox "Mysql user login (ex: root):" 16 55 root 2> $fichtemp
valret=$?
case $valret in
0)
admin=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2020-09-17 12:05:52 +02:00
rm $fichtemp
# ---------------------------- 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
$DIALOG --title "Init Dolibarr with demo values" --clear \
2022-02-07 15:46:02 +01:00
--passwordbox "Password for Mysql user login :" 16 55 2> $fichtemp
valret=$?
case $valret in
0)
passwd=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
2020-09-17 12:05:52 +02:00
rm $fichtemp
2019-02-13 15:35:30 +01:00
export documentdir=`cat $mydir/../../htdocs/conf/conf.php | grep '^\$dolibarr_main_data_root' | sed -e 's/$dolibarr_main_data_root=//' | sed -e 's/;//' | sed -e "s/'//g" | sed -e 's/"//g' `
2016-07-30 14:05:39 +02:00
# ---------------------------- confirmation
DIALOG=${DIALOG=dialog}
$DIALOG --title "Init Dolibarr with demo values" --clear \
2022-02-07 15:46:02 +01:00
--yesno "Do you confirm ? \n Dump file : '$dumpfile' \n Dump dir : '$mydir' \n Document dir : '$documentdir' \n Mysql database : '$base' \n Mysql port : '$port' \n Mysql login: '$admin' \n Mysql password : --hidden--" 15 55
case $? in
0) echo "Ok, start process...";;
1) exit;;
255) exit;;
esac
2008-12-28 06:22:00 +01:00
fi
2008-08-19 21:01:31 +02:00
# ---------------------------- run sql file
2008-12-28 06:22:00 +01:00
if [ "x$passwd" != "x" ]
then
export passwd="-p$passwd"
fi
2012-10-02 23:48:27 +02:00
#echo "mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile"
#mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
2016-03-12 18:33:32 +01:00
#echo "drop old table"
2017-06-19 02:31:55 +02:00
echo "drop table if exists llx_accounting_account;" | mysql -P$port -u$admin $passwd $base
2012-10-02 19:42:44 +02:00
echo "mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile"
2012-10-02 23:48:27 +02:00
mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
export res=$?
2008-10-08 01:04:12 +02:00
2020-06-12 19:11:00 +02:00
if [ $res -ne 0 ]; then
echo "Error to load database dump with mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile"
exit
fi
2020-03-30 14:57:44 +02:00
$mydir/updatedemo.php confirm
export res=$?
2016-07-30 14:05:39 +02:00
# ---------------------------- copy demo files
2017-01-11 22:02:08 +01:00
export documentdir=`cat $mydir/../../htdocs/conf/conf.php | grep '^\$dolibarr_main_data_root' | sed -e 's/$dolibarr_main_data_root=//' | sed -e 's/;//' | sed -e "s/'//g" | sed -e 's/"//g' `
2016-07-30 14:05:39 +02:00
if [ "x$documentdir" != "x" ]
then
2020-12-13 19:33:48 +01:00
$DIALOG --title "Reset document directory" --clear \
--inputbox "DELETE and recreate document directory $documentdir/:" 16 55 n 2> $fichtemp
2019-02-13 15:11:31 +01:00
valret=$?
case $valret in
0)
rep=`cat $fichtemp`;;
1)
exit;;
255)
exit;;
esac
echo "rep=$rep"
if [ "x$rep" = "xy" ]; then
echo rm -fr "$documentdir/*"
rm -fr $documentdir/*
fi
2016-07-30 14:05:39 +02:00
echo cp -pr $mydir/documents_demo/* "$documentdir/"
cp -pr $mydir/documents_demo/* "$documentdir/"
2019-02-13 15:11:31 +01:00
2019-02-13 15:14:12 +01:00
mkdir "$documentdir/doctemplates/" 2>/dev/null
2016-07-30 14:05:39 +02:00
echo cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
2019-02-13 15:11:31 +01:00
echo cp -pr $mydir/../../htdocs/install/medias/* "$documentdir/medias/image/"
cp -pr $mydir/../../htdocs/install/medias/* "$documentdir/medias/image/"
2019-02-13 15:14:12 +01:00
mkdir -p "$documentdir/ecm/Administrative documents" 2>/dev/null
mkdir -p "$documentdir/ecm/Images" 2>/dev/null
rm -f "$documentdir/doctemplates/"*/index.html
echo cp -pr $mydir/../../doc/images/* "$documentdir/ecm/Images"
cp -pr $mydir/../../doc/images/* "$documentdir/ecm/Images"
2019-02-13 15:19:12 +01:00
chmod -R u+w "$documentdir/"
chown -R www-data "$documentdir/"
2016-07-30 14:05:39 +02:00
else
2017-01-26 12:48:32 +01:00
echo Detection of documents directory from $mydir failed so demo files were not copied.
2016-07-30 14:05:39 +02:00
fi
2021-04-30 11:14:00 +02:00
if [ -s "$mydir/initdemopostsql.sql" ]; then
mysql -P$port $base < "$mydir/initdemopostsql.sql"
fi
2016-07-30 14:05:39 +02:00
if [ "x$res" = "x0" ]
then
echo "Success, file successfully loaded."
else
echo "Error, load failed."
fi
2008-10-08 01:04:12 +02:00
echo