Can we automate this?
Since Summer 14 release, Salesforce make the object available via API, where you can use Process Builder + Flow or Trigger to automate license assignment and license removal.
There are 2 object you need to work with:
Represents a license for an installed managed package.
This object only support record query, not create, update, and delete.
Represents a license for an installed managed package, assigned to a specific user.
This object support record create, delete, query, but not update.
I'll not go down to the detail on how to create Process Builder + Flow or Trigger code in this blog, but the idea is based on objects above, you need to get the PackageLicense Id, the create new record in UserPackageLicense, you just need to provide PackageLicenseId and UserId.
SELECT Id, NamespacePrefix, AllowedLicenses, UsedLicenses FROM PackageLicense WHERE Status = 'Active' AND AllowedLicenses > 0 ORDER BY NamespacePrefix
SELECT Id, PackageLicenseId, UserId FROM UserPackageLicense WHERE PackageLicenseId = '050o0000000DC8JAAW'