mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-21 19:28:02 +00:00
25 lines
550 B
Ruby
Executable File
25 lines
550 B
Ruby
Executable File
#!/opt/puppetlabs/puppet/bin/ruby
|
|
require 'json'
|
|
require 'open3'
|
|
require 'puppet'
|
|
|
|
def apt_get(action)
|
|
cmd = ['apt-get', action]
|
|
cmd << '-y' if ['upgrade', 'dist-upgrade', 'autoremove'].include?(action)
|
|
stdout, stderr, status = Open3.capture3(*cmd)
|
|
raise Puppet::Error, stderr if status != 0
|
|
{ status: stdout.strip }
|
|
end
|
|
|
|
params = JSON.parse(STDIN.read)
|
|
action = params['action']
|
|
|
|
begin
|
|
result = apt_get(action)
|
|
puts result.to_json
|
|
exit 0
|
|
rescue Puppet::Error => e
|
|
puts({ status: 'failure', error: e.message }.to_json)
|
|
exit 1
|
|
end
|