checkDialout.js 946 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. const childProcess = require("child_process");
  3. const ERROR_MESSAGES = {
  4. USER_NOT_IN_DIALOUT: "User not part of dialout group"
  5. };
  6. /**
  7. * Checks for the if the current Linux user is part of the dialout group
  8. * @param success callback if they are part of the dialout group
  9. * @param failure callback if they are not part of the dialout group
  10. */
  11. function checkDialout(success, failure) {
  12. childProcess.exec("id -Gn", (err, stdout, sterr) => {
  13. if (err) {
  14. failure(err);
  15. } else {
  16. const groups = stdout.split(" ");
  17. if (groups.indexOf("dialout") != -1) {
  18. success();
  19. } else {
  20. const dialoutMissingError = new Error(ERROR_MESSAGES.USER_NOT_IN_DIALOUT);
  21. failure(dialoutMissingError);
  22. }
  23. }
  24. });
  25. }
  26. module.exports = checkDialout;
  27. module.exports.ERROR_MESSAGES = ERROR_MESSAGES;