#!/bin/sh
#
echo "SCRIPT $0 starting"
MEUID=`id -u`

if [ -t 1 ]
then 
  echo "interactive mode"
  # echo ${MEUID} > /var/tmp/bbb
  RUNNING_CRON=1
else
  touch /var/tmp/aaa
  # echo ${MEUID} > /var/tmp/aaa
  RUNNING_CRON=0
fi

MYNAME=`uname -n`

pull_repo () {
  for i in `ls -d ${ZZ}`
  do
      echo "checking $i"
      if [ -d $i/.git ]
      then
          echo "pulling $i"
          (cd $i; git pull; git checkout main; git pull )
      fi
  done
}

if [ ${MEUID} = 0 ]
then
  ZZ=/zz/*
  pull_repo
else
  ZZ=~/git/private/z*
  pull_repo

  ZZ=~/git/public/z*
  pull_repo
fi

exit 0
