HackThis/hackthis.co.uk — pull request #163 by alexeypetrenko (2014-10-29 11:26:40+00:00)
Title: Fix isPackageInstalled false positives

Current implementation of `isPackageInstalled` returns `0` for all packages regardless of their state (installed or not).

Here is the `apt-cache policy` command output for cases when package is **installed** and **not installed**

**Installed:**
```
$ apt-cache policy apache2
apache2:
Installed: 2.4.7-1ubuntu4.1
Candidate: 2.4.7-1ubuntu4.1
Version table:
*** 2.4.7-1ubuntu4.1 0
500 http://fi.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
100 /var/lib/dpkg/status
2.4.7-1ubuntu4 0
500 http://fi.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
```

**Not installed:**
```
$ apt-cache policy apache2
apache2:
Installed: (none)
Candidate: 2.4.7-1ubuntu4.1
Version table:
2.4.7-1ubuntu4.1 0
500 http://fi.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
2.4.7-1ubuntu4 0
500 http://fi.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
```

As one can see text `Installed` is presented in both outputs. So, `apt-cache policy $1 | grep Installed` exit code would be the same for both cases.

As a fix for this problem I suggest to remove all lines matching `none` before looking for `Installed`.