Skip to content

Commit

Permalink
Fix PowerShell profile not loading (#889)
Browse files Browse the repository at this point in the history
* Update devcontainer-feature.json

* Fix profile loading

* Update devcontainer-feature.json

* Update devcontainer-feature.json

* Add -E to sudo so it inherits environment
  • Loading branch information
nebula-it authored Mar 5, 2024
1 parent 084df81 commit 4d2e62e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/powershell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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.",
Expand All @@ -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."
Expand Down
25 changes: 5 additions & 20 deletions src/powershell/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4d2e62e

Please sign in to comment.