Script "generate_file_lists.sh"
#!/bin/sh

# ----------------------------------
# generate_file_lists.sh
# version 1.1.9.7
# ----------------------------------

script_call_name=`basename ${0}`
usage_str=`echo "Usage:" ./"${script_call_name}" "[ --force ]"`

# --------------------------------------------------------------------------------

FORCE_OPT=""
for arg in $@
do
  [ $arg = "--force" ] && FORCE_OPT="yes" && continue
  if [ $arg = "--help" ] || [ $arg = "--usage" ]; then
    echo "${usage_str}"
    exit 0
  fi
  echo "${0}: unknown option '${arg}'"
done

[ -z "${BUILD_FARM}" ] && BUILD_FARM="${HOME}/build-farm"
if [ -d "${BUILD_FARM}" ]; then
  echo "base directory:" "${BUILD_FARM}"
else
  echo "ERROR: base directory '${BUILD_FARM}' doesn't exist. Abort."
  exit 1
fi

target_triplet=`gcc -v 2>&1 | grep "Target:" | awk '{print $2}' | tr '-' ' '`

if [ -z ${ARCH_NAME} ]; then
  case `uname -m` in
    ppc)
      ARCH_NAME="powerpc"
      ;;
    *)
      ARCH_NAME=`echo "${target_triplet}" | awk '{print $1}'`
      ;;
  esac
fi

[ -z "${BINPACKAGES_DIR}" ] && BINPACKAGES_DIR=PACKAGES/binpkg-"${ARCH_NAME}"
[ -d "${BUILD_FARM}/${BINPACKAGES_DIR}" ] || BINPACKAGES_DIR=PACKAGES/binpkg
if [ -d "${BUILD_FARM}/${BINPACKAGES_DIR}" ]; then
  echo "binary packages directory:" "${BUILD_FARM}/${BINPACKAGES_DIR}"
else
  echo "ERROR: binary packages directory '${BINPACKAGES_DIR}' doesn't exist. Abort."
  exit 1
fi

num_of_pkgs=`ls -l "${BUILD_FARM}/${BINPACKAGES_DIR}"/*.binpkg.* 2>/dev/null | wc -l`
if [ $num_of_pkgs -le 0 ]; then
  echo "STOP: no packages found inside binary packages directory; nothing to do"
  exit 0
fi

# check for required binaries
REQD_BINS=""
which md5sum >/dev/null 2>&1 || type md5sum >/dev/null 2>&1 || REQD_BINS="md5sum,${REQD_BINS}"
which diff >/dev/null 2>&1 || type diff >/dev/null 2>&1 || REQD_BINS="diff,${REQD_BINS}"
which tar >/dev/null 2>&1 || type tar >/dev/null 2>&1 || REQD_BINS="tar,${REQD_BINS}"
which file >/dev/null 2>&1 || type file >/dev/null 2>&1 || REQD_BINS="file,${REQD_BINS}"
if [ ! -z "${REQD_BINS}" ]; then
  echo -e `basename ${0}`: "Required binaries (${REQD_BINS}\010) are not present."
  exit 1
fi

cd "${BUILD_FARM}/${BINPACKAGES_DIR}"

have_lists=""
if [ -f ./.MD5SUMS ]; then
  printf "checking md5sums... "
  md5sum *.binpkg.* >./.MD5SUMS-NEW
  MD5SUMS_DIFF=`diff ./.MD5SUMS ./.MD5SUMS-NEW 2>/dev/null`
  if [ ! -z "${MD5SUMS_DIFF}" ]; then
    rm ./.MD5SUMS && mv ./.MD5SUMS-NEW ./.MD5SUMS
    echo "re-generated"
  else
    rm ./.MD5SUMS-NEW
    [ -d ./.FILELISTS ] && have_lists="yes"
    echo "match"
  fi 
else
  printf "generating md5sums... "
  md5sum *binpkg* >./.MD5SUMS
  echo "done"
fi

[ -z "${FORCE_OPT}" ] || have_lists=""

if [ -z "${have_lists}" ]
then
  echo "generating file lists:"
  rm -rf ./.FILELISTS && mkdir ./.FILELISTS
  for curr_entry in *binpkg*
  do
    if [ -f "${curr_entry}" ]; then
      is_bzip2=`file "${curr_entry}" | grep bzip2`
      is_gzip=`file "${curr_entry}" | grep gzip`

      if [ ! -z "${is_bzip2}" ]; then
        printf "    (bzip2) %s... " "${curr_entry}"
        tar tjf "${curr_entry}" >./.FILELISTS/${curr_entry}.list
        echo "done"
      elif [ ! -z "${is_gzip}" ]; then
        printf "     (gzip) %s... " "${curr_entry}"
        tar tzf "${curr_entry}" >./.FILELISTS/${curr_entry}.list
        echo "done"
      fi      
    fi
  done
fi
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.