diff options
-rwxr-xr-x | bash/mkproj.sh | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/bash/mkproj.sh b/bash/mkproj.sh new file mode 100755 index 0000000..75f41f9 --- /dev/null +++ b/bash/mkproj.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env sh + +###################################################################### +# @author : pico (pico@$HOSTNAME) +# @file : mkproj +# @created : Tuesday Dec 06, 2022 13:33:51 CST +# +# @description : shell script to simplify cgit +###################################################################### + +NC='\x1b[0m' +BLUE='\x1b[0;34m' +YELLOW='\033[0;33m' +RED='\x1b[0;31m' + +path="$HOME/.local/git" +config="$HOME/.config/git/git_template/hooks" +work="$HOME/git" + +echo "Start making bare repo" +echo -e "The repo will be located in $BLUE$path$NC" +read -r -p "Enter the repo name: " repo + +repo="${repo:-null}" +[ "${repo}" == 'null' ] && echo "no specific repo name was given" && exit 1 + +# dealing with bare repo +if [ ! -d $path ]; then + echo -e "$RED$path$NC doesn't exist." + read -n1 -r -p "Do you want to create it(y or n) " option + + # set default value to 'n' + if [ $option != 'y' ] && [ $option != 'n' ]; then + option='n' + fi + + # if y is given, create git directory + if [ $option == 'y' ]; then + mkdir -p "$path" + [ "$?" -ne 0 ] && echo "failed create path" || echo "$path created, now create repo" + fi + + # quit script + [ $option == 'n' ] && echo -e "${YELLOW}quit script$NC" +else + echo -e "${BLUE}$path${NC} exists, check if $repo exists" +fi + +# check if repo already exists +[ -d "$path/$repo" ] && \ + if [ -z "$(git -C $path/$repo rev-parse)" ]; then + echo -e "${YELLOW}$repo$NC exists, please check your git repo" + elif [ -s "$path/$repo" ]; then + echo -e "${YELLOW}$repo$NC is not empty, please check directory" + fi && \ + exit 1 + +echo -e "${YELLOW}$repo$NC does not exist, create repo" +git --bare init "$path/$repo" > /dev/null 2>&1 +#read owner +read -r -p "Enter the owner of the repo: " owner +#read description +read -r -p "Enter the description for this repo: " desc +# set info +[ ! -z "$owner" ] && echo "[gitweb]" >> "$path/$repo/config" && echo " owner = $owner" >> "$path/$repo/config" +[ ! -z "$desc" ] && echo "$desc" > "$path/$repo/description" + +echo -e "${YELLOW}finished bare repo creation!$NC" + +# set working tree +echo "" +echo -e "Centralized hooks are already set in ${BLUE}$config$NC" +echo -e -n "Do you want to set working tree? (git repo will be created in ${BLUE}$work$NC y/n): " +read -r wt + +if [ $wt == 'n' ] || [ $wt != 'y' ]; then + echo -e "${YELLOW}creation finished${NC}" + exit 1 +else + mkdir -p "$work/$repo" + [ "$?" -ne 0 ] && echo -e "failed creating ${BLUE}$work/$repo${NC}, please check permission" || echo -e "${YELLOW}creation finished${NC}" +fi |