Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sudo instead #94

Merged
merged 5 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/haskell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Haskell",
"id": "haskell",
"version": "1.1.0",
"version": "2.0.0",
"description": "Installs Haskell. An advanced, purely functional programming language",
"documentationURL": "https://github.com/devcontainers-contrib/features/tree/main/src/haskell",
"options": {
Expand Down
16 changes: 9 additions & 7 deletions src/haskell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ fi

# The installation script is designed to be run by the non-root user
# The files need to be in the remote user's ~/ home directory
ROOT_HOME="${HOME}"
export HOME="${_REMOTE_USER_HOME}"

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | $SHELL

export HOME="${ROOT_HOME}"
chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "${_REMOTE_USER_HOME}"
# So, how do we switch users? We use 'sudo -iu <username>' to get a
# login shell of another user! We use $_REMOTE_USER as defined in
# a spec proposal (but still implemented in Codespaces): https://github.com/devcontainers/spec/blob/main/proposals/features-user-env-variables.md
# Here's some more examples using it: https://github.com/search?q=org%3Adevcontainers+_REMOTE_USER&type=code
# We also use /bin/sh as defined in the script hash-bang line instead of $SHELL.
sudo -iu "$_REMOTE_USER" <<EOF
# Install instructions from https://www.haskell.org/ghcup/#
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
EOF

# without restarting the shell, ghci location would not be resolved from the updated PATH
exec $SHELL
Expand Down