Skip to contentSkip to conversation

base-files: profile: Whitespace clean up

PATCH In review Peter Kjellerstedt 2 participants 6 messages Apr 5, 2017 – Apr 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 base-files: profile: Whitespace clean up

---
 meta/recipes-core/base-files/base-files/profile | 29 +++++++++++++------------
 1 file changed, 15 insertions(+), 14 deletions(-)
meta/recipes-core/base-files/base-files/profile +15 -14
index c616616cee..22dfb4f219 100644
@@ -6,28 +6,29 @@ EDITOR="vi"			# needed for packages like cron, git-commit
 test -z "$TERM" && TERM="vt100"	# Basic terminal capab. For screen etc.
 
 if [ "$HOME" = "ROOTHOME" ]; then
-   PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
+	PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
 fi
 if [ "$PS1" ]; then
-# works for bash and ash (no other shells known to be in use here)
-   PS1='\u@\h:\w\$ '
+	# works for bash and ash (no other shells known to be in use here)
+	PS1='\u@\h:\w\$ '
 fi
 
 if [ -d /etc/profile.d ]; then
-  for i in /etc/profile.d/*.sh ; do
-    if [ -f $i -a -r $i ]; then
-      . $i
-    fi
-  done
-  unset i
+	for i in /etc/profile.d/*.sh; do
+		if [ -f $i -a -r $i ]; then
+			. $i
+		fi
+	done
+	unset i
 fi
 
 if [ -x /usr/bin/resize ] && termpath="`tty`"; then
-  # Make sure we are on a serial console (i.e. the device used starts with /dev/tty),
-  # otherwise we confuse e.g. the eclipse launcher which tries do use ssh
-  case "$termpath" in
-  /dev/tty[A-z]*) resize >/dev/null
-  esac
+	# Make sure we are on a serial console (i.e. the device used starts with
+	# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which
+	# tries do use ssh
+	case "$termpath" in
+		/dev/tty[A-z]*) resize >/dev/null
+	esac
 fi
 
 export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM
Signature · 1 line
2.12.0
#1 lore raw

PATCH v2 2/3 base-files: profile: Do not assume that the tty command exists

This avoids the following error when logging in to a host that does not have the tty command:

-sh: tty: not found

---
 meta/recipes-core/base-files/base-files/profile   | 6 +++---
 meta/recipes-core/base-files/base-files_3.0.14.bb | 4 ----
 2 files changed, 3 insertions(+), 7 deletions(-)
meta/recipes-core/base-files/base-files/profile +3 -3
index 22dfb4f219..ceaf15f799 100644
@@ -22,12 +22,12 @@ if [ -d /etc/profile.d ]; then
 	unset i
 fi
 
-if [ -x /usr/bin/resize ] && termpath="`tty`"; then
+if command -v resize >/dev/null && command -v tty >/dev/null; then
 	# Make sure we are on a serial console (i.e. the device used starts with
 	# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which
 	# tries do use ssh
-	case "$termpath" in
-		/dev/tty[A-z]*) resize >/dev/null
+	case $(tty) in
+		/dev/tty[A-z]*) resize >/dev/null;;
 	esac
 fi
 
meta/recipes-core/base-files/base-files_3.0.14.bb +0 -4
index f56969c52e..ca7bf06353 100644
@@ -128,10 +128,6 @@ do_install () {
 	install -m 0644 ${WORKDIR}/host.conf ${D}${sysconfdir}/host.conf
 	install -m 0644 ${WORKDIR}/motd ${D}${sysconfdir}/motd
 
-	if [ "/usr/bin" != "${bindir}" ]; then
-		sed -i "s,/usr/bin/resize,${bindir}/resize," ${D}${sysconfdir}/profile
-	fi
-
 	ln -sf /proc/mounts ${D}${sysconfdir}/mtab
 }
 
Signature · 1 line
2.12.0
#3 lore raw

PATCH v2 3/3 base-files: profile: Simplify setting variables conditionally

In reply to Peter Kjellerstedt

It is preferred to use [ <condition> ] || ... instead of [ <negated condition> ] && ... as the latter leaves $? set to 1.

---
 meta/recipes-core/base-files/base-files/profile | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
meta/recipes-core/base-files/base-files/profile +6 -8
index ceaf15f799..a062028226 100644
@@ -3,15 +3,13 @@
 
 PATH="/usr/local/bin:/usr/bin:/bin"
 EDITOR="vi"			# needed for packages like cron, git-commit
-test -z "$TERM" && TERM="vt100"	# Basic terminal capab. For screen etc.
+[ "$TERM" ] || TERM="vt100"	# Basic terminal capab. For screen etc.
 
-if [ "$HOME" = "ROOTHOME" ]; then
-	PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
-fi
-if [ "$PS1" ]; then
-	# works for bash and ash (no other shells known to be in use here)
-	PS1='\u@\h:\w\$ '
-fi
+# Add /sbin & co to $PATH for the root user
+[ "$HOME" != "ROOTHOME" ] || PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
+
+# Set the prompt for bash and ash (no other shells known to be in use here)
+[ -z "$PS1" ] || PS1='\u@\h:\w\$ '
 
 if [ -d /etc/profile.d ]; then
 	for i in /etc/profile.d/*.sh; do
Signature · 1 line
2.12.0
#4 lore raw

Re: [PATCHv2 3/3] base-files: profile: Simplify setting variables conditionally

Quoted 2 lines · Peter Kjellerstedt

It is preferred to use [ <condition> ] || ... instead of [ <negated condition> ] && ... as the latter leaves $? set to 1.

Your patch and the description above don't match. There are changes here which aren't <negated condition> and are stylistic changes instead afaict. We're past feature freeze so whilst I'm interested in genuine bugs, I do not really want code churn which just introduces risk.

Cheers,

Richard

Quoted 41 lines

---
 meta/recipes-core/base-files/base-files/profile | 14 ++++++--------

 1 file changed, 6 insertions(+), 8 deletions(-)
meta/recipes-core/base-files/base-files/profile +0 -0
index ceaf15f799..a062028226 100644
@@ -3,15 +3,13 @@


 PATH="/usr/local/bin:/usr/bin:/bin"
 EDITOR="vi" # needed for packages like cron,
git-commit
-test -z "$TERM" && TERM="vt100" # Basic terminal capab. For
screen etc.
+[ "$TERM" ] || TERM="vt100" # Basic terminal capab. For
screen etc.

meta/recipes-core/base-files/base-files/profile +0 -5
-if [ "$HOME" = "ROOTHOME" ]; then
-	PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
-fi
-if [ "$PS1" ]; then
-	# works for bash and ash (no other shells known to be in use

here)

meta/recipes-core/base-files/base-files/profile +2 -2
-	PS1='\u@\h:\w\$ '
-fi
+# Add /sbin & co to $PATH for the root user
+[ "$HOME" != "ROOTHOME" ] ||

PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin

meta/recipes-core/base-files/base-files/profile +2 -0
+
+# Set the prompt for bash and ash (no other shells known to be in

use here)
+[ -z "$PS1" ] || PS1='\u@\h:\w\$ '

 if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
--
2.12.0

#5 lore raw

Re: [PATCHv2 3/3] base-files: profile: Simplify setting variables conditionally

Quoted 8 lines

-----Original Message-----
From: Richard Purdie [mailto:[email protected]]
Sent: den 5 april 2017 16:44
To: Peter Kjellerstedt <[email protected]>; openembedded- [email protected]
Subject: Re: [OE-core] [PATCHv2 3/3] base-files: profile: Simplify setting variables conditionally

Quoted 6 lines
Quoted 2 lines · Peter Kjellerstedt

It is preferred to use [ <condition> ] || ... instead of [ <negated condition> ] && ... as the latter leaves $? set to 1.

Your patch and the description above don't match. There are changes here which aren't <negated condition> and are stylistic changes instead

Well, the intended meaning was that whatever <condition> was used in the first example should be negated in the second one, not to mean an explicit negate operator should be used, e.g., if the first <condition> is [ -z "$VAR" ], the second one would be [ "$VAR" ], not [ ! -z "$VAR" ].

Maybe my examples are just confusing things and I should just remove them?

Quoted 2 lines

afaict. We're past feature freeze so whilst I'm interested in genuine bugs, I do not really want code churn which just introduces risk.

As long as you take the second patch (which is a genuine bug), I am fine (the first one is pure whitespace clean up, so it should be safe to take as well).

Quoted 41 lines

Cheers,

Richard

Quoted 12 lines

---
 meta/recipes-core/base-files/base-files/profile | 14 ++++++--------

 1 file changed, 6 insertions(+), 8 deletions(-)
meta/recipes-core/base-files/base-files/profile +0 -0
index ceaf15f799..a062028226 100644
@@ -3,15 +3,13 @@
 
Quoted 2 lines

 PATH="/usr/local/bin:/usr/bin:/bin"
 EDITOR="vi" # needed for packages like

cron,

Quoted 22 lines

git-commit
-test -z "$TERM" && TERM="vt100" # Basic terminal capab. For
screen etc.
+[ "$TERM" ] || TERM="vt100" # Basic terminal capab. For
screen etc.

meta/recipes-core/base-files/base-files/profile +0 -5
-if [ "$HOME" = "ROOTHOME" ]; then
-	PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
-fi
-if [ "$PS1" ]; then
-	# works for bash and ash (no other shells known to be in use

here)

meta/recipes-core/base-files/base-files/profile +2 -2
-	PS1='\u@\h:\w\$ '
-fi
+# Add /sbin & co to $PATH for the root user
+[ "$HOME" != "ROOTHOME" ] ||

PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin

meta/recipes-core/base-files/base-files/profile +2 -0
+
+# Set the prompt for bash and ash (no other shells known to be in

use here)
+[ -z "$PS1" ] || PS1='\u@\h:\w\$ '

Quoted 4 lines
Quoted 4 lines

 if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
--
2.12.0

//Peter

#2 lore raw

Re: [PATCHv2 2/3] base-files: profile: Do not assume that the tty command exists

In reply to Peter Kjellerstedt
Quoted 5 lines · Peter Kjellerstedt

This avoids the following error when logging in to a host that does not have the tty command:

-sh: tty: not found

Quoted 7 lines

com>

---
 meta/recipes-core/base-files/base-files/profile   | 6 +++--- meta/recipes-core/base-files/base-files_3.0.14.bb | 4 ----

 2 files changed, 3 insertions(+), 7 deletions(-)

So instead we now break systems which don't have "command" which turns out to be all our default busybox configuration :(.

Thanks for spotting this Nathan...

Cheers,

Richard