#!/bin/bash
# This script creates devices on containers used during bring-up.
# Copyright (c) 2014-2015 by Cisco Systems, Inc.
# All rights reserved.

BOOTSTRAP_FILE="/etc/init.d/calvados_bootstrap.cfg"
source $BOOTSTRAP_FILE

# Thie script would be executed only if VIRT_METHOD=lxc
if [[ $VIRT_METHOD != "lxc" ]]; then
    exit 0
fi

devlistdata="/etc/sysconfig/devlistdata.txt"

if [ -f $devlistdata ]; then
    if [ ! -d "/dev/mapper" ]; then
       mkdir -p /dev/mapper
    fi
    while read line; do
        devicetype=`echo $line    | awk -F ' ' '{print $2}'`
        devicepath=`echo $line    | awk -F ' ' '{print $1}'`
        case $devicetype in
            b)
                [ -b $devicepath ] || /bin/mknod -m 0640 $line
                /bin/chown root:root $devicepath
                ;;
            c)
                [ -c  $devicepath ] || /bin/mknod -m 0660 $line
                /bin/chown root:root $devicepath
        esac
    done < "$devlistdata"
fi
