+ -

Pages

Wednesday, February 25, 2015

I needed an update check, I made one

This is more about the joy of being a programmer. You can build everything you put your mind to it.

For months now I writed almost every hour 'packer -Syyuu' for new updates, I was interested in having the latest version of firefox-nightly, atom and some other packages from aur. Today just found out about the generic monitor in xfce4 and I thought that I could do that in js. 7 minutes later with comments I had this:

var exec = require('child_process').exec;

var password = 'yourpassword' // Replace 'yourpassword' with your linux root password

// Parse 'packer -Syyuu' output and check if updates
// are available
var doScan = function () {
  exec('echo "' + password + '" | sudo -S packer -Syyuu', function (err, output) {
    if (err) {
      console.log('There was an error:\n' + err);
    } else {

      var check = function (str) {
        return output.match(str);
      }

      if (check('there is nothing to do') !== null && check('local database is up to date') !== null) {
        console.log('No updates available');
      } else {
        console.log('Updates available');
      }
    }
  });
}

doScan();
That's all.
5 Tao[X]: I needed an update check, I made one This is more about the joy of being a programmer. You can build everything you put your mind to it. For months now I writed almost every h...

No comments:

Post a Comment

< >