Skip to content

Instantly share code, notes, and snippets.

@IceDragon200
Last active August 29, 2015 14:14
Show Gist options
  • Save IceDragon200/07d07eca6004c66d1467 to your computer and use it in GitHub Desktop.
Save IceDragon200/07d07eca6004c66d1467 to your computer and use it in GitHub Desktop.

Changes

  • Edited the template, so it puts out each line instead of inlining them.
  • Used 4 interfaces instead of 2.
require 'erubis'
def rand_ip
4.times.map { rand(256) }.join('.')
end
class Context
class Subnet
attr_accessor :mask
def initialize
@mask = rand_ip
end
end
class Interface
@@index = 0
attr_accessor :name
attr_accessor :subnet
attr_accessor :ip
def initialize
@name = "bleh-icedeth#{@@index+=1}"
@ip = rand_ip
@subnet = Subnet.new
end
end
class Host
attr_accessor :interfaces
def initialize
@interfaces = Array.new(4) { Interface.new }
end
end
def initialize
@host = Host.new
end
def b
send(:binding)
end
end
context = Context.new
t = Erubis::Eruby.new(File.read('template.erb'))
data = t.result(context.b)
File.write('result.sh', data)
/bin/touch /etc/network/interfaces.d/icedeth1.conf
cat > /etc/network/interfaces.d/icedeth1.conf << EOF
auto icedeth1
iface icedeth1 inet static
address 35.71.230.154
netmask 144.241.171.105
EOF
/bin/touch /etc/network/interfaces.d/icedeth2.conf
cat > /etc/network/interfaces.d/icedeth2.conf << EOF
auto icedeth2
iface icedeth2 inet static
address 58.5.114.167
netmask 192.169.74.204
EOF
/bin/touch /etc/network/interfaces.d/icedeth3.conf
cat > /etc/network/interfaces.d/icedeth3.conf << EOF
auto icedeth3
iface icedeth3 inet static
address 159.88.80.141
netmask 214.102.149.195
EOF
/bin/touch /etc/network/interfaces.d/icedeth4.conf
cat > /etc/network/interfaces.d/icedeth4.conf << EOF
auto icedeth4
iface icedeth4 inet static
address 204.196.69.29
netmask 150.24.179.187
EOF
<% @host.interfaces.each do |int| %>
<% intface = int.name.split('-')[-1] %>
/bin/touch /etc/network/interfaces.d/<%= intface %>.conf
cat > /etc/network/interfaces.d/<%= intface %>.conf << EOF
auto <%= intface %>
iface <%= intface %> inet static
address <%= int.ip %>
netmask <%= int.subnet.mask %>
EOF
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment