Created
February 28, 2014 17:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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