nostril

A C cli tool for creating nostr events
git clone git://jb55.com/nostril
Log | Files | Refs | Submodules | README | LICENSE

refresh-submodules.sh (1044B)


      1 #! /bin/sh
      2 
      3 if [ $# = 0 ]; then
      4     echo "Usage: $0 <submoduledir1>..." >&2
      5     exit 1
      6 fi
      7 
      8 # If no git dir (or, if we're a submodule, git file), forget it.
      9 [ -e .git ] || exit 0
     10 
     11 # git submodule can't run in parallel.  Really.
     12 # Wait for it to finish if in parallel.
     13 if ! mkdir .refresh-submodules 2>/dev/null ; then
     14     # If we don't make progress in ~60 seconds, force delete and retry.
     15     LIMIT=$((50 + $$ % 20))
     16     i=0
     17     while [ $i -lt $LIMIT ]; do
     18 	[ -d .refresh-submodules ] || exit 0
     19 	sleep 1
     20 	i=$((i + 1))
     21     done
     22     rmdir .refresh-submodules
     23     exec "$0" "$@" || exit 1
     24 fi
     25 
     26 trap "rmdir .refresh-submodules" EXIT
     27 
     28 # Be a little careful here, since we do rm -rf!
     29 for m in "$@"; do
     30     if ! grep -q "path = $m\$" .gitmodules; then
     31 	echo "$m is not a submodule!" >&2
     32 	exit 1
     33     fi
     34 done
     35 
     36 # git submodule can segfault.  Really.
     37 if [ "$(git submodule status "$@" | grep -c '^ ')" != $# ]; then
     38     echo Reinitializing submodules "$@" ...
     39     git submodule sync "$@"
     40     rm -rf "$@"
     41     git submodule update --init --recursive "$@"
     42 fi