Unverified Commit 4d2e62e4 authored by Nebula's avatar Nebula Committed by GitHub

Fix PowerShell profile not loading (#889)

* Update devcontainer-feature.json

* Fix profile loading

* Update devcontainer-feature.json

* Update devcontainer-feature.json

* Add -E to sudo so it inherits environment
parent 084df810
{
"id": "powershell",
"version": "1.3.2",
"version": "1.3.3",
"name": "PowerShell",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/powershell",
"description": "Installs PowerShell along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like gpg.",
......@@ -20,7 +20,7 @@
"default": "",
"description": "Optional comma separated list of PowerShell modules to install."
},
"powershellProfileURL ": {
"powershellProfileURL": {
"type": "string",
"default": "",
"description": "Optional (publicly accessible) URL to download PowerShell profile."
......
......@@ -12,11 +12,9 @@ set -e
# Clean up
rm -rf /var/lib/apt/lists/*
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
POWERSHELL_VERSION=${VERSION:-"latest"}
POWERSHELL_MODULES="${MODULES:-""}"
POWERSHELL_PROFILE_URL="${PROFILE_URL}"
POWERSHELL_PROFILE_URL="${POWERSHELLPROFILEURL}"
MICROSOFT_GPG_KEYS_URI="https://packages.microsoft.com/keys/microsoft.asc"
POWERSHELL_ARCHIVE_ARCHITECTURES="amd64"
......@@ -165,26 +163,13 @@ if [ ${#POWERSHELL_MODULES[@]} -gt 0 ]; then
done
fi
# Determine the appropriate non-root user
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
USERNAME=root
fi
# If URL for powershell profile is provided, download it to '/opt/microsoft/powershell/7/profile.ps1'
if [ -n "$POWERSHELL_PROFILE_URL" ]; then
echo "Downloading PowerShell Profile from: $POWERSHELL_PROFILE_URL"
su ${USERNAME} -c "curl -sSL -o '/opt/microsoft/powershell/7/profile.ps1' '$POWERSHELL_PROFILE_URL'"
# Get profile path from currently installed pwsh
profilePath=$(pwsh -noni -c '$PROFILE.AllUsersAllHosts')
sudo -E curl -sSL -o "$profilePath" "$POWERSHELL_PROFILE_URL"
fi
# Clean up
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment