gitmeta.sh (1401B)
1 #!/bin/bash 2 3 nocontent_sha256="85ab6c163d43a17ea9cf7788308bca1466f1b0a8d1cc92e26e9bf63da4062aee" 4 localdir=$HOME/.local/share/gitrefresh 5 localdir_desc=$localdir/description 6 7 _level=3 8 while test $# != 0; do 9 case "$1" in 10 -v) 11 _debug=1 12 shift 13 _level=$1 14 shift 15 ;; 16 *) 17 break 18 ;; 19 esac 20 done 21 22 dbg() { 23 if [ "$1" -lt "$_level" ]; then 24 return 0 25 fi 26 27 case "$1" in 28 1) 29 lvl='debug' 30 clr='\e[0;36m' 31 ;; 32 2) 33 lvl='info' 34 clr='\e[0;32m' 35 ;; 36 37 3) 38 lvl='warn' 39 clr='\e[0;33m' 40 ;; 41 4) 42 lvl='error' 43 clr='\e[0;31m' 44 ;; 45 46 esac 47 48 if [ -z $_debug ]; then 49 return 0 50 fi 51 >&2 echo -e "$clr$(printf %-9s [$lvl])$2\e[0m" 52 } 53 wd=${1:-`pwd`} 54 wd=$(realpath $wd) 55 56 _IFS=$IFS 57 IFS=$(echo -en "\n\b") 58 used='' 59 pushd "$wd" > /dev/null 60 if [ "$?" -gt "0" ]; then 61 exit 1 62 fi 63 64 for d in $(find . -type d -not -name ".git"); do 65 if [ ! -z $used ]; then 66 if [[ "$d" =~ ^$used ]]; then 67 dbg 1 "still in repo, skipping $d" 68 continue 69 else 70 used='' 71 fi 72 fi 73 pushd "$d" > /dev/null 74 if [ $(git rev-parse HEAD 2> /dev/null) ]; then 75 used=$d 76 dbg 2 "found repo $d" 77 dsc="description" 78 if [ -d .git ]; then 79 dsc=.git/description 80 fi 81 h=$(sha256sum $dsc | awk '{ print $1; }') 82 if [ "$h" != $nocontent_sha256 ]; then 83 if [ -f $localdir_desc/$h ]; then 84 dbg 2 "already have $d ($h)" 85 else 86 cp -v $dsc $localdir_desc/$h 87 fi 88 fi 89 fi 90 popd > /dev/null 91 done 92 popd > /dev/null