git2gzip


SUBMITTED BY: Guest

DATE: Dec. 6, 2013, 9:36 a.m.

FORMAT: Bash

SIZE: 2.2 kB

HITS: 672

  1. #!/bin/bash
  2. # git2gz v0.1 GPL
  3. if [ -z "$1" ]
  4. then
  5. echo "No argument given."
  6. echo "Usage: `basename $0` git://git-domain.com/example/example.git"
  7. exit 1
  8. fi
  9. gitx=$1
  10. # prüfen ob notwendige Programme vorhanden sind
  11. which awk >/dev/null 2>&1
  12. if [ $? -ne 0 ]
  13. then
  14. echo "[awk] is not installed on your system!"
  15. exit 1
  16. fi
  17. which git >/dev/null 2>&1
  18. if [ $? -ne 0 ]
  19. then
  20. echo "[git] is not installed on your system!"
  21. exit 1
  22. fi
  23. # domain name extrahieren und prüfen ob erreichbar
  24. git_domain=`echo $gitx | awk -v FS="/" '{print $3}'`
  25. ping -c 1 $git_domain >/dev/null 2>&1
  26. if [ $? -ne 0 ]
  27. then
  28. echo "The Domain [`echo $git_domain`] ist not available"
  29. echo "or the network is not reachable"
  30. exit 2
  31. fi
  32. # Temporary ordner prüfem
  33. if [ -d "/tmp" -a -w "/tmp" ]
  34. then
  35. dtmp="/tmp/"
  36. else
  37. if [ ! -d ~/tmp ]
  38. then
  39. mkdir ~/tmp
  40. if [ $? -ne 0 ]
  41. then
  42. echo "Create the [tmp] failed!"
  43. exit 1
  44. fi
  45. fi
  46. dtmp="~/tmp/"
  47. fi
  48. s1=${gitx##*/}
  49. s2=${s1%%.*}
  50. now=`date +'_%Y%m%d'`
  51. gitn="$s2$now"
  52. gitcdir="$dtmp$gitn"
  53. if [ ! -d $gitcdir ]
  54. then
  55. mkdir $gitcdir
  56. fi
  57. git clone $gitx $gitcdir
  58. if [ $? -ne 0 ]
  59. then
  60. echo "[git] could not finish its work!"
  61. exit 1
  62. else
  63. gzn=$gitn
  64. n=0
  65. while [ -e $gzn.tar.gz ]
  66. do
  67. let ++n
  68. gzn="$gitn($n)"
  69. done
  70. tar czfv $gzn.tar.gz $gitcdir >/dev/null 2>&1
  71. if [ $? -ne 0 ]
  72. then
  73. echo "directory could not be packed!"
  74. exit 1
  75. fi
  76. fi
  77. rm -Rf $gitcdir
  78. if [ $? -ne 0 ]
  79. then
  80. echo "[tmp] directory could not be deleted!"
  81. exit 1
  82. fi
  83. du -h $gzn.tar.gz

comments powered by Disqus