Created
August 3, 2017 10:56
-
-
Save aespinosa/1ef46d6d466d8e65b071c627ad91f443 to your computer and use it in GitHub Desktop.
Some form of vagrant plugin to setup proxies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Allan | |
def initialize(app, env) | |
@app = app | |
@machine = env[:machine] | |
end | |
def call(env) | |
@app.call env | |
setup_debian_apt if @machine.box.name =~ /bento\/debian/ | |
setup_centos_yum if @machine.box.name =~ /centos\/7/ | |
setup_nix | |
end | |
def setup_nix | |
return if @machine.communicate.test 'cat /etc/nix/nix.conf' | |
@machine.ui.detail 'Setting up nix' | |
@machine.communicate.tap do |comm| | |
comm.sudo 'mkdir -p /nix /etc/nix && chown vagrant:vagrant /nix /etc/nix' | |
comm.execute 'echo binary-caches = http://proxy.dev:8081/repository/nixos-cache/ > /etc/nix/nix.conf' | |
end | |
end | |
def setup_debian_apt | |
return if @machine.communicate.test 'grep proxy.dev /etc/apt/sources.list' | |
@machine.ui.detail "Setting up Apt sources on #{@machine.box.name} based VM" | |
@machine.communicate.tap do |comm| | |
comm.sudo 'sed "s,httpredir.debian.org,proxy.dev:8081/repository," -i /etc/apt/sources.list' | |
comm.sudo 'sed "s,security.debian.org,proxy.dev:8081/repository/debian-security," -i /etc/apt/sources.list' | |
end | |
end | |
def setup_ubuntu_apt | |
@machine.ui.detail "Setting up Apt sources on #{machine.box.name} based VM" | |
@machine.communicate.tap do |comm| | |
comm.sudo 'sed "s,us.archive.ubuntu.com,proxy.dev:8081/repository," -i /etc/apt/sources.list' | |
comm.sudo 'sed "s,security.ubuntu.com/ubuntu,proxy.dev:8081/repository/ubuntu-security," -i /etc/apt/sources.list' | |
end | |
end | |
def setup_centos_yum | |
@machine.ui.detail "Setting up Yum sources on #{@machine.box.name} based VM" | |
@machine.communicate.tap do |comm| | |
comm.execute "awk '{ sub(/^mirrorlist/, \"#mirrorlist\") ; "\ | |
"sub(/^#baseurl/, \"baseurl\") ; "\ | |
"sub(/mirror.centos.org/, \"proxy.dev:8081/repository\"); "\ | |
"print }' /etc/yum.repos.d/CentOS-Base.repo > /tmp/CentOS-Base.repo" | |
comm.sudo 'cp -fv /tmp/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo' | |
end | |
end | |
end | |
class Stuff < Vagrant.plugin('2') | |
name 'allan' | |
action_hook 'setup_repos', :machine_action_up do |hook| | |
hook.append Allan | |
end | |
end | |
Vagrant.configure '2' do |config| | |
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true | |
config.vm.synced_folder '.', '/vagrant', disabled: true | |
config.ssh.insert_key = false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment