#!/bin/bash

target_file="/etc/dhcp3/dhclient6_eth1_832.conf"

interface="eth1"
vif="832"

auth_string=$(/bin/cli-shell-api showCfg interfaces ethernet $interface vif $vif dhcp-options client-option | grep "send rfc3118-auth" | awk '{ print $4 }' | awk -F ";" '{print $1}')
mac_livebox=$(/bin/cli-shell-api showCfg interfaces ethernet $interface vif $vif dhcp-options client-option | grep "dhcp-client-identifier" | awk '{ print $4 }' | awk -F ";" '{print $1}')


read -r -d '' conffile <<EOF
# $target_file\n
option dhcp6.auth code 11 = string;\n
option dhcp6.vendorclass code 16 = string;\n
option dhcp6.userclass code 15 = string;\n
option dhcp6.vendor-specific-info code 17 = string;\n
\n
#External interface (VLAN must be 832 for Orange)\n
interface "$interface.$vif" {\n
\t#Orange France specific options\n
\tsend dhcp6.vendor-specific-info 00:16:00:00:05:58:00:06:00:0e:49:50:56:36:5f:52:45:51:55:45:53:54:45:44;\n
\tsend dhcp6.vendorclass 00:00:04:0e:00:05:73:61:67:65:6d;\n
\tsend dhcp6.userclass 00:2b:46:53:56:44:53:4c:5f:6c:69:76:65:62:6f:78:2e:49:6e:74:65:72:6e:65:74:2e:73:6f:66:74:61:74:68:6f:6d:65:2e:6c:69:76:65:62:6f:78:34;\n
\tsend dhcp6.vendor-opts 00:00:05:58:00:06:00:0e:49:50:56:36:5f:52:45:51:55:45:53:54:45:44;\n
\n
\t#Authentication for Orange France DHCP server (same value as for DHCPv4)\n
\tsend dhcp6.auth $auth_string;\n
\n
\tsend dhcp6.client-id 00:03:00:$mac_livebox;\n
\n
\trequest dhcp6.name-servers, dhcp6.vendorclass, dhcp6.userclass, dhcp6.auth;\n
}\n
EOF

echo -e $conffile > $target_file

