#!/bin/bash
#
# resend_proxy_values
#
# gespeicherte Proxy-Werte erneut an ULS-DB senden
#
###############################################################################
#
if [[ -z "$1" ]]
 then
  echo "usage: `basename $0` <valuepath>"
  echo "  <valuepath> ist Pfad zu Verzeichnis mit den Ordnern FP, FPZ, TAB oder TGZ"
  exit 1
fi
#
TMPPATH="$1"
#
#
PATH=/srv/uls/wwwbin:/usr/bin:/usr/local/bin:$PATH
export PATH
#
function make_fp
{ ip=$1
  ( if cd $1
     then
      SEPPATH=gpwddat.$$
      ls | while read F
       do
        ( if mkdir $SEPPATH && cd $SEPPATH
           then
            fileunpack ../$F
            file2ulsdb -i $ip *.uls 2>&1 | head -3
            cd ..
            rm -r $SEPPATH
          fi
        )
      done
    fi
  )
}
#
function make_fpz
{ ip=$1
  ( if cd $1
     then
      SEPPATH=gpwddat.$$
      ls | while read F
       do
        ( if mkdir $SEPPATH && cd $SEPPATH
           then
            zcat ../$F | fileunpack
            file2ulsdb -i $ip *.uls 2>&1 | head -3
            cd ..
            rm -r $SEPPATH
          fi
        )
      done
    fi
  )
}
#
function make_tgz
{ ip=$1
  ( if cd $1
     then
      SEPPATH=gpwddat.$$
      ls | while read F
       do
        ( if mkdir $SEPPATH && cd $SEPPATH
           then
            tar xfz ../$F
            file2ulsdb -i $ip *.uls 2>&1 | head -3
            cd ..
            rm -r $SEPPATH
          fi
        )
      done
    fi
  )
}
#
if cd $TMPPATH
 then
  if [[ -d TAB ]]
   then
    ( if cd TAB
       then
        ls | while read IP
         do
          if [[ -d $IP ]]
           then
            (cd $IP && file2ulsdb -i $IP *.uls 2>&1 | head -3)
          fi
        done
      fi
    )
  fi
  if [[ -d FP ]]
   then
    ( if cd FP
       then
        ls | while read IP
         do
          if [[ -d $IP ]]
           then
            make_fp $IP
          fi
        done
      fi
    )
  fi
  if [[ -d FPZ ]]
   then
    ( if cd FPZ
       then
        ls | while read IP
         do
          if [[ -d $IP ]]
           then
            make_fpz $IP
          fi
        done
      fi
    )
  fi
  if [[ -d TGZ ]]
   then
    ( if cd TGZ
       then
        ls | while read IP
         do
          if [[ -d $IP ]]
           then
            make_tgz $IP
          fi
        done
      fi
    )
  fi
fi
