Script "list-packages.sh"
#!/bin/sh

# --------------------------
# list-packages.sh
# version 1.6.4.11
# --------------------------

# check for parameters

usage_str="Usage: ${0} [ --size ] [ --date ] [ --version ] [ --fname ]"
if [ "${1}" = "--help" ] || [ "${1}" = "--usage" ]; then
  printf "%s\n" "${usage_str}"
  exit 0
fi

DEFAULT_FORMAT_OPT="yes"
SIZE_OPT=""
DATE_OPT=""
VERSION_OPT=""
FNAME_OPT=""
if [ $# -gt 0 ]; then
  DEFAULT_FORMAT_OPT=""
  for arg in $@
  do
    is_option=`echo ${arg} | grep '\-\-'`
    if [ ! -z "${is_option}" ]; then
      [ $arg = "--size" ] && SIZE_OPT="yes" && continue
      [ $arg = "--date" ] && DATE_OPT="yes" && continue
      [ $arg = "--version" ] && VERSION_OPT="_BIGSYSTEM/" && continue
      [ $arg = "--fname" ] && FNAME_OPT="yes" && continue
      echo "${0}: unknown option '${arg}'"
    fi
  done
fi
if [ -z "${SIZE_OPT}" ] && [ -z "${DATE_OPT}" ] && [ -z "${VERSION_OPT}" ] && [ -z "${FNAME_OPT}" ]; then
  DEFAULT_FORMAT_OPT="yes"
fi

[ -z "${BUILD_FARM}" ] && BUILD_FARM="${HOME}/build-farm"
if [ ! -d "${BUILD_FARM}" ]; then
  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

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

# list them
##stat --printf="%12.s (%y) ./\033[1m%n\033[0m\n" *.binpkg.*
list_of_packages=`find . -type f -name "*.binpkg.*" -print0 | xargs -0 stat --printf="<%y> %s %n\n" | grep -v ".list" | sort -r`
package_count=0

# check for bc binary
bc_binary_found="yes"
which bc >/dev/null 2>&1 || type bc >/dev/null 2>&1 || bc_binary_found=""

echo "${list_of_packages}" | while read the_package
do
  size_of_pkg=`echo "${the_package}" | cut -d'>' -f2 | cut -d' ' -f2`
  date_of_pkg=`echo "${the_package}" | cut -d'<' -f2 | cut -d'>' -f1 | cut -d' ' -f1`
  file_name_of_pkg=`echo "${the_package}" | cut -d'/' -f2`
  title_of_pkg=`echo "${file_name_of_pkg}" | cut -d'-' -f1`
  version_of_pkg=`echo "${file_name_of_pkg}" | cut -d'-' -f2 | sed 's/v//'`

  printf "[#%.4d]  " `expr $package_count '+' 1`

  if [ ! -z "${DEFAULT_FORMAT_OPT}" ]; then
    if [ ! -z ${bc_binary_found} ]; then
      pkg_kb_size=`echo scale=2 \; ${size_of_pkg}/1024 | bc`
      printf "%10.1f%s" "${pkg_kb_size}" "K"
    else
      printf "%10.d" "${size_of_pkg}"
    fi
    printf "  "
    printf "%s" "${date_of_pkg}"
    printf "  "
    printf "\033[1m%s\033[0m v%s (%s)" "${title_of_pkg}" "${version_of_pkg}" "${file_name_of_pkg}"
  else
    if [ ! -z "${SIZE_OPT}" ]; then
      if [ ! -z ${bc_binary_found} ]; then
        pkg_kb_size=`echo scale=2 \; ${size_of_pkg}/1024 | bc`
        printf "%10.1f%s  " "${pkg_kb_size}" "K"
      else
        printf "%10.d  " "${size_of_pkg}"
      fi
    fi
    if [ ! -z "${DATE_OPT}" ]; then
      printf "%s  " "${date_of_pkg}"
    fi
    printf "\033[1m%s\033[0m " "${title_of_pkg}"
    if [ ! -z "${VERSION_OPT}" ]; then
      printf "v%s " "${version_of_pkg}" 
    fi
    if [ ! -z "${FNAME_OPT}" ]; then
      printf "(%s)" "${file_name_of_pkg}"
    fi
  fi

  printf "\n"
  package_count=`expr $package_count '+' 1`
done

printf "%s: \033[1m%d\033[0m\n" "Total number of packages" `echo "${list_of_packages}" | wc -l`
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.