diff --git a/doli b/doli index d22b03e7c6168796ac9569cf5d6374886ef14d99..02da5296e9e81b88ed1108d36bfe3a3b7924ed7d 100755 --- a/doli +++ b/doli @@ -21,6 +21,136 @@ is_docker() { fi } +info(){ + 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 + timestamp=$(date '+%Y-%m-%d %H:%M:%S') + + # Hostname + host=$(hostname) + + # Dolibarr instance name (parent of dolibarr_src) + instance_path=$(realpath dolibarr_src/.. 2>/dev/null) + instance_name=$(basename "$instance_path") + + echo -e "Generated at: $timestamp" + echo -e "Machine: $host" + echo -e "Instance: $instance_name" + echo -e "Instance path: $instance_path\n" + + ## Docker deployment + if [ "$(is_docker)" -eq 1 ]; then + echo "Docker deployment detected." + echo "Service: $APP_SERVICE" + echo "Database Service: $DB_SERVICE" + echo "User: $user" + echo "Database: $db" + echo "Document Path: $document_path" + else + echo "Non-Docker deployment detected." + echo "Please check your configuration manually." + fi + + ## PHP Version + if command -v php > /dev/null; then + php_version=$(php -r 'echo PHP_VERSION;') + echo "PHP Version: $php_version" + else + echo "PHP is not installed or not found in PATH." + fi + + ## Dolibarr Version + if [ -f "dolibarr_src/htdocs/install/version.php" ]; then + version=$(grep -oP '\$dolibarr_version\s*=\s*"\K[^"]+' dolibarr_src/htdocs/install/version.php) + echo "Dolibarr Version: $version" + else + echo "Dolibarr version file not found." + fi + + ## Dolibarr branch + if [ -d "dolibarr_src/.git" ]; then + cd dolibarr_src || exit + + branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null) + + status="${RED}No upstream${NC}" + + if [ -n "$upstream" ]; then + remote=$(echo "$upstream" | cut -d'/' -f1) + git fetch "$remote" > /dev/null 2>&1 + behind=$(git rev-list --count HEAD.."$upstream" 2>/dev/null) + + if [ "$behind" -gt 0 ]; then + status="${YELLOW}NOT UP TO DATE${NC}" + else + status="${GREEN}UP TO DATE${NC}" + fi + fi + + echo -e "Dolibarr Branch: $branch [$status]" + + cd - > /dev/null || exit + else + echo "Dolibarr source directory is not a Git repository." + fi + + ## Modules + BASE_DIR="dolibarr_src/htdocs/custom" + if [ -d "$BASE_DIR" ]; then + echo -e "\nCustom modules directory: $BASE_DIR\n" + echo "Modules in custom directory:" + printf "%-30s | %-15s | %-11s | %-9s | %s\n" "Module" "Git Branch" "Last Commit" "Commit ID" "Up to date" + printf "%-30s-+-%-15s-+-%-11s-+-%-9s-+-%s\n" \ + "$(printf '%.0s-' {1..30})" "$(printf '%.0s-' {1..15})" \ + "$(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 + module_name=$(basename "$dir") + module_name_short=$(printf "%-30.30s" "$module_name") + + if [ -d "$dir/.git" ]; then + branch=$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null) + branch=${branch:-"—"} + branch_short=$(printf "%-15.15s" "$branch") + + commit_date=$(git -C "$dir" log -1 --format="%cd" --date=short 2>/dev/null) + commit_date=${commit_date:-"—"} + + commit_id=$(git -C "$dir" rev-parse --short=8 HEAD 2>/dev/null) + commit_id=${commit_id:-"—"} + + upstream=$(git -C "$dir" rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null) + if [ -n "$upstream" ]; then + git -C "$dir" fetch --quiet 2>/dev/null + behind=$(git -C "$dir" rev-list --count HEAD.."$upstream" 2>/dev/null) + if [ "$behind" -gt 0 ]; then + pull_status="${YELLOW}NOT UP TO DATE${NC}" + else + pull_status="${GREEN}UP TO DATE${NC}" + fi + else + pull_status="${RED}NO UPSTREAM${NC}" + fi + + printf "%-30s | %-15s | %-11s | %-9s | %b\n" \ + "$module_name_short" "$branch_short" "$commit_date" "$commit_id" "$pull_status" + else + printf "%-30s | %-15s | %-11s | %-9s | %b\n" \ + "$module_name_short" "-" "-" "-" "${RED}NOT A GIT REPO${NC}" + fi + done + else + echo "${RED}ERROR : Custom modules directory not found: $BASE_DIR" + fi +} + usage() { echo -e "Usage $0 <command> [args]\n" echo -e "COMMANDS\n" @@ -30,16 +160,20 @@ usage() { 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 LNB database" + 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 LabNbook database (Docker only)" + echo -e "\t populate Dolibarr database (Docker only)" echo "mysql_restore" echo -e "\t restores database from a dump" echo "perms" @@ -97,140 +231,13 @@ case $action in usage ;; "info") - echo "** Info about your Dolibarr instance **" - - # Date and time - timestamp=$(date '+%Y-%m-%d %H:%M:%S') - - # Hostname - host=$(hostname) - - # Dolibarr instance name (parent of dolibarr_src) - instance_path=$(realpath dolibarr_src/.. 2>/dev/null) - instance_name=$(basename "$instance_path") - - - echo -e "Generated at: $timestamp" - echo -e "Machine: $host" - echo -e "Instance: $instance_name" - echo -e "Instance path: $instance_path\n" - - - - ## Docker deployment - if [ "$(is_docker)" -eq 1 ]; then - echo "Docker deployment detected." - echo "Service: $APP_SERVICE" - echo "Database Service: $DB_SERVICE" - echo "User: $user" - echo "Database: $db" - echo "Document Path: $document_path" - else - echo "Non-Docker deployment detected." - echo "Please check your configuration manually." - fi - - ## PHP Version - if command -v php > /dev/null; then - php_version=$(php -r 'echo PHP_VERSION;') - echo "PHP Version: $php_version" - else - echo "PHP is not installed or not found in PATH." - fi - - ## Dolibarr Version - if [ -f "dolibarr_src/htdocs/install/version.php" ]; then - version=$(grep -oP '\$dolibarr_version\s*=\s*"\K[^"]+' dolibarr_src/htdocs/install/version.php) - echo "Dolibarr Version: $version" - else - echo "Dolibarr version file not found." - fi - - ## Dolibarr branch - if [ -d "dolibarr_src/.git" ]; then - 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) - upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null) - - status="${RED}No upstream${NC}" - - if [ -n "$upstream" ]; then - remote=$(echo "$upstream" | cut -d'/' -f1) - git fetch "$remote" > /dev/null 2>&1 - behind=$(git rev-list --count HEAD.."$upstream" 2>/dev/null) - - if [ "$behind" -gt 0 ]; then - status="${YELLOW}Pull needed${NC}" - else - status="${GREEN}Up to date${NC}" - fi - fi - - echo -e "Dolibarr Branch: $branch [$status]" - - cd - > /dev/null || exit - else - echo "Dolibarr source directory is not a Git repository." - fi - - - ## Modules - BASE_DIR="dolibarr_src/htdocs/custom" - if [ -d "$BASE_DIR" ]; then - echo -e "\nCustom modules directory: $BASE_DIR\n" - echo "Modules in custom directory:" - printf "%-45s | %-20s | %-12s | %-10s | %s\n" "Module" "Git Branch" "Last Commit" "Commit ID" "Up to date" - printf "%-45s-+-%-20s-+-%-12s-+-%-10s-+-%s\n" \ - "$(printf '%.0s-' {1..45})" "$(printf '%.0s-' {1..20})" \ - "$(printf '%.0s-' {1..12})" "$(printf '%.0s-' {1..10})" "$(printf '%.0s-' {1..6})" - - find "$BASE_DIR" -maxdepth 1 -mindepth 1 -type d ! -name '.*' | sort | while read -r dir; do - module_name=$(basename "$dir") - - if [ -d "$dir/.git" ]; then - branch=$(git -C "$dir" rev-parse --abbrev-ref HEAD 2>/dev/null) - branch=${branch:-"—"} - branch_short=$(printf "%-20.20s" "$branch") - - commit_date=$(git -C "$dir" log -1 --format="%cd" --date=short 2>/dev/null) - commit_date=${commit_date:-"—"} - - commit_id=$(git -C "$dir" rev-parse --short=8 HEAD 2>/dev/null) - commit_id=${commit_id:-"—"} - - upstream=$(git -C "$dir" rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null) - if [ -n "$upstream" ]; then - git -C "$dir" fetch --quiet 2>/dev/null - behind=$(git -C "$dir" rev-list --count HEAD.."$upstream" 2>/dev/null) - if [ "$behind" -gt 0 ]; then - pull_status="${YELLOW}Pull needed${NC}" - else - pull_status="${GREEN}Up to date${NC}" - fi - else - pull_status="${RED}No upstream${NC}" - fi - - printf "%-45s | %-20s | %-12s | %-10s | %b\n" \ - "$module_name" "$branch_short" "$commit_date" "$commit_id" "$pull_status" - else - printf "%-45s | %-20s | %-12s | %-10s | %b\n" \ - "$module_name" "-" "-" "-" "${RED}Not a Git repo${NC}" - fi - done - else - echo "❌ Custom modules directory not found: $BASE_DIR" - fi - - - - + 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") set -x