Mailinglist Archive: opensuse-packaging (130 mails)
| < Previous | Next > |
Re: [opensuse-packaging] Proposal for a shell scripting policy
- From: Guido Berhoerster <guido+opensuse.org@xxxxxxxxxxxxxxxx>
- Date: Wed, 24 Mar 2010 08:48:13 +0100
- Message-id: <20100324074813.GF7496@xxxxxxxxxxxxxxxxxx>
Here is a rpmlint check which helps finding bashisms in /bin/sh
scripts, it produces errors if dash -n fails and informational
messages if checkbashisms finds anything (since it is just an
indicators and produces false positives).
It requires dash and checkbashism to be installed (the former is
in factory the latter can be obtained at
http://git.debian.org/?p=devscripts/devscripts.git)
--
Guido Berhoerster
#############################################################################
# File : BashismsCheck.py
# Package : rpmlint
# Author : Guido Berhoerster
# Purpose : check for bashisms in /bin/sh shell scripts
#############################################################################
import re
import AbstractCheck
import Config
import Pkg
from Filter import addDetails, printInfo, printError
class BashismsCheck(AbstractCheck.AbstractFilesCheck):
RE_BIN_SH = re.compile('#!\s*(/usr)?/bin/sh(\s+|$)')
def __init__(self):
AbstractCheck.AbstractFilesCheck.__init__(self, "BashismsCheck", ".*")
def check_file(self, pkg, filename):
try:
f = open(filename)
except:
return
try:
first_line = f.read(256).split("\n")[0]
if self.RE_BIN_SH.match(first_line):
status, output = Pkg.getstatusoutput(["/bin/dash", "-n",
filename])
if status == 2:
printError(pkg, "bin-sh-syntax-error", filename)
status, output = Pkg.getstatusoutput(["/usr/bin/checkbashisms",
filename])
if status == 1:
printInfo(pkg, "potential-bashisms", filename)
finally:
f.close()
check = BashismsCheck()
if Config.info:
addDetails('bin-sh-syntax-error',
'''A /bin/sh shell script contains a syntax error.''',
'potential-bashisms',
'''checkbashisms reported potential bashisms in a /bin/sh shell
script, you might want to manually check this script for bashisms.''')
scripts, it produces errors if dash -n fails and informational
messages if checkbashisms finds anything (since it is just an
indicators and produces false positives).
It requires dash and checkbashism to be installed (the former is
in factory the latter can be obtained at
http://git.debian.org/?p=devscripts/devscripts.git)
--
Guido Berhoerster
#############################################################################
# File : BashismsCheck.py
# Package : rpmlint
# Author : Guido Berhoerster
# Purpose : check for bashisms in /bin/sh shell scripts
#############################################################################
import re
import AbstractCheck
import Config
import Pkg
from Filter import addDetails, printInfo, printError
class BashismsCheck(AbstractCheck.AbstractFilesCheck):
RE_BIN_SH = re.compile('#!\s*(/usr)?/bin/sh(\s+|$)')
def __init__(self):
AbstractCheck.AbstractFilesCheck.__init__(self, "BashismsCheck", ".*")
def check_file(self, pkg, filename):
try:
f = open(filename)
except:
return
try:
first_line = f.read(256).split("\n")[0]
if self.RE_BIN_SH.match(first_line):
status, output = Pkg.getstatusoutput(["/bin/dash", "-n",
filename])
if status == 2:
printError(pkg, "bin-sh-syntax-error", filename)
status, output = Pkg.getstatusoutput(["/usr/bin/checkbashisms",
filename])
if status == 1:
printInfo(pkg, "potential-bashisms", filename)
finally:
f.close()
check = BashismsCheck()
if Config.info:
addDetails('bin-sh-syntax-error',
'''A /bin/sh shell script contains a syntax error.''',
'potential-bashisms',
'''checkbashisms reported potential bashisms in a /bin/sh shell
script, you might want to manually check this script for bashisms.''')
| < Previous | Next > |