MinimalistGit

Project to automate creating git repos on a minimal 'git daemon' server.
Log | Files | Refs | README | LICENSE

mkrepo (2961B)


      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. DONE Create a useful help menu
      9 # 4. TODO Create README.md for ${REPO}, unless flag is set to skip
     10 # 5. HOLD Implement 'template' repos
     11 # 6. HOLD Copy license file to ${REPO}, unless flag is set to skip
     12 
     13 REPODIR="/usr/local/www/git"
     14 TEMPLATE=0
     15 PRIVATE=0
     16 NO_DESC=0
     17 REMOTE=""
     18 
     19 help()
     20 {
     21     echo "Will put something here once flags are decided fully."
     22 
     23     echo "mkrepo [OPTIONS]"
     24     echo ""
     25     echo "-d: Does not add description to the repository"
     26     echo "-h: Print this help menu"
     27     echo "-n (NAME): The name of the new repo being created"
     28     echo "-r (URL): Create repository on server URL, this requires SSH be setup for that target in the relevant location"
     29 }
     30 
     31 createRepo()
     32 {
     33     if [ ${TEMPLATE} = 1 ] && [ ${PRIVATE} = 1 ]; then
     34         echo "Note: Behavior of private templates and regular templates are identical."
     35         EXT=.template
     36     elif [ ${PRIVATE} = 1 ]; then
     37         EXT=.private
     38     elif [ ${TEMPLATE} = 1 ]; then
     39         EXT=.template
     40     else
     41         EXT=.git
     42     fi
     43 
     44     # The remote option uses SSH to automatically perform remote operations
     45     # to avoid needing other orchestration tools
     46     # The commands are essentially the same as doing the actions locally,
     47     # they are just wrapped around SSH commands
     48     if [ -n ${REMOTE} ]; then
     49         ssh ${REMOTE} "git init --bare ${REPODIR}/${NAME}${EXT}"
     50         ssh ${REMOTE} "
     51             printf '#!/bin/sh\n
     52                     # This script is to generate the HTML for the git repo when a new commit is received\n
     53                     cd ${REPODIR}/${NAME}${EXT}\n
     54                     /usr/local/bin/stagit ./\n
     55                     /usr/local/bin/stagit-index ${REPODIR}/*git > ${REPODIR}/index.html' > ${REPODIR}/${NAME}${EXT}/hooks/post-receive"
     56             ssh ${REMOTE} "chmod u+x ${REPODIR}/${NAME}${EXT}/hooks/post-receive"
     57             exit 0
     58     fi
     59 
     60     git init --bare ${REPODIR}/${NAME}${EXT}
     61 
     62     if [ ${NO_DESC} != 1]; then
     63         $EDITOR ${REPODIR}/${NAME}${EXT}/description
     64     fi
     65 
     66     printf "#!/bin/sh\n
     67             # This script is to generate the HTML for the git repo when a new commit is received\n
     68             cd ${REPODIR}/${NAME}${EXT}\n
     69             /usr/local/bin/stagit ./\n
     70             /usr/local/bin/stagit-index ${REPODIR}/*git > ${REPODIR}/index.html" > ${REPODIR}/${NAME}${EXT}/hooks/post-receive
     71     chmod u+x ${REPODIR}/${NAME}${EXT}/hooks/post-receive
     72 
     73 }
     74 
     75 if [ "$#" -eq 0 ]; then
     76     help
     77 fi
     78 
     79 while getopts ":dhpr:tn:" f; do
     80     case $f in
     81         d) NO_DESC=1;;
     82         n) NAME=${OPTARG};;
     83         p) PRIVATE=1;;
     84         r) REMOTE=${OPTARG};;
     85         t) TEMPLATE=1;;
     86         h | *) help
     87                exit
     88            ;;
     89     esac
     90 done
     91 shift `expr $OPTIND - 1`
     92 
     93 createRepo $NAME $REMOTE $PRIVATE $TEMPLATE