#note: DISTRO_BINARY_COMPAT and DISTRO_FILE_PREFIX are visible here, exported in 2createpackages.
#140117 xARCHDIR, ARCHDIR and DISTRO_ARCHDIR_SYMLINKS exported in 2createpackages. 
#140117 note, 2createpackages may move /lib, /usr/lib, /usr/bin in template to ARCHDIR subdir.

#Ubuntu Jaunty
#i don't understand this. /usr/lib/cups/backend is empty...
if [ "$xARCHDIR" ];then #140117
 if [ -d usr/lib/${ARCHDIR}/cups/backend-available ];then
  if [ -d usr/lib/${ARCHDIR}/cups/backend ];then
   cp -a -f usr/lib/${ARCHDIR}/cups/backend-available/* usr/lib/${ARCHDIR}/cups/backend/
  fi
 fi
fi
if [ -d usr/lib/cups/backend-available ];then
 if [ -d usr/lib/cups/backend ];then
  cp -a -f usr/lib/cups/backend-available/* usr/lib/cups/backend/
 fi
fi

#need cups-config
if [ "$xARCHDIR" ];then #140117
 if [ -f ../cups_DEV/usr/bin/${ARCHDIR}/cups-config ];then
  mkdir -p usr/bin/${ARCHDIR}
  cp -f ../cups_DEV/usr/bin/${ARCHDIR}/cups-config usr/bin/${ARCHDIR}/
 fi
fi
if [ -f ../cups_DEV/usr/bin/cups-config ];then
 cp -f ../cups_DEV/usr/bin/cups-config usr/bin/
fi

#slackware 13.1, wants the html web interace files at usr/share/doc/cups-1.4.3...
DOCCUPS="`find usr/doc -maxdepth 1 -type d -name 'cups*' 2>/dev/null | head -n 1`"
if [ "$DOCCUPS" ];then
 BASEDOCCUPS="`basename $DOCCUPS`"
 rm -rf usr/share/doc/cups
 ln -s ../../doc/${BASEDOCCUPS} usr/share/doc/cups
 ln -s ../../doc/${BASEDOCCUPS} usr/share/doc/${BASEDOCCUPS}
 #reduce it a bit...
 for ONECUPSDOC in `find ${DOCCUPS} -maxdepth 1 -type d | tr '\n' ' '`
 do
  BASEONECUPS="`basename $ONECUPSDOC`"
  [ "$BASEONECUPS" = "help" ] && continue
  [ "$BASEONECUPS" = "images" ] && continue
  rm -rf usr/doc/${BASEDOCCUPS}/$BASEONECUPS
 done
fi

#slackware 13.1, have doc>exe...
[ -d usr/man ] && rm -rf usr/man
[ -d usr/share/man ] && rm -rf usr/share/man
[ -d usr/share/cups/examples ] && rm -rf usr/share/cups/examples

#drake puppy 0.1, july 2011, rcrsn51 advises that /etc/cups/snmp.conf "needs to be world-readable in order to detect network printers"
[ -f etc/cups/snmp.conf ] && chmod 644 etc/cups/snmp.conf

#111101 'help' directory seems not needed by web interface, move to _DOC...
CUPSHELPDIR="`find usr -type d -name help | sed -e 's%usr%%' | tr '\n' ' '`"
for ONECHD in $CUPSHELPDIR
do
 if [ -f usr${ONECHD}/cgi.html ];then
  mkdir -p ../cups_DOC/usr${ONECHD}
  cp -a -f usr${ONECHD}/* ../cups_DOC/usr${ONECHD}/
  rm -f usr${ONECHD}/*
 fi
done
#NOTE: the above is a hack. The variable PKGS_SPECS_TABLE in file DISTRO_PKGS_SPECS-*, has an entry like:
#yes|cups|cups|exe,dev,doc>exe,nls
#notice doc>exe, this ensures that 2createpackages won't move 'doc' dir to cups_DOC.
#but, we do want part of docs to go to cups_DOC, hence the hack.
#note, different distros have 'help' in different places:
#T2: /usr/share/doc/cups/help
#Slackware: /usr/doc/cups/help
#Debian: /usr/share/cups/doc-root/help

#111103 in addition to the above, also need to handle yes|cups|cups|exe,dev,doc,nls (no doc>exe)...
CUPSWEBINTERFACE="`find usr -type f -name favicon.ico`" #in same dir as index.html
if [ ! "$CUPSWEBINTERFACE" ];then
 if [ -d ../cups_DOC ];then
  CUPSWEBCSS="`find ../cups_DOC/usr -type f -name favicon.ico | head -n 1 | sed -e 's%\.\./cups_DOC/%%'`"
  if [ "$CUPSWEBCSS" ];then
   CUPSWEBDIR="`dirname $CUPSWEBCSS`"
   mkdir -p $CUPSWEBDIR
   cp -a -f ../cups_DOC/${CUPSWEBDIR}/* ${CUPSWEBDIR}/
   rm -rf ${CUPSWEBDIR}/help
  fi
 fi
fi

#140204 ubuntu trusty tahr
for AXX in `find usr -type d -name '[a-z][a-z]' 2>/dev/null | tr '\n' ' '`  #ex1: usr/share/cups/doc-root/fr  ex2: usr/share/cups/templates/fr
do
 DIRXX="`dirname $AXX`"
 mkdir -p ../cups_NLS/${DIRXX}
 mv -f $AXX ../cups_NLS/${DIRXX}/
done
[ -d usr/share/cups/ipptool ] && rm -rf usr/share/cups/ipptool
for ATXT in `find usr/share -type f -iname copyright -o -iname 'credits.*' -o -iname 'HOWTO*' -o -iname 'news*' -o -iname 'readme*' -o -iname 'changelog*' 2>/dev/null | tr '\n' ' '`
do
 DIRTXT="`dirname $ATXT`"
 mkdir -p ../cups_DOC/${DIRTXT}
 mv -f $ATXT ../cups_DOC/${DIRTXT}/
 [ "`ls -1 $DIRTXT`" = "" ] && rmdir $DIRTXT
done

#141016 got weirdness, comment this out, using cups 1.7.1 from quirky tahr (see zzcups pet)...
##141014 quirky unicorn, i recompiled cupsd without a systemd lib dependency, however,
##also need this symlink for the web interface to work...
#if [ "$DISTRO_BINARY_COMPAT" == "ubuntu" ];then
# case "$DISTRO_FILE_PREFIX" in
#  lucid)   true ;;
#  precise) true ;;
#  tahr)    true ;;
#  *) #unicorn
#   rm -rf usr/share/doc/cups
#   ln -s ../cups/doc-root usr/share/doc/cups
#   #ln -s doc-root usr/share/cups/online-docs
#  ;;
# esac
#fi


