2017-05-05 13:01:04 +02:00
#!/bin/bash
#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
2017-11-15 18:51:52 +01:00
#bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-suse.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-suse.sh) <ARGUMENTS>
2017-05-05 13:01:04 +02:00
2019-05-11 00:34:27 +02:00
#Usage - if you do not have the ability to run scripts directly from the web,
2017-05-05 13:01:04 +02:00
# pull all files in this repo folder and execute, this script
# automatically prefers local copies of sub-scripts
#Completely automated install requires a root account or sudo with a password requirement
#Switches
2019-03-08 22:00:04 +01:00
# -includeide - installs VSCode and VSCode PowerShell extension (only relevant to machines with desktop environment)
# -interactivetesting - do a quick launch test of VSCode (only relevant when used with -includeide)
# -skip-sudo-check - use sudo without verifying its availability (this is required to run in the VSTS Hosted Linux Preview)
2019-05-11 00:34:27 +02:00
# -preview - installs the latest preview release of PowerShell side-by-side with any existing production releasesS
2017-05-05 13:01:04 +02:00
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
2018-06-25 20:44:43 +02:00
VERSION = "1.2.0"
2017-05-05 13:01:04 +02:00
gitreposubpath = "PowerShell/PowerShell/master"
gitreposcriptroot = " https://raw.githubusercontent.com/ $gitreposubpath /tools "
thisinstallerdistro = suse
2017-11-03 16:47:26 +01:00
repobased = false
2017-05-05 13:01:04 +02:00
gitscriptname = "installpsh-suse.psh"
2018-06-28 20:46:58 +02:00
pwshlink = /usr/bin/pwsh
2017-05-05 13:01:04 +02:00
echo
2019-05-11 00:34:27 +02:00
echo " *** PowerShell Development Environment Installer $VERSION for $thisinstallerdistro "
2017-05-05 13:01:04 +02:00
echo " *** Original script is at: $gitreposcriptroot / $gitscriptname "
echo
echo " *** Arguments used: $* "
echo
# Let's quit on interrupt of subcommands
trap '
trap - INT # restore default INT handler
echo "Interrupted"
kill -s INT " $$ "
' INT
#Verify The Installer Choice (for direct runs of this script)
lowercase( ) {
2019-03-08 22:00:04 +01:00
echo " $1 " | tr "[:upper:]" "[:lower:]"
2017-05-05 13:01:04 +02:00
}
2019-03-08 22:00:04 +01:00
OS = $( lowercase " $( uname) " )
2017-05-05 13:01:04 +02:00
if [ " ${ OS } " = = "windowsnt" ] ; then
OS = windows
DistroBasedOn = windows
elif [ " ${ OS } " = = "darwin" ] ; then
OS = osx
DistroBasedOn = osx
else
2019-03-08 22:00:04 +01:00
OS = $( uname)
2017-05-05 13:01:04 +02:00
if [ " ${ OS } " = = "SunOS" ] ; then
OS = solaris
DistroBasedOn = sunos
elif [ " ${ OS } " = = "AIX" ] ; then
DistroBasedOn = aix
elif [ " ${ OS } " = = "Linux" ] ; then
if [ -f /etc/redhat-release ] ; then
DistroBasedOn = 'redhat'
2019-06-21 22:36:11 +02:00
elif [ -f /etc/system-release ] ; then
DIST = $( sed s/\ release.*// < /etc/system-release)
if [ [ $DIST = = *"Amazon Linux" * ] ] ; then
DistroBasedOn = 'amazonlinux'
else
DistroBasedOn = 'redhat'
fi
2017-05-05 13:01:04 +02:00
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn = 'suse'
elif [ -f /etc/mandrake-release ] ; then
DistroBasedOn = 'mandrake'
elif [ -f /etc/debian_version ] ; then
DistroBasedOn = 'debian'
fi
if [ -f /etc/UnitedLinux-release ] ; then
2019-03-08 22:00:04 +01:00
DIST = " ${ DIST } [ $( ( tr "\n" ' ' | sed s/VERSION.*//) < /etc/UnitedLinux-release )] "
2017-05-05 13:01:04 +02:00
DistroBasedOn = unitedlinux
fi
2019-03-08 22:00:04 +01:00
OS = $( lowercase " $OS " )
DistroBasedOn = $( lowercase " $DistroBasedOn " )
2017-05-05 13:01:04 +02:00
fi
fi
if [ " $DistroBasedOn " != " $thisinstallerdistro " ] ; then
2019-03-08 22:00:04 +01:00
echo " *** This installer is only for $thisinstallerdistro and you are running $DistroBasedOn , please run \" $gitreposcriptroot \install-powershell.sh\" to see if your distro is supported AND to auto-select the appropriate installer if it is. "
exit 1
2017-05-05 13:01:04 +02:00
fi
## Check requirements and prerequisites
2018-06-25 20:44:43 +02:00
#Check for sudo if not root
if [ [ " ${ CI } " = = "true" ] ] ; then
echo "Running on CI (as determined by env var CI set to true), skipping SUDO check."
set -- " $@ " '-skip-sudo-check'
2017-05-05 13:01:04 +02:00
fi
2018-06-25 20:44:43 +02:00
SUDO = ''
2019-03-08 22:00:04 +01:00
if ( ( EUID != 0 ) ) ; then
2018-06-25 20:44:43 +02:00
#Check that sudo is available
if [ [ ( " ' $* ' " = ~ skip-sudo-check) && ( " $( whereis sudo) " = = *'/' * && " $( sudo -nv 2>& 1) " != 'Sorry, user' *) ] ] ; then
SUDO = 'sudo'
else
echo "ERROR: You must either be root or be able to use sudo" >& 2
#exit 5
2017-05-05 13:01:04 +02:00
fi
fi
#Collect any variation details if required for this distro
2019-03-08 22:00:04 +01:00
# shellcheck disable=SC1091
2018-01-22 23:58:17 +01:00
source /etc/os-release
2019-03-08 22:00:04 +01:00
MAJORREV = ${ VERSION_ID / \. */ }
2017-05-05 13:01:04 +02:00
#END Collect any variation details if required for this distro
#If there are known incompatible versions of this distro, put the test, message and script exit here:
2019-03-08 22:00:04 +01:00
if [ [ $ID = = 'opensuse' && $MAJORREV -lt 42 ] ] ; then
2017-05-05 13:01:04 +02:00
echo " OpenSUSE $VERSION_ID is not supported! " >& 2
exit 2
fi
2019-03-08 22:00:04 +01:00
if [ [ $ID = = 'sles' && $MAJORREV -lt 12 ] ] ; then
2018-01-22 23:58:17 +01:00
echo " SLES $VERSION_ID is not supported! " >& 2
exit 2
fi
2017-05-05 13:01:04 +02:00
#END Verify The Installer Choice
2017-11-03 16:47:26 +01:00
echo
2019-05-11 00:34:27 +02:00
echo "*** Installing prerequisites for PowerShell..."
2017-11-03 16:47:26 +01:00
$SUDO zypper --non-interactive install \
glibc-locale \
glibc-i18ndata \
tar \
curl \
libunwind \
libicu \
openssl \
&& zypper --non-interactive clean --all
2017-05-05 13:01:04 +02:00
##END Check requirements and prerequisites
echo
2019-05-11 00:34:27 +02:00
echo " *** Installing PowerShell for $DistroBasedOn ... "
2017-05-05 13:01:04 +02:00
2018-06-28 20:46:58 +02:00
echo "ATTENTION: As of version 1.2.0 this script no longer uses pre-releases unless the '-preview' switch is used"
2018-06-25 20:44:43 +02:00
2018-06-28 20:46:58 +02:00
if [ [ " ' $* ' " = ~ preview ] ] ; then
2018-06-25 20:44:43 +02:00
echo
2018-06-28 20:46:58 +02:00
echo "-preview was used, the latest preview release will be installed (side-by-side with your production release)"
2019-03-08 22:00:04 +01:00
release = $( curl https://api.github.com/repos/powershell/powershell/releases/latest | sed '/tag_name/!d' | sed s/\" tag_name\" ://g | sed s/\" //g | sed s/v// | sed s/,//g | sed s/\ //g)
2018-06-28 20:46:58 +02:00
pwshlink = /usr/bin/pwsh-preview
2018-06-25 20:44:43 +02:00
else
2018-06-28 20:46:58 +02:00
echo "Finding the latest production release"
2018-06-25 20:44:43 +02:00
release = $( curl https://api.github.com/repos/PowerShell/PowerShell/releases | grep -Po '"tag_name":(\d*?,|.*?[^\\]",)' | grep -Po '\d+.\d+.\d+[\da-z.-]*' | grep -v '[a-z]' | sort | tail -n1)
2019-03-08 22:00:04 +01:00
fi
2018-06-28 20:46:58 +02:00
#DIRECT DOWNLOAD
package = powershell-${ release } -linux-x64.tar.gz
downloadurl = https://github.com/PowerShell/PowerShell/releases/download/v$release /$package
2017-05-05 13:01:04 +02:00
#REPO BASED (Not ready yet)
2019-05-11 00:34:27 +02:00
#echo "*** Setting up PowerShell repo..."
2017-05-05 13:01:04 +02:00
#echo "*** Current version on git is: $release, repo version may differ slightly..."
## Install the Microsoft public key so that zypper trusts the package
#sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
##Add the Repo
2019-05-11 00:34:27 +02:00
#$SUDO sh -c 'echo -e "[code]\nname=PowerShell\nbaseurl=https://packages.microsoft.com/yumrepos/microsoft-sles12-prod\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/powershellcore.repo'
2017-05-05 13:01:04 +02:00
## Update zypper
#$SUDO zypper refresh
## Install PowerShell
#$SUDO zypper --non-interactive install powershell
echo " Destination file: $package "
echo " Source URL: $downloadurl "
curl -L -o " $package " " $downloadurl "
if [ [ ! -r " $package " ] ] ; then
echo " ERROR: $package failed to download! Aborting... " >& 2
exit 1
fi
2017-11-15 18:51:52 +01:00
echo " Installing PowerShell to /opt/microsoft/powershell/ $release in overwrite mode "
2017-11-03 16:47:26 +01:00
## Create the target folder where powershell will be placed
2019-03-08 22:00:04 +01:00
$SUDO mkdir -p " /opt/microsoft/powershell/ $release "
2017-11-03 16:47:26 +01:00
## Expand powershell to the target folder
2019-03-08 22:00:04 +01:00
$SUDO tar zxf " $package " -C " /opt/microsoft/powershell/ $release "
2017-11-03 16:47:26 +01:00
## Change the mode of 'pwsh' to 'rwxr-xr-x' to allow execution
2019-03-08 22:00:04 +01:00
$SUDO chmod 755 " /opt/microsoft/powershell/ $release /pwsh "
2017-11-03 16:47:26 +01:00
## Create the symbolic link that points to powershell
2019-03-08 22:00:04 +01:00
$SUDO ln -sfn " /opt/microsoft/powershell/ $release /pwsh " $pwshlink
2017-11-03 16:47:26 +01:00
## 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
2019-03-08 22:00:04 +01:00
rm -f " $package "
2017-11-03 16:47:26 +01:00
2019-03-08 22:00:04 +01:00
# shellcheck disable=SC2016
2017-11-03 16:47:26 +01:00
pwsh -noprofile -c ' " Congratulations! PowerShell is installed at $PSHOME .
Run ` "pwsh`" to start a PowerShell session." '
2017-05-05 13:01:04 +02:00
success = $?
if [ [ " $success " != 0 ] ] ; then
echo "ERROR: PowerShell failed to install!" >& 2
exit " $success "
fi
if [ [ " ' $* ' " = ~ includeide ] ] ; then
echo
echo "*** Installing VS Code PowerShell IDE..."
echo "*** Setting up VS Code repo..."
$SUDO sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ntype=rpm-md\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/zypp/repos.d/vscode.repo'
$SUDO zypper refresh
$SUDO zypper --non-interactive install code
echo
echo "*** Installing VS Code PowerShell Extension"
code --install-extension ms-vscode.PowerShell
2018-06-25 20:44:43 +02:00
if [ [ " ' $* ' " = ~ -interactivetesting ] ] ; then
echo "*** Loading test code in VS Code"
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
code ./testpowershell.ps1
fi
2017-05-05 13:01:04 +02:00
fi
if [ [ " $repobased " = = true ] ] ; then
2019-05-11 00:34:27 +02:00
echo "*** NOTE: Run your regular package manager update cycle to update PowerShell"
2017-11-15 18:51:52 +01:00
else
2019-05-11 00:34:27 +02:00
echo "*** NOTE: Re-run this script to update PowerShell"
2017-05-05 13:01:04 +02:00
fi
2017-07-21 23:20:51 +02:00
echo "*** Install Complete"