#!/bin/sh

#note, only found one with a space in it:
# ./boot/initrd-tree/skeleton/home/portable/chromium/profile/First Run
# ...have removed ./boot/initrd-tree/skeleton/home/portable/chromium

echo -n '' > z-files.log1
echo -n '' > z-files.log2
echo -n '' > z-files.log0

while read aFILE
do
 if [ "${aFILE/ /}" != "${aFILE}" ];then #ignore filenames with spaces
  continue
 fi
 EXT="$(echo -n "$aFILE" | rev | cut -f 1 -d '.' | rev)"
 case "$EXT" in
  svg|xpm|png)
   continue
  ;;
 esac
 case "$aFILE" in
  *shellcms*) continue ;;
  *z-files.log*) continue ;;
  *home-folders-to-files*) continue ;;
  *PKGS_HOMEPAGES) continue ;;
 esac
 
 LINES="$(grep -E '/clients|}clients' "$aFILE")"
 if [ "$LINES" == "" ];then
  continue
 fi
 echo -n '.'
 
 echo "$aFILE" >> z-files.log0
 
 echo "${aFILE}:
${LINES}
" >> z-files.log1
 
 continue ###TEST###
 sed -i -e "s%/home/%/files/%g" ${aFILE}
 sed -i -e "s%/home$%/files%g" ${aFILE}
 sed -i -e "s%/home %/files %g" ${aFILE}
 sed -i -e "s%}home%}files%g" ${aFILE}
 sync

done <<_END
$(find . -type f)
_END

echo
echo -n "COUNT0: "
wc -l z-files.log0
exit ###TEST###

while read aFILE
do
 if [ "${aFILE/ /}" != "${aFILE}" ];then #ignore filenames with spaces
  continue
 fi
 EXT="$(echo -n "$aFILE" | rev | cut -f 1 -d '.' | rev)"
 case "$EXT" in
  svg|xpm|png)
   continue
  ;;
 esac
 case "$aFILE" in
  *shellcms*) continue ;;
  *files.log) continue ;;
  *home-folders-to-files) continue ;;
  *PKGS_HOMEPAGES) continue ;;
  *z-files.log1) continue ;;
  *z-files.log2) continue ;;
 esac
 
 LINES="$(grep -E '/home|}home' "$aFILE")"
 if [ "$LINES" == "" ];then
  continue
 fi
 echo -n '.'
 
 echo "${aFILE}:
${LINES}
" >> z-files.log2
 
done <<_END
$(find . -type f)
_END

sync
echo
echo -n "COUNT1: "
wc -l z-files.log1
echo -n "COUNT2: "
wc -l z-files.log2


