2
1

lib_sysv.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import os
  2. import re
  3. from checkpackagelib.base import _CheckFunction
  4. from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
  5. from checkpackagelib.lib import EmptyLastLine # noqa: F401
  6. from checkpackagelib.lib import NewlineAtEof # noqa: F401
  7. from checkpackagelib.lib import TrailingSpace # noqa: F401
  8. import checkpackagelib.tool
  9. from checkpackagelib.tool import Shellcheck # noqa: F401
  10. class Indent(_CheckFunction):
  11. INDENTED_WITH_SPACES = re.compile(r"^[\t]* ")
  12. def check_line(self, lineno, text):
  13. if self.INDENTED_WITH_SPACES.search(text.rstrip()):
  14. return ["{}:{}: should be indented with tabs ({}#adding-packages-start-script)"
  15. .format(self.filename, lineno, self.url_to_manual),
  16. text]
  17. class NotExecutable(checkpackagelib.tool.NotExecutable):
  18. def hint(self):
  19. return ", just make sure you use '$(INSTALL) -D -m 0755' in the .mk file"
  20. class Variables(_CheckFunction):
  21. DAEMON_VAR = re.compile(r"^DAEMON=[\"']{0,1}([^\"']*)[\"']{0,1}")
  22. PIDFILE_PATTERN = re.compile(r"/var/run/(\$DAEMON|\$\{DAEMON\}).pid")
  23. PIDFILE_VAR = re.compile(r"^PIDFILE=[\"']{0,1}([^\"']*)[\"']{0,1}")
  24. def before(self):
  25. self.name = None
  26. def check_line(self, lineno, text):
  27. name_found = self.DAEMON_VAR.search(text.rstrip())
  28. if name_found:
  29. if self.name:
  30. return ["{}:{}: DAEMON variable redefined ({}#adding-packages-start-script)"
  31. .format(self.filename, lineno, self.url_to_manual),
  32. text]
  33. self.name = name_found.group(1)
  34. if '/' in self.name:
  35. self.name = os.path.basename(self.name) # to be used in after() to check the expected filename
  36. return ["{}:{}: Do not include path in DAEMON ({}#adding-packages-start-script)"
  37. .format(self.filename, lineno, self.url_to_manual),
  38. text,
  39. 'DAEMON="{}"'.format(self.name)]
  40. return
  41. pidfile_found = self.PIDFILE_VAR.search(text.rstrip())
  42. if pidfile_found:
  43. pidfile = pidfile_found.group(1)
  44. if not self.PIDFILE_PATTERN.match(pidfile):
  45. return ["{}:{}: Incorrect PIDFILE value ({}#adding-packages-start-script)"
  46. .format(self.filename, lineno, self.url_to_manual),
  47. text,
  48. 'PIDFILE="/var/run/$DAEMON.pid"']
  49. def after(self):
  50. if self.name is None:
  51. return ["{}:0: DAEMON variable not defined ({}#adding-packages-start-script)"
  52. .format(self.filename, self.url_to_manual)]
  53. expected_filename = re.compile(r"S\d\d{}$".format(self.name))
  54. if not expected_filename.match(os.path.basename(self.filename)):
  55. return ["{}:0: filename should be S<number><number><daemon name> ({}#adding-packages-start-script)"
  56. .format(self.filename, self.url_to_manual),
  57. "expecting S<number><number>{}".format(self.name)]