git-init.sh (1444B)
1 #!/usr/bin/env sh 2 # POSIX shell script to add remote git repository 3 4 USER='git' 5 HOST='git' 6 LICENSE="${HOME}/docs/licenses/agpl-3.0.txt" 7 REMOTE='origin' 8 BRANCH='master' 9 DIR="git@git:/srv/git/${PWD##*/}.git" 10 GREEN='\033[32;01m' 11 RED='\033[31;01m' 12 NORMAL='\033[0m' 13 14 text() 15 { 16 case ${?} in 17 0) 18 printf "${GREEN}*${NORMAL} %s\n" "${*}" 19 ;; 20 *) 21 printf "${RED}*${NORMAL} %s\n" "${*}" >&2 22 exit 1 23 esac 24 } 25 26 main() 27 { 28 printf '%s: ' "Do you want to initialize a git repo on ${PWD}? (y/n)" 29 read -r choice; 30 case "${choice}" in 31 [Yy]|[Yy][Ee][Ss]) 32 : 33 ;; 34 *) false 35 text "Git initialization aborted" 36 exit 37 esac 38 text "Initializing git repository..." 39 git init . >/dev/null || text "Init failed." 40 text "Adding remote ${DIR}..." 41 git remote add "${REMOTE}" "${DIR}" || text "Add remote ${REMOTE} failed." 42 text "Adding LICENSE..." 43 cp "${LICENSE}" ./LICENSE || text "Add LICENSE failed." 44 text "Commiting..." 45 git add . 46 GPG_TTY=$(tty) git commit -S -m 'Initial commit.' || text "Commiting failed." 47 text "Creating ${DIR##*:}..." 48 ssh -l "${USER}" "${HOST}" "mkdir ${DIR##*:}; cd ${DIR##*:}; git init --bare ." || text "Directory creation on ${HOST} failed." 49 text "Pushing..." 50 git push --set-upstream "${REMOTE}" "${BRANCH}" || text "Push to ${REMOTE} failed..." 51 } 52 53 main "${@}"