Skip to content

Instantly share code, notes, and snippets.

@charles-hollenbeck
Created February 28, 2014 17:10
Show Gist options
  • Save charles-hollenbeck/9275120 to your computer and use it in GitHub Desktop.
Save charles-hollenbeck/9275120 to your computer and use it in GitHub Desktop.
Gets a list of packages needed to update and pushes a notification to a pushbullet device.
require 'net/https'
require 'uri'
require 'json'
PUSHBULLET_API_URL = "https://api.pushbullet.com/api/pushes"
PUSHBULLET_API_KEY = ""
PUSHBULLET_DEVICE_ID = ""
# make root only later
IO.popen("sudo apt-get update")
packages = `sudo apt-get upgrade -s`
parsed = packages.split("\n")
$new_pkgs = Array.new
parsed.each{ |l| $new_pkgs << l.split(" ")[1] if l[0..3] == "Inst" }
uri = URI.parse(PUSHBULLET_API_URL)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
req = Net::HTTP::Post.new(uri.request_uri)
req.basic_auth PUSHBULLET_API_KEY, ""
req.set_form_data( "device_iden" => PUSHBULLET_DEVICE_ID,
"type" => "list",
"title" => "Update to packages needed",
"items" => $new_pkgs)
res = http.request(req)
if res.code == 200
puts res.body
else
# Error reporting here
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment