From: christiangoeschel Date: Sat, 28 Sep 2024 02:48:48 +0000 (-0400) Subject: Changed REPO_NAME and ERR_MSG variable characteristics X-Git-Url: https://git.christiangoeschel.com/?a=commitdiff_plain;ds=inline;p=mygit.git Changed REPO_NAME and ERR_MSG variable characteristics --- 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() {