initdemo.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/bin/sh
  2. #------------------------------------------------------
  3. # Script to purge and init a database with demo values.
  4. # Note: "dialog" tool need to be available if no parameter provided.
  5. #
  6. # WARNING: This script erase all data of database
  7. # with data into dump file
  8. #
  9. # Regis Houssin - regis.houssin@inodbox.com
  10. # Laurent Destailleur - eldy@users.sourceforge.net
  11. #------------------------------------------------------
  12. # Usage: initdemo.sh
  13. # usage: initdemo.sh mysqldump_dolibarr_x.x.x.sql database port login pass
  14. #------------------------------------------------------
  15. export mydir=`echo "$0" | sed -e 's/initdemo.sh//'`;
  16. if [ "x$mydir" = 'x' -o "x$mydir" = 'x./' ]
  17. then
  18. export mydir="."
  19. fi
  20. export id=`id -u`;
  21. # ----------------------------- check if root
  22. if [ "x$id" != "x0" -a "x$id" != "x1001" ]
  23. then
  24. echo "Script must be ran as root"
  25. exit
  26. fi
  27. # ----------------------------- command line params
  28. dumpfile=$1;
  29. base=$2;
  30. port=$3;
  31. admin=$4;
  32. passwd=$5;
  33. # ----------------------------- if no params on command line
  34. if [ "x$passwd" = "x" ]
  35. then
  36. export dumpfile=`ls $mydir/mysqldump_dolibarr_*.sql | sort | tail -n 1`
  37. export dumpfile=`basename $dumpfile`
  38. # ----------------------------- input file
  39. DIALOG=${DIALOG=dialog}
  40. DIALOG="$DIALOG --ascii-lines"
  41. fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
  42. trap "rm -f $fichtemp" 0 1 2 5 15
  43. $DIALOG --title "Init Dolibarr with demo values" --clear \
  44. --inputbox "Input dump file :" 16 55 $dumpfile 2> $fichtemp
  45. valret=$?
  46. case $valret in
  47. 0)
  48. dumpfile=`cat $fichtemp`;;
  49. 1)
  50. exit;;
  51. 255)
  52. exit;;
  53. esac
  54. # ----------------------------- database name
  55. DIALOG=${DIALOG=dialog}
  56. DIALOG="$DIALOG --ascii-lines"
  57. fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
  58. trap "rm -f $fichtemp" 0 1 2 5 15
  59. $DIALOG --title "Init Dolibarr with demo values" --clear \
  60. --inputbox "Mysql database name :" 16 55 dolibarrdemo 2> $fichtemp
  61. valret=$?
  62. case $valret in
  63. 0)
  64. base=`cat $fichtemp`;;
  65. 1)
  66. exit;;
  67. 255)
  68. exit;;
  69. esac
  70. # ---------------------------- database port
  71. DIALOG=${DIALOG=dialog}
  72. fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
  73. trap "rm -f $fichtemp" 0 1 2 5 15
  74. $DIALOG --title "Init Dolibarr with demo values" --clear \
  75. --inputbox "Mysql port (ex: 3306):" 16 55 3306 2> $fichtemp
  76. valret=$?
  77. case $valret in
  78. 0)
  79. port=`cat $fichtemp`;;
  80. 1)
  81. exit;;
  82. 255)
  83. exit;;
  84. esac
  85. # ---------------------------- compte admin mysql
  86. DIALOG=${DIALOG=dialog}
  87. fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
  88. trap "rm -f $fichtemp" 0 1 2 5 15
  89. $DIALOG --title "Init Dolibarr with demo values" --clear \
  90. --inputbox "Mysql root login (ex: root):" 16 55 root 2> $fichtemp
  91. valret=$?
  92. case $valret in
  93. 0)
  94. admin=`cat $fichtemp`;;
  95. 1)
  96. exit;;
  97. 255)
  98. exit;;
  99. esac
  100. # ---------------------------- mot de passe admin mysql
  101. DIALOG=${DIALOG=dialog}
  102. fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
  103. trap "rm -f $fichtemp" 0 1 2 5 15
  104. $DIALOG --title "Init Dolibarr with demo values" --clear \
  105. --inputbox "Password for Mysql root login :" 16 55 2> $fichtemp
  106. valret=$?
  107. case $valret in
  108. 0)
  109. passwd=`cat $fichtemp`;;
  110. 1)
  111. exit;;
  112. 255)
  113. exit;;
  114. esac
  115. # ---------------------------- confirmation
  116. DIALOG=${DIALOG=dialog}
  117. $DIALOG --title "Init Dolibarr with demo values" --clear \
  118. --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
  119. case $? in
  120. 0) echo "Ok, start process...";;
  121. 1) exit;;
  122. 255) exit;;
  123. esac
  124. fi
  125. # ---------------------------- run sql file
  126. if [ "x$passwd" != "x" ]
  127. then
  128. export passwd="-p$passwd"
  129. fi
  130. #echo "mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile"
  131. #mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
  132. #echo "drop old table"
  133. echo "drop table if exists llx_accounting_account;" | mysql -P$port -u$admin $passwd $base
  134. echo "mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile"
  135. mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
  136. export res=$?
  137. # ---------------------------- copy demo files
  138. 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' `
  139. if [ "x$documentdir" != "x" ]
  140. then
  141. echo cp -pr $mydir/documents_demo/* "$documentdir/"
  142. cp -pr $mydir/documents_demo/* "$documentdir/"
  143. echo cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
  144. cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
  145. mkdir -p "$documentdir/ecm/Administrative documents"
  146. mkdir -p "$documentdir/ecm/Images"
  147. rm -f "$documentdir/doctemplates/"*/index.html
  148. echo cp -pr $mydir/../../doc/images/* "$documentdir/ecm/Images"
  149. cp -pr $mydir/../../doc/images/* "$documentdir/ecm/Images"
  150. else
  151. echo Detection of documents directory from $mydir failed so demo files were not copied.
  152. fi
  153. if [ "x$res" = "x0" ]
  154. then
  155. echo "Success, file successfully loaded."
  156. else
  157. echo "Error, load failed."
  158. fi
  159. echo