NewRepo.sh (1706B)
1 #!/bin/sh 2 # This script is intended to automate creating new repositories 3 # for a basic Git daemon server. 4 # 5 # The process should look like: 6 # 1. DONE Create ${REPO} 7 # 2. DONE Set description for ${REPO}, unless flag is set to skip 8 # 3. TODO Create README.md for ${REPO}, unless flag is set to skip 9 # 4. HOLD Implement 'template' repos 10 # 5. HOLD Copy license file to ${REPO}, unless flag is set to skip 11 12 REPODIR="/usr/local/www/git" 13 TEMPLATE=0 14 PRIVATE=0 15 NO_DESC=0 16 17 help() 18 { 19 echo "Will put something here once flags are decided fully." 20 } 21 22 createRepo() 23 { 24 if [ ${TEMPLATE} = 1 ] && [ ${PRIVATE} = 1 ]; then 25 echo "Note: Behavior of private templates and regular templates are identical." 26 EXT=.template 27 elif [ ${PRIVATE} = 1 ]; then 28 EXT=.private 29 elif [ ${TEMPLATE} = 1 ]; then 30 EXT=.template 31 else 32 EXT=.git 33 fi 34 35 git init --bare ${REPODIR}/${NAME}${EXT} 36 37 if [ ${NO_DESC} != 1]; then 38 vim ${REPODIR}/${NAME}${EXT}/description 39 fi 40 41 printf "#!/bin/sh\n 42 # This script is to generate the HTML for the git repo when a new commit is received\n 43 cd ${REPODIR}/${NAME}${EXT}\n 44 /usr/local/bin/stagit ./\n 45 /usr/locla/bin/stagit-index ${REPODIR}/*git > ${REPODIR}/index.html" > ${REPODIR}/${NAME}${EXT}/hooks/post-receive 46 chmod u+x ${REPODIR}/${NAME}${EXT}/hooks/post-receive 47 48 } 49 50 if [ "$#" -eq 0 ]; then 51 help 52 fi 53 54 while getopts ":Dhptn:" f; do 55 case $f in 56 D) NO_DESC=1;; 57 n) NAME=${OPTARG};; 58 p) PRIVATE=1;; 59 t) TEMPLATE=1;; 60 h | *) help 61 exit 62 ;; 63 esac 64 done 65 shift `expr $OPTIND - 1` 66 67 createRepo $NAME $PRIVATE $TEMPLATE