view scripts/update-git-remotes @ 1202:306a7562f05e draft

????????: abs <post@abslimit.info> ?? ????? master ???? ????? ????????? ? ???????????? ? ?origin/master?. ?????????, ??????? ????? ???????? ? ??????: ????? ????: db/as/49608/owner ????? ????: db/dom/ano/abslimit/owner ????? ????: db/dom/ano/netstalking/owner ????? ????: db/ip/15/0A/0B/00/cidr ????? ????: db/ip/15/0A/0B/00/owner ????? ????: db/usr/abslimit/git
author abs <abs@abslimit.info>
date Sun, 13 May 2018 14:57:04 +0300
parents 79ed5d9678a8
children 2dcb03d77b03
line wrap: on
line source

#!/bin/sh
#
# Synchronizes git remotes with the user db
#

if ! `dirname "$0"`/check_db_safety; then
 exit 1
fi

USR_DB_DIR=./db/usr
GIT_REPO=./.git
GIT_REMOTES_DIR=$GIT_REPO/refs/remotes

for u in `ls -1 "$USR_DB_DIR"`; do
  git_url_file="$USR_DB_DIR/$u/git"

  if [ -f "$git_url_file" ]; then
    git_url=`cat "$git_url_file"`
    git_remote_name="anonet_$u"

    if [ -d "$GIT_REMOTES_DIR/$git_remote_name" ]; then
      if [ x"$git_url" != x`git remote get-url "$git_remote_name"` ]; then
        echo "changing $u" >&2
        git remote set-url "$git_remote_name" "$git_url"
      else
        # The remote already exists and is the same
        echo "skipping $u" >&2
      fi
    else
      echo "adding $u" >&2
      git remote add -t master -m master "$git_remote_name" "$git_url"
    fi
  fi
done

for r in `ls -1 "$GIT_REMOTES_DIR" | grep '^anonet_'`; do
  u=`echo $r | sed 's/^anonet_//'`
  if [ ! -f "$USR_DB_DIR/$u/git" ]; then
    echo "deleting $u" >&2
    git remote rm "$r"
    rm -rf "$GIT_REMOTES_DIR/$r"
  fi
done