forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdownload.sh
More file actions
executable file
·150 lines (136 loc) · 4.97 KB
/
Copy pathdownload.sh
File metadata and controls
executable file
·150 lines (136 loc) · 4.97 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# Let's quit on interrupt of subcommands
trap '
trap - INT # restore default INT handler
echo "Interrupted"
kill -s INT "$$"
' INT
get_url() {
fork=$2
release=v6.0.0-beta.4
echo "https://github.com/$fork/PowerShell/releases/download/$release/$1"
}
fork="PowerShell"
# Get OS specific asset ID and package name
case "$OSTYPE" in
linux*)
source /etc/os-release
# Install curl and wget to download package
case "$ID" in
centos*)
if ! hash curl 2>/dev/null; then
echo "curl not found, installing..."
sudo yum install -y curl
fi
package=powershell-6.0.0_beta.4-1.el7.x86_64.rpm
;;
ubuntu)
if ! hash curl 2>/dev/null; then
echo "curl not found, installing..."
sudo apt-get install -y curl
fi
case "$VERSION_ID" in
14.04)
package=powershell_6.0.0-beta.4-1ubuntu1.14.04.1_amd64.deb
;;
16.04)
package=powershell_6.0.0-beta.4-1ubuntu1.16.04.1_amd64.deb
;;
*)
echo "Ubuntu $VERSION_ID is not supported!" >&2
exit 2
esac
;;
opensuse)
if ! hash curl 2>/dev/null; then
echo "curl not found, installing..."
sudo zypper install -y curl
fi
case "$VERSION_ID" in
42.1)
package=powershell-6.0.0_beta.4-1.suse.42.1.x86_64.rpm
;;
*)
echo "OpenSUSE $VERSION_ID is not supported!" >&2
exit 2
esac
;;
*)
echo "$NAME is not supported!" >&2
exit 2
esac
;;
darwin*)
# We don't check for curl as macOS should have a system version
package=powershell-6.0.0-beta.4-osx.10.12-x64.pkg
;;
*)
echo "$OSTYPE is not supported!" >&2
exit 2
;;
esac
curl -L -o "$package" $(get_url "$package" "$fork")
if [[ ! -r "$package" ]]; then
echo "ERROR: $package failed to download! Aborting..." >&2
exit 1
fi
# Installs PowerShell package
case "$OSTYPE" in
linux*)
source /etc/os-release
# Install dependencies
echo "Installing PowerShell with sudo..."
case "$ID" in
centos)
# yum automatically resolves dependencies for local packages
sudo yum install "./$package"
;;
ubuntu)
# dpkg does not automatically resolve dependencies, but spouts ugly errors
sudo dpkg -i "./$package" &> /dev/null
# Resolve dependencies
sudo apt-get install -f
;;
opensuse)
# Install the Microsoft public key so that zypper trusts the package
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
# zypper automatically resolves dependencies for local packages
sudo zypper --non-interactive install "./$package" &> /dev/null
;;
*)
esac
;;
darwin*)
patched=0
if hash brew 2>/dev/null; then
if [[ ! -d $(brew --prefix openssl) ]]; then
echo "Installing OpenSSL with brew..."
if ! brew install openssl; then
echo "ERROR: OpenSSL failed to install! Crypto functions will not work..." >&2
# Don't abort because it is not fatal
elif ! brew install curl --with-openssl; then
echo "ERROR: curl failed to build against OpenSSL; SSL functions will not work..." >&2
# Still not fatal
else
# OpenSSL installation succeeded; remember to patch System.Net.Http after PowerShell installation
patched=1
fi
fi
else
echo "ERROR: brew not found! OpenSSL may not be available..." >&2
# Don't abort because it is not fatal
fi
echo "Installing $package with sudo ..."
sudo installer -pkg "./$package" -target /
if [[ $patched -eq 1 ]]; then
echo "Patching System.Net.Http for libcurl and OpenSSL..."
find /usr/local/microsoft/powershell -name System.Net.Http.Native.dylib | xargs sudo install_name_tool -change /usr/lib/libcurl.4.dylib /usr/local/opt/curl/lib/libcurl.4.dylib
fi
;;
esac
powershell -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME"'
success=$?
if [[ "$success" != 0 ]]; then
echo "ERROR: PowerShell failed to install!" >&2
exit "$success"
fi