#!/bin/sh -e

# This is documented here:
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines
if ! whoami &>/dev/null; then
  if [ -w /etc/passwd ]; then
    echo "${USER_NAME:-kubevirt-v2v-conversion}:x:$(id -u):$(id -g):${USER_NAME:-kubevirt-v2v-conversion} user:${HOME}:/sbin/nologin" >> /etc/passwd
  fi
fi
#####

set -x
VDDK="/opt/vmware-vix-disklib-distrib/"
ls -l "/usr/lib64/nbdkit/plugins/nbdkit-vddk-plugin.so"
ls -ld "$VDDK"
lib="$(find "$VDDK" -name 'libvixDiskLib.so.[67]' -printf '%h\n' -quit)"
LD_LIBRARY_PATH="$lib" nbdkit vddk --dump-plugin libdir="$VDDK"
LIBGUESTFS_BACKEND='direct' libguestfs-test-tool -t 0
set +x

echo
echo "...  OK  ..."
echo

echo "Listing content of /data"
ls -lR /data
echo

echo "Starting virt-v2v-wrapper..."
exec /usr/bin/virt-v2v-wrapper $@ < /data/input/conversion.json
