From 48dd1959dd90d57b671cb26bfce48fcd35edbcf8 Mon Sep 17 00:00:00 2001 From: christiangoeschel Date: Fri, 27 Sep 2024 22:24:42 -0400 Subject: [PATCH 1/1] Refactored server/mkrepo --- server/mkrepo | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 server/mkrepo 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 ${@} -- 2.39.5