forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstallTarballPackage.sh
41 lines (32 loc) · 1.16 KB
/
InstallTarballPackage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
# Exit on errors
set -e
# Example use:
# ./InstallTarballPackage.sh "6.0.0-beta.9" "powershell-6.0.0-beta.9-linux-x64.tar.gz"
usage() {
echo "usage: $0 <powershell version> <powershell package name>"
exit 1
}
POWERSHELL_VERSION=$1
if [ ! "$POWERSHELL_VERSION" ]; then
usage
fi
POWERSHELL_PACKAGE=$2
if [ ! "$POWERSHELL_PACKAGE" ]; then
usage
fi
POWERSHELL_LINKFILE=/usr/bin/pwsh
# Download the powershell .tar.gz package
curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v$POWERSHELL_VERSION/$POWERSHELL_PACKAGE
# Create the target folder where powershell will be placed
mkdir -p /opt/microsoft/powershell/$POWERSHELL_VERSION
# Expand powershell to the target folder
tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/$POWERSHELL_VERSION
# Create the symbolic link that points to powershell
ln -s /opt/microsoft/powershell/$POWERSHELL_VERSION/pwsh $POWERSHELL_LINKFILE
# Add the symbolic link path to /etc/shells
if [ ! -f /etc/shells ]; then
echo $POWERSHELL_LINKFILE > /etc/shells ;
else
grep -q "^${POWERSHELL_LINKFILE}$" /etc/shells || echo $POWERSHELL_LINKFILE >> /etc/shells ;
fi