2000-07-05 22:42:16 +08:00
|
|
|
#############################################################################
|
|
|
|
# Project : Linux-Mandrake
|
|
|
|
# Module : rpmlint
|
|
|
|
# File : PostCheck.py
|
|
|
|
# Version : $Id$
|
|
|
|
# Author : Frederic Lepied
|
|
|
|
# Created On : Wed Jul 5 13:30:17 2000
|
|
|
|
# Purpose : Check post/pre scripts
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
from Filter import *
|
|
|
|
import AbstractCheck
|
|
|
|
import rpm
|
|
|
|
import re
|
2000-08-01 03:45:17 +08:00
|
|
|
import os
|
|
|
|
import commands
|
|
|
|
|
|
|
|
extract_dir=Config.getOption('ExtractDir', '/tmp')
|
|
|
|
|
|
|
|
def incorrect_shell_script(shellscript):
|
|
|
|
tmpfile = "%s/.bash-script.%d" % (extract_dir, os.getpid())
|
|
|
|
if not shellscript:
|
|
|
|
return 0
|
|
|
|
file=open(tmpfile, 'w')
|
|
|
|
file.write(shellscript)
|
|
|
|
file.close()
|
|
|
|
ret=commands.getstatusoutput("/bin/bash -n %s" % tmpfile)
|
|
|
|
os.remove(tmpfile)
|
|
|
|
return ret[0]
|
2000-07-05 22:42:16 +08:00
|
|
|
|
|
|
|
class PostCheck(AbstractCheck.AbstractCheck):
|
|
|
|
braces_regex=re.compile("[^#]*%{")
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
AbstractCheck.AbstractCheck.__init__(self, "PostCheck")
|
|
|
|
|
|
|
|
def check(self, pkg, verbose):
|
|
|
|
# Check only binary package
|
|
|
|
if pkg.isSource():
|
|
|
|
return
|
|
|
|
|
2000-08-01 03:45:17 +08:00
|
|
|
for tag in ((rpm.RPMTAG_PREIN, rpm.RPMTAG_PREINPROG, "%pre"),
|
|
|
|
(rpm.RPMTAG_POSTIN, rpm.RPMTAG_POSTINPROG, "%post"),
|
|
|
|
(rpm.RPMTAG_PREUN, rpm.RPMTAG_PREUNPROG, "%preun"),
|
|
|
|
(rpm.RPMTAG_POSTUN, rpm.RPMTAG_POSTUNPROG, "%postun")):
|
2000-07-05 22:42:16 +08:00
|
|
|
script = pkg[tag[0]]
|
2000-08-01 03:45:17 +08:00
|
|
|
prog = pkg[tag[1]]
|
|
|
|
if script:
|
|
|
|
if PostCheck.braces_regex.search(script):
|
|
|
|
printError(pkg, "braces-in-" + tag[2])
|
|
|
|
if prog == "/bin/sh" or prog == "/bin/bash":
|
|
|
|
if incorrect_shell_script(script):
|
|
|
|
printError(pkg, "shell-syntax-error-in-" + tag[2])
|
2000-07-05 22:42:16 +08:00
|
|
|
|
|
|
|
# Create an object to enable the auto registration of the test
|
|
|
|
check=PostCheck()
|
|
|
|
|
|
|
|
# PostCheck.py ends here
|