From: christiangoeschel Date: Sat, 28 Sep 2024 02:24:42 +0000 (-0400) Subject: Refactored server/mkrepo X-Git-Url: https://git.christiangoeschel.com/?a=commitdiff_plain;h=48dd1959dd90d57b671cb26bfce48fcd35edbcf8;p=mygit.git Refactored server/mkrepo --- 48dd1959dd90d57b671cb26bfce48fcd35edbcf8 diff --git a/server/mkrepo b/server/mkrepo new file mode 100644 index 0000000..2539bbe --- /dev/null +++ b/server/mkrepo @@ -0,0 +1,51 @@ +#!/bin/bash +# +# What: mkrepo +# Date: 27 Sept 2024 +# Author: Christian Goeschel Ndjomouo (cgoesc2@wgu.edu) +# Description: Create an empty git repository + +# ------------------------------------------------------------- +# Global variables + +declare -r GIT_DIR="/srv/git" +declare -r REPO_NAME +declare -r ERR_MSG + +function create_repo() { + + if [[ -d "${GIT_DIR}/${REPO_NAME}" ]]; then + ERR_MSG="Repo ${REPO_NAME} already exists" + return 1 + fi + + /usr/bin/mkdir -p "${GIT_DIR}/${REPO_NAME}" && + cd ${GIT_DIR}/${REPO_NAME} && + git init --bare + + if [[ "${?}" != "0" ]]; then + ERR_MSG="Could not create repo ${REPO_NAME}" + return 1 + fi + + return 0 +} + +function main() { + + if [[ -z "${1}" ]]; then + echo "The repository name cannot be an empty string!" + exit 1 + fi + REPO_NAME="${1}.git" + + create_repo + if [[ "${?}" != "" ]]; then + echo "${ERR_MSG}" + exit 1 + fi + + exit 0 +} + +main ${@}