Skip to content

Commit 45258da

Browse files
committed
feat(powershell): enhance installation script for architecture support
- Updates the installation script to detect ARM64 and x86_64 architectures. - Implements a direct download method for ARM64, including version fetching and extraction. - Retains the original repository installation method for x86_64. - Ensures proper cleanup and symlink creation for easy access.
1 parent 67823bb commit 45258da

File tree

1 file changed

+63
-23
lines changed

1 file changed

+63
-23
lines changed

src/scripts/install-powershell.sh

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,71 @@
33
# Install PowerShell following official documentation
44
# https://learn.microsoft.com/en-us/powershell/scripting/install/install-ubuntu
55

6-
# Update packages and install required dependencies
7-
apt-get update
8-
apt-get install -y --no-install-recommends \
9-
wget \
10-
apt-transport-https \
11-
software-properties-common
12-
13-
# Detect architecture and Ubuntu version
6+
# Detect architecture
147
ARCH=$(uname -m)
15-
UBUNTU_VERSION=$(lsb_release -rs)
168

17-
# Download the Microsoft repository GPG keys
18-
wget -q "https://packages.microsoft.com/config/ubuntu/${UBUNTU_VERSION}/packages-microsoft-prod.deb"
19-
20-
# Register the Microsoft repository GPG keys
21-
dpkg -i packages-microsoft-prod.deb
22-
23-
# Delete the Microsoft repository GPG keys file
24-
rm packages-microsoft-prod.deb
25-
26-
# Update the list of packages after we added packages.microsoft.com
27-
apt-get update
28-
29-
# Install PowerShell
30-
apt-get install -y powershell
9+
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
10+
echo "Installing PowerShell for ARM64 architecture..."
11+
12+
# For ARM64, we need to download the tar.gz package directly
13+
# Get the latest release info
14+
PWSH_VERSION=$(curl -s https://api.github.com/repos/PowerShell/PowerShell/releases/latest | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
15+
16+
if [ -z "$PWSH_VERSION" ]; then
17+
echo "Failed to get PowerShell version, using fallback version"
18+
PWSH_VERSION="7.4.6"
19+
fi
20+
21+
echo "Installing PowerShell version: $PWSH_VERSION"
22+
23+
# Download PowerShell for ARM64
24+
wget -q "https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-arm64.tar.gz" -O /tmp/powershell.tar.gz
25+
26+
# Create directory for PowerShell
27+
mkdir -p /opt/microsoft/powershell/7
28+
29+
# Extract PowerShell
30+
tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/7
31+
32+
# Set execute permissions
33+
chmod +x /opt/microsoft/powershell/7/pwsh
34+
35+
# Create symlinks
36+
ln -sf /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh
37+
ln -sf /opt/microsoft/powershell/7/pwsh /usr/bin/powershell
38+
39+
# Clean up
40+
rm /tmp/powershell.tar.gz
41+
42+
else
43+
echo "Installing PowerShell for x86_64 architecture..."
44+
45+
# For x86_64, use the standard repository method
46+
# Update packages and install required dependencies
47+
apt-get update
48+
apt-get install -y --no-install-recommends \
49+
wget \
50+
apt-transport-https \
51+
software-properties-common
52+
53+
# Detect Ubuntu version
54+
UBUNTU_VERSION=$(lsb_release -rs)
55+
56+
# Download the Microsoft repository GPG keys
57+
wget -q "https://packages.microsoft.com/config/ubuntu/${UBUNTU_VERSION}/packages-microsoft-prod.deb"
58+
59+
# Register the Microsoft repository GPG keys
60+
dpkg -i packages-microsoft-prod.deb
61+
62+
# Delete the Microsoft repository GPG keys file
63+
rm packages-microsoft-prod.deb
64+
65+
# Update the list of packages after we added packages.microsoft.com
66+
apt-get update
67+
68+
# Install PowerShell
69+
apt-get install -y powershell
70+
fi
3171

3272
# Create a symbolic link for 'powershell' command
3373
ln -sf /usr/bin/pwsh /usr/bin/powershell

0 commit comments

Comments
 (0)