#!/bin/sh

if [ "$1" = "--help" ]; then
	cat <<EOF
usage: vbuilder login -n <container> [-t]

options:
  --help                   show this text
  -n, --name <container>   name of environment (required)
  -t, --tmpfs              use tmpfs for the upper layer of overlayfs

EOF
	exit 0
fi

LIBEXECDIR="/usr/libexec/vbuilder"
CONTAINER=""
TMPFS=0

while [ $# -gt 0 ]; do
	case $1 in
		-n|--name)
			shift
			CONTAINER=$1
			;;
		-t|--tmpfs)
			TMPFS=1
			;;
		*)
			;;
	esac

	shift
done

. $LIBEXECDIR/common.sh

prepare_container
start_container
wait_container_ready

lxc-attach -n $CONTAINER -- bash --login ||:

shutdown_container

umount_tmpfs
