Skip to content

Commit b6f48a9

Browse files
committed
Address more comments.
1 parent 580b154 commit b6f48a9

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/haskell/install.sh

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,51 @@
22
set -e
33

44
GHCUP_VERSION="0.1.19.2"
5-
GHCUP_BIN="x86_64-linux-ghcup-${GHCUP_VERSION}"
5+
# Source /etc/os-release to get OS info
6+
. /etc/os-release
7+
# Fetch host/container arch.
8+
architecture="$(dpkg --print-architecture)"
9+
GHCUP_BIN="${architecture}-linux-ghcup-${GHCUP_VERSION}"
10+
611
BOOTSTRAP_HASKELL_GHC_VERSION="${VERSION:-"recommended "}"
712

813
# Maybe install curl, gcc, make
914
for x in curl gcc make; do
1015
which $x > /dev/null || (apt update && apt install $x -y -qq)
1116
done
1217

13-
GHCUP_DIR=~/.ghcup/bin
18+
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
19+
rm -f /etc/profile.d/00-restore-env.sh
20+
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
21+
chmod +x /etc/profile.d/00-restore-env.sh
22+
23+
# Determine the appropriate non-root user
24+
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
25+
USERNAME=""
26+
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
27+
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
28+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
29+
USERNAME=${CURRENT_USER}
30+
break
31+
fi
32+
done
33+
if [ "${USERNAME}" = "" ]; then
34+
USERNAME=root
35+
fi
36+
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
37+
USERNAME=root
38+
fi
39+
40+
GHCUP_DIR=${USERNAME}/.ghcup/bin
1441
mkdir -p $GHCUP_DIR
15-
curl https://downloads.haskell.org/~ghcup/${GHCUP_VERSION}/x86_64-linux-ghcup-${GHCUP_VERSION} --output ${GHCUP_BIN}
42+
curl https://downloads.haskell.org/~ghcup/${GHCUP_VERSION}/${architecture}-linux-ghcup-${GHCUP_VERSION} --output ${GHCUP_BIN}
1643
echo "25b7fc417c1a811dd7ff439b67ea647a59cf5b8d71b274f97e917d50b2150d5b ${GHCUP_BIN}" | sha256sum --check --status
1744

1845
mv ${GHCUP_BIN} $GHCUP_DIR/ghcup
1946
chmod a+x $GHCUP_DIR/ghcup
2047

48+
export GHCUP_INSTALL_BASE_PREFIX=${USERNAME}
49+
2150
${GHCUP_DIR}/ghcup install ghc $BOOTSTRAP_HASKELL_GHC_VERSION
2251
${GHCUP_DIR}/ghcup install cabal $CABALVERSION
2352
${GHCUP_DIR}/ghcup install hls $HLSVERSION
@@ -27,3 +56,8 @@ ${GHCUP_DIR}/ghcup set ghc $BOOTSTRAP_HASKELL_GHC_VERSION
2756
${GHCUP_DIR}/ghcup set cabal $CABALVERSION
2857
${GHCUP_DIR}/ghcup set hls $HLSVERSION
2958
${GHCUP_DIR}/ghcup set stack $STACKVERSION
59+
60+
# Clean up
61+
rm -rf /var/lib/apt/lists/*
62+
63+
echo "Done!"

0 commit comments

Comments
 (0)