<commit_before>#!/bin/bash

set -e

srcroot=${srcroot:-$(dirname $(readlink -f "$0"))}
all_images=$(echo centos{5,6,7}.{amd64,i386} debian{6,7}.{amd64,i386})

with_path="/usr/bin/env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"

makeimg_mount_target () {
  target=$(mktemp -d)
  trap "makeimg_umount_target; makeimg_remove_target" INT QUIT TERM EXIT
}

makeimg_umount_target () {
  for fs in $(grep "$target" /proc/self/mounts | cut -d\  -f2)
  do makeimg_umount "$fs";  done
}

makeimg_remove_target () {
  rm -rf "$target"
}

makeimg_configure_debian () {
  debian_conf_post_script="$target/bootstrap/post-script"
  cp -a "$srcroot/../bootstrap" "$target/bootstrap"
  case "$dist" in
    7)
      name=wheezy
      cat <<EOF >"$debian_conf_post_script"
#!/bin/sh
chroot "$target" $with_path /bootstrap/debian7-bootstrap.sh
EOF
      ;;
    6)
      name=squeeze
      cat <<EOF >"$debian_conf_post_script"
#!/bin/sh
chroot "$target" $with_path /bootstrap/debian6-bootstrap.sh
EOF
      ;;
    *)
      return 1
      ;;
  esac

  chmod 755 "$debian_conf_post_script"
}

makeimg_debian () {
  local name
  local arch
  local dist
  local debian_conf_post_script
  arch=$1
  dist=$2

  echo "MAKE debian-$dist-$arch"
  makeimg_mount_target
  makeimg_configure_debian
  debootstrap --arch=$arch --foreign --variant=minbase --include=iproute,iputils-ping,netbase $name "$target" "${debian_mirror:-http://cdn.debian.net/debian}"
  env DEBOOTSTRAP_DIR="$target/debootstrap" debootstrap --second-stage --second-stage-target="$target"
  "$debian_conf_post_script"
  makeimg_umount_target

  tar -C "$target" -c . | docker import - leela/debian$dist-$arch
  makeimg_remove_target
}

makeimg_configure_centos () {
  centos_conf_pre_script="$target/bootstrap/pre-script"
  centos_conf_post_script="$target/bootstrap/post-script"

  echo "CONF centos-$dist-$arch"
  cp -a "$srcroot/../bootstrap" "$target/bootstrap"

  cat <<EOF >"$centos_conf_pre_script"
#!/bin/sh

sed -i s/enabled=0/enabled=1/g "$target/etc/yum.repos.d/CentOS-Base.repo"
sed -i s/'\$releasever'/$dist/g "$target/etc/yum.repos.d/CentOS-Base.repo" "$target/etc/yum.conf"
if [ "$arch" = i386 ]
then
  mkdir -p "$target/etc/rpm"
  echo "i686-redhat-linux" >"$target/etc/rpm/platform"
  echo "i386-redhat-linux" >>"$target/etc/rpm/platform"
fi
EOF

  case "$dist" in
    5)
      cat <<EOF >"$centos_conf_post_script"
#!/bin/sh
chroot "$target" /bootstrap/centos5-bootstrap.sh
chroot "$target" yum upgrade -y
EOF
      ;;

    6)
      cat <<EOF >"$centos_conf_post_script"
#!/bin/sh
chroot "$target" /bootstrap/centos6-bootstrap.sh
chroot "$target" yum upgrade -y
EOF
      ;;

    7)
      cat <<EOF >"$centos_conf_post_script"
#!/bin/sh
chroot "$target" /bootstrap/centos7-bootstrap.sh
chroot "$target" yum upgrade -y
EOF<commit_msg>bugfix: rinse creates / with mode 0700<commit_after>#!/bin/bash

set -e

srcroot=${srcroot:-$(dirname $(readlink -f "$0"))}
all_images=$(echo centos{5,6,7}.{amd64,i386} debian{6,7}.{amd64,i386})

with_path="/usr/bin/env PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"

makeimg_mount_target () {
  target=$(mktemp -d)
  trap "makeimg_umount_target; makeimg_remove_target" INT QUIT TERM EXIT
}

makeimg_umount_target () {
  for fs in $(grep "$target" /proc/self/mounts | cut -d\  -f2)
  do makeimg_umount "$fs";  done
}

makeimg_remove_target () {
  rm -rf "$target"
}

makeimg_configure_debian () {
  debian_conf_post_script="$target/bootstrap/post-script"
  cp -a "$srcroot/../bootstrap" "$target/bootstrap"
  case "$dist" in
    7)
      name=wheezy
      cat <<EOF >"$debian_conf_post_script"
#!/bin/sh
chown 755 "$target"
chroot "$target" $with_path /bootstrap/debian7-bootstrap.sh
EOF
      ;;
    6)
      name=squeeze
      cat <<EOF >"$debian_conf_post_script"
#!/bin/sh
chown 755 "$target"
chroot "$target" $with_path /bootstrap/debian6-bootstrap.sh
EOF
      ;;
    *)
      return 1
      ;;
  esac

  chmod 755 "$debian_conf_post_script"
}

makeimg_debian () {
  local name
  local arch
  local dist
  local debian_conf_post_script
  arch=$1
  dist=$2

  echo "MAKE debian-$dist-$arch"
  makeimg_mount_target
  makeimg_configure_debian
  debootstrap --arch=$arch --foreign --variant=minbase --include=iproute,iputils-ping,netbase $name "$target" "${debian_mirror:-http://cdn.debian.net/debian}"
  env DEBOOTSTRAP_DIR="$target/debootstrap" debootstrap --second-stage --second-stage-target="$target"
  "$debian_conf_post_script"
  makeimg_umount_target

  tar -C "$target" -c . | docker import - leela/debian$dist-$arch
  makeimg_remove_target
}

makeimg_configure_centos () {
  centos_conf_pre_script="$target/bootstrap/pre-script"
  centos_conf_post_script="$target/bootstrap/post-script"

  echo "CONF centos-$dist-$arch"
  cp -a "$srcroot/../bootstrap" "$target/bootstrap"

  cat <<EOF >"$centos_conf_pre_script"
#!/bin/sh

sed -i s/enabled=0/enabled=1/g "$target/etc/yum.repos.d/CentOS-Base.repo"
sed -i s/'\$releasever'/$dist/g "$target/etc/yum.repos.d/CentOS-Base.repo" "$target/etc/yum.conf"
if [ "$arch" = i386 ]
then
  mkdir -p "$target/etc/rpm"
  echo "i686-redhat-linux" >"$target/etc/rpm/platform"
  echo "i386-redhat-linux" >>"$target/etc/rpm/platform"
fi
EOF

  case "$dist" in
    5)
      cat <<EOF >"$centos_conf_post_script"
#!/bin/sh
chown 755 "$target"
chroot "$target" /bootstrap/centos5-bootstrap.sh
chroot "$target" yum upgrade -y
EOF
      ;;

    6)
      cat <<EOF >"$centos_conf_post_script"
#!/bin/sh
chown 755 "$target"
chroot "$target" /bootstrap/centos6-bootstrap.sh
chroot "$target" yum upgrade -y
EOF
      ;;

    7)
      cat <<EOF >"$centos_conf_post_script"
#!/bin/sh
chown 755 "$target"
chroot "$target" /bootstrap/centos7-bootstrap.sh
chroot "$target" yum upgrade -y
EOF
{'fraction_non_alphanumeric': 0.16153712397843853, 'fraction_numerical': 0.01860545992001391, 'mean_word_length': 3.8953191489361703, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5421274', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2186, 'n_words': 417}