<commit_before>#!/bin/bash
set -e

# command boilerplate code
BASE_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
CMD_PATH="${BASH_SOURCE[0]}"
source $BASE_PATH/lstack.sh
source $BASE_PATH/install/creds.sh

main() {
  local image=$1

  running? || exit $?

  if [ ! -f "$image" ]; then
    error "Invalid image file '$image'."
    usage
    exit 1
  fi

  file "$image" | grep "QCOW Image" > /dev/null 2>&1 || {
    error "Invalid image. Only QCOW images supported for now."
    usage
    exit 1
  }

  if [ ! -r "$image" ]; then
    error "The image '$image' is not readable."
    exit 1
  fi

  needs_root

  fifo=$(mktemp -u)
  mkfifo $fifo
  {
    md5sum "$image" | awk '{print $1}' > $fifo
  } &

  # hardlink the image to the container
  info "Importing the image into Glance..."
  __gid=$(glance_import "$image" "$importimg_name")
  if [ -z "$__gid " ]; then
    error "Error importing the image"
  fi

  __gmd5=$(glance_md5 "$__gid")

  while true; do
    if read md5 < $fifo; then
      break;
    fi
    sleep 1
  done

  rm -f $fifo
  if [ "$md5" = "$__gmd5" ]; then
    info "Image imported"
  else
    error "The MD5 of the imported image does not match the source MD5"
    exit 1
  fi
}

usage() {
  echo
  echo "Usage: lstack importimg [options] <image-file>"
  echo
  echo FLAGS
  echo
  columnize "--name",      "Instance name   (default: lstack-%timestamp)"
  echo
}

importimg_name="lstack-$(date +%s)"
importimg_option_name()   ( importimg_name="$1"; shift; d "$@" )
importimg_option_help()   ( usage; )
importimg_command_help()  ( usage; )
importimg_ () ( main )

d() {
  # Assume there are no flags if there's only one argument
  if [ $# = 1 ]; then
    main $@
  else
    dispatch importimg "$@"
  fi
}

dispatch importimg "$@"
<commit_msg>Added missing exit 1<commit_after>#!/bin/bash
set -e

# command boilerplate code
BASE_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../" && pwd )"
CMD_PATH="${BASH_SOURCE[0]}"
source $BASE_PATH/lstack.sh
source $BASE_PATH/install/creds.sh

main() {
  local image=$1

  running? || exit $?

  if [ ! -f "$image" ]; then
    error "Invalid image file '$image'."
    usage
    exit 1
  fi

  file "$image" | grep "QCOW Image" > /dev/null 2>&1 || {
    error "Invalid image. Only QCOW images supported for now."
    usage
    exit 1
  }

  if [ ! -r "$image" ]; then
    error "The image '$image' is not readable."
    exit 1
  fi

  needs_root

  fifo=$(mktemp -u)
  mkfifo $fifo
  {
    md5sum "$image" | awk '{print $1}' > $fifo
  } &

  # hardlink the image to the container
  info "Importing the image into Glance..."
  __gid=$(glance_import "$image" "$importimg_name")
  if [ -z "$__gid " ]; then
    error "Error importing the image"
    exit 1
  fi

  __gmd5=$(glance_md5 "$__gid")

  while true; do
    if read md5 < $fifo; then
      break;
    fi
    sleep 1
  done

  rm -f $fifo
  if [ "$md5" = "$__gmd5" ]; then
    info "Image imported"
  else
    error "The MD5 of the imported image does not match the source MD5"
    exit 1
  fi
}

usage() {
  echo
  echo "Usage: lstack importimg [options] <image-file>"
  echo
  echo FLAGS
  echo
  columnize "--name",      "Instance name   (default: lstack-%timestamp)"
  echo
}

importimg_name="lstack-$(date +%s)"
importimg_option_name()   ( importimg_name="$1"; shift; d "$@" )
importimg_option_help()   ( usage; )
importimg_command_help()  ( usage; )
importimg_ () ( main )

d() {
  # Assume there are no flags if there's only one argument
  if [ $# = 1 ]; then
    main $@
  else
    dispatch importimg "$@"
  fi
}

dispatch importimg "$@"

{'fraction_non_alphanumeric': 0.14669652855543114, 'fraction_numerical': 0.012318029115341545, 'mean_word_length': 2.8336909871244633, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '2195392', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1273, 'n_words': 399}