Skip to content

Commit

Permalink
Merge pull request #14 from rehanone/develop/fix-ohmyzsh-template-issue
Browse files Browse the repository at this point in the history
- Fix the issue with multiple line replacement for plugins section in…
  • Loading branch information
rehanone authored Jan 5, 2019
2 parents da7d45b + 4ac5237 commit b0ba0d1
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ohmyzsh::theme { ['root', 'user1']: } # would install 'clean' theme as default
ohmyzsh::theme { ['root', 'user1']: theme => 'robbyrussell' } # specific theme
# activate plugins for a user
ohmyzsh::plugins { 'user1': plugins => 'git github' }
ohmyzsh::plugins { 'user1': plugins => ['git', 'github'] }
```


Expand Down
38 changes: 24 additions & 14 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "puppetlabs/ubuntu-16.04-64-puppet"
config.vm.box_url = "https://atlas.hashicorp.com/puppetlabs/boxes/ubuntu-16.04-64-puppet"
config.vm.box = "bento/ubuntu-18.04"
config.vm.box_url = "https://app.vagrantup.com/bento/boxes/ubuntu-18.04"

config.vm.synced_folder ".", "/etc/puppet/modules/ohmyzsh"
config.vm.synced_folder ".", "/etc/puppetlabs/code/environments/production/modules/ohmyzsh"

config.vm.provision :shell, inline: <<-EOF
gem install rspec-puppet --no-user-install --no-ri --no-rdoc
gem install puppetlabs_spec_helper --no-user-install --no-ri --no-rdoc
apt-get update
readonly source_file="puppet6-release-bionic.deb"
readonly source_url="https://apt.puppetlabs.com/"
if [ -f ${source_file} ]; then
echo "File ${source_file} exists."
else
echo "File ${source_file} does not exist."
echo "Downloading it from ${source_url}${source_file}"
apt-get install -y wget
wget ${source_url}${source_file}
dpkg -i ${source_file}
apt-get update
apt-get install -y puppet-agent
fi
puppet module install puppetlabs/stdlib
puppet module install puppetlabs/vcsrepo
EOF

config.vm.provision :puppet do |puppet|
puppet.manifests_path = "tests"
puppet.manifest_file = "vagrant.pp"
puppet.options = "../"
puppet.options = "--verbose --debug"
end

config.vm.provision :serverspec do |spec|
spec.pattern = 'spec/*_spec.rb'
puppet.manifests_path = "examples"
puppet.manifest_file = "init.pp"
# puppet.module_path = ["."]
# puppet.options = "../"
# puppet.options = "--verbose --debug"
end
end
6 changes: 6 additions & 0 deletions examples/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class { 'ohmyzsh': }

# for a single user
ohmyzsh::install { 'vagrant': disable_auto_update => true, set_sh => true }

ohmyzsh::plugins { 'vagrant': plugins => ['git', 'github'] }
4 changes: 0 additions & 4 deletions examples/vagrant.pp

This file was deleted.

96 changes: 96 additions & 0 deletions files/zshrc.zsh-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=( git )

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#
# === Copyright
#
# Copyright 2017
# Copyright 2019
#
class ohmyzsh(
class ohmyzsh (
Stdlib::Httpsurl $source,
Stdlib::Absolutepath $home,
Stdlib::Absolutepath $zsh_shell_path,
Expand Down
33 changes: 23 additions & 10 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
#
define ohmyzsh::install(
Enum[present, latest]
$ensure = latest,
Boolean $set_sh = false,
$ensure = latest,
Boolean $set_sh = false,
Boolean $disable_auto_update = false,
Boolean $override_template = true,
) {

include ohmyzsh
Expand Down Expand Up @@ -58,14 +59,26 @@
require => Package['git'],
}

exec { "ohmyzsh::cp .zshrc ${name}":
creates => "${home}/.zshrc",
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
path => ['/bin', '/usr/bin'],
onlyif => "getent passwd ${name} | cut -d : -f 6 | xargs test -e",
user => $name,
require => Vcsrepo["${home}/.oh-my-zsh"],
before => File_Line["ohmyzsh::disable_auto_update ${name}"],
if $override_template {
file { "${home}/.zshrc":
ensure => file,
replace => 'no',
owner => $name,
group => $name,
mode => '0644',
source => "puppet:///modules/${module_name}/zshrc.zsh-template",
require => Vcsrepo["${home}/.oh-my-zsh"],
}
} else {
exec { "ohmyzsh::cp .zshrc ${name}":
creates => "${home}/.zshrc",
command => "cp ${home}/.oh-my-zsh/templates/zshrc.zsh-template ${home}/.zshrc",
path => ['/bin', '/usr/bin'],
onlyif => "getent passwd ${name} | cut -d : -f 6 | xargs test -e",
user => $name,
require => Vcsrepo["${home}/.oh-my-zsh"],
before => File_Line["ohmyzsh::disable_auto_update ${name}"],
}
}

if $set_sh {
Expand Down
30 changes: 21 additions & 9 deletions spec/defines/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
testcases = {
'user1' => {
params: {},
expect: { source: 'https://github.com/robbyrussell/oh-my-zsh.git', home: '/home/user1', sh: false },
expect: { source: 'https://github.com/robbyrussell/oh-my-zsh.git', home: '/home/user1', sh: false, override_template: true },
},
'user2' => {
params: { set_sh: true, disable_auto_update: true },
expect: { source: 'https://github.com/robbyrussell/oh-my-zsh.git', home: '/home/user2', sh: true, disable_auto_update: true },
params: { set_sh: true, disable_auto_update: true, override_template: false },
expect: { source: 'https://github.com/robbyrussell/oh-my-zsh.git', home: '/home/user2', sh: true, disable_auto_update: true, override_template: false },
},
'root' => {
params: {},
expect: { source: 'https://github.com/robbyrussell/oh-my-zsh.git', home: '/root', sh: false },
expect: { source: 'https://github.com/robbyrussell/oh-my-zsh.git', home: '/root', sh: false, override_template: true },
},
}

Expand All @@ -33,12 +33,24 @@
.with_source(values[:expect][:source])
.with_revision('master')
end
it do
is_expected.to contain_exec("ohmyzsh::cp .zshrc #{user}")
.with_creates("#{values[:expect][:home]}/.zshrc")
.with_command("cp #{values[:expect][:home]}/.oh-my-zsh/templates/zshrc.zsh-template #{values[:expect][:home]}/.zshrc")
.with_user(user)

if values[:expect][:override_template]
it do
is_expected.to contain_file("#{values[:expect][:home]}/.zshrc")
.with_ensure('file')
.with_replace('no')
.with_owner(user)
.with_mode('0644')
end
else
it do
is_expected.to contain_exec("ohmyzsh::cp .zshrc #{user}")
.with_creates("#{values[:expect][:home]}/.zshrc")
.with_command("cp #{values[:expect][:home]}/.oh-my-zsh/templates/zshrc.zsh-template #{values[:expect][:home]}/.zshrc")
.with_user(user)
end
end

if values[:expect][:sh]
it do
case facts[:osfamily]
Expand Down

0 comments on commit b0ba0d1

Please sign in to comment.