cloud-init profile.d files use bash-specific builtin "local"

Bug #1784713 reported by Merlie Allen
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Low
Scott Moser
cloud-init (Ubuntu)
Fix Released
Low
Unassigned

Bug Description

/etc/profile, which is read by the Bourne-like shells (including ksh),
runs the scripts in /etc/profile.d. The scripts from the cloud-init
package Z99-cloudinit-warnings.sh and Z99-cloud-locale-test.sh
use the bash-builtin "local" which is not recognized by ksh resulting
in these errors at login:

/etc/profile[23]: .[141]: local: not found [No such file or directory]
/etc/profile[23]: .[142]: local: not found [No such file or directory]
/etc/profile[23]: .[143]: local: not found [No such file or directory]
/etc/profile[23]: .[178]: local: not found [No such file or directory]
/etc/profile[23]: .[179]: local: not found [No such file or directory]

$ grep -n local\ Z99*
Z99-cloudinit-warnings.sh:7: local warning="" idir="/var/lib/cloud/instance" n=0
Z99-cloudinit-warnings.sh:8: local warndir="$idir/warnings"
Z99-cloudinit-warnings.sh:9: local ufile="$HOME/.cloud-warnings.skip" sfile="$warndir/.skip"
Z99-cloud-locale-test.sh:14: local bad_names="" bad_lcs="" key="" val="" var="" vars="" bad_kv=""
Z99-cloud-locale-test.sh:15: local w1 w2 w3 w4 remain
Z99-cloud-locale-test.sh:56: local bad invalid="" to_gen="" sfile="/usr/share/i18n/SUPPORTED"
Z99-cloud-locale-test.sh:57: local pkgs=""
Z99-cloud-locale-test.sh:70: local pkgs=""

ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: cloud-init 18.2-27-g6ef92c98-0ubuntu1~18.04.1
ProcVersionSignature: Ubuntu 4.15.0-29.31-generic 4.15.18
Uname: Linux 4.15.0-29-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.2
Architecture: amd64
CloudName: Other
Date: Tue Jul 31 20:04:30 2018
PackageArchitecture: all
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/ksh
SourcePackage: cloud-init
UpgradeStatus: No upgrade log present (probably fresh install)

Related branches

Revision history for this message
Merlie Allen (merlieallen) wrote :
description: updated
Scott Moser (smoser)
Changed in cloud-init (Ubuntu):
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Scott Moser (smoser) wrote :

Can you test if this works?

http://paste.ubuntu.com/p/wyPPhjRRzP/

Revision history for this message
Scott Moser (smoser) wrote :

@Merlie,
could you please test the attached merge proposal and report if it works?

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

This bug is fixed with commit 538af8e6 to cloud-init on branch master.
To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=538af8e6

Scott Moser (smoser)
Changed in cloud-init:
assignee: nobody → Scott Moser (smoser)
importance: Undecided → Low
status: New → Fix Committed
Scott Moser (smoser)
Changed in cloud-init (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Scott Moser (smoser) wrote : Fixed in cloud-init version 18.4.

This bug is believed to be fixed in cloud-init in version 18.4. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
Eli the Bearded (ubuntu-34) wrote :

$ apt list --installed 2>&1 | grep -E '^(cloud-init|ksh)/'
cloud-init/focal-updates,now 21.2-3-g899bfaa9-0ubuntu2~20.04.1 all [installed]
ksh/focal,now 2020.0.0-5 amd64 [installed]
$ echo $SHELL
/bin/ksh
$ . /etc/profile.d/Z99-cloud-locale-test.sh
-ksh: .[14]: local: local can only be used in a function
$ . /etc/profile.d/Z99-cloudinit-warnings.sh
-ksh: .[7]: local: local can only be used in a function
$

These produce warnings, although with slightly different sources named, when run by ksh via /etc/profile at login on 20.04.3 LTS.

Revision history for this message
Scott Moser (smoser) wrote :

@Eli,

I can recreate your problem, but it looks to me like a bug in ksh. ksh complains that 'local can only be used in a function, when as shown below it *is* being used in a function.'

My suggestion is to file a bug with ksh2020.

root@focal1:~# ksh -c 'foo() { local a=1; echo $?; }; foo'
ksh: local: local can only be used in a function
1

root@focal1:~# ksh2020 -c 'foo() { local a; echo $?; }; foo'
ksh2020: local: local can only be used in a function
1

also oddly, ksh seems to report itself in '$SHELL' as /bin/sh.

root@focal1:~# /usr/bin/ksh2020 -c 'foo() { local a=1; echo $?; }; echo $SHELL; foo'
/bin/sh
/usr/bin/ksh2020: local: local can only be used in a function
1

Revision history for this message
Guillaume (e1msih) wrote :

It isn't fixed for ubuntu 18.04 :

# dpkg -l cloud-init | grep cloud
ii cloud-init 22.2-0ubuntu1~18.04.3 all Init scripts for cloud instances

With an user having ksh as shell :
su: /etc/profile.d/Z99-cloud-locale-test.sh[100]: local: not found
su: /etc/profile.d/Z99-cloud-locale-test.sh[100]: local: not found
su: /etc/profile.d/Z99-cloudinit-warnings.sh[29]: local: not found
su: /etc/profile.d/Z99-cloudinit-warnings.sh[29]: local: not found
su: /etc/profile.d/Z99-cloudinit-warnings.sh[29]: local: not found

Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.