bash2dash conversion

Submitted by zhe.he@windriver.com on Sept. 18, 2016, 2:51 a.m. | Patch ID: 131795

Details

Message ID 1474167109-6666-1-git-send-email-zhe.he@windriver.com
State New
Headers show

Commit Message

zhe.he@windriver.com Sept. 18, 2016, 2:51 a.m.
From: "Tim K. Chan" <nirvanatk@gmail.com>

Change bash style to dash style

Signed-off-by: Tim K. Chan <nirvanatk@gmail.com>
[Adjust context]
Signed-off-by: He Zhe <zhe.he@windriver.com>
---
 meta/classes/systemd.bbclass                            |  4 ++--
 meta/classes/update-rc.d.bbclass                        |  6 +++---
 meta/classes/useradd_base.bbclass                       |  4 ++--
 meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb |  2 +-
 meta/recipes-core/glibc/glibc-package.inc               |  2 +-
 meta/recipes-devtools/guile/guile_2.0.12.bb             |  6 ++++--
 meta/recipes-devtools/rpm/rpm_5.4.16.bb                 | 13 +++++++++++--
 7 files changed, 24 insertions(+), 13 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index db7873f..7370489 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -28,7 +28,7 @@  if [ -n "$D" ]; then
     OPTS="--root=$D"
 fi
 
-if type systemctl >/dev/null 2>/dev/null; then
+if command -p systemctl >/dev/null 2>/dev/null; then
 	systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE}
 
 	if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
@@ -44,7 +44,7 @@  if [ -n "$D" ]; then
     OPTS="--root=$D"
 fi
 
-if type systemctl >/dev/null 2>/dev/null; then
+if command -p systemctl >/dev/null 2>/dev/null; then
 	if [ -z "$D" ]; then
 		systemctl stop ${SYSTEMD_SERVICE}
 	fi
diff --git a/meta/classes/update-rc.d.bbclass b/meta/classes/update-rc.d.bbclass
index 82b8024..dee80c8 100644
--- a/meta/classes/update-rc.d.bbclass
+++ b/meta/classes/update-rc.d.bbclass
@@ -15,7 +15,7 @@  updatercd_preinst() {
 if [ -z "$D" -a -f "${INIT_D_DIR}/${INITSCRIPT_NAME}" ]; then
 	${INIT_D_DIR}/${INITSCRIPT_NAME} stop
 fi
-if type update-rc.d >/dev/null 2>/dev/null; then
+if command -p update-rc.d >/dev/null 2>/dev/null; then
 	if [ -n "$D" ]; then
 		OPT="-f -r $D"
 	else
@@ -26,7 +26,7 @@  fi
 }
 
 updatercd_postinst() {
-if type update-rc.d >/dev/null 2>/dev/null; then
+if command -p update-rc.d >/dev/null 2>/dev/null; then
 	if [ -n "$D" ]; then
 		OPT="-r $D"
 	else
@@ -43,7 +43,7 @@  fi
 }
 
 updatercd_postrm() {
-if type update-rc.d >/dev/null 2>/dev/null; then
+if command -p update-rc.d >/dev/null 2>/dev/null; then
 	if [ -n "$D" ]; then
 		OPT="-f -r $D"
 	else
diff --git a/meta/classes/useradd_base.bbclass b/meta/classes/useradd_base.bbclass
index f4dc713..35d5f06 100644
--- a/meta/classes/useradd_base.bbclass
+++ b/meta/classes/useradd_base.bbclass
@@ -59,10 +59,10 @@  perform_groupmems () {
 		gshadow="no"
 		touch $rootdir${sysconfdir}/gshadow
 	fi
-	local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
+	local mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*" $rootdir/etc/group || true`"
 	if test "x$mem_exists" = "x"; then
 		eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO groupmems \$opts\" || true
-		mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*" $rootdir/etc/group || true`"
++		mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*" $rootdir/etc/group || true`"
 		if test "x$mem_exists" = "x"; then
 			bbfatal "${PN}: groupmems command did not succeed."
 		fi
diff --git a/meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb b/meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb
index 8550177..e415445 100644
--- a/meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb
+++ b/meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb
@@ -56,7 +56,7 @@  do_install () {
 
 pkg_postinst_${PN} () {
 	if [ -z "$D" ]; then
-		if command -v systemd-tmpfiles >/dev/null; then
+		if command -p systemd-tmpfiles >/dev/null; then
 			systemd-tmpfiles --create ${sysconfdir}/tmpfiles.d/resolvconf.conf
 		elif [ -e ${sysconfdir}/init.d/populate-volatile.sh ]; then
 			${sysconfdir}/init.d/populate-volatile.sh update
diff --git a/meta/recipes-core/glibc/glibc-package.inc b/meta/recipes-core/glibc/glibc-package.inc
index 6df8b9e..557f32a 100644
--- a/meta/recipes-core/glibc/glibc-package.inc
+++ b/meta/recipes-core/glibc/glibc-package.inc
@@ -206,7 +206,7 @@  glibc_package_preprocess () {
 
 pkg_postinst_nscd () {
 	if [ -z "$D" ]; then
-		if command -v systemd-tmpfiles >/dev/null; then
+		if command -p systemd-tmpfiles >/dev/null; then
 			systemd-tmpfiles --create ${sysconfdir}/tmpfiles.d/nscd.conf
 		elif [ -e ${sysconfdir}/init.d/populate-volatile.sh ]; then
 			${sysconfdir}/init.d/populate-volatile.sh update
diff --git a/meta/recipes-devtools/guile/guile_2.0.12.bb b/meta/recipes-devtools/guile/guile_2.0.12.bb
index d2fe511..3ada0f1 100644
--- a/meta/recipes-devtools/guile/guile_2.0.12.bb
+++ b/meta/recipes-devtools/guile/guile_2.0.12.bb
@@ -91,8 +91,10 @@  guile_cross_config() {
 	then
 	        # Create guile-config returning target values instead of native values
 	        install -d ${SYSROOT_DESTDIR}${STAGING_BINDIR_CROSS}
-        	echo '#!'`which ${BUILD_SYS}-guile`$' \\\n--no-auto-compile -e main -s\n!#\n(define %guile-build-info '\'\( \
-			> ${B}/guile-config.cross
+		echo -n '#!' > ${B}/guile-config.cross
+		echo -n `which x86_64-linux-guile` >> ${B}/guile-config.cross
+		printf ' \\\n--no-auto-compile -e main -s\n!#\n(define %%guile-build-info ' >> ${B}/guile-config.cross
+		echo "'(" >> ${B}/guile-config.cross
 	        sed -n -e 's:^[ \t]*{[ \t]*":  (:' \
 			-e 's:",[ \t]*": . ":' \
 			-e 's:" *}, *\\:"):' \
diff --git a/meta/recipes-devtools/rpm/rpm_5.4.16.bb b/meta/recipes-devtools/rpm/rpm_5.4.16.bb
index 84adef6..be3b942 100644
--- a/meta/recipes-devtools/rpm/rpm_5.4.16.bb
+++ b/meta/recipes-devtools/rpm/rpm_5.4.16.bb
@@ -554,13 +554,22 @@  do_install_append() {
 	install -m 0755 ${WORKDIR}/perfile_rpmdeps.sh ${D}/${libdir}/rpm/perfile_rpmdeps.sh
 
 	# Remove unpackaged files (based on list in rpm.spec)
-	rm -f ${D}/${libdir}/rpm/{Specfile.pm,cpanflute,cpanflute2,rpmdiff,rpmdiff.cgi,sql.prov,sql.req,tcl.req,trpm}
+	rm -f ${D}/${libdir}/rpm/Specfile.pm
+	rm -f ${D}/${libdir}/rpm/cpanflute
+	rm -f ${D}/${libdir}/rpm/cpanflute2
+	rm -f ${D}/${libdir}/rpm/rpmdiff
+	rm -f ${D}/${libdir}/rpm/rpmdiff.cgi
+	rm -f ${D}/${libdir}/rpm/sql.prov
+	rm -f ${D}/${libdir}/rpm/sql.req
+	rm -f ${D}/${libdir}/rpm/tcl.req
+	rm -f ${D}/${libdir}/rpm/trpm
 
 	rm -f ${D}/${mandir}/man8/rpmcache.8*
 	rm -f ${D}/${mandir}/man8/rpmgraph.8*
 	rm -f ${D}/${mandir}/*/man8/rpmcache.8*
 	rm -f ${D}/${mandir}/*/man8/rpmgraph.8*
-	rm -rf ${D}/${mandir}/{fr,ko}
+	rm -rf ${D}/${mandir}/fr
+	rm -rf ${D}/${mandir}/ko
 
 	rm -f ${D}/${includedir}/popt.h
 	rm -f ${D}/${libdir}/libpopt.*

Comments

Peter Kjellerstedt Sept. 19, 2016, 11:57 a.m.
> -----Original Message-----
> From: openembedded-core-bounces@lists.openembedded.org
> [mailto:openembedded-core-bounces@lists.openembedded.org] On Behalf Of
> zhe.he@windriver.com
> Sent: den 18 september 2016 04:52
> To: openembedded-core@lists.openembedded.org
> Subject: [OE-core] [PATCH] bash2dash conversion
                             ^^^^^^^^^
Typically this is referred to as "Remove bashisms"...

> From: "Tim K. Chan" <nirvanatk@gmail.com>
> 
> Change bash style to dash style
> 
> Signed-off-by: Tim K. Chan <nirvanatk@gmail.com>
> [Adjust context]
> Signed-off-by: He Zhe <zhe.he@windriver.com>
> ---
>  meta/classes/systemd.bbclass                            |  4 ++--
>  meta/classes/update-rc.d.bbclass                        |  6 +++---
>  meta/classes/useradd_base.bbclass                       |  4 ++--
>  meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb |  2 +-
>  meta/recipes-core/glibc/glibc-package.inc               |  2 +-
>  meta/recipes-devtools/guile/guile_2.0.12.bb             |  6 ++++--
>  meta/recipes-devtools/rpm/rpm_5.4.16.bb                 | 13 +++++++++++--
>  7 files changed, 24 insertions(+), 13 deletions(-)

[cut]

> diff --git a/meta/classes/useradd_base.bbclass
> b/meta/classes/useradd_base.bbclass
> index f4dc713..35d5f06 100644
> --- a/meta/classes/useradd_base.bbclass
> +++ b/meta/classes/useradd_base.bbclass
> @@ -59,10 +59,10 @@ perform_groupmems () {
>  		gshadow="no"
>  		touch $rootdir${sysconfdir}/gshadow
>  	fi
> -	local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*"$rootdir/etc/group || true`"
> +	local mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*"$rootdir/etc/group || true`"
>  	if test "x$mem_exists" = "x"; then
>  		eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO groupmems \$opts\" || true
> -		mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*"$rootdir/etc/group || true`"
> ++		mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*"$rootdir/etc/group || true`"
>  		if test "x$mem_exists" = "x"; then
>  			bbfatal "${PN}: groupmems command did not succeed."
>  		fi

The above change cannot be correct. Changing the expression "[^:]" 
(which means "anything but :") to "[!:]" (which means "! or :") is 
definitely not the same....

> diff --git a/meta/recipes-devtools/guile/guile_2.0.12.bb
> b/meta/recipes-devtools/guile/guile_2.0.12.bb
> index d2fe511..3ada0f1 100644
> --- a/meta/recipes-devtools/guile/guile_2.0.12.bb
> +++ b/meta/recipes-devtools/guile/guile_2.0.12.bb
> @@ -91,8 +91,10 @@ guile_cross_config() {	
>  	then
>  	        # Create guile-config returning target values instead of native values
>  	        install -d ${SYSROOT_DESTDIR}${STAGING_BINDIR_CROSS}
> -        	echo '#!'`which ${BUILD_SYS}-guile`$' \\\n--no-auto-compile -e main -s\n!#\n(define %guile-build-info '\'\( \
> -			> ${B}/guile-config.cross
> +		echo -n '#!' > ${B}/guile-config.cross
> +		echo -n `which x86_64-linux-guile` >> ${B}/guile-config.cross
> +		printf ' \\\n--no-auto-compile -e main -s\n!#\n(define %%guile-build-info ' >> ${B}/guile-config.cross
> +		echo "'(" >> ${B}/guile-config.cross
>  	        sed -n -e 's:^[ \t]*{[ \t]*":  (:' \
>  			-e 's:",[ \t]*": . ":' \
>  			-e 's:" *}, *\\:"):' \

I suggest to replace the entire guile_cross_config() function with this:

guile_cross_config() {
	# this is only for target recipe
	[ "${PN}" = "${BPN}" ] || return 0

	vars=$(sed -n -e 's:^[ \t]*{[ \t]*":  (:' \
	              -e 's:",[ \t]*": . ":' \
	              -e 's:" *}, *\\:"):' \
	              -e 's:^.*cachedir.*$::' \
	              -e '/^  (/p' \
	       < ${B}/libguile/libpath.h)

	# Create guile-config returning target values instead of native values
	install -d ${SYSROOT_DESTDIR}${bindir_crossscripts}
	cat <<EOF >${B}/guile-config.cross
#!$(which ${BUILD_SYS}-guile) \\
--no-auto-compile -e main -s
!#
(define %guile-build-info '(
$vars
))
EOF
	cat ${B}/meta/guile-config >> ${B}/guile-config.cross
	install ${B}/guile-config.cross ${SYSROOT_DESTDIR}${bindir_crossscripts}/guile-config
}

That should make it a lot simpler to see what is going on.
Please note that I have corrected the installation path as well.

//Peter
Ross Burton Sept. 19, 2016, 12:07 p.m.
On 19 September 2016 at 12:57, Peter Kjellerstedt <
peter.kjellerstedt@axis.com> wrote:

> > ++            mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,
> ]*,\)*$username\(,[!,]*\)*"$rootdir/etc/group || true`"
> >               if test "x$mem_exists" = "x"; then
> >                       bbfatal "${PN}: groupmems command did not succeed."
> >               fi
>
> The above change cannot be correct. Changing the expression "[^:]"
> (which means "anything but :") to "[!:]" (which means "! or :") is
> definitely not the same....


My prediction is that this series is generated by running checkbashism over
the fragments, it fires a false-positive here (from memory because it
thinks it is processing a bash glob or something, not grep regex).

Note that I just submitted my verify-bashism script which has a whitelist
for things - such as use of command - which whilst not in POSIX are in fact
in bash/dash/ash so for all intents and purposes will work.

Ross
zhe.he@windriver.com Sept. 22, 2016, 8:18 a.m.
On 09/19/2016 07:57 PM, Peter Kjellerstedt wrote:
>> -----Original Message-----
>> From: openembedded-core-bounces@lists.openembedded.org
>> [mailto:openembedded-core-bounces@lists.openembedded.org] On Behalf Of
>> zhe.he@windriver.com
>> Sent: den 18 september 2016 04:52
>> To: openembedded-core@lists.openembedded.org
>> Subject: [OE-core] [PATCH] bash2dash conversion
>                              ^^^^^^^^^
> Typically this is referred to as "Remove bashisms"...

Yes.

>
>> From: "Tim K. Chan" <nirvanatk@gmail.com>
>>
>> Change bash style to dash style
>>
>> Signed-off-by: Tim K. Chan <nirvanatk@gmail.com>
>> [Adjust context]
>> Signed-off-by: He Zhe <zhe.he@windriver.com>
>> ---
>>  meta/classes/systemd.bbclass                            |  4 ++--
>>  meta/classes/update-rc.d.bbclass                        |  6 +++---
>>  meta/classes/useradd_base.bbclass                       |  4 ++--
>>  meta/recipes-connectivity/resolvconf/resolvconf_1.79.bb |  2 +-
>>  meta/recipes-core/glibc/glibc-package.inc               |  2 +-
>>  meta/recipes-devtools/guile/guile_2.0.12.bb             |  6 ++++--
>>  meta/recipes-devtools/rpm/rpm_5.4.16.bb                 | 13 +++++++++++--
>>  7 files changed, 24 insertions(+), 13 deletions(-)
> [cut]
>
>> diff --git a/meta/classes/useradd_base.bbclass
>> b/meta/classes/useradd_base.bbclass
>> index f4dc713..35d5f06 100644
>> --- a/meta/classes/useradd_base.bbclass
>> +++ b/meta/classes/useradd_base.bbclass
>> @@ -59,10 +59,10 @@ perform_groupmems () {
>>  		gshadow="no"
>>  		touch $rootdir${sysconfdir}/gshadow
>>  	fi
>> -	local mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*"$rootdir/etc/group || true`"
>> +	local mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*"$rootdir/etc/group || true`"
>>  	if test "x$mem_exists" = "x"; then
>>  		eval flock -x $rootdir${sysconfdir} -c \"$PSEUDO groupmems \$opts\" || true
>> -		mem_exists="`grep "^$groupname:[^:]*:[^:]*:\([^,]*,\)*$username\(,[^,]*\)*"$rootdir/etc/group || true`"
>> ++		mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*"$rootdir/etc/group || true`"
>>  		if test "x$mem_exists" = "x"; then
>>  			bbfatal "${PN}: groupmems command did not succeed."
>>  		fi
> The above change cannot be correct. Changing the expression "[^:]" 
> (which means "anything but :") to "[!:]" (which means "! or :") is 
> definitely not the same....

Thanks for careful review. I really missed correcting thisfalse-positive report.

>> diff --git a/meta/recipes-devtools/guile/guile_2.0.12.bb
>> b/meta/recipes-devtools/guile/guile_2.0.12.bb
>> index d2fe511..3ada0f1 100644
>> --- a/meta/recipes-devtools/guile/guile_2.0.12.bb
>> +++ b/meta/recipes-devtools/guile/guile_2.0.12.bb
>> @@ -91,8 +91,10 @@ guile_cross_config() {	
>>  	then
>>  	        # Create guile-config returning target values instead of native values
>>  	        install -d ${SYSROOT_DESTDIR}${STAGING_BINDIR_CROSS}
>> -        	echo '#!'`which ${BUILD_SYS}-guile`$' \\\n--no-auto-compile -e main -s\n!#\n(define %guile-build-info '\'\( \
>> -			> ${B}/guile-config.cross
>> +		echo -n '#!' > ${B}/guile-config.cross
>> +		echo -n `which x86_64-linux-guile` >> ${B}/guile-config.cross
>> +		printf ' \\\n--no-auto-compile -e main -s\n!#\n(define %%guile-build-info ' >> ${B}/guile-config.cross
>> +		echo "'(" >> ${B}/guile-config.cross
>>  	        sed -n -e 's:^[ \t]*{[ \t]*":  (:' \
>>  			-e 's:",[ \t]*": . ":' \
>>  			-e 's:" *}, *\\:"):' \
> I suggest to replace the entire guile_cross_config() function with this:
>
> guile_cross_config() {
> 	# this is only for target recipe
> 	[ "${PN}" = "${BPN}" ] || return 0
>
> 	vars=$(sed -n -e 's:^[ \t]*{[ \t]*":  (:' \
> 	              -e 's:",[ \t]*": . ":' \
> 	              -e 's:" *}, *\\:"):' \
> 	              -e 's:^.*cachedir.*$::' \
> 	              -e '/^  (/p' \
> 	       < ${B}/libguile/libpath.h)
>
> 	# Create guile-config returning target values instead of native values
> 	install -d ${SYSROOT_DESTDIR}${bindir_crossscripts}
> 	cat <<EOF >${B}/guile-config.cross
> #!$(which ${BUILD_SYS}-guile) \\
> --no-auto-compile -e main -s
> !#
> (define %guile-build-info '(
> $vars
> ))
> EOF
> 	cat ${B}/meta/guile-config >> ${B}/guile-config.cross
> 	install ${B}/guile-config.cross ${SYSROOT_DESTDIR}${bindir_crossscripts}/guile-config
> }
>
> That should make it a lot simpler to see what is going on.
> Please note that I have corrected the installation path as well.

Definitely simpler and clearer. I'll test and send v2.

Thanks,
Zhe

> //Peter
>
>
zhe.he@windriver.com Sept. 22, 2016, 8:20 a.m.
On 09/19/2016 08:07 PM, Burton, Ross wrote:
>
> On 19 September 2016 at 12:57, Peter Kjellerstedt <peter.kjellerstedt@axis.com <mailto:peter.kjellerstedt@axis.com>>wrote:
>
>     > ++            mem_exists="`grep "^$groupname:[!:]*:[!:]*:\([!,]*,\)*$username\(,[!,]*\)*"$rootdir/etc/group || true`"
>     >               if test "x$mem_exists" = "x"; then
>     >                       bbfatal "${PN}: groupmems command did not succeed."
>     >               fi
>
>     The above change cannot be correct. Changing the expression "[^:]"
>     (which means "anything but :") to "[!:]" (which means "! or :") is
>     definitely not the same....
>
>
> My prediction is that this series is generated by running checkbashism over the fragments, it fires a false-positive here (from memory because it thinks it is processing a bash glob or something, not grep regex).
>
> Note that I just submitted my verify-bashism script which has a whitelist for things - such as use of command - which whilst not in POSIX are in fact in bash/dash/ash so for all intents and purposes will work.
>

Yes, I'm using checkbashism and have found some false-positive reports but missed this one. Thank you for pointing out.

Zhe

> Ross