@@ -245,7 +245,7 @@ function build_sketch { # build_sketch <ide_path> <user_path> <path-to-ino> [ext
245245 fi
246246
247247 # Install libraries from ci.json if they exist
248- install_libs -ai " $ide_path " -s " $sketchdir " -v
248+ install_libs -ai " $ide_path " -s " $sketchdir "
249249 install_result=$?
250250 if [ $install_result -ne 0 ]; then
251251 echo " ERROR: Library installation failed for $sketchname " >&2
@@ -588,6 +588,21 @@ function build_sketches { # build_sketches <ide_path> <user_path> <target> <path
588588 return 0
589589}
590590
591+ # Return 0 if the string looks like a git URL we should pass to --git-url
592+ is_git_like_url () {
593+ local u=$1
594+ [[ " $u " =~ ^https? ://.+ ]] || [[ " $u " =~ ^git@[^:]+:.+ ]]
595+ }
596+
597+ # If status!=0, print errors/warnings from captured output (fallback to full output)
598+ print_err_warnings () {
599+ local status=$1 ; shift
600+ local out=$*
601+ if [ " $status " -ne 0 ]; then
602+ printf ' %s\n' " $out " | grep -Ei " error|warning|warn" >&2 || printf ' %s\n' " $out " >&2
603+ fi
604+ }
605+
591606function install_libs { # install_libs <ide_path> <sketchdir> [-v]
592607 local ide_path=" "
593608 local sketchdir=" "
@@ -622,13 +637,10 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
622637 return 1
623638 fi
624639
625- # No ci.json => nothing to install
626640 if [ ! -f " $sketchdir /ci.json" ]; then
627641 [ " $verbose " = true ] && echo " No ci.json found in $sketchdir , skipping library installation"
628642 return 0
629643 fi
630-
631- # Validate JSON early
632644 if ! jq -e . " $sketchdir /ci.json" > /dev/null 2>&1 ; then
633645 echo " ERROR: $sketchdir /ci.json is not valid JSON" >&2
634646 return 1
@@ -658,24 +670,21 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
658670 local libs
659671 libs=$( jq -r ' .libs[]? // empty' " $sketchdir /ci.json" )
660672
661- # Detect if any lib is a Git URL (needs unsafe install )
673+ # Detect any git-like URL (GitHub/GitLab/Bitbucket/self-hosted/ssh )
662674 for lib in $libs ; do
663- if [[ " $lib " == https://github.com/ * ]] ; then
675+ if is_git_like_url " $lib " ; then
664676 needs_unsafe=true
665677 break
666678 fi
667679 done
668680
669- # Enable unsafe installs if needed, remember original setting
670681 if [ " $needs_unsafe " = true ]; then
671682 [ " $verbose " = true ] && echo " Checking current unsafe install setting..."
672683 original_unsafe_setting=$( " $ide_path /arduino-cli" config get library.enable_unsafe_install 2> /dev/null || echo " false" )
673684 if [ " $original_unsafe_setting " = " false" ]; then
674685 [ " $verbose " = true ] && echo " Enabling unsafe installs for Git URLs..."
675- if ! " $ide_path /arduino-cli" config set library.enable_unsafe_install true > /dev/null 2>&1 ; then
686+ " $ide_path /arduino-cli" config set library.enable_unsafe_install true > /dev/null 2>&1 || \
676687 echo " WARNING: Failed to enable unsafe installs, Git URL installs may fail" >&2
677- # continue; the install will surface a real error if it matters
678- fi
679688 else
680689 [ " $verbose " = true ] && echo " Unsafe installs already enabled"
681690 fi
@@ -685,15 +694,14 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
685694 for lib in $libs ; do
686695 [ " $verbose " = true ] && echo " Processing library: $lib "
687696
688- if [[ " $lib " == https://github.com/ * ]] ; then
689- [ " $verbose " = true ] && echo " Installing library from GitHub URL: $lib "
697+ if is_git_like_url " $lib " ; then
698+ [ " $verbose " = true ] && echo " Installing library from git URL: $lib "
690699 if [ " $verbose " = true ]; then
691700 " $ide_path /arduino-cli" lib install --git-url " $lib "
692701 install_status=$?
693702 else
694703 output=$( " $ide_path /arduino-cli" lib install --git-url " $lib " 2>&1 )
695704 install_status=$?
696- [ $install_status -ne 0 ] && echo " $output " | grep -Ei " error|warning|warn" >&2 || true
697705 fi
698706 else
699707 [ " $verbose " = true ] && echo " Installing library by name: $lib "
@@ -703,10 +711,18 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
703711 else
704712 output=$( " $ide_path /arduino-cli" lib install " $lib " 2>&1 )
705713 install_status=$?
706- [ $install_status -ne 0 ] && echo " $output " | grep -Ei " error|warning|warn" >&2 || true
707714 fi
708715 fi
709716
717+ # Treat "already installed"/"up to date" as success (idempotent)
718+ if [ $install_status -ne 0 ] && echo " $output " | grep -qiE ' already installed|up to date' ; then
719+ install_status=0
720+ fi
721+
722+ if [ " $verbose " != true ]; then
723+ print_err_warnings " $install_status " " $output "
724+ fi
725+
710726 if [ $install_status -ne 0 ]; then
711727 echo " ERROR: Failed to install library: $lib " >&2
712728 rc=$install_status
@@ -716,7 +732,6 @@ function install_libs { # install_libs <ide_path> <sketchdir> [-v]
716732 fi
717733 done
718734
719- # Restore unsafe setting if we changed it
720735 if [ " $needs_unsafe " = true ] && [ " $original_unsafe_setting " = " false" ]; then
721736 [ " $verbose " = true ] && echo " Restoring original unsafe install setting..."
722737 " $ide_path /arduino-cli" config set library.enable_unsafe_install false > /dev/null 2>&1 || true
0 commit comments