]> git.christiangoeschel.com Git - mygit.git/commitdiff
Changed REPO_NAME and ERR_MSG variable characteristics master
authorchristiangoeschel <cndjomouo@icloud.com>
Sat, 28 Sep 2024 02:48:48 +0000 (22:48 -0400)
committerchristiangoeschel <cndjomouo@icloud.com>
Sat, 28 Sep 2024 02:48:48 +0000 (22:48 -0400)
server/delrepo [new file with mode: 0644]
server/mkrepo

diff --git a/server/delrepo b/server/delrepo
new file mode 100644 (file)
index 0000000..4d89881
--- /dev/null
@@ -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 ${@}
index 589508d223a701ae7f9f6af3a7cf328ba1a303c3..8098f445cb3b28f693801d77bed75cc9fe7f08f0 100644 (file)
@@ -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() {