Skip to content
Snippets Groups Projects
Commit ea9e2cc6 authored by David Beniamine's avatar David Beniamine
Browse files

Merge branch 'doli-script-update' into 'master'

Doli script update

See merge request !6
parents cf2964d9 5cd6b306
Branches master
No related tags found
1 merge request!6Doli script update
...@@ -21,83 +21,13 @@ is_docker() { ...@@ -21,83 +21,13 @@ is_docker() {
fi fi
} }
usage() { info(){
echo -e "Usage $0 <command> [args]\n"
echo -e "COMMANDS\n"
echo "bash"
echo -e "\t opens 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 useful logs"
echo "logs <term1> <term2> ..."
echo -e "\t Follow all useful logs and highlight terms"
echo "mysql"
echo -e "\t pen a mysql prompt in LNB database"
echo "mysql_dump"
echo -e "\t creates a database dump"
echo "mysql_init"
echo -e "\t populate LabNbook database (Docker only)"
echo "mysql_restore"
echo -e "\t restores database from a dump"
echo "perms"
echo -e "\t sets default files permissions"
echo "restart"
echo -e "\t restart the docker stack or apache2"
echo "shell"
echo -e "\t run a php shell, same as $0 artisan tinker"
echo "up"
echo -e "\t starts the docker stack"
echo "tags"
echo -e "\t generate ctags"
echo "fail2ban"
echo -e "\t root only - put fail2ban jail and filter in good directory with good log path"
}
if [ "$(is_docker)" -eq 1 ]; then
if [ -z "$(which docker-compose)" ]; then
compose="docker compose"
else
compose="docker-compose"
fi
cmd="$compose exec $APP_SERVICE"
cmdmy="$compose exec $DB_SERVICE"
cmdmyInput="docker exec -i $($compose ps -q $DB_SERVICE)"
cmdrestart="$compose restart"
cmdup="$compose up"
cmddown="$compose down"
else
cmdrestart="apache2ctl restart"
fi
if [ ! -z "$(which ccze)" ]; then
reader="ccze -A"
else
reader="tee"
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
;;
"info")
echo "** Info about your Dolibarr instance **" echo "** Info about your Dolibarr instance **"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Date and time # Date and time
timestamp=$(date '+%Y-%m-%d %H:%M:%S') timestamp=$(date '+%Y-%m-%d %H:%M:%S')
...@@ -109,14 +39,11 @@ case $action in ...@@ -109,14 +39,11 @@ case $action in
instance_path=$(realpath dolibarr_src/.. 2>/dev/null) instance_path=$(realpath dolibarr_src/.. 2>/dev/null)
instance_name=$(basename "$instance_path") instance_name=$(basename "$instance_path")
echo -e "Generated at: $timestamp" echo -e "Generated at: $timestamp"
echo -e "Machine: $host" echo -e "Machine: $host"
echo -e "Instance: $instance_name" echo -e "Instance: $instance_name"
echo -e "Instance path: $instance_path\n" echo -e "Instance path: $instance_path\n"
## Docker deployment ## Docker deployment
if [ "$(is_docker)" -eq 1 ]; then if [ "$(is_docker)" -eq 1 ]; then
echo "Docker deployment detected." echo "Docker deployment detected."
...@@ -150,11 +77,6 @@ case $action in ...@@ -150,11 +77,6 @@ case $action in
if [ -d "dolibarr_src/.git" ]; then if [ -d "dolibarr_src/.git" ]; then
cd dolibarr_src || exit cd dolibarr_src || exit
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null) upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null)
...@@ -166,9 +88,9 @@ case $action in ...@@ -166,9 +88,9 @@ case $action in
behind=$(git rev-list --count HEAD.."$upstream" 2>/dev/null) behind=$(git rev-list --count HEAD.."$upstream" 2>/dev/null)
if [ "$behind" -gt 0 ]; then if [ "$behind" -gt 0 ]; then
status="${YELLOW}Pull needed${NC}" status="${YELLOW}NOT UP TO DATE${NC}"
else else
status="${GREEN}Up to date${NC}" status="${GREEN}UP TO DATE${NC}"
fi fi
fi fi
...@@ -179,24 +101,24 @@ case $action in ...@@ -179,24 +101,24 @@ case $action in
echo "Dolibarr source directory is not a Git repository." echo "Dolibarr source directory is not a Git repository."
fi fi
## Modules ## Modules
BASE_DIR="dolibarr_src/htdocs/custom" BASE_DIR="dolibarr_src/htdocs/custom"
if [ -d "$BASE_DIR" ]; then if [ -d "$BASE_DIR" ]; then
echo -e "\nCustom modules directory: $BASE_DIR\n" echo -e "\nCustom modules directory: $BASE_DIR\n"
echo "Modules in custom directory:" echo "Modules in custom directory:"
printf "%-45s | %-20s | %-12s | %-10s | %s\n" "Module" "Git Branch" "Last Commit" "Commit ID" "Up to date" printf "%-30s | %-15s | %-11s | %-9s | %s\n" "Module" "Git Branch" "Last Commit" "Commit ID" "Up to date"
printf "%-45s-+-%-20s-+-%-12s-+-%-10s-+-%s\n" \ printf "%-30s-+-%-15s-+-%-11s-+-%-9s-+-%s\n" \
"$(printf '%.0s-' {1..45})" "$(printf '%.0s-' {1..20})" \ "$(printf '%.0s-' {1..30})" "$(printf '%.0s-' {1..15})" \
"$(printf '%.0s-' {1..12})" "$(printf '%.0s-' {1..10})" "$(printf '%.0s-' {1..6})" "$(printf '%.0s-' {1..11})" "$(printf '%.0s-' {1..9})" "$(printf '%.0s-' {1..6})"
find "$BASE_DIR" -maxdepth 1 -mindepth 1 -type d ! -name '.*' | sort | while read -r dir; do find "$BASE_DIR" -maxdepth 1 -mindepth 1 -type d ! -name '.*' | sort | while read -r dir; do
module_name=$(basename "$dir") module_name=$(basename "$dir")
module_name_short=$(printf "%-30.30s" "$module_name")
if [ -d "$dir/.git" ]; then if [ -d "$dir/.git" ]; then
branch=$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null) branch=$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null)
branch=${branch:-"—"} branch=${branch:-"—"}
branch_short=$(printf "%-20.20s" "$branch") branch_short=$(printf "%-15.15s" "$branch")
commit_date=$(git -C "$dir" log -1 --format="%cd" --date=short 2>/dev/null) commit_date=$(git -C "$dir" log -1 --format="%cd" --date=short 2>/dev/null)
commit_date=${commit_date:-"—"} commit_date=${commit_date:-"—"}
...@@ -209,28 +131,113 @@ case $action in ...@@ -209,28 +131,113 @@ case $action in
git -C "$dir" fetch --quiet 2>/dev/null git -C "$dir" fetch --quiet 2>/dev/null
behind=$(git -C "$dir" rev-list --count HEAD.."$upstream" 2>/dev/null) behind=$(git -C "$dir" rev-list --count HEAD.."$upstream" 2>/dev/null)
if [ "$behind" -gt 0 ]; then if [ "$behind" -gt 0 ]; then
pull_status="${YELLOW}Pull needed${NC}" pull_status="${YELLOW}NOT UP TO DATE${NC}"
else else
pull_status="${GREEN}Up to date${NC}" pull_status="${GREEN}UP TO DATE${NC}"
fi fi
else else
pull_status="${RED}No upstream${NC}" pull_status="${RED}NO UPSTREAM${NC}"
fi fi
printf "%-45s | %-20s | %-12s | %-10s | %b\n" \ printf "%-30s | %-15s | %-11s | %-9s | %b\n" \
"$module_name" "$branch_short" "$commit_date" "$commit_id" "$pull_status" "$module_name_short" "$branch_short" "$commit_date" "$commit_id" "$pull_status"
else else
printf "%-45s | %-20s | %-12s | %-10s | %b\n" \ printf "%-30s | %-15s | %-11s | %-9s | %b\n" \
"$module_name" "-" "-" "-" "${RED}Not a Git repo${NC}" "$module_name_short" "-" "-" "-" "${RED}NOT A GIT REPO${NC}"
fi fi
done done
else else
echo "❌ Custom modules directory not found: $BASE_DIR" echo "${RED}ERROR : Custom modules directory not found: $BASE_DIR"
fi
}
usage() {
echo -e "Usage $0 <command> [args]\n"
echo -e "COMMANDS\n"
echo "bash"
echo -e "\t opens 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 "info"
echo -e "\t displays information about your Dolibarr instance"
echo "info_export"
echo -e "\t displays information about your Dolibarr instance and export to file"
echo "logs"
echo -e "\t Follow all useful logs"
echo "logs <term1> <term2> ..."
echo -e "\t Follow all useful logs and highlight terms"
echo "mysql"
echo -e "\t pen a mysql prompt in Dolibarr database"
echo "mysql_dump"
echo -e "\t creates a database dump"
echo "mysql_init"
echo -e "\t populate Dolibarr database (Docker only)"
echo "mysql_restore"
echo -e "\t restores database from a dump"
echo "perms"
echo -e "\t sets default files permissions"
echo "restart"
echo -e "\t restart the docker stack or apache2"
echo "shell"
echo -e "\t run a php shell, same as $0 artisan tinker"
echo "up"
echo -e "\t starts the docker stack"
echo "tags"
echo -e "\t generate ctags"
echo "fail2ban"
echo -e "\t root only - put fail2ban jail and filter in good directory with good log path"
}
if [ "$(is_docker)" -eq 1 ]; then
if [ -z "$(which docker-compose)" ]; then
compose="docker compose"
else
compose="docker-compose"
fi
cmd="$compose exec $APP_SERVICE"
cmdmy="$compose exec $DB_SERVICE"
cmdmyInput="docker exec -i $($compose ps -q $DB_SERVICE)"
cmdrestart="$compose restart"
cmdup="$compose up"
cmddown="$compose down"
else
cmdrestart="apache2ctl restart"
fi fi
if [ ! -z "$(which ccze)" ]; then
reader="ccze -A"
else
reader="tee"
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
;;
"info")
info
;;
"info_export")
# Run info command and export to file with date
current_date=$(date +%Y%m%d_%H%M%S)
info > "dolibarr_info_${current_date}.txt"
echo "Dolibarr info exported to dolibarr_info_${current_date}.txt"
;; ;;
"logs") "logs")
set -x set -x
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment