From 24cfb6e08cf8c8b34dc1a2c6b0441ded6a0ae8bf Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Tue, 27 Nov 2018 01:01:58 +0100 Subject: code re-formatting --- git-repo | 305 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 152 insertions(+), 153 deletions(-) (limited to 'git-repo') diff --git a/git-repo b/git-repo index 9feacd7..6e910bc 100755 --- a/git-repo +++ b/git-repo @@ -7,207 +7,207 @@ C_bg_default=$(echo -e "\e[49m") C_bg_lblue=$(echo -e "\e[104m") _getent() { - local db=$1 - local key=$2 - getent $db $key | cut -d ':' -f 1 + local db=$1 + local key=$2 + getent $db $key | cut -d ':' -f 1 } _list_repo_dirs() { - find "$1" -maxdepth 6 -type d -not -path '*.git/*' -name '*.git' 2>/dev/null + find "$1" -maxdepth 6 -type d -not -path '*.git/*' -name '*.git' 2>/dev/null } do_list() { - if [ -n "$1" ]; then - local root_path=$(readlink -f "$1") - else - local root_path=$BASEDIR - fi - echo -n "Working.. listing repositories under $root_path" - for repo_path in $(_list_repo_dirs $root_path | sort); do - echo -ne "\r" # to remove working - eval $(stat --format 'local repo_path_uid=%u repo_path_gid=%g repo_path_mode=%a' "$repo_path") - if [ "$repo_path_uid" != "$UID" ]; then - # so there must be a matching gid - local pass=false - for user_gid in $(id -G); do - if [ "$repo_path_gid" == "$user_gid" ]; then - pass=true - fi - done - if ! $pass; then - continue # skip that repo since uid and gids don't match - fi - + if [ -n "$1" ]; then + local root_path=$(readlink -f "$1") + else + local root_path=$BASEDIR + fi + echo -n "Working.. listing repositories under $root_path" + for repo_path in $(_list_repo_dirs $root_path | sort); do + echo -ne "\r" # to remove working + eval $(stat --format 'local repo_path_uid=%u repo_path_gid=%g repo_path_mode=%a' "$repo_path") + if [ "$repo_path_uid" != "$UID" ]; then + # so there must be a matching gid + local pass=false + for user_gid in $(id -G); do + if [ "$repo_path_gid" == "$user_gid" ]; then + pass=true fi + done + if ! $pass; then + continue # skip that repo since uid and gids don't match + fi - local shortdesc=$(cut -c 1-40 < "$repo_path/description") - local permissions="owner=$(_getent passwd $repo_path_uid)" - local color="$C_bg_green" - if [ $(( 0$repo_path_mode & 070 )) -gt 0 ]; then # shared - permissions="$permissions group=$(_getent group $repo_path_gid)" - color="$C_bg_lblue" - fi - if [ $(( 0$repo_path_mode & 07 )) -gt 0 ]; then # public - permissions="$permissions PUBLIC" + fi + + local shortdesc=$(cut -c 1-40 < "$repo_path/description") + local permissions="owner=$(_getent passwd $repo_path_uid)" + local color="$C_bg_green" + if [ $(( 0$repo_path_mode & 070 )) -gt 0 ]; then # shared + permissions="$permissions group=$(_getent group $repo_path_gid)" + color="$C_bg_lblue" + fi + if [ $(( 0$repo_path_mode & 07 )) -gt 0 ]; then # public + permissions="$permissions PUBLIC" if ! [ -f "$repo_path/PUBLIC" ]; then permissions="${permissions}-but-cgit-marker-file-missing" fi - color="$C_bg_magenta" - fi - printf "%s%-60s (%s) (%s)\n" "$color" "$repo_path$C_bg_default" "$permissions" "$shortdesc" - done + color="$C_bg_magenta" + fi + printf "%s%-60s (%s) (%s)\n" "$color" "$repo_path$C_bg_default" "$permissions" "$shortdesc" + done } _create_repo() { - local label=$1 - local shared=$2 - local group=$3 - local is_public=$4 + local label=$1 + local shared=$2 + local group=$3 + local is_public=$4 - read -p 'New repository name.git: ' - local repo_name=$REPLY + read -p 'New repository name.git: ' + local repo_name=$REPLY - if ! `expr "$repo_name" : '.*\.git' >/dev/null`; then - echo "Repository name must end with .git" - return 1 - fi + if ! `expr "$repo_name" : '.*\.git' >/dev/null`; then + echo "Repository name must end with .git" + return 1 + fi - local repo_dir=$BASEDIR/$USER/${repo_name} + local repo_dir=$BASEDIR/$USER/${repo_name} - test \! -e "$repo_dir" || { echo "Repo $repo_dir already exist"; exit 1; } + test \! -e "$repo_dir" || { echo "Repo $repo_dir already exist"; exit 1; } - read -p 'Set Description: ' - local repo_desc=$REPLY + read -p 'Set Description: ' + local repo_desc=$REPLY - read -p "Create $label in $repo_dir Ok? (y/N)" - test "$REPLY" == "y" || exit 1 + read -p "Create $label in $repo_dir Ok? (y/N)" + test "$REPLY" == "y" || exit 1 - mkdir -p "$repo_dir" - git init -q --bare --shared=$shared "$repo_dir" - git config receive.denyNonFastforwards false - chgrp -R "$group" "$repo_dir" - echo "$repo_desc" > "$repo_dir/description" + mkdir -p "$repo_dir" + git init -q --bare --shared=$shared "$repo_dir" + git config receive.denyNonFastforwards false + chgrp -R "$group" "$repo_dir" + echo "$repo_desc" > "$repo_dir/description" - if $is_public; then - touch "$repo_dir/PUBLIC" - echo "created $repo_dir/PUBLIC to expose via cgit" - fi + if $is_public; then + touch "$repo_dir/PUBLIC" + echo "created $repo_dir/PUBLIC to expose via cgit" + fi - echo "done creating $label in $repo_dir" - echo "use 'git repo show $repo_dir' for details" - return 0 + echo "done creating $label in $repo_dir" + echo "use 'git repo show $repo_dir' for details" + return 0 } do_create_public() { - _create_repo "public repository" "0664" "share" true - return $? + _create_repo "public repository" "0664" "share" true + return $? } do_create_shared() { - _create_repo "group-writeable repository" "0660" "share" false - return $? + _create_repo "group-writeable repository" "0660" "share" false + return $? } do_create_private() { - _create_repo "private repository" "0600" "$USER" false - return $? + _create_repo "private repository" "0600" "$USER" false + return $? } do_show() { - for repo_path in $*; do - if ! [ -f "$repo_path/HEAD" ]; then - repo_path="$BASEDIR/$repo_path" - fi - if ! [ -f "$repo_path/HEAD" ]; then - echo "Not a git repository: $repo_path" - continue - fi - - local repo_file_mode=$(stat --format %a "$repo_path") - local repo_file_uid=$(stat --format %u "$repo_path") - local repo_file_user=$(_getent passwd $repo_file_uid) - local repo_file_gid=$(stat --format %g "$repo_path") - local repo_file_group=$(_getent group $repo_file_gid) - local repo_git_shared=$(GIT_DIR="$repo_path" git config --get core.sharedrepository) - - echo " Directory: $repo_path" - echo " ✔ Permissions mode ${repo_file_mode} (uid=${repo_file_uid}/${repo_file_user} gid=${repo_file_gid}/${repo_file_group})" - echo " git core.sharedrepository=$repo_git_shared" - echo " ⚡ Clone read/write SSH: git clone 'ssh://localnet.cc${repo_path}'" - if [ $(( 0$repo_file_mode & 07 )) -gt 0 ]; then - echo " Clone read/- HTTP: git clone 'http://localnet.cc/cgit/cgit.cgi/${repo_path#$BASEDIR/}'" - fi - echo " Update remote: git remote set-url origin 'ssh://localnet.cc${repo_path}" - echo " ☛ To update description execute: $EDITOR $repo_path/description" - echo "" - done + for repo_path in $*; do + if ! [ -f "$repo_path/HEAD" ]; then + repo_path="$BASEDIR/$repo_path" + fi + if ! [ -f "$repo_path/HEAD" ]; then + echo "Not a git repository: $repo_path" + continue + fi + + local repo_file_mode=$(stat --format %a "$repo_path") + local repo_file_uid=$(stat --format %u "$repo_path") + local repo_file_user=$(_getent passwd $repo_file_uid) + local repo_file_gid=$(stat --format %g "$repo_path") + local repo_file_group=$(_getent group $repo_file_gid) + local repo_git_shared=$(GIT_DIR="$repo_path" git config --get core.sharedrepository) + + echo " Directory: $repo_path" + echo " ✔ Permissions mode ${repo_file_mode} (uid=${repo_file_uid}/${repo_file_user} gid=${repo_file_gid}/${repo_file_group})" + echo " git core.sharedrepository=$repo_git_shared" + echo " ⚡ Clone read/write SSH: git clone 'ssh://localnet.cc${repo_path}'" + if [ $(( 0$repo_file_mode & 07 )) -gt 0 ]; then + echo " Clone read/- HTTP: git clone 'http://localnet.cc/cgit/cgit.cgi/${repo_path#$BASEDIR/}'" + fi + echo " Update remote: git remote set-url origin 'ssh://localnet.cc${repo_path}" + echo " ☛ To update description execute: $EDITOR $repo_path/description" + echo "" + done } do_mirror() { - local root_path=$(readlink -f "$1") - for repo_path in $(_list_repo_dirs $root_path); do - local is_mirror=$(GIT_DIR="$repo_path" git config --get remote.origin.mirror) - if [ "$is_mirror" != "true" ]; then - continue # skip non-mirror repo - fi - echo "Mirror $repo_path from $(GIT_DIR="$repo_path" git config --get remote.origin.url)" - GIT_DIR="$repo_path" git fetch --force --prune origin - done + local root_path=$(readlink -f "$1") + for repo_path in $(_list_repo_dirs $root_path); do + local is_mirror=$(GIT_DIR="$repo_path" git config --get remote.origin.mirror) + if [ "$is_mirror" != "true" ]; then + continue # skip non-mirror repo + fi + echo "Mirror $repo_path from $(GIT_DIR="$repo_path" git config --get remote.origin.url)" + GIT_DIR="$repo_path" git fetch --force --prune origin + done } do_make_public() { - local repo_path=$1 - test -f "$repo_path/HEAD" || { echo "$repo_path is not a git repository"; exit 1; } - set -x - git init -q --bare --shared=0664 "$repo_path" - find "$repo_path" -type d -exec chown $USER:share \{\} \; - find "$repo_path" -type d -exec chmod 0775 \{\} \; - find "$repo_path" -type f -exec chmod 0664 \{\} \; - touch "$repo_path/PUBLIC" - set +x + local repo_path=$1 + test -f "$repo_path/HEAD" || { echo "$repo_path is not a git repository"; exit 1; } + set -x + git init -q --bare --shared=0664 "$repo_path" + find "$repo_path" -type d -exec chown $USER:share \{\} \; + find "$repo_path" -type d -exec chmod 0775 \{\} \; + find "$repo_path" -type f -exec chmod 0664 \{\} \; + touch "$repo_path/PUBLIC" + set +x } do_make_shared() { - local repo_path=$1 - test -f "$repo_path/HEAD" || { echo "$repo_path is not a git repository"; exit 1; } - set -x - git init -q --bare --shared=0660 "$repo_path" - find "$repo_path" -type d -exec chown $USER:share \{\} \; - find "$repo_path" -type d -exec chmod 0770 \{\} \; - find "$repo_path" -type f -exec chmod 0660 \{\} \; - chgrp -R share "$repo_path" - rm -f "$repo_path/PUBLIC" - set +x + local repo_path=$1 + test -f "$repo_path/HEAD" || { echo "$repo_path is not a git repository"; exit 1; } + set -x + git init -q --bare --shared=0660 "$repo_path" + find "$repo_path" -type d -exec chown $USER:share \{\} \; + find "$repo_path" -type d -exec chmod 0770 \{\} \; + find "$repo_path" -type f -exec chmod 0660 \{\} \; + chgrp -R share "$repo_path" + rm -f "$repo_path/PUBLIC" + set +x } do_make_private() { - local repo_path=$1 - test -f "$repo_path/HEAD" || { echo "$repo_path is not a git repository"; exit 1; } - set -x - git init -q --bare --shared=0600 "$repo_path" - find "$repo_path" -type d -exec chown $USER:$USER \{\} \; - find "$repo_path" -type d -exec chmod 0700 \{\} \; - find "$repo_path" -type f -exec chmod 0600 \{\} \; - chgrp -R $USER "$repo_path" - rm -f "$repo_path/PUBLIC" - set +x + local repo_path=$1 + test -f "$repo_path/HEAD" || { echo "$repo_path is not a git repository"; exit 1; } + set -x + git init -q --bare --shared=0600 "$repo_path" + find "$repo_path" -type d -exec chown $USER:$USER \{\} \; + find "$repo_path" -type d -exec chmod 0700 \{\} \; + find "$repo_path" -type f -exec chmod 0600 \{\} \; + chgrp -R $USER "$repo_path" + rm -f "$repo_path/PUBLIC" + set +x } case "$1" in - list) do_list "$2" ;; - create-public) do_create_public ;; - create-shared) do_create_shared ;; - create-private) do_create_private ;; - make-public) do_make_public "$2" ;; - make-shared) do_make_shared "$2" ;; - make-private) do_make_private "$2" ;; - show) - shift - do_show $* - ;; - mirror) do_mirror "$2" ;; - *) - cat <