forked from openSUSE/rpmlint-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BashismsCheck.py
46 lines (35 loc) · 1.54 KB
/
BashismsCheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#############################################################################
# File : BashismsCheck.py
# Purpose : check /bin/sh shell scripts for bashisms
#############################################################################
import stat
import AbstractCheck
import Pkg
from Filter import printWarning, printInfo, addDetails
class BashismsCheck(AbstractCheck.AbstractFilesCheck):
def __init__(self):
AbstractCheck.AbstractFilesCheck.__init__(self, "BashismsCheck", ".*")
def check_file(self, pkg, filename):
pkgfile = pkg.files()[filename]
if not (stat.S_ISREG(pkgfile.mode) and
pkgfile.magic.startswith('POSIX shell script')):
return
try:
status, output = Pkg.getstatusoutput(["dash", "-n", filename])
if status == 2:
printWarning(pkg, "bin-sh-syntax-error", filename)
status, output = Pkg.getstatusoutput(
["checkbashisms", filename])
if status == 1:
printInfo(pkg, "potential-bashisms", filename)
except (FileNotFoundError, UnicodeDecodeError):
pass
check = BashismsCheck()
addDetails(
'bin-sh-syntax-error',
'''A /bin/sh shell script contains a POSIX shell syntax error.
This might indicate a potential bash-specific feature being used,
try dash -n <file> for more detailed error message.''',
'potential-bashisms',
'''checkbashisms reported potential bashisms in a /bin/sh shell
script, you might want to manually check this script for bashisms.''')