<commit_before>#
# Common variables
#

APPNAME="owncloud"

# ownCloud version
VERSION="9.0.2"

# Package name for MediaGoblin dependencies
DEPS_PKG_NAME="owncloud-deps"

# Remote URL to fetch ownCloud tarball
OWNCLOUD_SOURCE_URL="https://download.owncloud.org/community/owncloud-${VERSION}.tar.bz2"

# Remote URL to fetch ownCloud tarball checksum
OWNCLOUD_SOUCE_SHA256="845c43fe981fa0fd07fc3708f41f1ea15ecb11c2a15c65a4de191fc85b237c74"

# App package root directory should be the parent folder
PKGDIR=$(cd ../; pwd)

#
# Common helpers
#

# Print a message to stderr and exit
# usage: die msg [retcode]
die() {
  printf "%s" "$1" 1>&2
  exit "${2:-1}"
}

# Download and extract ownCloud sources to the given directory
# usage: extract_owncloud DESTDIR [AS_USER]
extract_owncloud() {
  local DESTDIR=$1
  local AS_USER=${2:-admin}

  # retrieve and extract Roundcube tarball
  oc_tarball="/tmp/owncloud.tar.bz2"
  rm -f "$oc_tarball"
  wget -q -O "$oc_tarball" "$OWNCLOUD_SOURCE_URL" \
    || die "Unable to download ownCloud tarball"
  echo "$OWNCLOUD_SOUCE_SHA256 $oc_tarball" | sha256sum -c >/dev/null \
    || die "Invalid checksum of downloaded tarball"
  exec_as "$AS_USER" tar xjf "$oc_tarball" -C "$DESTDIR" --strip-components 1 \
    || die "Unable to extract ownCloud tarball"
  rm -f "$oc_tarball"

  # apply patches
  (cd "$DESTDIR" \
   && for p in ${PKGDIR}/patches/*.patch; do \
        exec_as "$AS_USER" patch -p1 < $p; done) \
    || die "Unable to apply patches to ownCloud"
}

# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
exec_as() {
  local USER=$1
  shift 1

  if [[ $USER = $(whoami) ]]; then
    eval "$@"
  else
    # use sudo twice to be root and be allowed to use another user
    sudo sudo -u "$USER" "$@"
  fi
}

# Execute a command with occ as a given user from a given directory
# usage: exec_occ WORKDIR AS_USER COMMAND [ARG ...]
exec_occ() {
  local WORKDIR=$1
  local AS_USER=$2
  shift 2

  (cd "$WORKDIR" && exec_as "$AS_USER" \
      php occ --no-interaction --quiet --no-ansi "$@")
}
<commit_msg>[fix] Do not be quiet in occ commands<commit_after>#
# Common variables
#

APPNAME="owncloud"

# ownCloud version
VERSION="9.0.2"

# Package name for MediaGoblin dependencies
DEPS_PKG_NAME="owncloud-deps"

# Remote URL to fetch ownCloud tarball
OWNCLOUD_SOURCE_URL="https://download.owncloud.org/community/owncloud-${VERSION}.tar.bz2"

# Remote URL to fetch ownCloud tarball checksum
OWNCLOUD_SOUCE_SHA256="845c43fe981fa0fd07fc3708f41f1ea15ecb11c2a15c65a4de191fc85b237c74"

# App package root directory should be the parent folder
PKGDIR=$(cd ../; pwd)

#
# Common helpers
#

# Print a message to stderr and exit
# usage: die msg [retcode]
die() {
  printf "%s" "$1" 1>&2
  exit "${2:-1}"
}

# Download and extract ownCloud sources to the given directory
# usage: extract_owncloud DESTDIR [AS_USER]
extract_owncloud() {
  local DESTDIR=$1
  local AS_USER=${2:-admin}

  # retrieve and extract Roundcube tarball
  oc_tarball="/tmp/owncloud.tar.bz2"
  rm -f "$oc_tarball"
  wget -q -O "$oc_tarball" "$OWNCLOUD_SOURCE_URL" \
    || die "Unable to download ownCloud tarball"
  echo "$OWNCLOUD_SOUCE_SHA256 $oc_tarball" | sha256sum -c >/dev/null \
    || die "Invalid checksum of downloaded tarball"
  exec_as "$AS_USER" tar xjf "$oc_tarball" -C "$DESTDIR" --strip-components 1 \
    || die "Unable to extract ownCloud tarball"
  rm -f "$oc_tarball"

  # apply patches
  (cd "$DESTDIR" \
   && for p in ${PKGDIR}/patches/*.patch; do \
        exec_as "$AS_USER" patch -p1 < $p; done) \
    || die "Unable to apply patches to ownCloud"
}

# Execute a command as another user
# usage: exec_as USER COMMAND [ARG ...]
exec_as() {
  local USER=$1
  shift 1

  if [[ $USER = $(whoami) ]]; then
    eval "$@"
  else
    # use sudo twice to be root and be allowed to use another user
    sudo sudo -u "$USER" "$@"
  fi
}

# Execute a command with occ as a given user from a given directory
# usage: exec_occ WORKDIR AS_USER COMMAND [ARG ...]
exec_occ() {
  local WORKDIR=$1
  local AS_USER=$2
  shift 2

  (cd "$WORKDIR" && exec_as "$AS_USER" \
      php occ --no-interaction --no-ansi "$@")
}

{'fraction_non_alphanumeric': 0.12590448625180897, 'fraction_numerical': 0.03183791606367583, 'mean_word_length': 3.696489241223103, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959798', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1510, 'n_words': 454}