Bug 21059 – install.sh: posix_terminal returns false on Linux Mint 20
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-07-20T14:22:03Z
Last change time
2020-07-21T21:48:21Z
Keywords
pull
Assigned to
No Owner
Creator
John Hall
Comments
Comment #0 by john.michael.hall — 2020-07-20T14:22:03Z
As originally discussed at
https://forum.dlang.org/post/[email protected]
I just upgraded a machine to Linux Mint 20 on a fresh install and tried to run the install script. It fails with
main: line 178: USERPROFILE: unbound variable
This line should only be called on Windows, which I found strange. It turns out that this is driven by
```
posix_terminal() {
# If this script is run on Windows cmd by passing it as argument to bash.exe,
# the shell level will be 1. If it is run from a POSIX terminal, it will be > 1.
if [ "$SHLVL" = 1 ]; then
false
else
true
fi
}
```
Running `echo $SHLVL` prints `1`
Running
```
bash
echo $SHLVL
```
prints `2`
Running `echo $SHELL` prints `/bin/bash`
The issue seems to be related to an update to Ubuntu 16:
https://askubuntu.com/questions/856532/why-is-shlvl-initially-2-in-ubuntu-16-10-but-not-earlier-versions
Comment #1 by john.michael.hall — 2020-07-20T15:10:22Z
Confirmed:
$ curl -fsS https://dlang.org/install.sh | bash -s dmd
main: line 178: USERPROFILE: unbound variable
Workaround:
$ wget https://dlang.org/install.sh
$ chmod +x install.sh
$ ./install.sh
$ source ~/dlang/dmd-2.093.0/activate
$ dmd --version
DMD64 D Compiler v2.093.0
Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved written by Walter Bright
So the pipe into bash does not seem to increment $SHLVL.
Comment #3 by dlang-bot — 2020-07-20T21:10:27Z
@veelo created dlang/installer pull request #463 "Fixes issue 21059: installer fails when piped on Posix." fixing this issue:
- Fixes issue 21059.
The assumption that $SHLVL increases when the script is run does not always hold. $SHLVL does not increase if the script is piped into bash, thereby failing to detect Posix. If the default terminal shell is not bash, $SHLVL might also be 1 on Posix.
https://github.com/dlang/installer/pull/463
Comment #4 by dlang-bot — 2020-07-21T21:48:21Z
dlang/installer pull request #463 "Fixes issue 21059: installer fails when piped on Posix." was merged into stable:
- 719ebf6f472b2b2d58b56fef2aebbf530cc5bcf3 by Bastiaan Veelo:
Fixes issue 21059.
The assumption that $SHLVL increases when the script is run does not always hold. $SHLVL does not increase if the script is piped into bash, thereby failing to detect Posix. If the default terminal shell is not bash, $SHLVL might also be 1 on Posix.
https://github.com/dlang/installer/pull/463