<commit_before>#!/usr/bin/env bash

set -exfu
umask 0022

function main {
  local loader='sudo env DEBIAN_FRONTEND=noninteractive'
  local nm_branch="v20170617"
  local nm_remote="gh"
  local url_remote="https://github.com/imma/ubuntu"

  ssh -o StrictHostKeyChecking=no git@github.com true 2>/dev/null || true

  if [[ ! -d .git || -f .bootstrapping ]]; then
    touch .bootstrapping

    $loader apt-get install -y awscli
    $loader dpkg --configure -a
    $loader apt-get update
    $loader apt-get install -y make python build-essential aptitude git rsync
    $loader aptitude hold grub-legacy-ec2 docker-ce lxd
    $loader apt-get upgrade -y

    ssh -o StrictHostKeyChecking=no git@github.com true 2>/dev/null || true

    tar xvfz /data/cache/git/ubuntu-v20170616.tar.gz
    git reset --hard
    rsync -ia .gitconfig.template .gitconfig

    git remote add "${nm_remote}" "${url_remote}" 2>/dev/null || true
    git remote set-url "${nm_remote}" "${url_remote}"
    rm -f .ssh/config
    git fetch "${nm_remote}"
    git branch -D "${nm_remote}/$nm_branch" || true
    git branch --set-upstream-to "${nm_remote}/$nm_branch"
    git reset --hard "${nm_remote}/${nm_branch}"
    git checkout "${nm_branch}" 
    if ! git submodule update --init; then
      set +f
      for a in work/*/; do
        a="${a%/}"
        if [[ ! -L "$a" ]]; then
          if ! git submodule update --init "$a"; then
            rm -rf ".git/modules/$a" "$a"
            git submodule update --init "$a"
          fi
        fi
      done
      set -f
      git submodule foreach 'git reset --hard; git clean -ffd'
    fi
    git submodule update --init

    pushd work/base
    script/bootstrap
    popd

    rm -f .bootstrapping
  fi

  export BOARD_PATH="$HOME"

  work/base/script/bootstrap
  work/jq/script/bootstrap
  work/block/script/cibuild

  source work/block/script/profile ~

  make cache
  source .bash_profile

  git reset --hard
  chmod 700 .gnupg
  rsync -ia .ssh/config.template .ssh/config
  chmod 600 .ssh/config

  git fetch
  git reset --hard
  git clean -ffd
  block sync
  block bootstrap
  sync
}

case "$(id -u -n)" in
  root)
    umask 022

    cat > /etc/sudoers.d/90-cloud-init-users <<____EOF
    # Created by cloud-init v. 0.7.9 on Fri, 21 Jul 2017 08:42:58 +0000
    # User rules for ubuntu
    ubuntu ALL=(ALL) NOPASSWD:ALL
____EOF

    ssh -A -o BatchMode=yes -o StrictHostKeyChecking=no ubuntu@localhost "$0"
    ;;
  *)
    main "$@"<commit_msg>fetch earlier<commit_after>#!/usr/bin/env bash

set -exfu
umask 0022

function main {
  local loader='sudo env DEBIAN_FRONTEND=noninteractive'
  local nm_branch="v20170617"
  local nm_remote="gh"
  local url_remote="https://github.com/imma/ubuntu"

  ssh -o StrictHostKeyChecking=no git@github.com true 2>/dev/null || true

  if [[ ! -d .git || -f .bootstrapping ]]; then
    touch .bootstrapping

    $loader apt-get install -y awscli
    $loader dpkg --configure -a
    $loader apt-get update
    $loader apt-get install -y make python build-essential aptitude git rsync
    $loader aptitude hold grub-legacy-ec2 docker-ce lxd
    $loader apt-get upgrade -y

    ssh -o StrictHostKeyChecking=no git@github.com true 2>/dev/null || true

    tar xvfz /data/cache/git/ubuntu-v20170616.tar.gz
    git reset --hard
    rsync -ia .gitconfig.template .gitconfig

    git remote add "${nm_remote}" "${url_remote}" 2>/dev/null || true
    git remote set-url "${nm_remote}" "${url_remote}"
    rm -f .ssh/config
    git fetch "${nm_remote}"
    git branch -D "${nm_remote}/$nm_branch" || true
    git branch --set-upstream-to "${nm_remote}/$nm_branch"
    git reset --hard "${nm_remote}/${nm_branch}"
    git checkout "${nm_branch}" 
    if ! git submodule update --init; then
      set +f
      for a in work/*/; do
        a="${a%/}"
        if [[ ! -L "$a" ]]; then
          if ! git submodule update --init "$a"; then
            rm -rf ".git/modules/$a" "$a"
            git submodule update --init "$a"
          fi
        fi
      done
      set -f
      git submodule foreach 'git reset --hard; git clean -ffd'
    fi
    git submodule update --init

    pushd work/base
    script/bootstrap
    popd

    rm -f .bootstrapping
  fi

  export BOARD_PATH="$HOME"

  git fetch
  git reset --hard
  git clean -ffd

  work/base/script/bootstrap
  work/jq/script/bootstrap
  work/block/script/cibuild

  source work/block/script/profile ~

  make cache
  source .bash_profile

  git reset --hard
  chmod 700 .gnupg
  rsync -ia .ssh/config.template .ssh/config
  chmod 600 .ssh/config

  block sync
  block bootstrap
  sync
}

case "$(id -u -n)" in
  root)
    umask 022

    cat > /etc/sudoers.d/90-cloud-init-users <<____EOF
    # Created by cloud-init v. 0.7.9 on Fri, 21 Jul 2017 08:42:58 +0000
    # User rules for ubuntu
    ubuntu ALL=(ALL) NOPASSWD:ALL
____EOF

    ssh -A -o BatchMode=yes -o StrictHostKeyChecking=no ubuntu@localhost "$0"
    ;;
  *)
    main "$@"
{'fraction_non_alphanumeric': 0.12482269503546099, 'fraction_numerical': 0.022289766970618033, 'mean_word_length': 2.4541637508747374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '1026221', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1671, 'n_words': 509}