summaryrefslogtreecommitdiff
path: root/jails/gubbhub/gubbshell/delete-repo
blob: ee8b2c688f3fa22a80d181a2c2c2347422d3e586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env sh

set -euo pipefail

if ! id -nG | grep -qwF "gitadm"; then
    echo $'\e[31myou are not an admin\e[0m'
    exit 13
fi

if [ $# -lt 1 ]; then
  echo $'\e[31mrepository name is required\e[0m'
  exit 1
fi

name="$1"
path="$(echo "$1" | sed 's/ /-/' | tr '[:upper:]' '[:lower:]').git"

read -p $'\e[33mare you sure you want to delete the repo '"\"$name\" at \"$path\""$'\e[0m \e[1m[no]\e[0m: ' confirm

delete="false"
case "$(echo "$confirm" | tr '[:upper:]' '[:lower:]')" in
    y|yes|ye) delete="true" ;;
esac

if [ "$delete" = "true" ]; then
    echo -n "deleting repository \"$name\"..."
    rm -rf "$path"
    echo "done!"
fi

# delete the dir if empty
dir=$(dirname "$path")
find "$dir" -maxdepth 0 -type d -delete