From ad3ac30d1d60688f5173dac2921a0792f330aea8 Mon Sep 17 00:00:00 2001 From: christiangoeschel Date: Fri, 27 Sep 2024 22:48:48 -0400 Subject: [PATCH] Changed REPO_NAME and ERR_MSG variable characteristics --- server/delrepo | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ server/mkrepo | 4 ++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 server/delrepo diff --git a/server/delrepo b/server/delrepo new file mode 100644 index 0000000..4d89881 --- /dev/null +++ b/server/delrepo @@ -0,0 +1,50 @@ +#!/bin/bash +# +# What: delrepo +# Date: 27 Sept 2024 +# Author: Christian Goeschel Ndjomouo (cgoesc2@wgu.edu) +# Description: Delete an a git repository + +# ------------------------------------------------------------- +# Global variables + +declare -r GIT_DIR="/srv/git" +declare -x REPO_NAME +declare -x ERR_MSG + +function delete_repo() { + + if [[ ! -d "${GIT_DIR}/${REPO_NAME}" ]]; then + ERR_MSG="Repo ${REPO_NAME} doesn't exist" + return 1 + fi + + rm -rf "${GIT_DIR}/${REPO_NAME}" && + if [[ "${?}" != "0" ]]; then + ERR_MSG="Could not delete 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" + + delete_repo + if [[ "${?}" != "0" ]]; then + echo "${ERR_MSG}" + exit 1 + fi + + echo "Successfully deleted repository ${REPO_NAME}" + + exit 0 +} + +main ${@} diff --git a/server/mkrepo b/server/mkrepo index 589508d..8098f44 100644 --- a/server/mkrepo +++ b/server/mkrepo @@ -9,8 +9,8 @@ # Global variables declare -r GIT_DIR="/srv/git" -declare -r REPO_NAME -declare -r ERR_MSG +declare -x REPO_NAME +declare -x ERR_MSG function create_repo() { -- 2.39.5