From owner-freebsd-current Wed Jun 5 14:49: 0 2002 Delivered-To: freebsd-current@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 4977937B40A; Wed, 5 Jun 2002 14:48:43 -0700 (PDT) Received: from hades.hell.gr (patr530-b140.otenet.gr [212.205.244.148]) by mailsrv.otenet.gr (8.12.3/8.12.3) with ESMTP id g55Lmb7Y000151; Thu, 6 Jun 2002 00:48:38 +0300 (EEST) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.3/8.12.3) with ESMTP id g55Lmaaq022348; Thu, 6 Jun 2002 00:48:36 +0300 (EEST) (envelope-from keramida@freebsd.org) Received: (from charon@localhost) by hades.hell.gr (8.12.3/8.12.3/Submit) id g55LjC0S022295; Thu, 6 Jun 2002 00:45:13 +0300 (EEST) (envelope-from keramida@freebsd.org) Date: Thu, 6 Jun 2002 00:45:12 +0300 From: Giorgos Keramidas To: dougb@freebsd.org Cc: freebsd-current@freebsd.org, freebsd-hackers@freebsd.org Subject: Removing perl usage from mergemaster Message-ID: <20020605214512.GA16384@hades.hell.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hello dougb & all, Here's a patch that removes all trails of Perl usage from mergemaster. The parts that I want your careful scrutiny directed at are the new stat_mode() shell function, and the parts that I have touched lines removing Perl code. I have done some testing to the resulting mergemaster script, mostly by comparing the results of stat_mode() and the old Perl code (having them both run, and print their output, before mergemaster calls "exit 1"). If you find that you like the changes, then the recent mergemaster problems on CURRENT machines that have no perl port installed will go away ;) I have tried to keep the code of stat_mode() clean, despite the fact that it could possibly be written also as: # # Print in STDOUT the octal mode of a file and/or directory. # stat_mode () { echo $(( ~$(echo "obase=10; ibase=8; ${2}" | bc ) & $( echo "obase=10;ibase=8;07777" | bc ) & $( echo "obase=10; ibase=2; " \ $( ls -ld "${1}" | \ cut -c2-10 | \ sed -e '/^..[sS]/ s/^.*$/&+100000000000/' \ -e '/^.....[sS]/ s/^.*$/&+10000000000/' \ -e '/^........[tT]/ s/^.*$/&+1000000000/' | \ sed -e 's/[st]/x/g' -e 's/ST/-/g' | \ sed -e 's/[rwx]/1/g' | \ sed -e 's/[^1+]/0/g' ) \ | bc ) )) | awk '{printf "%04o\n", $0}' } The ls output parsing was inspired by an old post by Alfred Perlstein, and I have only added the proper sed-lines to convert it to a valid binary number. The rest, shell evaluations, substitutions and all is something you can safely blame me for. Until now, I have verified that this produces the same output, but it's admittedly harder to decipher than the one I have included in the diff below. It is still here, for us to use, if you all feel that it's better to avoid the use of variables in stat_mode(). Whatever you all feel better with... I think Doug's opinion as the maintainer of mergemaster is of the utmost importance here. Anyone else with a better idea for removing the dependency of mergemaster on Perl, is welcome to step up and offer us his assistance though :) Giorgos. --- patch begins --- Index: mergemaster.sh =================================================================== RCS file: /home/ncvs/src/usr.sbin/mergemaster/mergemaster.sh,v retrieving revision 1.31 diff -u -r1.31 mergemaster.sh --- mergemaster.sh 28 May 2002 07:25:44 -0000 1.31 +++ mergemaster.sh 5 Jun 2002 21:25:09 -0000 @@ -214,6 +214,28 @@ esac } +stat_mode () { + pathname="$1" + confirmed_umask="$2" + + decimal_umask=$( echo "obase=10; ibase=8; ${confirmed_umask}" | bc ) + binary_mode=$( ls -ld "${pathname}" | \ + cut -c2-10 | \ + sed -e '/^..[sS]/ s/^.*$/&+100000000000/' \ + -e '/^.....[sS]/ s/^.*$/&+10000000000/' \ + -e '/^........[tT]/ s/^.*$/&+1000000000/' | \ + sed -e 's/[st]/x/g' -e 's/ST/-/g' | \ + sed -e 's/[rwx]/1/g' | \ + sed -e 's/[^1+]/0/g' ) + decimal_mode=$( echo "obase=10; ibase=2; ${binary_mode}" | bc ) + mode_mask=$( echo "obase=10;ibase=8;07777" | bc ) + masked_mode=$(( ${mode_mask} & ${decimal_mode} )) + umasked_mode=$(( ${masked_mode} & ~${decimal_umask} )) + octal_mode=$( echo ${umasked_mode} | awk '{printf "%04o\n", $0}' ) + unset decimal_umask binary_mode decimal_mode mode_mask masked_mode umasked_mode + echo "${octal_mode}" +} + # Set the default path for the temporary root environment # TEMPROOT='/var/tmp/temproot' @@ -641,13 +663,11 @@ esac if [ -n "${DESTDIR}${INSTALL_DIR}" -a ! -d "${DESTDIR}${INSTALL_DIR}" ]; then - DIR_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ - oct("$ARGV[1]"))' "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` + DIR_MODE=`stat_mode "${TEMPROOT}/${INSTALL_DIR}" "${CONFIRMED_UMASK}"` install -d -o root -g wheel -m "${DIR_MODE}" "${DESTDIR}${INSTALL_DIR}" fi - FILE_MODE=`perl -e 'printf "%04o\n", (((stat("$ARGV[0]"))[2] & 07777) &~ \ - oct("$ARGV[1]"))' "${1}" "${CONFIRMED_UMASK}"` + FILE_MODE=`stat_mode "${1}" "${CONFIRMED_UMASK}"` if [ ! -x "${1}" ]; then case "${1#.}" in --- patch ends --- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message