-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
421 lines (412 loc) · 16.3 KB
/
install.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/bin/bash
# script version
ver=1.2
#SUSE Whiptail Pre-Req Install
if [ -f /etc/SuSE-release ] ; then
whiptail -v > /dev/null 2>&1
exitstatus=$?
if [ $exitstatus != 0 ]; then
echo "Whiptail not found. Whiptail is required for this PowerShell Installation GUI Script."
echo
read -p "Press enter to install Whiptail..."
echo
echo "Now installing Newt package with Whiptail..."
echo
echo "Please wait..."
sudo zypper --non-interactive install newt && echo "Successfully installed Newt with Whiptail. PowerShell Core Install script will now proceed."
echo
echo
fi
fi
### Begin GUI install...
# passwd capture function
function capturePass {
# password capture
psw=$(whiptail --title "PowerShell Core Install | Sudo Password Capture" --passwordbox "Sudo is required to install PowerShell Core. Please enter your sudo password to proceed with the install." 10 60 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
whiptail --title "PowerShell Core Installation" --msgbox "Sudo password captured successfully!" 8 78
else
#Password if cancelled
whiptail --title "PowerShell Core Installation" --msgbox "Sudo password not captured, install cancelled." 10 60
fi
}
# sudo check
sudo=$(whoami | grep root)
exitstatus=$?
if [ $exitstatus = 0 ]; then
whiptail --title "PowerShell Core Installation" --msgbox "Sudo password not required. Install being run as root." 10 60
else
whiptail --title "PowerShell Core Installation" --msgbox "Sudo password required!" 8 78
capturePass
fi
function envSelection {
choice=$(whiptail --title "Environment Selection" --menu "Please choose your environment" 16 78 5 \
"ubuntu14" "14.04" \
"ubuntu16" "16.04" \
"ubuntu17" "17.04" \
"debian8" "Debian 8" \
"debian9" "Debian 9" \
"opensuse42" "OpenSUSE 42" \
"centos7" "CentOS 7" \
"rhel7" "RHEL 7" \
"back" "Back to main menu" 3>&2 2>&1 1>&3)
# Change to lower case and remove spaces.
option=$(echo $choice | tr '[:upper:]' '[:lower:]' | sed 's/ //g')
case "${option}" in
ubuntu14) installPSCore14
;;
ubuntu16) installPSCore16
;;
ubuntu17) installPSCore17
;;
debian8) installDebian8
;;
debian9) installDebian9
;;
opensuse42) installOpenSuse42
;;
centos7) installCentos7
;;
rhel7) installrhel7
;;
back) do_main_menu
;;
*) whiptail --title "PowerShell Core Installer" --msgbox "You have chosen to cancel this installation." 8 78
status=1
exit
;;
esac
}
function envSelectazrm {
envSelection
installAzureRM
end
exit 0
}
function envselctall {
envSelection
installAzureRM
azCliCheck
end
exit 0
}
function optInstall {
choice=$(whiptail --title "Optional Features" --menu "Please choose which components you would like to install" 16 78 5 \
"azureRM" "AzureRM Modules" \
"azureCli" "Azure CLI 2.0" \
"back" "" 3>&2 2>&1 1>&3)
case $choice in
azureRM) installAzureRM
;;
azureCli) azCliCheck
;;
back) do_main_menu
;;
*) whiptail --title "PowerShell Core Installer" --msgbox "You have chosen to cancel this installation." 8 78
status=1
exit
;;
esac
}
function installDebian8 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Install system components
sudo apt-get update
sudo apt-get install apt-transport-https -y
# Import the public repository GPG keys
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - > /dev/null 2>&1
# Register the Microsoft Product feed
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-jessie-prod jessie main" > /etc/apt/sources.list.d/microsoft.list'
# Update the list of products
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for Debian 8" 6 60 0
end
}
function installDebian9 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Install system components
sudo -S <<< $psw apt-get update
sudo -S <<< $psw apt-get install gnupg apt-transport-https dirmngr -y
# Import the public repository GPG keys
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - > /dev/null 2>&1
# Register the Microsoft Product feed
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list'
# Update the list of products
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for Debian 9" 6 60 0
end
}
function installOpenSuse42 {
{
for ((i=0; i<=100; i+=20)); do
# Pre-reqs
sudo zypper --non-interactive install \
glibc-locale \
glibc-i18ndata \
tar \
curl \
libunwind \
libicu \
openssl > /dev/null 2>&1
sudo zypper --non-interactive clean --all > /dev/null 2>&1
# Install
release=`curl -s https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\"tag_name\"://g | sed s/\"//g | sed s/v//g | sed s/,//g | sed s/\ //g`
#DIRECT DOWNLOAD
pwshlink=/usr/bin/pwsh
package=powershell-${release}-linux-x64.tar.gz
downloadurl=https://github.com/PowerShell/PowerShell/releases/download/v$release/$package
curl -L -o "$package" "$downloadurl" > /dev/null 2>&1
## Create the target folder where powershell will be placed
sudo mkdir -p /opt/microsoft/powershell/$release
## Expand powershell to the target folder
sudo tar zxf $package -C /opt/microsoft/powershell/$release > /dev/null 2>&1
## Change the mode of 'pwsh' to 'rwxr-xr-x' to allow execution
sudo chmod 755 /opt/microsoft/powershell/$release/pwsh
## Create the symbolic link that points to powershell
sudo ln -sfn /opt/microsoft/powershell/$release/pwsh $pwshlink
## Add the symbolic link path to /etc/shells
if [ ! -f /etc/shells ] ; then
echo $pwshlink | sudo tee /etc/shells ;
else
grep -q "^${pwshlink}$" /etc/shells || echo $pwshlink | sudo tee --append /etc/shells > /dev/null ;
fi
## Remove the downloaded package file
rm -f $package
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for OpenSUSE 42" 6 60 0
end
}
function installCentos7 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Register the Microsoft RedHat repository
curl -s https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo > /dev/null 2>&1
# Install PowerShell
sudo yum install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for CentOS 7" 6 60 0
end
}
function installrhel7 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Repodata
sudo yum makecache fast > /dev/null 2>&1
# Register the Microsoft RedHat repository
curl -s https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo
# Install PowerShell
sudo yum install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for RHEL 7" 6 60 0
end
}
function installPSCore14 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Import the public repository GPG keys
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
# Register the Microsoft Ubuntu repository
curl -s https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
# Update apt-get
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for Ubuntu 14.04" 6 60 0
end
}
function installPSCore16 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Import the public repository GPG keys
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
# Register the Microsoft Ubuntu repository
curl -s https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
# Update apt-get
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for Ubuntu 16.04" 6 60 0
end
}
function installPSCore17 {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
# Import the public repository GPG keys
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - > /dev/null 2>&1
# Register the Microsoft Ubuntu repository
curl -s https://packages.microsoft.com/config/ubuntu/17.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
# Update apt-get
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing PowerShell Core for Ubuntu 17.04" 6 60 0
end
}
function installAzureRM {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
#Azure RM NetCore Preview Module Install
sudo pwsh -Command Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
sudo pwsh -Command Install-Module -Name AzureRM.Netcore
sudo pwsh -Command Import-Module -Name AzureRM.Netcore
if [[ $? -eq 0 ]]
then
echo "Successfully installed PowerShell Core with AzureRM NetCore Module."
else
echo "PowerShell Core with AzureRM NetCore Module did not install successfully." >&2
fi
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing AzureRM Modules" 8 78 0
}
function rpmAzInstall {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
yum check-update > /dev/null 2>&1
sudo yum install azure-cli -y
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing Azure CLI 2.0 for RPM" 6 60 0
}
function zypAzInstall {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/azure-cli.repo'
sudo zypper --gpg-auto-import-keys --no-gpg-checks -q refresh
sudo zypper --non-interactive -q install azure-cli
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing Azure CLI 2.0 for Zypper" 6 60 0
}
function installAzCli {
{
for ((i=0; i<=100; i+=20)); do
# sudo -S - auth sudo in advance
sudo -S <<< $psw ls > /dev/null 2>&1
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \
sudo tee /etc/apt/sources.list.d/azure-cli.list > /dev/null 2>&1
sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 52E16F86FEE04B979B07E28DB02C46DF417A0893 > /dev/null 2>&1
sudo apt-get install -y apt-transport-https
sudo apt-get update && sudo apt-get install azure-cli -y
if [[ $? -eq 0 ]]
then
echo "Successfully installed Azure CLI 2.0"
else
echo "Azure CLI 2.0 not installed successfully" >&2
fi
sleep 1
echo $i
done
} | whiptail --title "PowerShell Core Installer" --gauge "Installing Azure CLI 2.0" 6 60 0
}
# Package Management Check
function azCliCheck {
# Debian
if [ -f /etc/debian_version ]; then
installAzCli
# Rhel
elif [ -f /etc/redhat-release ]; then
rpmAzInstall
# Suse
elif [ -f /etc/SuSE-release ]; then
zypAzInstall
# Rhel and CentOS
elif [ -f /etc/redhat-release ]; then
rpmAzInstall
else
echo "Cannot install Azure CLI. Package manager could not be determeined. Please open an issue." > ~/err_pwshcore.log
fi
}
function about {
whiptail --title "About" --msgbox " \
PowerShell Core Install Menu Assist
Written by Jessica Deen
This menu will help install the latest version of PowerShell
Core and optional components if desired.
For additional details see: https://github.com/jldeen/pwshcore
" 35 70 35
}
function end {
whiptail --title "PowerShell Core Installation" --msgbox "PowerShell Core Installer has completed successfully." 8 78
}
#------------------------------------------------------------------------------
function do_main_menu () {
SELECTION=$(whiptail --title "PowerShell Core Install Assist $ver" --menu "Arrow/Enter Selects or Tab Key" 20 70 10 --cancel-button Quit --ok-button Select \
"a " "PowerShell Core Install Only" \
"b " "PowerShell Core Install + AzureRM Modules" \
"c " "PowerShell Core Install + AzureRM Modules and Azure CLI 2.0" \
"d " "Optional Components Menu" \
"f " "About" \
"q " "Quit Menu Back to Console" 3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
exit 0
elif [ $RET -eq 0 ]; then
case "$SELECTION" in
a\ *) envSelection ;;
b\ *) envSelectazrm ;;
c\ *) envselctall ;;
d\ *) optInstall ;;
f\ *) about ;;
q\ *) exit 0 ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running selection $SELECTION" 20 60 1
fi
}
while true; do
do_main_menu
done