#!/bin/bash

vz_version=$(cat /etc/virtuozzo-release | awk '{print $3}')
case $vz_version in
	4.*|5.*|6.*) echo "Docker requires Virtuozzo 7.0, but got $vz_version" >&2; exit 1;;
	7.*) : ;;
	*) echo "Unknown Virtuozzo version: $vz_version" >&2; exit 1;;
esac

# This is copy of docker pre-install-hn script from VZ docker template 
VZLIST="/usr/sbin/vzlist"
VERSION=1

VEROOT=$1
VEID=$2

function error_msg() {
	echo $*
	exit 1
}

# Check for needed features
$VZLIST -H -o features $VEID 2>/dev/null | grep 'bridge:off' > /dev/null 2>&1
[ $? -eq 0 ] && error_msg "Failed to install docker template: feature bridge should be on"

$VZLIST -H -o netfilter $VEID 2>/dev/null | grep '^full' > /dev/null 2>&1
[ $? -ne 0 ] && error_msg "Failed to install docker template: netfilter should be full"

exit 0
