Qual: Clean up (spelling/shellcheck) initdemo/initdata files (#28195)
# Qual: Clean up (spelling/shellcheck) initdemo/initdata files Cleanup the readme's and the script
This commit is contained in:
parent
24b017fbc8
commit
f10d06a357
3 changed files with 105 additions and 91 deletions
|
|
@ -2,6 +2,6 @@ README
|
|||
------
|
||||
|
||||
Scripts in this directory can be used to load massive data or purge data of a database instance.
|
||||
WARNING: Some of this script may delete definitely data.
|
||||
WARNING: Some of these scripts may permanently delete data.
|
||||
|
||||
To init data for a demo, use instead the tool into dev/initdemo
|
||||
To initialize data for a demo, use the tools in dev/initdemo instead.
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
README
|
||||
======
|
||||
|
||||
Scripts in this directory can be used to reload or save a demo database.
|
||||
Install of package "dialog" is required.
|
||||
The scripts in this directory can be used to reload or save a demo database.
|
||||
The package `dialog` is required.
|
||||
|
||||
|
||||
Init demo
|
||||
-------------
|
||||
|
||||
The script initdemo.sh will erase current database with data intodev/initdemo/mysqldump_dolibarr_x.y.z.sql and copy files into documents_demo into officiel document directory.
|
||||
The script `initdemo.sh` will erase the current database with data from `dev/initdemo/mysqldump_dolibarr_x.y.z.sql` and copy files from `documents_demo` to the official document directory.
|
||||
|
||||
Do a chmod 700 initdemo.sh
|
||||
then run ./initdemo.sh to launch Graphic User Interface.
|
||||
You many to execute `chmod 700 initdemo.sh`
|
||||
then run `./initdemo.sh` to launch the Graphical User Interface.
|
||||
|
||||
After loading the demo files, admin login may be:
|
||||
After loading the demo files, the admin login may be one of the following:
|
||||
- admin / admin
|
||||
or
|
||||
- admin / adminadmin
|
||||
|
|
@ -22,11 +22,10 @@ or
|
|||
Update demo
|
||||
-------------
|
||||
|
||||
The goal of script dev/initdemo/updatedemo.php is to update dates into the demo data so samples are up to date.
|
||||
The goal of the script `dev/initdemo/updatedemo.php` is to update the dates in the demo data so that samples are up to date.
|
||||
|
||||
|
||||
Save demo
|
||||
-------------
|
||||
|
||||
The script dev/initdemo.savedemo.sh will save current database into a database dump file.
|
||||
|
||||
The script `dev/initdemo.savedemo.sh` will save the current database into a database dump file.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
|
||||
|
||||
#------------------------------------------------------
|
||||
# Script to purge and init a database with demo values.
|
||||
# Note: "dialog" tool need to be available if no parameter provided.
|
||||
# Script to purge and initialize a database with demo values.
|
||||
# Note: "dialog" tool needs to be available if no parameter provided.
|
||||
#
|
||||
# WARNING: This script erase all data of database
|
||||
# WARNING: This script erase all the data in the database
|
||||
# with data into dump file
|
||||
#
|
||||
# Regis Houssin - regis.houssin@inodbox.com
|
||||
|
|
@ -12,36 +14,36 @@
|
|||
# Usage: initdemo.sh confirm
|
||||
# usage: initdemo.sh confirm mysqldump_dolibarr_x.x.x.sql database port login pass
|
||||
#------------------------------------------------------
|
||||
# shellcheck disable=2006,2034,2046,2064,2068,2086,2155,2166,2186,2172,2268
|
||||
# shellcheck disable=2012,2016,2115
|
||||
|
||||
|
||||
export mydir=`echo "$0" | sed -e 's/initdemo.sh//'`;
|
||||
if [ "x$mydir" = 'x' -o "x$mydir" = 'x./' ]
|
||||
export mydir
|
||||
mydir=${0//initdemo.sh/}
|
||||
if [ "$mydir" = "" ] || [ "$mydir" = "./" ]
|
||||
then
|
||||
export mydir="."
|
||||
fi
|
||||
export id=`id -u`;
|
||||
export id
|
||||
id=$(id -u)
|
||||
|
||||
|
||||
# ----------------------------- check if root
|
||||
if [ "x$id" != "x0" -a "x$id" != "x1001" ]
|
||||
if [ "$id" != "0" ] && [ "$id" != "1001" ]
|
||||
then
|
||||
echo "Script must be ran as root"
|
||||
echo "Script must be executed as root"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
# ----------------------------- command line params
|
||||
confirm=$1;
|
||||
dumpfile=$2;
|
||||
base=$3;
|
||||
port=$4;
|
||||
admin=$5;
|
||||
passwd=$6;
|
||||
confirm=$1
|
||||
dumpfile=$2
|
||||
base=$3
|
||||
port=$4
|
||||
admin=$5
|
||||
passwd=$6
|
||||
|
||||
# ----------------------------- check params
|
||||
if [ "x$confirm" != "xconfirm" ]
|
||||
if [ "$confirm" != "confirm" ]
|
||||
then
|
||||
echo "----- $0 -----"
|
||||
echo "Usage: initdemo.sh confirm [mysqldump_dolibarr_x.x.x.sql database port login pass]"
|
||||
|
|
@ -50,110 +52,121 @@ fi
|
|||
|
||||
|
||||
# ----------------------------- if no params on command line
|
||||
if [ "x$passwd" = "x" ]
|
||||
if [ "$passwd" = "" ]
|
||||
then
|
||||
export dumpfile=`ls -v $mydir/mysqldump_dolibarr_*.sql | tail -n 1`
|
||||
export dumpfile=`basename $dumpfile`
|
||||
# TODO: WHY 2 ASSIGNMENTS TO dumpfile
|
||||
export dumpfile
|
||||
# shellcheck disable=2012
|
||||
dumpfile=$(ls -v "$mydir/mysqldump_dolibarr_"*".sql" | tail -n 1)
|
||||
export dumpfile
|
||||
dumpfile=$(basename "$dumpfile"ls -v "$mydir/mysqldump_dolibarr_"*".sql" )
|
||||
|
||||
# ----------------------------- input file
|
||||
DIALOG=${DIALOG=dialog}
|
||||
DIALOG=${DIALOG:=dialog}
|
||||
DIALOG="$DIALOG --ascii-lines"
|
||||
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
|
||||
fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$
|
||||
# shellcheck disable=2064,2172
|
||||
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=$?
|
||||
case $valret in
|
||||
0)
|
||||
dumpfile=`cat $fichtemp` ;;
|
||||
dumpfile=$(cat "$fichtemp") ;;
|
||||
1)
|
||||
exit ;;
|
||||
255)
|
||||
exit ;;
|
||||
esac
|
||||
rm $fichtemp
|
||||
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
|
||||
DIALOG=${DIALOG:=dialog}
|
||||
DIALOG="'$DIALOG' --ascii-lines"
|
||||
fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$
|
||||
# shellcheck disable=2064,2172
|
||||
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` ;;
|
||||
base=$(cat "$fichtemp") ;;
|
||||
1)
|
||||
exit ;;
|
||||
255)
|
||||
exit ;;
|
||||
esac
|
||||
rm $fichtemp
|
||||
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=${DIALOG:=dialog}
|
||||
fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$
|
||||
# shellcheck disable=2064,2172
|
||||
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
|
||||
--inputbox "Mysql port (ex: 3306):" 16 55 3306 2> "$fichtemp"
|
||||
|
||||
valret=$?
|
||||
|
||||
case $valret in
|
||||
0)
|
||||
port=`cat $fichtemp` ;;
|
||||
port=$(cat "$fichtemp") ;;
|
||||
1)
|
||||
exit ;;
|
||||
255)
|
||||
exit ;;
|
||||
esac
|
||||
rm $fichtemp
|
||||
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 \
|
||||
--inputbox "Mysql user login (ex: root):" 16 55 root 2> $fichtemp
|
||||
DIALOG=${DIALOG:=dialog}
|
||||
fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$
|
||||
# shellcheck disable=2064,2172
|
||||
trap "rm -f '$fichtemp'" 0 1 2 5 15
|
||||
"$DIALOG" --title "Init Dolibarr with demo values" --clear \
|
||||
--inputbox "Mysql user login (ex: root):" 16 55 root 2> "$fichtemp"
|
||||
|
||||
valret=$?
|
||||
|
||||
case $valret in
|
||||
0)
|
||||
admin=`cat $fichtemp` ;;
|
||||
admin=$(cat "$fichtemp") ;;
|
||||
1)
|
||||
exit ;;
|
||||
255)
|
||||
exit ;;
|
||||
esac
|
||||
rm $fichtemp
|
||||
rm "$fichtemp"
|
||||
|
||||
# ---------------------------- password admin mysql (root)
|
||||
DIALOG=${DIALOG=dialog}
|
||||
fichtemp=`tempfile 2>/dev/null` || fichtemp=/tmp/test$$
|
||||
trap "rm -f $fichtemp" 0 1 2 5 15
|
||||
DIALOG=${DIALOG:=dialog}
|
||||
fichtemp=$(mktemp 2>/dev/null) || fichtemp=/tmp/test$$
|
||||
# shellcheck disable=2064,2172
|
||||
trap "rm -f '$fichtemp'" 0 1 2 5 15
|
||||
$DIALOG --title "Init Dolibarr with demo values" --clear \
|
||||
--passwordbox "Password for Mysql user login :" 16 55 2> $fichtemp
|
||||
--passwordbox "Password for Mysql user login :" 16 55 2> "$fichtemp"
|
||||
|
||||
valret=$?
|
||||
|
||||
case $valret in
|
||||
0)
|
||||
passwd=`cat $fichtemp` ;;
|
||||
passwd=$(cat "$fichtemp") ;;
|
||||
1)
|
||||
exit ;;
|
||||
255)
|
||||
exit ;;
|
||||
esac
|
||||
rm $fichtemp
|
||||
rm "$fichtemp"
|
||||
|
||||
|
||||
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' `
|
||||
export documentdir
|
||||
# shellcheck disable=2016
|
||||
documentdir=$(< "$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')
|
||||
|
||||
|
||||
# ---------------------------- confirmation
|
||||
DIALOG=${DIALOG=dialog}
|
||||
DIALOG=${DIALOG:=dialog}
|
||||
$DIALOG --title "Init Dolibarr with demo values" --clear \
|
||||
--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
|
||||
|
||||
|
|
@ -167,38 +180,40 @@ fi
|
|||
|
||||
|
||||
# ---------------------------- run sql file
|
||||
if [ "x$passwd" != "x" ]
|
||||
if [ "$passwd" != "" ]
|
||||
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 "drop old table"
|
||||
echo "drop table if exists llx_accounting_account;" | mysql -P$port -u$admin $passwd $base
|
||||
echo "mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile"
|
||||
mysql -P$port -u$admin $passwd $base < $mydir/$dumpfile
|
||||
echo "drop table if exists llx_accounting_account;" | mysql "-P$port" "-u$admin" "$passwd" "$base"
|
||||
echo "mysql -P$port -u$admin -p***** $base < '$mydir/$dumpfile'"
|
||||
mysql "-P$port" "-u$admin" "$passwd" "$base" < "$mydir/$dumpfile"
|
||||
export res=$?
|
||||
|
||||
if [ $res -ne 0 ]; then
|
||||
echo "Error to load database dump with mysql -P$port -u$admin -p***** $base < $mydir/$dumpfile"
|
||||
echo "Error to load database dump with mysql -P$port -u$admin -p***** $base < '$mydir/$dumpfile'"
|
||||
exit
|
||||
fi
|
||||
|
||||
$mydir/updatedemo.php confirm
|
||||
"$mydir/updatedemo.php" confirm
|
||||
export res=$?
|
||||
|
||||
# ---------------------------- copy demo files
|
||||
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' `
|
||||
if [ "x$documentdir" != "x" ]
|
||||
export documentdir
|
||||
# shellcheck disable=2016
|
||||
documentdir=$(< "$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')
|
||||
if [ "$documentdir" != "" ]
|
||||
then
|
||||
$DIALOG --title "Reset document directory" --clear \
|
||||
--inputbox "DELETE and recreate document directory $documentdir/:" 16 55 n 2> $fichtemp
|
||||
"$DIALOG" --title "Reset document directory" --clear \
|
||||
--inputbox "DELETE and recreate document directory '$documentdir/':" 16 55 n 2> "$fichtemp"
|
||||
|
||||
valret=$?
|
||||
|
||||
case $valret in
|
||||
0)
|
||||
rep=`cat $fichtemp` ;;
|
||||
rep=$(cat "$fichtemp") ;;
|
||||
1)
|
||||
exit ;;
|
||||
255)
|
||||
|
|
@ -206,40 +221,40 @@ then
|
|||
esac
|
||||
|
||||
echo "rep=$rep"
|
||||
if [ "x$rep" = "xy" ]; then
|
||||
echo rm -fr "$documentdir/*"
|
||||
rm -fr $documentdir/*
|
||||
if [ "$rep" = "y" ]; then
|
||||
echo "rm -fr '$documentdir/'*"
|
||||
rm -fr "${documentdir:?}/"*
|
||||
fi
|
||||
|
||||
echo cp -pr $mydir/documents_demo/* "$documentdir/"
|
||||
cp -pr $mydir/documents_demo/* "$documentdir/"
|
||||
echo "cp -pr '$mydir/documents_demo/'* '$documentdir/'"
|
||||
cp -pr "$mydir/documents_demo/"* "$documentdir/"
|
||||
|
||||
mkdir "$documentdir/doctemplates/" 2>/dev/null
|
||||
echo cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
|
||||
cp -pr $mydir/../../htdocs/install/doctemplates/* "$documentdir/doctemplates/"
|
||||
echo cp -pr "$mydir/../../htdocs/install/doctemplates/"* "$documentdir/doctemplates/"
|
||||
cp -pr "$mydir/../../htdocs/install/doctemplates/"* "$documentdir/doctemplates/"
|
||||
|
||||
echo cp -pr $mydir/../../htdocs/install/medias/* "$documentdir/medias/image/"
|
||||
cp -pr $mydir/../../htdocs/install/medias/* "$documentdir/medias/image/"
|
||||
echo cp -pr "$mydir/../../htdocs/install/medias/"* "$documentdir/medias/image/"
|
||||
cp -pr "$mydir/../../htdocs/install/medias/"* "$documentdir/medias/image/"
|
||||
|
||||
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"
|
||||
echo cp -pr "$mydir/../../doc/images/"* "$documentdir/ecm/Images"
|
||||
cp -pr "$mydir/../../doc/images/"* "$documentdir/ecm/Images"
|
||||
|
||||
chmod -R u+w "$documentdir/"
|
||||
chown -R www-data "$documentdir/"
|
||||
else
|
||||
echo Detection of documents directory from $mydir failed so demo files were not copied.
|
||||
echo "Detection of 'documents' directory in '$mydir' failed so demo files were not copied."
|
||||
fi
|
||||
|
||||
|
||||
if [ -s "$mydir/initdemopostsql.sql" ]; then
|
||||
mysql -P$port $base < "$mydir/initdemopostsql.sql"
|
||||
mysql "-P$port" "$base" < "$mydir/initdemopostsql.sql"
|
||||
fi
|
||||
|
||||
|
||||
if [ "x$res" = "x0" ]
|
||||
if [ "$res" = "0" ]
|
||||
then
|
||||
echo "Success, file successfully loaded."
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue