git 저장소 생성/삭제 스크립트

#!/bin/bash
############################################################
#
# Git Repository 생성 및 초기화
# ./mkrepo.sh <git repo name> <description>
#
############################################################
GIT_BASE_DIR="/mnt/scm/git"

usage() {
  echo "$0 \<git repo name\> \<description\>"
}

if [ $# -lt 2 ]
then
  usage
  exit 1
fi

GIT_DIR="${GIT_BASE_DIR}/$1.git"

if [ -d "${GIT_DIR}" ]
then
  echo "${GIT_DIR} directory already exists."
  exit 1
fi

mkdir -p "${GIT_DIR}"
git init --bare --shared ${GIT_DIR}
echo -n "$2" > "${GIT_DIR}/description"
chown scm:scm ${GIT_DIR}
if [ -f "${GIT_DIR}/HEAD" ]
then
  echo "${GIT_DIR} successfully created."
else
  echo "ERROR: Failed to create ${GIT_DIR}."
fi

#!/bin/bash
############################################################
#
# Git Repository 삭제
# ./rmrepo.sh <git repo name>
#
############################################################
GIT_BASE_DIR="/mnt/scm/git"

usage() {
  echo "$0 \<git repo name\>"
}

if [ $# -eq 0 ]
then
  usage
  exit 1
fi

GIT_DIR="${GIT_BASE_DIR}/$1.git"

if [ ! -d "${GIT_DIR}" ]
then
  echo "${GIT_DIR} directory does not exist."
  exit 1
fi

rm -rf ${GIT_DIR}
if [ ! -d "${GIT_DIR}" ]
then
  echo "${GIT_DIR} successfully removed."
else
  echo "ERROR: Failed to remove ${GIT_DIR}."
fi
위로 스크롤