module DevenvBuild module Files class Provision < Base def initialize(options) super provisioning_modules = [] DevenvBuild::Provisioning.provisioning_modules.map do |k, v| provisioning_modules << v if options[k] end @provisioning_modules = provisioning_modules end def filename File.join(options[:destination_directory], File.join('provision', 'provision.sh')) end def template <<-PROVISION_EOF #!/bin/bash echo "Setting up locales..." /usr/sbin/update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 echo "Setting up APT mirrors..." `cat >/etc/apt/sources.list <<\\EOF deb mirror://mirrors.ubuntu.com/mirrors.txt xenial main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-updates main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-backports main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt xenial-security main restricted universe multiverse EOF ` USER=`tail -n 1 /etc/passwd | sed s/:.*//g` HOME="/home/$USER" export DEBIAN_FRONTEND=noninteractive apt-get -y update apt-get -y upgrade apt-get -y install build-essential curl git-core imagemagick subversion python-software-properties \\ zip unzip rlwrap openssl linux-tools-generic systemtap htop gdb tree rar unrar \\ screen vim zsh ## BEFORE ############################################################################################## #{before} ######################################################################################################## apt-get -y update ## MIDDLE ############################################################################################## #{middle} ######################################################################################################## # Setup hostname echo "Setup hostname..." echo "devenv" > /etc/hostname echo "127.0.0.1 devenv" >> /etc/hosts hostname devenv # Setup environment echo "Setup environment..." `cat >$HOME/.environment.sh <<\\EOF # Environment variables export PS1="[\\[\\033[1;34m\\]\\u\\[\\033[0m\\]@\\h:\\[\\033[1;37m\\]\\w\\[\\033[0m\\]]$ " EOF ` echo 'source ~/.environment.sh' >> $HOME/.bash_profile touch $HOME/.secret_keys.sh chown $USER:$USER $HOME/.environment.sh chown $USER:$USER $HOME/.secret_keys.sh ## AFTER ############################################################################################## #{after} ######################################################################################################## apt-get -y autoremove apt-get -y autoclean apt-get -y clean PROVISION_EOF end private def section(section_name) @provisioning_modules.map do |m| <<-MOD_EOF ## Setup for #{m.class.to_s} ####################### #{m.send(section_name)} #################################################### MOD_EOF end.join("\n") end def before section(:before) end def middle section(:middle) end def after section(:after) end end end end