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

# -----------------------------
# accept_new_packages.sh
# version 1.1.4.7
# -----------------------------

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

[ -z "${USERNAME}" ] && USERNAME=`logname`
# sed 's/^[ \t]*//;s/[ \t]*$//' is used to delete both leading and trailing whitespace
USERHOME=`finger -l "${USERNAME}" 2>/dev/null | grep "Directory:" | cut -f1 | cut -d':' -f2 | sed 's/^[ \t]*//;s/[ \t]*$//'`
[ -z "${USERHOME}" ] && USERHOME="/home/"`logname`
printf "User: %s  \tHome directory: %s\n" "${USERNAME}" "${USERHOME}"

[ -z "${BUILDFARM_DIR}" ] && BUILDFARM_DIR="${USERHOME}/build-farm"
if [ -d "${BUILDFARM_DIR}" ]; then
  echo "base directory:" "${BUILDFARM_DIR}"
else
  printf "ERROR: base directory '%s' doesn't exist. Abort.\n" "${BUILDFARM_DIR}"
  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 "${PACKAGES_DIR}" ] && PACKAGES_DIR="PACKAGES"
if [ -d "${BUILDFARM_DIR}/${PACKAGES_DIR}" ]; then
  echo "packages directory:" "${BUILDFARM_DIR}/${PACKAGES_DIR}"
else
  echo "ERROR: packages directory '${PACKAGES_DIR}' doesn't exist. Abort."
  exit 1
fi
[ -z "${SRCPACKAGES_DIR}" ] && SRCPACKAGES_DIR="${PACKAGES_DIR}/srcpkg"
if [ -d "${BUILDFARM_DIR}/${SRCPACKAGES_DIR}" ]; then
  echo "source packages directory:" "${BUILDFARM_DIR}/${SRCPACKAGES_DIR}"
else
  echo "ERROR: source packages directory '${SRCPACKAGES_DIR}' doesn't exist. Abort."
  exit 1
fi
[ -z "${BINPACKAGES_DIR}" ] && BINPACKAGES_DIR="${PACKAGES_DIR}/binpkg-${ARCH_NAME}"
[ -d "${BUILDFARM_DIR}/${BINPACKAGES_DIR}" ] || BINPACKAGES_DIR=PACKAGES/binpkg
if [ -d "${BUILDFARM_DIR}/${BINPACKAGES_DIR}" ]; then
  echo "binary packages directory:" "${BUILDFARM_DIR}/${BINPACKAGES_DIR}"
else
  echo "ERROR: binary packages directory '${BINPACKAGES_DIR}' doesn't exist. Abort."
  exit 1
fi

cd "${BUILDFARM_DIR}/${PACKAGES_DIR}"
list_of_src_packages=`find . -maxdepth 1 -name "*.srcpkg.*" -print | sort`
list_of_bin_packages=`find . -maxdepth 1 -name "*.binpkg.*" -print | grep -v "\.list" | sort`
list_of_kernel_packages=`find . -maxdepth 1 -name "*.kernelpkg.*" -print | grep -v "\.list" | sort`
list_of_binpkg_and_kernelpkg=`printf "%s\n%s" "${list_of_bin_packages}" "${list_of_kernel_packages}"`

if [ ! -z "${list_of_src_packages}" ] || [ ! -z "${list_of_binpkg_and_kernelpkg}" ]; then
  if [ ! -z "${list_of_src_packages}" ]; then
    echo "new source packages:"
    echo "${list_of_src_packages}" | while read the_srcpkg; do
      [ -z "${the_srcpkg}" ] && continue
      _pkg_title=`basename "${the_srcpkg}" | cut -d'-' -f1`
      printf "\t\033[1m%s\033[0m (%s)\n" "${_pkg_title}" `basename "${the_srcpkg}"`
      _prev_pkg=`find ../"${SRCPACKAGES_DIR}" -maxdepth 1 -name "${_pkg_title}-*" -print | tr '\n' ' '`
      if [ ! -z "${_prev_pkg}" ]; then
        printf "\t\tremoving existing package(s): %s..." "${_prev_pkg}"
        rm -f ../"${SRCPACKAGES_DIR}"/"${_pkg_title}"-* 2>/dev/null && echo " ok"
      else
        printf "\t\tthis is entirely new package!\n"
      fi
      printf "\t\t"
      mv -f "${the_srcpkg}" ../"${SRCPACKAGES_DIR}"/ 2>&1 && printf -- "--> %s" ../"${SRCPACKAGES_DIR}"/`basename "${the_srcpkg}"`
      printf "\n"
    done
  fi

  if [ ! -z "${list_of_binpkg_and_kernelpkg}" ]; then
    mkdir -p "${BUILDFARM_DIR}/${BINPACKAGES_DIR}"/.FILELISTS
    echo "new binary packages:"
    echo "${list_of_binpkg_and_kernelpkg}" | while read the_binpkg; do
      [ -z "${the_binpkg}" ] && continue
      _pkg_basename=`basename "${the_binpkg}"`
      _pkg_title=`echo "${_pkg_basename}" | cut -d'-' -f1`
      printf "\t\033[1m%s\033[0m (%s)\n" "${_pkg_title}" "${_pkg_basename}"
      _prev_pkg=`find ../"${BINPACKAGES_DIR}" -maxdepth 1 -name "${_pkg_title}-*" -print | tr '\n' ' '`
      if [ ! -z "${_prev_pkg}" ]; then
        printf "\t\tremoving existing package(s): %s..." "${_prev_pkg}"
           rm -f ../"${BINPACKAGES_DIR}"/"${_pkg_title}"-* 2>/dev/null && echo " ok"
        _pkg_filellist=`find ../"${BINPACKAGES_DIR}"/.FILELISTS -maxdepth 1 -name "${_pkg_title}-*" -print | tr '\n' ' '`
        if [ ! -z "${_pkg_filellist}" ]; then
          printf "\t\tremoving old package's file list(s): %s..." "${_pkg_filellist}"
          rm -f ../"${BINPACKAGES_DIR}"/.FILELISTS/"${_pkg_title}"-* 2>/dev/null && echo " ok"
        fi
      else
        printf "\t\tthis is entirely new package!\n"
      fi
      printf "\t\t"
      mv -f "${the_binpkg}" ../"${BINPACKAGES_DIR}"/ 2>&1 && printf -- "--> %s" ../"${BINPACKAGES_DIR}/${_pkg_basename}"
      printf "\n"
      cd "${BUILDFARM_DIR}/${BINPACKAGES_DIR}"
      printf "\t\tgenerating file list..."
      if [ -f "${_pkg_basename}" ]; then
        is_bzip2=`file "${_pkg_basename}" | grep bzip2`
        is_gzip=`file "${_pkg_basename}" | grep gzip`
        if [ ! -z "${is_bzip2}" ]; then
          printf " (bzip2 package) %s.list... " "${_pkg_basename}"
          tar tjf "${_pkg_basename}" >./.FILELISTS/"${_pkg_basename}".list
          echo " ok"
        elif [ ! -z "${is_gzip}" ]; then
          printf " (gzip package) %s.list... " "${_pkg_basename}"
          tar tzf "${_pkg_basename}" >./.FILELISTS/"${_pkg_basename}".list
          echo " ok"
        fi
      else
        echo " fail!"
      fi
      cd "${BUILDFARM_DIR}/${PACKAGES_DIR}"
    done

    cd "${BUILDFARM_DIR}/${BINPACKAGES_DIR}"
    printf "re-generating md5sums..."
    md5sum *binpkg* >./.MD5SUMS
    echo " done"
    cd "${BUILDFARM_DIR}/${PACKAGES_DIR}"
  fi
else
  echo "No packages to accept."
  exit 0
fi
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.