#! /bin/bash

mc857_check_current_dir_1.sh mc857-2020-1-a || exit 1

# find ./ -type d \( -name trunk -o -name 'branches' \) -print | sort > .treedirs
# find ./ -type d -name '[0-9][0-9][0-9][0-9][0-9][0-9]' -print | sort > .radirs

# for aula in 2020-[0-9][0-9]-[0-9][0-9] ; do 
#   for sub in pos pun put ; do 
#     subdir=${aula}/${sub}
#     if [[ -d ${subdir}/trunk ]]; then
#       echo "mv -vi ${subdir}/trunk ${subdir}/main"
#     fi
#   done
# done
# 
# 
# for radir in `cat .radirs` ; do
#   newdir=`echo ${radir} | sed -e 's:/branches/:/:g'`
#   echo "mv -vi ${radir} ${newdir}"
# done

# Lista arquivos em "pos/${ra}" iguais à versão em "pos/main":
# rm -f .rmdups
# for aula in 2020-[0-9][0-9]-[0-9][0-9] ; do 
#   subdir=${aula}/pos
#   if [[ -d ${subdir} ]]; then
#     pushd ${subdir}
#       chmod -R a-w main
#       find [0-9]*/ -type f -print | sed -e 's:^[./0-9]*::g' | sort | uniq > .sources
#       for ra in [0-9]* ; do 
#         for ff in `cat .sources`; do 
#           if cmp -s ${ra}/${ff} main/${ff}; then
#             echo "rm -v ${subdir}/${ra}/${ff}" >> ../../.rmdups
#           fi
#         done
#       done
#     popd
#   fi
# done
 
# # Compara lista de arquivos em "pun" com arquivos em "pos"
# for aula in 2020-[0-9][0-9]-[0-9][0-9] ; do 
#   pushd ${aula}
#     if [[ ( -d pos ) && ( -d put ) ]]; then
#       ras=( `( ( cd pos && ls -d [0-9]* ); ( cd put && ls -d [0-9]* ) ) | sort | uniq` )
#       for ra in ${ras[@]} ; do 
#         for ff in `cat pos/.sources`; do 
#           if [[ ( -e pos/${ra}/${ff} ) && ( ! ( -e put/${ra}/${ff} ) ) ]]; then
#             echo "** only in pos/${ra}: ${ff}" 1>&2 
#           elif [[ ( ! ( -e pos/${ra}/${ff} ) ) && ( -e put/${ra}/${ff} ) ]]; then
#             echo "** only in put/${ra}: ${ff}" 1>&2 
#           fi
#         done
#       done
#     elif [[ ( -d pos ) ]]; then
#       echo "** has pos but no put" 1>&2 
#     elif [[ ( -d put ) ]]; then
#       echo "** has put but no pos" 1>&2 
#     else
#       echo "** has neither put nor pos" 1>&2 
#     fi
#   popd
# done
