From 6abf6012310fcdad46af0ce96884d6a557a15f2d Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 7 Dec 2011 17:59:34 -0500 Subject: [PATCH] initial commit, starting to centralize configs --- .gitignore | 4 + Gemfile | 4 + Rakefile | 1 + lib/puppet-standalone-mashup.rb | 9 ++ lib/puppet-standalone-mashup/capistrano.rb | 108 ++++++++++++++++++ lib/puppet-standalone-mashup/version.rb | 7 ++ puppet-standalone-mashup.gemspec | 29 +++++ .../lib/puppet/modules/common_directories.rb | 29 +++++ .../lib/puppet/parser/functions/bin_path.rb | 9 ++ .../lib/puppet/parser/functions/build_path.rb | 8 ++ .../puppet/parser/functions/install_path.rb | 8 ++ .../lib/puppet/parser/functions/sbin_path.rb | 9 ++ .../puppet/parser/functions/symlink_path.rb | 8 ++ shared/lib/puppet/provider/bash_rc/install.rb | 38 ++++++ .../lib/puppet/provider/bash_rc_d/install.rb | 21 ++++ .../lib/puppet/provider/configure/action.rb | 25 ++++ .../provider/download_and_unpack/action.rb | 36 ++++++ shared/lib/puppet/provider/gem/gem_install.rb | 31 +++++ .../lib/puppet/provider/god_init/install.rb | 69 +++++++++++ .../provider/make_and_install/action.rb | 24 ++++ shared/lib/puppet/type/bash_rc.rb | 11 ++ shared/lib/puppet/type/bash_rc_d.rb | 14 +++ shared/lib/puppet/type/configure.rb | 26 +++++ shared/lib/puppet/type/download_and_unpack.rb | 22 ++++ shared/lib/puppet/type/gem.rb | 18 +++ shared/lib/puppet/type/god_init.rb | 22 ++++ shared/lib/puppet/type/make_and_install.rb | 22 ++++ .../build_and_install/manifests/init.pp | 30 +++++ skel/apply.erb | 5 + skel/debian/bootstrap.erb | 16 +++ skel/redhat/bootstrap.erb | 33 ++++++ skel/rename.erb | 14 +++ 32 files changed, 710 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 lib/puppet-standalone-mashup.rb create mode 100644 lib/puppet-standalone-mashup/capistrano.rb create mode 100644 lib/puppet-standalone-mashup/version.rb create mode 100644 puppet-standalone-mashup.gemspec create mode 100644 shared/lib/puppet/modules/common_directories.rb create mode 100644 shared/lib/puppet/parser/functions/bin_path.rb create mode 100644 shared/lib/puppet/parser/functions/build_path.rb create mode 100644 shared/lib/puppet/parser/functions/install_path.rb create mode 100644 shared/lib/puppet/parser/functions/sbin_path.rb create mode 100644 shared/lib/puppet/parser/functions/symlink_path.rb create mode 100644 shared/lib/puppet/provider/bash_rc/install.rb create mode 100644 shared/lib/puppet/provider/bash_rc_d/install.rb create mode 100644 shared/lib/puppet/provider/configure/action.rb create mode 100644 shared/lib/puppet/provider/download_and_unpack/action.rb create mode 100644 shared/lib/puppet/provider/gem/gem_install.rb create mode 100644 shared/lib/puppet/provider/god_init/install.rb create mode 100644 shared/lib/puppet/provider/make_and_install/action.rb create mode 100644 shared/lib/puppet/type/bash_rc.rb create mode 100644 shared/lib/puppet/type/bash_rc_d.rb create mode 100644 shared/lib/puppet/type/configure.rb create mode 100644 shared/lib/puppet/type/download_and_unpack.rb create mode 100644 shared/lib/puppet/type/gem.rb create mode 100644 shared/lib/puppet/type/god_init.rb create mode 100644 shared/lib/puppet/type/make_and_install.rb create mode 100644 shared/modules/build_and_install/manifests/init.pp create mode 100644 skel/apply.erb create mode 100644 skel/debian/bootstrap.erb create mode 100644 skel/redhat/bootstrap.erb create mode 100644 skel/rename.erb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f57018b --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in puppet-standalone-mashup.gemspec +gemspec diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2995527 --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require "bundler/gem_tasks" diff --git a/lib/puppet-standalone-mashup.rb b/lib/puppet-standalone-mashup.rb new file mode 100644 index 0000000..5c25048 --- /dev/null +++ b/lib/puppet-standalone-mashup.rb @@ -0,0 +1,9 @@ +require "puppet-standalone-mashup/version" + +module Puppet + module Standalone + module Mashup + # Your code goes here... + end + end +end diff --git a/lib/puppet-standalone-mashup/capistrano.rb b/lib/puppet-standalone-mashup/capistrano.rb new file mode 100644 index 0000000..41423b5 --- /dev/null +++ b/lib/puppet-standalone-mashup/capistrano.rb @@ -0,0 +1,108 @@ +require 'erb' + +def _cset(name, *args, &block) + unless exists?(name) + set(name, *args, &block) + end +end + +module PuppetStandaloneMashup + BASE = Pathname(File.expand_path('../../..', __FILE__)) +end + +Capistrano::Configuration.instance.load do + _cset(:puppet_dir) { '/tmp/puppet' } + _cset(:additional_puppet_bin_path) { nil } + _cset(:base_dir) { '/usr/local' } + _cset(:rename_server) { true } + _cset(:use_sudo) { true } + + @dir_made = false + + def sudo + use_sudo ? "sudo -p 'sudo password: '" : "" + end + + desc "Apply the configuration" + task :apply do + top.copy + top.copy_shared + top.copy_skel + + run "cd #{puppet_dir} && #{sudo} ./apply" + end + + desc "Bootstrap the server" + task :bootstrap do + top.copy + top.copy_shared + top.copy_skel + + if rename_server + top.rename + end + + run "cd #{puppet_dir} && #{sudo} ./bootstrap" + end + + desc "Rename the server" + task :rename do + hostname = Capistrano::CLI.ui.ask("Hostname: ") + + run "cd #{puppet_dir} && #{sudo} ./rename #{hostname}" + end + + desc "Copy puppet configs to remote server" + task :copy do + top.ensure_puppet_dir + + Dir["*"].each { |file| top.upload file, File.join(puppet_dir, file) } + end + + desc "Copy skel files to remote server" + task :copy_skel do + top.ensure_puppet_dir + + [ '*.erb', "#{distribution}/*.erb" ].each do |dir| + Dir[PuppetStandaloneMashup::BASE.join('skel').join(dir).to_s].each do |file| + data = StringIO.new(ERB.new(File.read(file)).result(binding)) + + top.upload data, target = File.join(puppet_dir, File.basename(file, '.erb')) + + run "chmod a+x #{target}" + end + end + end + + desc "Copy shared" + task :copy_shared do + top.ensure_puppet_dir + + top.upload PuppetStandaloneMashup::BASE.join('shared').to_s, File.join(puppet_dir, 'shared') + end + + desc "Ensure Puppet target dir exists" + task :ensure_puppet_dir do + if !@dir_made + run "#{sudo} rm -Rf #{puppet_dir}" + run "mkdir -p #{puppet_dir}" + + @dir_made = true + end + end + + desc "Make sudo nice" + task :make_sudo_nice do + make_nice = "~/make_nice" + + run %{echo "%sudo ALL=NOPASSWD: /bin/rm, /tmp/puppet/apply" > #{make_nice}} + run %{#{sudo} chmod 440 #{make_nice}} + run %{#{sudo} chown root:root #{make_nice}} + run %{#{sudo} mv ~/make_nice /etc/sudoers.d/} + end + + def with_additional_puppet_bin_path + additional_puppet_bin_path ? %{PATH="#{additional_puppet_bin_path}:$PATH"} : '' + end +end + diff --git a/lib/puppet-standalone-mashup/version.rb b/lib/puppet-standalone-mashup/version.rb new file mode 100644 index 0000000..f9cc56a --- /dev/null +++ b/lib/puppet-standalone-mashup/version.rb @@ -0,0 +1,7 @@ +module Puppet + module Standalone + module Mashup + VERSION = "0.0.1" + end + end +end diff --git a/puppet-standalone-mashup.gemspec b/puppet-standalone-mashup.gemspec new file mode 100644 index 0000000..eb1ff9f --- /dev/null +++ b/puppet-standalone-mashup.gemspec @@ -0,0 +1,29 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "puppet-standalone-mashup/version" + +Gem::Specification.new do |s| + s.name = "puppet-standalone-mashup" + s.version = Puppet::Standalone::Mashup::VERSION + s.authors = ["John Bintz"] + s.email = ["john@coswellproductions.com"] + s.homepage = "" + s.summary = %q{TODO: Write a gem summary} + s.description = %q{TODO: Write a gem description} + + s.rubyforge_project = "puppet-standalone-mashup" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + # specify any dependencies here; for example: + # s.add_development_dependency "rspec" + # s.add_runtime_dependency "rest-client" + + s.add_runtime_dependency 'guard' + s.add_runtime_dependency 'guard-shell' + s.add_runtime_dependency 'capistrano' + s.add_runtime_dependency 'capistrano-ext' +end diff --git a/shared/lib/puppet/modules/common_directories.rb b/shared/lib/puppet/modules/common_directories.rb new file mode 100644 index 0000000..971e2f9 --- /dev/null +++ b/shared/lib/puppet/modules/common_directories.rb @@ -0,0 +1,29 @@ +module Puppet + module Modules + module CommonDirectories + def build_path(src_path, name, version) + File.join(src_path, "#{name}-#{version}") + end + + def install_path(install_path, name, version) + File.join(install_path, "#{name}-#{version}") + end + + def symlink_path(install_path, name) + File.join(install_path, name) + end + + def bin_path(install_path, name) + File.join(install_path, name, 'bin') + end + + def sbin_path(install_path, name) + File.join(install_path, name, 'sbin') + end + end + end +end + +class Puppet::Parser::Scope + include Puppet::Modules::CommonDirectories +end diff --git a/shared/lib/puppet/parser/functions/bin_path.rb b/shared/lib/puppet/parser/functions/bin_path.rb new file mode 100644 index 0000000..8dbf493 --- /dev/null +++ b/shared/lib/puppet/parser/functions/bin_path.rb @@ -0,0 +1,9 @@ +require 'puppet/modules/common_directories' + +module Puppet::Parser::Functions + newfunction(:bin_path, :type => :rvalue) do |args| + bin_path(lookupvar('base::install_path'), *args) + end +end + + diff --git a/shared/lib/puppet/parser/functions/build_path.rb b/shared/lib/puppet/parser/functions/build_path.rb new file mode 100644 index 0000000..d1cc0aa --- /dev/null +++ b/shared/lib/puppet/parser/functions/build_path.rb @@ -0,0 +1,8 @@ +require 'puppet/modules/common_directories' + +module Puppet::Parser::Functions + newfunction(:build_path, :type => :rvalue) do |args| + build_path(lookupvar('base::src_path'), *args) + end +end + diff --git a/shared/lib/puppet/parser/functions/install_path.rb b/shared/lib/puppet/parser/functions/install_path.rb new file mode 100644 index 0000000..bb7e0fa --- /dev/null +++ b/shared/lib/puppet/parser/functions/install_path.rb @@ -0,0 +1,8 @@ +require 'puppet/modules/common_directories' + +module Puppet::Parser::Functions + newfunction(:install_path, :type => :rvalue) do |args| + install_path(lookupvar('base::install_path'), *args) + end +end + diff --git a/shared/lib/puppet/parser/functions/sbin_path.rb b/shared/lib/puppet/parser/functions/sbin_path.rb new file mode 100644 index 0000000..53e5013 --- /dev/null +++ b/shared/lib/puppet/parser/functions/sbin_path.rb @@ -0,0 +1,9 @@ +require 'puppet/modules/common_directories' + +module Puppet::Parser::Functions + newfunction(:sbin_path, :type => :rvalue) do |args| + sbin_path(lookupvar('base::install_path'), *args) + end +end + + diff --git a/shared/lib/puppet/parser/functions/symlink_path.rb b/shared/lib/puppet/parser/functions/symlink_path.rb new file mode 100644 index 0000000..d40daa8 --- /dev/null +++ b/shared/lib/puppet/parser/functions/symlink_path.rb @@ -0,0 +1,8 @@ +require 'puppet/modules/common_directories' + +module Puppet::Parser::Functions + newfunction(:symlink_path, :type => :rvalue) do |args| + symlink_path(lookupvar('base::install_path'), *args) + end +end + diff --git a/shared/lib/puppet/provider/bash_rc/install.rb b/shared/lib/puppet/provider/bash_rc/install.rb new file mode 100644 index 0000000..bf09e75 --- /dev/null +++ b/shared/lib/puppet/provider/bash_rc/install.rb @@ -0,0 +1,38 @@ +Puppet::Type.type(:bash_rc).provide(:install) do + desc "Configure /etc/bash.bashrc to also load from /etc/bash.bashrc.d/*.sh" + + def create + data.unshift %{for file in `find #{dir} -name "*.sh" -type f`; do source $file; done} + data.unshift %{# #{file} managed by puppet} + + save + + FileUtils.mkdir_p dir + end + + def destroy + data.shift + data.shift + + save + + FileUtils.rm_rf dir + end + + def exists? + data.first['puppet'] + end + + private + def data + @data ||= File.readlines(file) + end + + def save + File.open(file, 'wb') { |fh| fh.print data.collect(&:strip).join("\n") } + end + + def file ; '/etc/bash.bashrc' ; end + def dir ; '/etc/bash.bashrc.d' ; end +end + diff --git a/shared/lib/puppet/provider/bash_rc_d/install.rb b/shared/lib/puppet/provider/bash_rc_d/install.rb new file mode 100644 index 0000000..f331fc2 --- /dev/null +++ b/shared/lib/puppet/provider/bash_rc_d/install.rb @@ -0,0 +1,21 @@ +Puppet::Type.type(:bash_rc_d).provide(:install) do + desc "Configure a new directory to be added to every user's PATH" + + def create + file.open('wb') { |fh| fh.puts "export PATH=#{@resource[:path]}/#{@resource[:name]}/bin:$PATH" } + end + + def destroy + file.unlink + end + + def exists? + file.file? + end + + private + def file + Pathname("/etc/bash.bashrc.d/#{@resource[:name]}.sh") + end +end + diff --git a/shared/lib/puppet/provider/configure/action.rb b/shared/lib/puppet/provider/configure/action.rb new file mode 100644 index 0000000..16e7042 --- /dev/null +++ b/shared/lib/puppet/provider/configure/action.rb @@ -0,0 +1,25 @@ +Puppet::Type.type(:configure).provide(:action) do + desc "Configure a program to install" + + def create + system %{bash -c '#{path} cd #{@resource[:build_path]} ; make clean ; make distclean ; ./configure --prefix=#{@resource[:install_path]} #{@resource[:options]}'}.tap { |o| p o } + end + + def destroy + File.unlink config_status + end + + def exists? + File.file? config_status + end + + private + def config_status + File.join(@resource[:build_path], 'config.status') + end + + def path + @resource[:path].empty? ? '' : "export PATH=#{@resource[:path]}:$PATH ; " + end +end + diff --git a/shared/lib/puppet/provider/download_and_unpack/action.rb b/shared/lib/puppet/provider/download_and_unpack/action.rb new file mode 100644 index 0000000..9e60fdc --- /dev/null +++ b/shared/lib/puppet/provider/download_and_unpack/action.rb @@ -0,0 +1,36 @@ +Puppet::Type.type(:download_and_unpack).provide(:action) do + desc "Download an unpack a remote repository" + + def create + system %{bash -c 'cd #{@resource[:src_path]} ; (curl #{@resource[:url]} | tar #{tar_command} -)'} + end + + def destroy + FileUtils.rm_rf dir + end + + def exists? + File.directory?(dir) + end + + private + def file + File.join(@resource[:src_path], File.basename(@resource[:url])) + end + + def dir + file.gsub(%r{\.tar\.(gz|bz2)$}, '') + end + + def tar_command + case @resource[:url] + when /\.gz/ + "zxvf" + when /\.bz2/ + "jxvf" + else + raise StandardError.new("Unknown format: #{@resource[:src_path]}") + end + end +end + diff --git a/shared/lib/puppet/provider/gem/gem_install.rb b/shared/lib/puppet/provider/gem/gem_install.rb new file mode 100644 index 0000000..89e9a09 --- /dev/null +++ b/shared/lib/puppet/provider/gem/gem_install.rb @@ -0,0 +1,31 @@ +Puppet::Type.type(:gem).provide(:install) do + desc "Install a Ruby Gem" + + def create + gem_command('install --no-ri --no-rdoc') + end + + def destroy + system gem_command('uninstall -x -I') + end + + def exists? + system gem_command('list -i') + $?.exitstatus == 0 + end + + private + def version + version = '' + if @resource[:version] && !@resource[:version].empty? + version = " -v #{@resource[:version]}" + end + version + end + + def gem_command(what) + command = %{bash -c 'PATH=#{@resource[:path]} gem #{what} #{@resource[:name]} #{version}'} + %x{#{command}} + end +end + diff --git a/shared/lib/puppet/provider/god_init/install.rb b/shared/lib/puppet/provider/god_init/install.rb new file mode 100644 index 0000000..8974366 --- /dev/null +++ b/shared/lib/puppet/provider/god_init/install.rb @@ -0,0 +1,69 @@ +require 'erb' + +Puppet::Type.type(:god_init).provide(:install) do + desc "Install a God script" + + def create + File.open(file, 'wb') { |fh| fh.print(ERB.new(config).result(binding)) } + end + + def destroy + File.unlink file + end + + def exists? + File.file? file + end + + private + def file + "/etc/god.d/#{@resource[:name]}.god" + end + + def start + @resource[:start] || '' + end + + def stop + @resource[:stop] || '' + end + + def name + @resource[:name] || '' + end + + def pid_file + @resource[:pid_file] || '' + end + + def config + <<-GOD +God.watch do |w| + w.name = "<%= name %>" + w.interval = 15.seconds + + w.start = lambda { system("<%= start %>") } + w.start_grace = 15.seconds + + <% if !stop.empty? %> + w.stop = lambda { system("<%= stop %>") } + w.stop_grace = 15.seconds + <% end %> + + <% if pid_file %> + w.pid_file = "<%= pid_file %>"; + <% else %> + w.behavior(:clean_pid_file) + <% end %> + + w.start_if do |start| + start.condition(:process_running) do |c| + c.interval = 5.seconds + c.running = false + end + end +end +GOD + end +end + diff --git a/shared/lib/puppet/provider/make_and_install/action.rb b/shared/lib/puppet/provider/make_and_install/action.rb new file mode 100644 index 0000000..188a89a --- /dev/null +++ b/shared/lib/puppet/provider/make_and_install/action.rb @@ -0,0 +1,24 @@ +require 'fileutils' + +Puppet::Type.type(:make_and_install).provide(:action) do + desc "Configure a program to install" + + def create + system %{bash -c 'cd #{@resource[:build_path]} ; make && make install'} + File.symlink(@resource[:install_path], symlink_path) + end + + def destroy + FileUtils.rm_rf @resource[:install_path] + FileUtils.rm_rf symlink_path + end + + def exists? + File.directory?(@resource[:install_path]) && File.symlink?(symlink_path) + end + + private + def symlink_path + File.join(File.dirname(@resource[:install_path]), @resource[:name]) + end +end diff --git a/shared/lib/puppet/type/bash_rc.rb b/shared/lib/puppet/type/bash_rc.rb new file mode 100644 index 0000000..764856d --- /dev/null +++ b/shared/lib/puppet/type/bash_rc.rb @@ -0,0 +1,11 @@ +require 'fileutils' + +Puppet::Type.newtype(:bash_rc) do + @doc = "An /etc/bash.bashrc file configured to also load from /etc/bash.bashrc.d/*.sh" + + ensurable + + newparam(:name) do + desc "The useless name" + end +end diff --git a/shared/lib/puppet/type/bash_rc_d.rb b/shared/lib/puppet/type/bash_rc_d.rb new file mode 100644 index 0000000..05a2fb1 --- /dev/null +++ b/shared/lib/puppet/type/bash_rc_d.rb @@ -0,0 +1,14 @@ +Puppet::Type.newtype(:bash_rc_d) do + @doc = "A /etc/bash.bashrc.d/*.sh file, used to add vendored applications to the path" + + ensurable + + newparam(:name) do + desc "The name of the application to add" + end + + newparam(:path) do + desc "The base path for vendored applications" + end +end + diff --git a/shared/lib/puppet/type/configure.rb b/shared/lib/puppet/type/configure.rb new file mode 100644 index 0000000..ddd9f55 --- /dev/null +++ b/shared/lib/puppet/type/configure.rb @@ -0,0 +1,26 @@ +Puppet::Type.newtype(:configure) do + @doc = "Configuring a program to install" + + ensurable + + newparam(:name) do + desc "The name of the program" + end + + newparam(:build_path) do + desc "The location of downloaded sources" + end + + newparam(:install_path) do + desc "The location to install builds" + end + + newparam(:options) do + desc "Options to build the software" + end + + newparam(:path) do + desc "Path for executables" + end +end + diff --git a/shared/lib/puppet/type/download_and_unpack.rb b/shared/lib/puppet/type/download_and_unpack.rb new file mode 100644 index 0000000..67a2f46 --- /dev/null +++ b/shared/lib/puppet/type/download_and_unpack.rb @@ -0,0 +1,22 @@ +Puppet::Type.newtype(:download_and_unpack) do + @doc = "A downloaded file, unpacked" + + ensurable + + newparam(:name) do + desc "The name of the file" + end + + newparam(:url) do + desc "The source of the file" + end + + newparam(:src_path) do + desc "The location where the file should be downloaded" + end + + newparam(:version) do + desc "The version to install" + end +end + diff --git a/shared/lib/puppet/type/gem.rb b/shared/lib/puppet/type/gem.rb new file mode 100644 index 0000000..483f5f8 --- /dev/null +++ b/shared/lib/puppet/type/gem.rb @@ -0,0 +1,18 @@ +Puppet::Type.newtype(:gem) do + @doc = 'A Ruby Gem' + + ensurable + + newparam(:name) do + desc "The name of the gem" + end + + newparam(:version) do + desc "The version of the gem" + end + + newparam(:path) do + desc "The binary search path" + end +end + diff --git a/shared/lib/puppet/type/god_init.rb b/shared/lib/puppet/type/god_init.rb new file mode 100644 index 0000000..c82fb8d --- /dev/null +++ b/shared/lib/puppet/type/god_init.rb @@ -0,0 +1,22 @@ +Puppet::Type.newtype(:god_init) do + @doc = "A God configuration" + + ensurable + + newparam(:name) do + desc "The name of the process" + end + + newparam(:start) do + desc "The command to start the process" + end + + newparam(:stop) do + desc "The command to stop the process" + end + + newparam(:pid_file) do + desc "A pid file" + end +end + diff --git a/shared/lib/puppet/type/make_and_install.rb b/shared/lib/puppet/type/make_and_install.rb new file mode 100644 index 0000000..2445b87 --- /dev/null +++ b/shared/lib/puppet/type/make_and_install.rb @@ -0,0 +1,22 @@ +Puppet::Type.newtype(:make_and_install) do + @doc = "Make and install a program" + + ensurable + + newparam(:name) do + desc "The name of the program" + end + + newparam(:build_path) do + desc "The location of downloaded sources" + end + + newparam(:install_path) do + desc "The location to install builds" + end + + newparam(:options) do + desc "Options to build the software" + end +end + diff --git a/shared/modules/build_and_install/manifests/init.pp b/shared/modules/build_and_install/manifests/init.pp new file mode 100644 index 0000000..4380f0c --- /dev/null +++ b/shared/modules/build_and_install/manifests/init.pp @@ -0,0 +1,30 @@ +define build_and_install($version, $source, $path = '', $configure = '') { + $full_source = inline_template($source) + + $build_path = build_path($name, $version) + $install_path = install_path($name, $version) + $symlink_path = symlink_path($name) + + download_and_unpack { $name: + url => $full_source, + src_path => $base::src_path, + ensure => present + } + + configure { $name: + build_path => $build_path, + install_path => $install_path, + options => $configure, + path => $path, + require => Download_and_unpack[$name], + ensure => present + } + + make_and_install { $name: + build_path => $build_path, + install_path => $install_path, + require => Configure[$name], + ensure => present + } +} + diff --git a/skel/apply.erb b/skel/apply.erb new file mode 100644 index 0000000..50e8a29 --- /dev/null +++ b/skel/apply.erb @@ -0,0 +1,5 @@ +#!/bin/bash + +mkdir -p ~/.puppet +<%= use_sudo ? "sudo env" : "" %> RUBYLIB="${PWD}/shared/lib" <%= with_additional_puppet_bin_path %> puppet apply --confdir=$PWD --modulepath=$PWD/modules:$PWD/shared/modules --templatedir=$PWD/templates -v $@ manifests/site.pp + diff --git a/skel/debian/bootstrap.erb b/skel/debian/bootstrap.erb new file mode 100644 index 0000000..d3d2593 --- /dev/null +++ b/skel/debian/bootstrap.erb @@ -0,0 +1,16 @@ +#!/bin/bash + +if [ ! $UID -eq 0 ]; then + sudo $0 + exit +fi + +apt-get update +apt-get -y upgrade +apt-get -y dist-upgrade +apt-get install -y rubygems1.8 puppet +apt-get remove -y puppet facter +gem install puppet --no-ri --no-rdoc +./apply +shutdown -r now + diff --git a/skel/redhat/bootstrap.erb b/skel/redhat/bootstrap.erb new file mode 100644 index 0000000..ef4a114 --- /dev/null +++ b/skel/redhat/bootstrap.erb @@ -0,0 +1,33 @@ +#!/bin/bash + +base_dir=<%= base_dir %> + +if [ ! -f ${base_dir}/ruby-base/bin/ruby ]; then + echo "Installing Ruby to ${base_dir}/ruby-base..." + mkdir -p ${base_dir}/tmp + cd ${base_dir}/tmp + + RUBY=ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.9.2-p290.tar.bz2 + RUBY_FILENAME=${RUBY##*/} + RUBY_VERSION=${RUBY_FILENAME%%.tar.bz2} + curl $RUBY > $RUBY_FILENAME + rm -Rf $RUBY_VERSION + tar jxvf $RUBY_FILENAME + mv $RUBY_VERSION "$RUBY_VERSION-base" + + cd "$RUBY_VERSION-base" + + ./configure --prefix=${base_dir}/ruby-base --disable-pthread + make + make install +fi + +PATH=${base_dir}/ruby-base/bin:$PATH + +if [ ! -f ${base_dir}/ruby-base/bin/puppet ]; then + echo "Installing Puppet..." + gem install puppet +fi + +mkdir ~/.puppet +./apply diff --git a/skel/rename.erb b/skel/rename.erb new file mode 100644 index 0000000..bf9573d --- /dev/null +++ b/skel/rename.erb @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ ! $UID -eq 0 ]; then + sudo $0 $1 + exit +fi + +echo $1 > /etc/hostname +cat /etc/hosts | sed "s#^\\(127.0.0.1\\)\\(.*\\)\$#\\1 $1 \\2#g" > /etc/hosts.tmp +mv /etc/hosts.tmp /etc/hosts +hostname $1 + +echo "Server renamed to $1" +