From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by nuthatch.gentoo.org with esmtp (Exim 4.43) id 1EFHri-0001Zf-Sa for garchives@archives.gentoo.org; Tue, 13 Sep 2005 20:58:55 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.13.4/8.13.4) with SMTP id j8DKrSUp012664; Tue, 13 Sep 2005 20:53:28 GMT Received: from smtp.gentoo.org (smtp.gentoo.org [134.68.220.30]) by robin.gentoo.org (8.13.4/8.13.4) with ESMTP id j8DKrR4c005909 for <gentoo-osx@lists.gentoo.org>; Tue, 13 Sep 2005 20:53:27 GMT Received: from dsl67-66.fastxdsl.nl ([62.251.66.67] helo=hermes.orakel.ods.org) by smtp.gentoo.org with esmtp (Exim 4.43) id 1EFHqt-0000GS-1Z for gentoo-osx@lists.gentoo.org; Tue, 13 Sep 2005 20:58:03 +0000 Received: from aphrodite.orakel.ods.org ([172.17.2.15]) by hermes.orakel.ods.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.50) id 1EFHqs-0000EJ-VG for gentoo-osx@gentoo.org; Tue, 13 Sep 2005 22:58:03 +0200 Message-ID: <43273D5D.7040308@gentoo.org> Date: Tue, 13 Sep 2005 22:58:05 +0200 From: Grobian <grobian@gentoo.org> Organization: Gentoo Foundation User-Agent: Thunderbird 1.0+ (Macintosh/20050813) Precedence: bulk List-Post: <mailto:gentoo-osx@lists.gentoo.org> List-Help: <mailto:gentoo-osx+help@gentoo.org> List-Unsubscribe: <mailto:gentoo-osx+unsubscribe@gentoo.org> List-Subscribe: <mailto:gentoo-osx+subscribe@gentoo.org> List-Id: Gentoo Linux mail <gentoo-osx.gentoo.org> X-BeenThere: gentoo-osx@gentoo.org Reply-to: gentoo-osx@lists.gentoo.org MIME-Version: 1.0 To: gentoo-osx@lists.gentoo.org Subject: [gentoo-osx] SheBang script Content-Type: multipart/mixed; boundary="------------050401040304080606060906" X-Content-Scanned: by hermes.orakel.ods.org (Exim Exiscan) using SpamAssassin and ClamAV X-Archives-Salt: 31ea81c2-8113-4d37-be9a-fc937c49080d X-Archives-Hash: c97ee217d5ff14e577bb92d8205a4fe0 This is a multi-part message in MIME format. --------------050401040304080606060906 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Ok, I didn't really know where to put it, but I wanted to share my efforts with some people in an early phase. This is the result of half an hour script-fu hacking. I think it might be useful with regard to the upcoming portage. See introductionary comment in the attach to get an idea what it does. It currently only generates diff -u output, but it's quite easy to "| patch" it, and much safer for now to see what is happening, and if that is desired ;) -- Fabian Groffen Gentoo for Mac OS X --------------050401040304080606060906 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="shebang" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="shebang" #!/usr/bin/env sh # SheBang(tm) - a Gentoo script to rape files in a given directory for # the purpose of supporting a variable 'prefix'. # # Fabian Groffen <grobian at gentoo (dot] org> # 0.1 - initial mockup (20050913) # # This script searches for executable script files in the given # directory and all its sub-directories and tries to process them in # such a way, that the actual PATH environment controls how they are # executed. An example would be a script file having at the first line: # #!/usr/bin/perl # this will be changed into: # #!/usr/bin/env perl # where the actual location of 'perl' is resolved at runtime by 'env' # using the current PATH environment. The location of 'env' can be set # using the variable ENV_PATH below. # path to the env executable ENV_PATH="/usr/bin/env" if [ -z $1 ]; then echo "$0 needs an argument: the directory to process" > /dev/stderr exit 1; fi # make a list with candidate files... well actually find 'em all and let # file(1) tell us if it is text somehow. Let awk do some magic to read # the file and see if the first line starts with "#!". CANDS=`find $1 -type f -exec file '{}' \; | grep text | cut -d: -f1 | \ awk ' { file = $1 getline < file if ($0 ~ /^#!/) print file close(file) } '` # we basically have only candidate files in our hands now, so we should # continue with the script-fu to see if we can do something with the # "#!/some/where/file" thing... for cand in $CANDS; do # first get the first line of the file without the #! line=`head -n1 $cand | cut -c3-` # then see if we know this executable thing command=`echo $line | cut -d' ' -f 1` name=`basename $command` case "$name" in sh) fine=1; ;; bash) fine=1; ;; perl) fine=1; ;; awk) fine=1; ;; *) # we don't know these, and maybe we shouldn't touch them fine=0; ;; esac if [ $fine -eq 1 ]; then # we know these, and they are fine awk -v name="$name" \ -v file="$cand" \ -v envpath="$ENV_PATH" \ -v command="$command" ' BEGIN { for (i = 1; (getline line < file) > 0; i++) { if (i == 1) { out = "#!" envpath " " name out = out substr($0, length(command) + 2 + 1) print out } else { print line } } close(file) } ' | diff -u $cand - fi done --------------050401040304080606060906-- -- gentoo-osx@gentoo.org mailing list