From 81873de46fa20d0d13ee44659850c07c2b247816 Mon Sep 17 00:00:00 2001 From: danix Date: Tue, 18 Dec 2018 15:12:50 +0100 Subject: initial commit --- delete | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 delete (limited to 'delete') diff --git a/delete b/delete new file mode 100755 index 0000000..f8664d4 --- /dev/null +++ b/delete @@ -0,0 +1,58 @@ +#! /bin/bash + +# usage: delete - PERMANENTLY delete a repository if existing. +# CAREFUL, this action cannot be undone. This command will ask for confirmation. + +GITDIR="/var/git" + +function is_bare() { + repodir=$1 + if "$(git --git-dir="$repodir" rev-parse --is-bare-repository)" = true + then + true + else + false + fi +} + +if [ ! -z $1 ]; then + PROJECT=$1 +else + read -p 'Project to delete: ' PROJECT +fi + +if [ -d ${GITDIR}/${PROJECT}.git ]; then + if [[ $(ls -A ${GITDIR}/${PROJECT}.git) ]]; then + if is_bare ${GITDIR}/${PROJECT}.git + then + echo "You are going to delete the git repository \"${PROJECT}.git\" Do you really want to continue? Note, this action cannot be reverted. [y/N]" + read delAnswer + case $delAnswer in + Y|y) + rm -rfv ${PROJECT}.git + if [ $? == 0 ]; then + echo "Successfully deleted ${PROJECT}.git" + else + echo "An error occurred while deleting ${PROJECT}.git" + fi + ;; + N|n) + echo "Aborting due to user request." + exit 173 + ;; + *) + echo "you said \"$delAnswer\" which I don't understand. Assuming No. Aborting." + exit 177 + ;; + esac + else + echo "\"${PROJECT}.git\" doesn't look like a git repository. Check with your System Administrator." + exit 177 + fi + else + echo "\"${PROJECT}.git\" is an empty directory, Skipping. Check with your System Administrator." + exit 177 + fi +fi + + -- cgit v1.2.3