Select Git revision
doli 3.98 KiB
#!/bin/bash
get_conf_val () {
grep $1 dolibarr_src/htdocs/conf/conf.php | cut -d '=' -f 2 | sed -e "s/^'//" -e "s/';$//"
}
APP_SERVICE="dolibarr"
DB_SERVICE="mariadb"
user=$(get_conf_val main_db_user)
db=$(get_conf_val main_db_name)
PASS_VARIABLE="PASS"
DUMP_PATH="dumps/internal.sql.gz"
document_path=$(get_conf_val main_data_root)
is_docker() {
if [ ! -z "$(which docker-compose 2>/dev/null)" ];
then
echo "1"
else
echo "0"
fi
}
usage() {
echo -e "Usage $0 <command> [args]\n"
echo -e "COMMANDS\n"
echo "bash"
echo -e "\topens a bash terminal in front container or just run bash"
echo "down"
echo -e "\t stops the docker stack"
echo "help"
echo -e "\t displays this messages and exit"
echo "logs"
echo -e "\t Follow all usefull logs"
echo "mysql"
echo -e "\topen a mysql prompt in LNB database"
echo "mysql_dump"
echo -e "\tcreates a database dump"
echo "mysql_init"
echo -e "\tpopulate LabNbook database (Docker only)"
echo "mysql_restore"
echo -e "\trestores database from a dump"
echo "perms"
echo -e "\tsets default files permissions"
echo "restart"
echo -e "\t restart the docker stack or apache2"
echo "shell"
echo -e "\trun a php shell, same as $0 artisan tinker"
echo "up"
echo -e "\t starts the docker stack"
echo "tags"
echo -e "\t generate ctags"
}
if [ "$(is_docker)" -eq 1 ]; then
cmd="docker-compose exec $APP_SERVICE"
cmdmy="docker-compose exec $DB_SERVICE"
cmdmyInput="docker exec -i $(docker-compose ps -q $DB_SERVICE)"
cmdrestart="docker-compose restart"
cmdup="docker-compose up"
cmddown="docker-compose down"
else
cmdrestart="apache2ctl restart"
fi
pass=$(get_conf_val main_db_pass)
mysql="mariadb -u $user $db -p$pass"
DIR="$(dirname $0)"
action=$1
shift
# Keep actions sorted
case $action in
"bash")
$cmd bash
;;
"down")
$cmddown
;;
"help")
usage
;;
"logs")
set -x
$cmd tail -f $document_path/dolibarr.log \
$document_path/dolibarr_payment.log \
$document_path/dolibarr_cron.log \
$document_path/cron_run_jobs.php.log \
$document_path/dolibarr.log \
/var/log/apache2/access.log
/var/log/apache2/error.log
set +x
;;
"mysql")
set -x
$cmdmy $mysql
set +x
;;
"mysql_dump")
$cmdmy mariadb-dump --databases $db -u $user -p$pass | gzip > ${db}_$(date +%Y%m%d_%H%M%S).sql.gz
;;
"mysql_restore")
if [ -z "$1" ]; then
echo "Usage $0 mysql_restore <file>"
exit 1
fi
read -p "Do you want to restore your database from file '$1' ? This command will erase your current data. (y/n). " yn
case $yn in
[Yy]* )
zcat $1 | $cmdmyInput $mysql
;;
[Nn]* )
exit
;;
* )
echo "Please answer yes or no.";;
esac
;;
"mysql_init")
read -p "Do you want to init your database with default data? This command will erase your current data. (y/n). " yn
case $yn in
[Yy]* )
zcat $DUMP_PATH | $cmdmyInput $mysql
;;
[Nn]* )
exit
;;
* )
echo "Please answer yes or no.";;
esac
;;
"perms")
$cmd chown -R $(id -u):33 dolibarr/
$cmd chown -R $(id -u):33 $document_path
$cmd chmod -R g+w $document_path
$cmd chmod -R g-w dolibarr/htdocs
$cmd chmod -R g+w dolibarr/htdocs/custom
$cmd touch $document_path/install.lock
;;
"restart")
$cmdrestart $@
;;
"shell")
if [ $(is_docker) -eq 1 ]; then
docker cp doli_shell.php $(docker-compose ps -q $APP_SERVICE):/var/www
fi
$cmd php -a -d auto_prepend_file=/var/www/doli_shell.php
;;
"up")
$cmdup $@
;;
"tags")
workdir=$PWD
cd $DIR/dolibarr_src
ctags -R --fields=+aimlS --languages=php
;;
*)
echo "ERROR: No command given"
usage
exit 1
;;
esac