# Repos
#
filter_name="$@"
+exec_user() {
+ declare user="$1"
+ shift
+
+ if [ "$USER" = "$user" ]; then
+ eval "$*"
+ elif [ "$USER" = "root" ]; then
+ su - $user -c "cd \"$(pwd)\" && $*"
+ else
+ echo "Wrong user current user=$USER repo user=$user"
+ return 1
+ fi
+}
+
+_git_name() {
+# NB 17.04.23: Should replace other git_name in the future
+# NB 17.04.23: git config --local remote.origin.url generate an error when not the same user
+ awk -F'= *' ' \
+match($0,/^\[([^]]+)\]/,m){ cat=match(m[1],/^remote .origin.$/) } \
+cat && /url =/{ \
+ sub(/^[^:]+:/,"",$2); \
+ sub(/^.*\//,"",$2); \
+ sub(/(\/|\.git)$/,"",$2); \
+ sub(/^.*\/$/,"",$2); \
+ print $2; \
+} \
+' .git/config
+}
+
for dir in $(nb_repos); do
[ -d "$dir/.git" ] || continue
[ ! -w "$dir/.git" ] && echo ">No Permission $dir" && echo && continue
+
+ #
+ # Get user
+ #
+ user=`ls -dl "$dir/.git" | awk '{print $3}'`
+ if [ -z "$user" ]
+ then
+ echo "Can't read user owner for '$dir'" 1>&2
+ fi
+
cd "$dir" || continue
# name from git not from path
- name=$(git_name) || continue
- [ -z "$name" ] && continue
+ name=$(exec_user $user git_name) || continue
+ # NB 17.04.23 echo "$name"
+ if [ -z "$name" ]
+ then
+ echo "Can't read remote.origin.url from '$dir'"
+ continue
+ fi
# args filter on name
fi
# branch
- branch=$(git_branch) || continue
+ branch=$(exec_user $user git_branch) || continue
[ -z "$branch" ] && continue
+ # NB 17.04.23 echo " $branch" && continue
+
# preff to post report
preff="git.$dir"
- #
- # Get user
- #
- user=`ls -dl "$dir/.git" | awk '{print $3}'`
-
# include extra scripts
! [ -r "$NB_ROOT/lib/$NAME/repo.sh" ] || . "$NB_ROOT/lib/$NAME/repo.sh" || exit
cmd="${cmd}GIT_SSH=$GIT_SSH cd \"$dir\" && git pull"
[ "$CLEANUP" = "1" ] && cmd="$cmd && git gc"
- if [ 1 = 1 ] && ! git_conn_check; then
+ if [ 1 = 1 ] && ! exec_user $user git_conn_check; then
echo
elif [ "$USER" = "$user" ]; then
bash -c "$cmd"
elif [ "$USER" = "root" ]; then
su - $user -c "$cmd"
+ echo " $user | $cmd" && continue
else
echo "Wrong user current user=$USER repo user=$user"
false
local usage="Usage: git_change_url URL_FROM URL_TO"
local ufrom=${1:?$usage}; shift
local uto=${1:?$usage}; shift
- [ "$(git config --get remote.origin.url)" = "$ufrom" ] || return
+ [ "$(exec_user $user git config --get remote.origin.url)" = "$ufrom" ] || return
echo "Update git url for $ufrom to $uto"
git remote set-url origin $uto
nb_api_post_host_info "${preff:-git.$(pwd)}.set-url" "$uto"