#!/usr/bin/perl

my $usage = "\nScript : Input Network Infomation\n\nUsage : ./network_setting.pl DeviceName IP_Addr Gateway DNS1 DNS2\n";
die "$usage\n" if (@ARGV < 5);

$devicename = shift;
chomp $devicename;

$ipaddr = shift;
chomp $ipaddr;

$gatewayaddr = shift;
chomp $gatewayaddr;

$dns1 = shift;
chomp $dns1;

$dns2 = shift;
chomp $dns2;

`cp ./01-network-manager-all.yaml ./01-network-manager-all.yaml_org`;

`perl -pi -e 's/(devicename)/$devicename/g if 1..100' ./01-network-manager-all.yaml`;
`perl -pi -e 's/(ipaddr)/$ipaddr/g if 1..100' ./01-network-manager-all.yaml`;
`perl -pi -e 's/(gatewayaddr)/$gatewayaddr/g if 1..100' ./01-network-manager-all.yaml`;
`perl -pi -e 's/(dns1)/$dns1/g if 1..100' ./01-network-manager-all.yaml`;
`perl -pi -e 's/(dns2)/$dns2/g if 1..100' ./01-network-manager-all.yaml`;

`cp -rf ./01-network-manager-all.yaml /etc/netplan/`;

`mv ./01-network-manager-all.yaml_org ./01-network-manager-all.yaml`;
`netplan apply`;

print "\n". $username . "Network Setting complete...\nPlease Reboot...\n\n";
