
#
# Modelz 1-x
#
echo $GERAET - Modelz 1-x

export TAG=`date "+%j"`
export path="001-xxx"

for grl in mA mC mJa mL mSh mSt; do
  cd $QBASEA/$grl/1
  
  for snr in `ls`; do
    cd $snr
    echo "doing $grl/$snr, files: `ls | grep -v Thumbs.db | wc -l`"
    
    if [ -d "$ZBASEA/$grl/$path/$snr" ]; then
	  echo " $grl	$path	$snr existiert!"
    else
		  cd $ZBASEA
		  mkdir -p "$grl/$path/$snr"
		  echo "$ZBASEA/$grl/$path/$snr wurde angelegt!"
		  fi
		cd $QBASEA/$grl/1/$snr
    ls | grep -v Thumbs.db | while read jpg
    do
      zahl=`expr $zahl + 1`
      if [ -e "$ZBASEA/$grl/$path/$snr/$jpg" ];
      then
        # DATEI SCHON VORHANDEN
        sum1=`cksum "$QBASEA/$grl/1/$snr/$jpg"|awk -F' ' '{print $1}'`
        sum2=`cksum "$ZBASEA/$grl/$path/$snr/$jpg"|awk -F' ' '{print $1}'`
        if [ "$sum1" = "$sum2" ];
        then
          # Datei identisch
          echo "QBASEA/$grl/1/$snr/$jpg $ZBASEA/$grl/$path/$snr/$jpg " >> $ZBASEA/$grl/doppelt.txt
          export jpgg="$jpg"
          export dummyz=$zahl"+"
        else
          export dummyz=$zahl"-"
          export jpgg=`echo $jpg | sed -e 's/\./_\./g'`
          while [ -e "$ZBASEA/$grl/$path/$snr/$jpgg" ];
          do
            export jpgg=`echo $jpgg | sed -e 's/\./_\./g'`
          done	
          echo "$QBASEA/$i/$jpg $ZBASEA/$grl/$path/$snr/$jpg " >> $ZBASEA/$grl/Name_geaendert.txt
        fi
      else
        # DATEI FRISCH UND NEU
        export dummyz=$zahl
        export jpgg="$jpg"
      fi;
		
      echo -n "$dummyz "
      mv "$QBASEA/$grl/1/$snr/$jpg" "$ZBASEA/$grl/$path/$snr/$jpgg" 2>/dev/null
    done
    
	cd $QBASEA/$grl/1
	rm -rf $snr
	echo ""
  done
done


for grl in mD mG mH mK mM mMa mNk t19; do
  cd $QBASEA/$grl
  for gnr in `ls`; do
    cd $QBASEA/$grl/$gnr/
    export path=`ls | grep -v s`
    cd $path
    for snr in `ls`; do
      #echo " "$grl" "$gnr" "$snr" "$path
      if [ -d "$ZBASEA/$grl/$gnr/$path/$snr" ]; then
        echo " $grl	$path	$snr existiert!"
      else
        mkdir -p "$ZBASEA/$grl/$gnr/$path/$snr"
        echo "$ZBASEA/$grl/$gnr/$path/$snr wurde angelegt!"
      fi

      cd $QBASEA/$grl/$gnr/$path/$snr
      echo "doing $grl/$gnr/$path/$snr, files: `ls | grep -v Thumbs.db | wc -l`"
      ls | grep -v Thumbs.db | while read jpg
      do
        zahl=`expr $zahl + 1`
        if [ -e "$ZBASEA/$grl/$gnr/$path/$snr/$jpg" ];
        then
          # DATEI SCHON VORHANDEN
          sum1=`cksum "$QBASEA/$grl/$gnr/$path/$snr/$jpg"|awk -F' ' '{print $1}'`
          sum2=`cksum "$ZBASEA/$grl/$gnr/$path/$snr/$jpg"|awk -F' ' '{print $1}'`
          if [ "$sum1" = "$sum2" ];
          then
            # Datei identisch
            echo "$QBASEA/$i/$jpg $ZBASEA/$grl/$gnr/$path/$snr/$jpg " >> $ZBASEA/$grl/doppelt.txt
            export jpgg="$jpg"
            export dummyz=$zahl"+"
          else
            export dummyz=$zahl"-"
            export jpgg=`echo $jpg | sed -e 's/\./_\./g'`
            while [ -e "$ZBASEA/$grl/$gnr/$path/$snr/$jpgg" ];
            do
              export jpgg=`echo $jpgg | sed -e 's/\./_\./g'`
            done	
          echo "$QBASEA/$i/$jpg $ZBASEA/$grl/$gnr$path/$snr/$jpg " >> $ZBASEA/$grl/Name_geaendert.txt
          fi
        else
          # DATEI FRISCH UND NEU
          export dummyz=$zahl
          export jpgg="$jpg"
        fi;
		
		  echo -n "$dummyz "
		  mv "$QBASEA/$grl/$gnr/$path/$snr/$jpg" "$ZBASEA/$grl/$gnr/$path/$snr/$jpgg" 2>/dev/null
      done
    cd $QBASEA/$grl/$gnr/$path
    rm -rf $snr
    echo ""
    done
  done
done
