in chef/cookbooks/cpe_gorilla/resources/cpe_gorilla_configure.rb [33:135]
def install
return unless node['cpe_gorilla']['install']
gorilla_prefs = node['cpe_gorilla']['preferences'].compact
local_manifest = node['cpe_gorilla']['local_manifest'].compact
if gorilla_prefs.empty? || gorilla_prefs.nil?
Chef::Log.warn('config is not populated, skipping configuration')
return
end
directory node['cpe_gorilla']['dir'] do
rights :read, 'S-1-1-0'
rights :full_control, 'S-1-5-32-544'
action :create
end
local_manifest_path = ::File.join(node['cpe_gorilla']['dir'], 'chef_manifest.yaml')
file local_manifest_path do
rights :read, 'S-1-1-0'
rights :full_control, 'S-1-5-32-544'
content YAML.dump(JSON.parse(local_manifest.to_json))
end
config_yaml = ::File.join(node['cpe_gorilla']['dir'], 'config.yaml')
file config_yaml do
rights :read, 'S-1-1-0'
rights :full_control, 'S-1-5-32-544'
content YAML.dump(JSON.parse(gorilla_prefs.to_json))
end
exe_info = node['cpe_gorilla']['exe'].compact
if exe_info.empty? || exe_info.nil?
Chef::Log.warn('gorilla package is not populated, skipping install')
return
end
bin_dir = ::File.join(node['cpe_gorilla']['dir'], 'bin')
directory bin_dir do
rights :read, 'S-1-1-0'
rights :full_control, 'S-1-5-32-544'
action :create
end
gorilla_ps1 = ::File.join(bin_dir, 'gorilla_task_splay.ps1')
template 'gorilla scheduled task ps1' do
path gorilla_ps1
source 'gorilla_task_splay.erb'
end
gorilla_exe = ::File.join(bin_dir, 'gorilla.exe')
cpe_remote_file node['cpe_gorilla']['exe']['name'] do
file_name "#{node['cpe_gorilla']['exe']['name']}-"\
"#{node['cpe_gorilla']['exe']['version']}.exe"
checksum node['cpe_gorilla']['exe']['checksum']
path gorilla_exe
end
runline = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ' \
"-NoProfile -ExecutionPolicy Bypass \"#{gorilla_ps1}\""
powershell_script 'Unblock Gorilla PS1' do
code <<-PSSCRIPT
Unblock-File
PSSCRIPT
only_if { node.file_blocked?(gorilla_ps1) }
end
windows_task node['cpe_gorilla']['exe']['name'] do
command runline
frequency :minute
frequency_modifier node['cpe_gorilla']['task']['minutes_per_run']
run_level :highest
only_if { node['cpe_gorilla']['task']['create_task'] }
action [:create, :enable]
end
windows_task "#{node['cpe_gorilla']['exe']['name']}-onlogon" do
command gorilla_exe
frequency :on_logon
run_level :highest
only_if { node['cpe_gorilla']['task']['create_task'] }
end
windows_path bin_dir do
action :add
end
end