forked from envato-archive/babushka-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrom_benhoskings.rb
148 lines (128 loc) · 4.71 KB
/
from_benhoskings.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Deps reproduced from benhosking's repository, in order to remove the
# external dependency, as well as remove anything we didn't need.
# e.g. passenger, non-ubuntu deps
dep 'nginx installed.src' do
requires 'pcre.managed', #DONE
'libssl headers.managed', #DONE
'zlib headers.managed' #DONE
merge :versions, {:nginx => '0.7.65', :nginx_upload_module => '2.0.12'}
source "http://nginx.org/download/nginx-#{var(:versions)[:nginx]}.tar.gz"
extra_source "http://www.grid.net.ru/nginx/download/nginx_upload_module-#{var(:versions)[:nginx_upload_module]}.tar.gz"
configure_args "--with-pcre", "--with-http_ssl_module",
"--add-module='../../nginx_upload_module-#{var(:versions)[:nginx_upload_module]}/nginx_upload_module-#{var(:versions)[:nginx_upload_module]}'"
setup {
prefix var(:nginx_prefix, :default => '/opt/nginx')
provides var(:nginx_prefix) / 'sbin/nginx'
}
configure { log_shell "configure", default_configure_command, :sudo => Babushka::GemHelper.should_sudo? }
build { log_shell "build", "make", :sudo => Babushka::GemHelper.should_sudo? }
install { log_shell "install", "make install", :sudo => Babushka::GemHelper.should_sudo? }
met? {
if !File.executable?(var(:nginx_prefix) / 'sbin/nginx')
unmet "nginx isn't installed"
else
installed_version = shell(var(:nginx_prefix) / 'sbin/nginx -V') { |shell| shell.stderr }.val_for('nginx version').sub('nginx/', '')
if installed_version != var(:versions)[:nginx]
unmet "an outdated version of nginx is installed (#{installed_version})"
else
met "nginx-#{installed_version} is installed"
end
end
}
end
dep 'www user and group' do #DONE
met? { grep(/^www:/, '/etc/passwd') and grep(/^www:/, '/etc/group') }
meet {
sudo "groupadd www"
sudo "useradd -g www www -s /bin/false"
}
end
dep 'webserver startup script' do
requires 'nginx installed.src', #DONE
'rcconf.managed' #DONE
met? { shell("rcconf --list").val_for('nginx') == 'on' }
meet {
render_erb 'nginx/nginx.init.d.erb', :to => '/etc/init.d/nginx', :perms => '755', :sudo => true
sudo 'update-rc.d nginx defaults'
}
end
# packages
dep 'pcre.managed' do
installs { via :apt, 'libpcre3-dev' }
provides 'pcretest'
end
dep 'libssl headers.managed' do
installs { via :apt, 'libssl-dev' }
provides []
end
dep 'zlib headers.managed' do
installs { via :apt, 'zlib1g-dev' }
provides []
end
dep('rcconf.managed') { installs { via :apt, 'rcconf' } }
dep('sshd.managed') { installs { via :apt, 'openssh-server' } }
dep 'sed.managed' do
after {
in_dir '/opt/local/bin' do
sudo "ln -s gsed sed"
end
}
end
dep 'vim.managed'
dep 'htop.managed'
dep 'jnettop.managed'
dep 'screen.managed'
dep 'nmap.managed'
dep 'tree.managed'
# system
dep 'system' do
requires 'secured ssh logins', #DONE
'lax host key checking', #DONE
'admins can sudo', #DONE
'tmp cleaning grace period', #DONE
'core software' #DONE
end
dep 'core software' do
requires 'vim.managed', #DONE
'curl.managed', #DONE
'htop.managed', #DONE
'jnettop.managed', #DONE
'screen.managed', #DONE
'nmap.managed', #DONE
'tree.managed' #DONE
end
dep 'secured ssh logins' do
requires 'sshd.managed', #DONE
'sed.managed' #DONE
met? {
# -o NumberOfPasswordPrompts=0
output = failable_shell('ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no nonexistentuser@localhost').stderr
if output.downcase['connection refused']
log_ok "sshd doesn't seem to be running."
elsif (auth_methods = output.scan(/Permission denied \((.*)\)\./).join.split(/[^a-z]+/)).empty?
log_error "sshd returned unexpected output."
else
returning auth_methods == %w[publickey] do |result|
log_verbose "sshd #{'only ' if result}accepts #{auth_methods.to_list} logins.", :as => (result ? :ok : :error)
end
end
}
meet {
change_with_sed 'PasswordAuthentication', 'yes', 'no', '/etc/ssh/sshd_config'
change_with_sed 'ChallengeResponseAuthentication', 'yes', 'no', '/etc/ssh/sshd_config'
}
after { sudo "/etc/init.d/ssh restart" }
end
dep 'lax host key checking' do #DONE
requires 'sed.managed' #DONE
met? { grep /^StrictHostKeyChecking[ \t]+no/, '/etc/ssh/ssh_config' }
meet { change_with_sed 'StrictHostKeyChecking', 'yes', 'no', '/etc/ssh/ssh_config' }
end
dep 'tmp cleaning grace period', :for => :ubuntu do
met? { !grep(/^[^#]*TMPTIME=0/, "/etc/default/rcS") }
meet { change_line "TMPTIME=0", "TMPTIME=30", "/etc/default/rcS" }
end
dep 'public key' do
met? { grep /^ssh-dss/, '~/.ssh/id_dsa.pub' }
meet { shell("ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ''").tap_log }
end