summaryrefslogtreecommitdiff
path: root/git-repo
diff options
context:
space:
mode:
authorYves Fischer <yvesf+git@xapek.org>2017-01-07 21:55:23 +0000
committerYves Fischer <yvesf+git@xapek.org>2017-01-07 21:55:23 +0000
commitcb6fa05c1e44fa39838d86919a6c2d72a94653d9 (patch)
treed49acc77de5f927b34cc77f16eac4760a79c919a /git-repo
parent3c73384598e99f2f755450a3a9e63569e259ef1d (diff)
downloadgit-repo-cb6fa05c1e44fa39838d86919a6c2d72a94653d9.tar.gz
git-repo-cb6fa05c1e44fa39838d86919a6c2d72a94653d9.zip
move BASEDIR to /git
Diffstat (limited to 'git-repo')
-rwxr-xr-xgit-repo72
1 files changed, 43 insertions, 29 deletions
diff --git a/git-repo b/git-repo
index 8bded4f..55cfa1e 100755
--- a/git-repo
+++ b/git-repo
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
-BASEDIR=$HOME/git
+BASEDIR=/git
C_bg_green=$(echo -e "\e[42m")
C_bg_magenta=$(echo -e "\e[45m")
C_bg_default=$(echo -e "\e[49m")
C_bg_lblue=$(echo -e "\e[104m")
-
+
_getent() {
local db=$1
local key=$2
@@ -13,14 +13,14 @@ _getent() {
}
_list_repo_dirs() {
- find "$1" -maxdepth 6 -type d -path "/home/*/git/*" -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=/home
+ local root_path=$BASEDIR
fi
echo -n "Working.. listing repositories under $root_path"
for repo_path in $(_list_repo_dirs $root_path | sort); do
@@ -40,20 +40,18 @@ do_list() {
fi
- # and is it marked as shared ?
- local repo_git_shared=$(GIT_DIR="$repo_path" git config --get core.sharedrepository)
-
- local repo_name="~${repo_path#/home/}"
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
- local shared="($C_bg_magenta$repo_path_mode$C_bg_default git.shared=${repo_git_shared} gid=$repo_path_gid/$(_getent group $repo_path_gid))"
- elif [ $(( 0$repo_path_mode & 070 )) -gt 0 ]; then # shared
- local shared="($C_bg_lblue$repo_path_mode$C_bg_default git.shared=${repo_git_shared} gid=$repo_path_gid/$(_getent group $repo_path_gid))"
- else
- local shared="($C_bg_green$repo_path_mode$C_bg_default)"
- fi
-
- printf "%-60s %s (%s)\n" "$repo_name" "$shared" "$shortdesc"
+ permissions="$permissions PUBLIC"
+ color="$C_bg_magenta"
+ fi
+ printf "%s%-60s (%s) (%s)\n" "$color" "$repo_path$C_bg_default" "$permissions" "$shortdesc"
done
}
@@ -71,7 +69,7 @@ _create_repo() {
return 1
fi
- local repo_dir=$BASEDIR/${repo_name}
+ local repo_dir=$BASEDIR/$USER/${repo_name}
test \! -e "$repo_dir" || { echo "Repo $repo_dir already exist"; exit 1; }
@@ -82,7 +80,7 @@ _create_repo() {
test "$REPLY" == "y" || exit 1
mkdir -p "$repo_dir"
- git init --bare --shared=$shared "$repo_dir"
+ git init -q --bare --shared=$shared "$repo_dir"
chgrp -R "$group" "$repo_dir"
echo "$repo_desc" > "$repo_dir/description"
@@ -113,35 +111,43 @@ do_create_private() {
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
-
- echo "========== Actions on: $repo_path"
+
local repo_file_mode=$(stat -f %Lp "$repo_path")
local repo_file_uid=$(stat -f %u "$repo_path")
local repo_file_user=$(_getent passwd $repo_file_uid)
local repo_file_gid=$(stat -f %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 " ⚡ To clone from remote execute: "
- echo " git clone 'ssh://localnet.cc/~${repo_path##/home/}'"
+ 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 " git clone 'http://localnet.cc/cgit/cgit.cgi/${repo_path##/home/}' (read-only)"
+ 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 " ☛ For limited ssh-access with current user configure ~/.ssh/authorized_keys with:"
- echo " command=\"git shell -c \\\"\$SSH_ORIGINAL_COMMAND\\\"\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3....."
+ echo ""
done
}
do_mirror() {
local root_path=$(readlink -f "$1")
for repo_path in $(_list_repo_dirs $root_path); do
- local mirror_url=$(sed -n -e 's/^Mirror for \(https.*\)$/\1/p' < $repo_path/description)
- #todo
+ 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
}
@@ -165,6 +171,7 @@ do_make_shared() {
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
}
@@ -177,6 +184,7 @@ do_make_private() {
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
}
@@ -201,9 +209,9 @@ Unknown subcommand: '$1'
Subcommands of git repo:
list [<dir>] List infos (optional: only below <dir>)
show <dir...> Show Commands for repo <dir>
- mirror <dir> Mirror git repositories under <dir> by looking
+ mirror <dir> Mirror git repositories under <dir> by looking
for 'Mirror for https://..' in description"
- create-public Create new repository that is
+ create-public Create new repository that is
- Read/Write by Owner
- Read/Write by 'share' group.
- Read-Only through www via cgit
@@ -215,6 +223,12 @@ Subcommands of git repo:
make-public <dir> Change permissions to public
make-shared <dir> Change permissions to shared
make-private <dir> Change permissions to private
+
+
+ ☛ Base directory of repositories: $BASEDIR
+ ☛ Color codes: ${C_bg_magenta}public${C_bg_default}, ${C_bg_lblue}shared${C_bg_default}, ${C_bg_green}private${C_bg_default}
+ ☛ For limited ssh-access with current user configure ~/.ssh/authorized_keys with:
+ command=\"git shell -c \\\"\$SSH_ORIGINAL_COMMAND\\\"\",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa AAAAB3.....
HERE
;;
esac