Commit Graph

42 Commits

Author SHA1 Message Date
Ivan Zakharyaschev
ef66de16d5 shell.req: more idiomatic regexp for reading the shebang (use ?)
Compared with a similar regexp in Emacs sources --
http://git.altlinux.org/gears/e/emacs24.git?p=emacs24.git;a=blob;f=lisp/progmodes/sh-script.el;h=4700324d376db79e27d05e5352fff2f7e841a603;hb=HEAD#l1637
: "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)"

Conclusion: mostly identical meaning, with the exception of a more
liberal path of env in Emacs.

But ALT Sisyphus has /usr/bin/env only, so I don't see a good reason
to make the regexp more general. (If a different path is written
there, it won't work in ALT Sisyphus.)
2016-05-27 15:19:10 +03:00
Ivan Zakharyaschev
f9bf39c2aa shell.req: use the version of (ba|)sh from the shebang 2016-05-24 23:08:04 +03:00
Alexey Tourbin
9b87852e0f shell.req: avoid 'type -t' call for paths
This is to improve 'buildreq -bi' support: 'type -t' will stat
absolute paths and buildreq will make self-dependency.  Note
that in the next command PATH is nullified to avoid stat/search
for regular commands.
2011-02-09 06:31:40 +03:00
Alexey Tourbin
48c22c9ff9 shell.req: fixed English 2010-04-08 11:24:54 +04:00
Alexey Tourbin
4e9dcb1346 shell.req: removed $sh --rpm-requires test 2010-04-08 11:24:52 +04:00
Alexey Tourbin
859a56a738 shell.req: reverted extra "functions vs executable" diagnostics 2010-04-08 11:24:51 +04:00
Alexey Tourbin
6bc8c52298 shell.req: manage "has execuatable candidate" verbosity for files under RPM_BUILD_ROOT 2007-12-03 12:32:11 +03:00
Alexey Tourbin
3cb16e8f3f shell.req: set empty PATH= for 'type -t' check, to avoid filesystem lookups 2007-11-30 13:45:03 +03:00
Alexey Tourbin
6c5142c792 shell.req: removed "function" from "alias|keyword|builtin" check
It seems that our /bin/bash interpreter does not have any "built-in"
functions by default.

$ bash -c 'foo() { :; }; set' |grep ' ()'
foo ()
$ bash -c 'set' |grep ' ()'
$

Thus funcions can be user-defined only.  Generally, what was wrong
with this "function" check is that it was executed in shell.req context.
That is, since e.g. "Info" and "Fatal" are functions within shell.req,
all other dependencies on "Info" and "Fatal" were simply ignored.
This was wrong and this has now been fixed.

Another possibility to ignore current shell.req context while checking
for built-in things is to spawn "clean" shell instance:

-	case "$(type -t -- "$2")" in
+	case "$($sh -c 'type -t "$1"' "$0" "$2")" in

But this can be rather expensive at this early "cleanup" stage.
2007-11-21 14:14:54 +03:00
Alexey Tourbin
68bf0157e9 shell.req (ShellReq): still check if executable candidates are available, even in the first pass
$ cat test.sh
rsync() { command rsync -vP "$@" ; }
$ scripts/shell.req.in test.sh
shell.req.in: /home/at/git.alt/rpm/test.sh: rsync() is possibly used before its definition
shell.req.in: /home/at/git.alt/rpm/test.sh: rsync() has execuatable candidate: rsync -> rsync (skip)
$
2007-10-29 13:36:36 +03:00
Alexey Tourbin
d601c3e625 shell.req (ShellReqEND): still check if executable candidates are available
$ cat test1.sh test2.sh
mail
mail() { :; }
$ scripts/shell.req.in test1.sh test2.sh
shell.req.in: /home/at/git.alt/rpm/test1.sh: mail() is possibly defined in /home/at/git.alt/rpm/test2.sh
shell.req.in: /home/at/git.alt/rpm/test1.sh: mail() has execuatable candidate: mail -> /bin/mail (skip)
$
2007-10-09 17:00:25 +04:00
Alexey Tourbin
638b19576a shell.req: aded comment to ShellReqEND 2007-10-09 00:51:29 +04:00
Alexey Tourbin
f7e409e475 shell.req: AddReq/AddProv: factored common code 2007-10-09 00:22:42 +04:00
Alexey Tourbin
6ead9f4389 shell.req: updated /.provides.sh code 2007-10-08 02:42:27 +04:00
Alexey Tourbin
a39795104e shell.req: reworked without temporary files 2007-10-08 02:10:53 +04:00
Alexey Tourbin
d77304d084 shell.req: fixed bug: read does need final newline 2007-10-08 01:22:37 +04:00
Alexey Tourbin
45ac74978f shell.req: renamed "reqs" varible to "out" 2007-10-08 01:08:33 +04:00
Alexey Tourbin
28b996a376 shell.req: consider removing "function" from alias|builtin check 2007-10-08 01:04:26 +04:00
Alexey Tourbin
28850f17b5 shell.req: fold dups after CleanupRpmRequires 2007-10-08 00:54:23 +04:00
Alexey Tourbin
536241cbbe shell.req (CleanupRpmRequires): allow e.g. executable(\ls) and executable("ls") 2007-10-08 00:40:15 +04:00
Alexey Tourbin
66df05529b shell.req: moved alias|builtin check into CleanupRpmRequires 2007-10-08 00:39:03 +04:00
Alexey Tourbin
a90f03397c shell.req: cleanup and validate "$sh --rpm-requires" output 2007-10-07 23:07:11 +04:00
Alexey Tourbin
566bc6ace5 shell.req: added early first pass for self-requires elimination 2007-10-03 14:33:21 +04:00
Alexey Tourbin
83fa94a314 shell.req: initial attempt to implement self-requires elimination 2007-10-03 14:04:25 +04:00
Alexey Tourbin
5844214067 shell.req: find re-exec interpreter only if the script is executable 2007-09-24 02:59:25 +04:00
Alexey Tourbin
2b1c36538f find-package: implemented protection against shell metacharacters and evil paths
There are two possibilities for protection:
1) we should protect at least from very evil shell metacharacters,
like [$*], and also from [:cntrl:] (e.g. newline).
2) we can provide an exhaustive list of characters that are valid
for non-evil pathnames and commands, and issue mandatory warning
if the command or path appears to be evil.

I chose the latter approach.
Valid character range is 'A-Za-z0-9/@=.,:_+-'.

Note that (almost) all files from our base build system
are valid paths:

$ valid='A-Za-z0-9/@=.,:_+-'
$ hsh-run -- rpm -qal |grep "[^$valid]"
/usr/bin/[
/usr/share/man/man1/[.1.bz2
(contains no files)
(contains no files)
$

Later we'll see if the range of valid characters needs to be extended.
2007-09-10 13:32:26 +04:00
Alexey Tourbin
7b199c08da shell.req: use "file -bL" 2007-08-28 02:12:58 +04:00
Alexey Tourbin
806a7e6491 shell.req: reworked
Now "sh --rpm-requires" failures are always verbose:

$ ln -s /usr/lib/rpm @RPMCONFIGDIR@
$ scripts/shell.req.in /usr/lib/rpm/tcl.req
/usr/lib/rpm/tcl.req: line 32: syntax error near unexpected token `}'
/usr/lib/rpm/tcl.req: line 32: `}'
shell.req.in: /usr/lib/rpm/tcl.req is ${RPM_TCLSH:-/usr/bin/tclsh} script!
shell.req.in: /usr/lib/rpm/tcl.req: invalid pathname ${RPM_TCLSH:-/usr/bin/tclsh}
$ echo $?
0
$

$ scripts/shell.req.in /usr/bin/perldoc
/usr/bin/perldoc: line 6: syntax error near unexpected token `Pod::Perldoc-'
/usr/bin/perldoc: line 6: `exit( Pod::Perldoc->run() );'
shell.req.in: /usr/bin/perldoc: /bin/sh --rpm-requires failed
$ echo $?
1
$
2007-08-28 01:22:46 +04:00
Alexey Tourbin
60ca916d3b shell.req.in: quote grep arguments with "--"
There's a bug in "sh --rpm-requires" mode:

$ sh --rpm-requires /dev/stdin <<<'exec -a PERL /usr/bin/perl'
executable(-a)
$

Then "-a" is passed to grep as its first argument (search pattern).
2007-08-03 19:04:29 +04:00
Alexey Tourbin
b8c1488e12 shell.req: better error diagnostics 2007-03-12 15:05:57 +03:00
Alexey Tourbin
e69e87503e scripts/shell.req.in: fixed sed filter
See my previous commit.  It goes like this:

$ /usr/lib/rpm/shell.req -v /usr/bin/buildreq
shell.req: /usr/bin/buildreq: cat -> /bin/cat -> coreutils (via rpmdb)
shell.req: /usr/bin/buildreq: cmp -> /usr/bin/cmp -> diffutils (via rpmdb)
shell.req: /usr/bin/buildreq: function(Info) not found (skip)
shell.req: /usr/bin/buildreq: function(show_help) not found (skip)
shell.req: /usr/bin/buildreq: function(show_usage) not found (skip)
shell.req: /usr/bin/buildreq: rm -> /bin/rm -> coreutils (via rpmdb)
shell.req: /usr/bin/buildreq: sed -> /bin/sed -> sed (via rpmdb)
coreutils
diffutils
sed
$

I argue that this behaviour, i.e. function(Info) processing, is erroneous.
There are two reasons: 1) it is impossible to resolve function(Info) neither
via FindPackage nor via .provides.sh (the latter has just plain function names);
2) the fact that Info has been detected as function means that Info() function
is defined in the very same file, i.e. /usr/bin/buildreq.  This means that
function(Info) is self-provided dependency and thus should not be processed
at all.
2007-03-11 15:00:27 +03:00
Alexey Tourbin
6dd0803866 adapted shell.req and shell.prov
1) added scripts/shell.req.files and scripts/shell.prov.files.
scripts/shell.req.files has new patterns for '/usr/bin/env bash'
and '/bin/ash'.

2) adapted scripts/shell.req.in and scripts/shell.prov.in
by using ArgvFileAction.  Also made them work with empty RPM_BUILD_ROOT.

Note: now shell.req produces dependencies from .provides.sh even
if the latter is inside RPM_BUILD_ROOT.  The reason is that .provides.sh
and the script can reside in two different subpackages (and otherwise,
rpm will optimize out the dependency).

3) removed corresponding old code from autodeps/linux.req.in
and autodeps/linux.prov.in.
2007-03-11 15:00:23 +03:00
5416277102 Removed cvsid tags. 2006-05-14 17:05:34 +04:00
1eedbeba03 redirect test run of bash --rpm-requires to /dev/null 2005-07-01 10:46:58 +00:00
4eae428069 use /bin/bash for Bourne-Again shell scripts, and /bin/sh for all the rest 2005-06-29 18:21:40 +00:00
ebc53cf631 use functions 2003-11-09 16:47:45 +00:00
8b81f418b6 use functions 2003-11-09 16:30:18 +00:00
243abe98b9 use printf instead of echo where appropriate 2003-11-07 17:56:45 +00:00
7b8bc46bfe Implemented shell functions requires/provides autodetection 2003-04-25 16:51:52 +00:00
b8fa98159d minor code cleanups 2003-04-22 14:24:35 +00:00
f9ad206e5c updated copyright information 2003-02-01 17:48:24 +00:00
8b8d4d39aa sync with rpm4 branch: added new files 2002-03-25 20:37:46 +00:00