]> git.christiangoeschel.com Git - mygit.git/commitdiff
Refactored server/mkrepo
authorchristiangoeschel <cndjomouo@icloud.com>
Sat, 28 Sep 2024 02:24:42 +0000 (22:24 -0400)
committerchristiangoeschel <cndjomouo@icloud.com>
Sat, 28 Sep 2024 02:24:42 +0000 (22:24 -0400)
server/mkrepo [new file with mode: 0644]

diff --git a/server/mkrepo b/server/mkrepo
new file mode 100644 (file)
index 0000000..2539bbe
--- /dev/null
@@ -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 ${@}