Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 23fd2a1

Browse files
Merge pull request #5 from codenamephp/dev
[RELEASE 1.0.0]
2 parents f8da502 + f16b08e commit 23fd2a1

10 files changed

Lines changed: 161 additions & 89 deletions

File tree

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ services: docker
1212

1313
env:
1414
global:
15-
- secure: "KlrhCf/nRXd4szf51jfW1U5qyTHK4L1ioDjuWwUWoXPyuRqfMdDS1xbI92UZPQzfW46odRr2TLFrA/WxvV2pzS3ByB2g85nJjYcf2sokXL+w8VKs0TGvra0njOwU6rm8ZTTp4TB4nLOlhkTXCAP2GunkVX8DXYTAVO1QX68HJI/vDyRbLXFJavytyGJeaJnxguLKLB7acgHk1mxw8LPsZya0CVgNzaVOcWsZRAwmmP3gm5myofpxKC+w8IufkXaO//HbDsgsLWQL3AwS6+SPU3RrtA47Cssz5BttfZeSSma0olw8phE8UHcNoD6z9rZnokv+p6e3vov3zjJKapPBkOQKDSYL+1d9MapHx4GJEQy6MrCNuhSLF0tQkESrmuul/YOm2qiexXgwx3NG+0VBunG5xyDprfGLXmWzHCLPKaBVMABnJwpyBbSOya3YoSzAuyeP6a7yJSazB5Vm3GW9+fCLP2c1Dd8UYwZVmlEtLBQilB6PkIgixZvypLRpKOX6BBLWYlHKzKQzxx37tYdQPB8OFbQs5nuBYW5uDqS75etWE3Gv11uFk6yk+PZnNTVJeShH4Rvw91psZnJUswpCt9BfLBjefXn6NJQpiDnmCITkthfv/np/giAYOKED1cqxTpwx8wYOo+0Le2npa8yyP02qt751xblDPUvYZWiu8Bw="
15+
- secure: "sXKZDMGoJsYZe1zgmD6IO569Q4OlSzU4icDI5it106JYfWJwghc0COXU3xKNUrOCWMHG2v8jRGjjF/45gMLJ0Op8ouZMFPo3r+q2LzNF/Y0n1bZtRuIoGaTSzZCIOYFmilJE/35a48rO1Bhz1oldYHPbn/5G/8j4XZT1awR4OT8qx0Rx9+eRPeHF/ftauJ25+zwjej24eyW2HBJeO3z7hG4c8vgu3DPo9FbN6+8gjvpWXsybrqV5Dvx1cRbKd/LqjM1wAlS8OJI9GTuUoUCt2hYGWPX0EIAwfswBX72ySmNiHSF7Bt6FIYbqyDbZpuyIxyTue9DBszlTNGi8RcHA3J0vZXxCXgUYOuh6i41+MhJ6m5w04iW9w05q6aX0vSQ/0/qQhemwJ+qBydZTt6pOv8sIGMx96wZI9oGGgKBluXxqicTvB8dOSHOxfx0KVWi8aKSnuoA0A/ejvI7k87LA4O4NT+OTvm+UIXD0hb77pOsNB9g2GLpDbuQe64Zk3Rxx/4jf4kaGKZebj430md7SggrVPMJCOq4wqdqM1HqCkADHzNavdOcToZajV4KmOXwu8bF/5pwJ66Yf3Ibs9dLFFnI8USTNlPau0aEsq+jgTSij+SB7XH8d964I8Rt9sNUQpT7mVI7dKmQI697sj1gtl5v/h7Mer+QXXv2tWo87gGg="
1616
addons:
1717
apt:
1818
sources:
@@ -25,13 +25,17 @@ install:
2525
- eval "$(chef shell-init bash)"
2626
- openssl aes-256-cbc -K $encrypted_264707aa6565_key -iv $encrypted_264707aa6565_iv -in codenamephp.pem.enc -out codenamephp.pem -d
2727
- gem install github_changelog_generator
28+
- gem install activesupport
2829

2930
script:
30-
- chef exec rake default documentation
31+
- chef exec rake default
3132

3233
deploy:
3334
- provider: script
3435
on:
3536
branch: master
3637
skip_cleanup: true
3738
script: chef exec rake release
39+
40+
after_script:
41+
- chef exec rake documentation

CHANGELOG.md

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
# Change Log
22

3-
## [v2.0.0](https://github.com/codenamephp/chef.cookbook.dev/tree/v2.0.0) (2018-08-17)
4-
[Full Changelog](https://github.com/codenamephp/chef.cookbook.dev/compare/v1.0.0...v2.0.0)
3+
## [Unreleased](https://github.com/codenamephp/chef.cookbook.bash/tree/HEAD)
54

65
**Implemented enhancements:**
76

8-
- DNSMasq: Use drop folder \(/etc/dnsmasq.d\) for config [\#12](https://github.com/codenamephp/chef.cookbook.dev/issues/12)
9-
- Remove jdk recipe [\#9](https://github.com/codenamephp/chef.cookbook.dev/issues/9)
10-
- Add gnome-terminal [\#7](https://github.com/codenamephp/chef.cookbook.dev/issues/7)
7+
- Init for all users with data dir [\#4](https://github.com/codenamephp/chef.cookbook.bash/issues/4)
8+
- Add github token to changelog generator [\#2](https://github.com/codenamephp/chef.cookbook.bash/issues/2)
119

12-
## [v1.0.0](https://github.com/codenamephp/chef.cookbook.dev/tree/v1.0.0) (2018-06-06)
13-
[Full Changelog](https://github.com/codenamephp/chef.cookbook.dev/compare/v0.2.0...v1.0.0)
10+
**Closed issues:**
1411

15-
**Merged pull requests:**
16-
17-
- Update metadata.rb [\#6](https://github.com/codenamephp/chef.cookbook.dev/pull/6) ([bastianschwarz](https://github.com/bastianschwarz))
18-
19-
## [v0.2.0](https://github.com/codenamephp/chef.cookbook.dev/tree/v0.2.0) (2018-06-05)
20-
**Implemented enhancements:**
21-
22-
- Add Visual Studio Code [\#2](https://github.com/codenamephp/chef.cookbook.dev/issues/2)
23-
- Move to new structure and travis [\#1](https://github.com/codenamephp/chef.cookbook.dev/issues/1)
24-
25-
**Merged pull requests:**
26-
27-
- Deleting Berksfile.lock since it will cause the relase to fail \(stove… [\#5](https://github.com/codenamephp/chef.cookbook.dev/pull/5) ([bastianschwarz](https://github.com/bastianschwarz))
28-
- Release 1.0.0 [\#4](https://github.com/codenamephp/chef.cookbook.dev/pull/4) ([bastianschwarz](https://github.com/bastianschwarz))
29-
- Merge master [\#3](https://github.com/codenamephp/chef.cookbook.dev/pull/3) ([bastianschwarz](https://github.com/bastianschwarz))
12+
- Lets see if auto changelog works [\#1](https://github.com/codenamephp/chef.cookbook.bash/issues/1)
3013

3114

3215

README.md

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Chef Cookbook Dev
2-
[![Build Status](https://travis-ci.org/codenamephp/chef.cookbook.dev.svg?branch=dev)](https://travis-ci.org/codenamephp/chef.cookbook.dev)
1+
# Chef Cookbook Bash
2+
[![Build Status](https://travis-ci.org/codenamephp/chef.cookbook.bash.svg?branch=dev)](https://travis-ci.org/codenamephp/chef.cookbook.bash)
33

4-
Cookbook that contains recipes for dev tools, like vscode, chrome, openjdk ...
4+
Makes sure bash is installed and handles bash configurations
55

66
## Requirements
77

@@ -15,20 +15,15 @@ Cookbook that contains recipes for dev tools, like vscode, chrome, openjdk ...
1515

1616
### Cookbook Depdendencies
1717

18-
- [resolver][resolver_url]
19-
20-
## Tools
21-
- [Google Chrome][chrome_url]
22-
- [Visual Studio Code][vscode_url]
23-
- [DNS Masq][dnsmasq_url]
24-
- [gnome-terminal][gnome-terminal_url]
18+
- [apt][apt_url]
19+
- [bashrc_manager][bashrc_manager_url]
2520

2621
## Usage
2722

2823
Add the cookbook to your Berksfile:
2924

3025
```ruby
31-
cookbook 'codenamephp_dev'
26+
cookbook 'codenamephp_bash'
3227
```
3328

3429
Add the tools cookbook to your runlist, e.g. in a role:
@@ -39,46 +34,20 @@ Add the tools cookbook to your runlist, e.g. in a role:
3934
"chef_type": "role",
4035
"json_class": "Chef::Role",
4136
"run_list": [
42-
"recipe[codenamephp_dev::chrome]"
37+
"recipe[codenamephp_bash]"
4338
]
4439
}
4540
```
46-
47-
Note that the default recipe is a No-Op, so you need to add the tools you want
48-
4941
### Attributes
5042

51-
#### resolver
52-
- `['resolver']['nameservers']` The array of ips to add to the resolver config. Defaults to `['127.0.0.1', '8.8.8.8', '8.8.4.4', '10.0.2.3']`
43+
There are currently no attributes.
44+
5345
## Recipes
5446

5547
### Default
56-
The default cookbook (as stated multiple times) is a No-Op. Pick and choose the tools you want via the recipes.
57-
58-
### Chrome
59-
Adds the google apt repository and installs [Google Chrome][chrome_url] from package.
60-
61-
### DNSMasq
62-
Purges the [Avahi Deamon][avahi_url] which is installed at least on Ubuntu and tends to occupy ports. Also the [resolver Cookbook][resolver_url]
63-
is used to add localhost, [Google DNS][google_dns_url] and `10.0.2.3` which is needed in [VirtualBox][virutalbox_url] for network operations to work.
64-
The IPs can be overridden/added to via the attributes.
65-
66-
At last, [DNSMasq][dnsmasq_url] is installed and the local domain and all subdomains is resolved to `127.0.0.1`.
67-
68-
### gnome-terminal
69-
Just installs the gnome-terminal from package.
70-
71-
### Unzip
72-
Just installs unzip from package (no gui client is installed)
7348

74-
### VSCode
75-
Adds the VSCode package repository to apt and installs [VSCode][vscode_url] from package.
49+
The default recipe initializes the bashrc.d folder using the /etc/skel and for each user with uid > 1000 (so all non-system users) that have a user directory. No special
50+
configs are added. Since all files from the folder are used, you can just add your configs as a template using your own cookbook.
7651

77-
[chrome_url]: https://www.google.de/chrome
78-
[vscode_url]: https://code.visualstudio.com/
79-
[dnsmasq_url]: https://wiki.archlinux.de/title/Dnsmasq
80-
[gnome-terminal_url]: https://en.wikipedia.org/wiki/GNOME_Terminal
81-
[resolver_url]: https://supermarket.chef.io/cookbooks/resolver
82-
[avahi_url]: https://wiki.ubuntuusers.de/Avahi/
83-
[google_dns_url]: https://developers.google.com/speed/public-dns/
84-
[virtualbox_url]: https://www.virtualbox.org/
52+
[apt_url]: https://supermarket.chef.io/cookbooks/apt
53+
[bashrc_manager_url]: https://supermarket.chef.io/cookbooks/bashrc_manager

Rakefile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require 'active_support'
2+
require 'active_support/core_ext'
3+
14
# Checks if we are inside a Continuous Integration machine.
25
#
36
# @return [Boolean] whether we are inside a CI.
@@ -16,7 +19,7 @@ def concurrency
1619
end
1720

1821
def origin_branch
19-
ENV['TRAVIS_PULL_REQUEST_BRANCH'] || ENV['TRAVIS_BRANCH'] || 'dev'
22+
ENV['TRAVIS_PULL_REQUEST_BRANCH'].presence || ENV['TRAVIS_BRANCH'].presence || 'dev'
2023
end
2124

2225
task default: %w[style unit integration]
@@ -26,12 +29,7 @@ namespace :git do
2629
task :setup do
2730
sh 'git config --local user.name "Travis CI"'
2831
sh 'git config --local user.email "[email protected]"'
29-
sh 'git remote set-url --push origin "https://' + ENV['GH_TOKEN'].to_s + '@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git"', verbose: false do |ok, status|
30-
unless ok
31-
raise "Command failed with status (#{status.exitstatus}): " \
32-
'git remote set-url --push origin "https://[GITHUB_TOKEN_HIDDEN]@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git"'
33-
end
34-
end
32+
sh 'git remote set-url --push origin "https://' + ENV['GH_TOKEN'].to_s + '@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git"', verbose: false
3533
end
3634
end
3735

@@ -126,18 +124,21 @@ task :integration, %i[regexp action concurrency] => ci? || use_dokken? ? %w[inte
126124
namespace :documentation do
127125
desc 'Generate changelog'
128126
task changelog: ['git:setup'] do
129-
sh 'git clone [email protected]:' + ENV['TRAVIS_REPO_SLUG'] + '.git --branch ' + origin_branch + ' --single-branch .tmp'
130-
sh 'cd .tmp'
131-
sh 'github_changelog_generator'
132-
sh 'git status'
133-
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + origin_branch
127+
unless File.directory?('.tmp')
128+
sh 'git clone "https://' + ENV['GH_TOKEN'].to_s + '@github.com/' + ENV['TRAVIS_REPO_SLUG'] + '.git" --branch ' + origin_branch + ' --single-branch .tmp'
129+
end
130+
Dir.chdir('.tmp') do
131+
sh "github_changelog_generator -t #{ENV['GH_TOKEN']}"
132+
sh 'git status'
133+
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + origin_branch
134+
end
134135
end
135136

136137
desc 'Generate changelog from current commit message for release'
137138
task changelog_release: ['git:setup'] do
138139
match = Regexp.new('\[RELEASE\s([\d\.]+)\]').match(ENV['TRAVIS_COMMIT_MESSAGE'])
139140
unless match.nil?
140-
sh 'github_changelog_generator --future-release ' + match[1].to_s
141+
sh "github_changelog_generator -t #{ENV['GH_TOKEN']} --future-release #{match[1]}"
141142
sh 'git status'
142143
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + ENV['TRAVIS_BRANCH']
143144
end

attributes/default.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
default['codenamephp_bash']['user'] = 'root'

metadata.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111

1212
supports 'debian', '~>9.1'
1313

14+
depends 'apt', '~> 7.0'
1415
depends 'bashrc_manager', '~> 1.0'

recipes/default.rb

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
#
2-
# Cookbook:: codenamephp_dev
2+
# Cookbook:: codenamephp_bash
33
# Recipe:: default
44
#
5-
# Copyright:: 2017, The Authors, All Rights Reserved.
5+
# Copyright:: 2018, The Authors, All Rights Reserved.
66

7+
include_recipe 'apt'
78
package 'bash'
89

9-
bashrc_manager 'dummy' do
10-
user node['codenamephp_bash']['user']
11-
content '# this file exists only to setup the bashrc drop folder'
10+
directory 'create .bashrc.d folder in /etc/skel' do
11+
path '/etc/skel/.bashrc.d'
12+
mode 0o755
13+
end
14+
15+
file 'copy default .bashrc to init in dropfolder' do
16+
path '/etc/skel/.bashrc.d/init'
17+
mode 0o755
18+
content(lazy { ::File.open('/etc/skel/.bashrc').read })
19+
action :create_if_missing
20+
end
21+
22+
template '/etc/skel/.bashrc' do
23+
source '.bashrc.erb'
24+
mode 0o755
25+
end
26+
27+
node['etc']['passwd'].each do |user, data|
28+
next unless data['uid'].to_i >= 1000 && File.directory?(data['dir'])
29+
30+
bashrc_manager "init bashrc.d for user #{user}" do
31+
user user
32+
content '# this file exists only to setup the bashrc drop folder'
33+
end
1234
end

spec/unit/recipes/default_spec.rb

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,76 @@
99
describe 'codenamephp_bash::default' do
1010
context 'When all attributes are default, on an unspecified platform' do
1111
let(:chef_run) do
12-
runner = ChefSpec::SoloRunner.new
13-
runner.converge(described_recipe)
12+
ChefSpec::SoloRunner.new do |node|
13+
node.override['etc']['passwd'] = []
14+
end.converge(described_recipe)
1415
end
1516

1617
it 'converges successfully' do
1718
expect { chef_run }.to_not raise_error
1819
end
20+
21+
it 'includes the apt cookbook' do
22+
expect(chef_run).to include_recipe('apt')
23+
end
24+
25+
it 'installs bash from package' do
26+
expect(chef_run).to install_package('bash')
27+
end
28+
29+
it 'copies the default .bashrc to init file in dropfolder' do
30+
allow(File).to receive(:open).and_call_original
31+
allow(File).to(receive(:open).with('/etc/skel/.bashrc') do
32+
double = double(File)
33+
allow(double).to receive(:read).and_return 'some content'
34+
double
35+
end)
36+
37+
expect(chef_run).to create_if_missing_file('copy default .bashrc to init in dropfolder').with(
38+
path: '/etc/skel/.bashrc.d/init',
39+
mode: 0o755,
40+
content: 'some content'
41+
)
42+
end
43+
44+
it 'updates the skel .bashrc with template content' do
45+
expect(chef_run).to create_template('/etc/skel/.bashrc').with(source: '.bashrc.erb', mode: 0o755)
46+
end
47+
end
48+
49+
context 'When users were detected' do
50+
let(:chef_run) do
51+
ChefSpec::SoloRunner.new do |node|
52+
node.override['etc']['passwd'] = {
53+
'user1' => { 'dir' => '/home/user1', 'uid' => 1000, 'gid' => 123 },
54+
'user2' => { 'dir' => '/home/user2', 'uid' => 1001, 'gid' => 456 },
55+
'user3' => { 'dir' => '/home/user3', 'uid' => 500, 'gid' => 789 },
56+
'user4' => { 'dir' => '/home/user4', 'uid' => 1002, 'gid' => 789 }
57+
}
58+
end.converge(described_recipe)
59+
end
60+
61+
before(:each) do
62+
allow(File).to receive(:directory?).with(anything).and_call_original
63+
allow(File).to receive(:directory?).with('/home/user1').and_return true
64+
allow(File).to receive(:directory?).with('/home/user2').and_return true
65+
allow(File).to receive(:directory?).with('/home/user3').and_return true
66+
allow(File).to receive(:directory?).with('/home/user4').and_return false
67+
end
68+
69+
it 'converges successfully' do
70+
expect { chef_run }.to_not raise_error
71+
end
72+
73+
it 'executes the resource for every user with a home directory' do
74+
expect(chef_run).to add_bashrc_manager('init bashrc.d for user user1').with(
75+
user: 'user1',
76+
content: '# this file exists only to setup the bashrc drop folder'
77+
)
78+
expect(chef_run).to add_bashrc_manager('init bashrc.d for user user2').with(
79+
user: 'user2',
80+
content: '# this file exists only to setup the bashrc drop folder'
81+
)
82+
end
1983
end
2084
end

templates/default/.bashrc.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Managed by Chef. Local changes will be overwritten.
2+
# To manually add resources to the bashrc, create a file in the ~/.bashrc.d folder and add your changes there.
3+
4+
for file in ~/.bashrc.d/* ; do
5+
source ${file}
6+
done

test/smoke/default/default_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,27 @@
1010
describe command('bash') do
1111
it { should exist }
1212
end
13+
14+
describe file('/etc/skel/.bashrc') do
15+
it { should exist }
16+
it { should be_file }
17+
its('content') { should match(%r{# To manually add resources to the bashrc, create a file in the \~\/\.bashrc\.d folder and add your changes there\.}) }
18+
its('mode') { should cmp '0755' }
19+
its('owner') { should eq 'root' }
20+
end
21+
22+
describe file('/etc/skel/.bashrc.d') do
23+
it { should exist }
24+
it { should be_directory }
25+
its('mode') { should cmp '0755' }
26+
its('owner') { should eq 'root' }
27+
end
28+
29+
describe file('/etc/skel/.bashrc.d/init') do
30+
it { should exist }
31+
it { should be_file }
32+
its('content') { should match(%r{# \~\/\.bashrc: executed by bash\(1\) for non-login shells\.}) }
33+
its('mode') { should cmp '0755' }
34+
its('owner') { should eq 'root' }
35+
end
1336
end

0 commit comments

Comments
 (0)