2
1

lib_sysv.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 ignore(self):
  19. return 'etc/init.d/' in self.filename
  20. def hint(self):
  21. return ", just make sure you use '$(INSTALL) -D -m 0755' in the .mk file"
  22. class Variables(_CheckFunction):
  23. DAEMON_VAR = re.compile(r"^DAEMON=[\"']{0,1}([^\"']*)[\"']{0,1}")
  24. PIDFILE_PATTERN = re.compile(r"/var/run/(\$DAEMON|\$\{DAEMON\}).pid")
  25. PIDFILE_VAR = re.compile(r"^PIDFILE=[\"']{0,1}([^\"']*)[\"']{0,1}")
  26. def before(self):
  27. self.name = None
  28. def check_line(self, lineno, text):
  29. name_found = self.DAEMON_VAR.search(text.rstrip())
  30. if name_found:
  31. if self.name:
  32. return ["{}:{}: DAEMON variable redefined ({}#adding-packages-start-script)"
  33. .format(self.filename, lineno, self.url_to_manual),
  34. text]
  35. self.name = name_found.group(1)
  36. if '/' in self.name:
  37. self.name = os.path.basename(self.name) # to be used in after() to check the expected filename
  38. return ["{}:{}: Do not include path in DAEMON ({}#adding-packages-start-script)"
  39. .format(self.filename, lineno, self.url_to_manual),
  40. text,
  41. 'DAEMON="{}"'.format(self.name)]
  42. return
  43. pidfile_found = self.PIDFILE_VAR.search(text.rstrip())
  44. if pidfile_found:
  45. pidfile = pidfile_found.group(1)
  46. if not self.PIDFILE_PATTERN.match(pidfile):
  47. return ["{}:{}: Incorrect PIDFILE value ({}#adding-packages-start-script)"
  48. .format(self.filename, lineno, self.url_to_manual),
  49. text,
  50. 'PIDFILE="/var/run/$DAEMON.pid"']
  51. def after(self):
  52. if self.name is None:
  53. return ["{}:0: DAEMON variable not defined ({}#adding-packages-start-script)"
  54. .format(self.filename, self.url_to_manual)]
  55. expected_filename = re.compile(r"S\d\d{}$".format(self.name))
  56. if not expected_filename.match(os.path.basename(self.filename)):
  57. return ["{}:0: filename should be S<number><number><daemon name> ({}#adding-packages-start-script)"
  58. .format(self.filename, self.url_to_manual),
  59. "expecting S<number><number>{}".format(self.name)]