diff --git a/doli b/doli index 365f4ad43ad7370ba16fb455292149a1e96a90b3..d22b03e7c6168796ac9569cf5d6374886ef14d99 100755 --- a/doli +++ b/doli @@ -96,6 +96,142 @@ case $action in "help") 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 + + + + + ;; "logs") set -x # All parameters after $1 are highlight terms