2017-05-05 11:01:04 +00:00
#!/bin/bash
#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
2017-11-15 17:51:52 +00:00
#bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-debian.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-debian.sh) <ARGUMENTS>
2017-05-05 11:01:04 +00:00
2018-03-06 22:01:50 +00:00
#Usage - if you do not have the ability to run scripts directly from the web,
2017-05-05 11:01:04 +00: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
# -includeide - the script is being run headless, do not perform actions that require response from the console
# -interactivetests - requires a human user in front of the machine - loads a script into the ide to test with F5 to ensure the IDE can run scripts
2017-12-11 18:28:43 +00:00
# -skip-sudo-check - skips the check that the user has permission to use sudo. This is required to run in the VSTS Hosted Linux Preview.
2017-05-05 11:01:04 +00:00
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
2018-06-25 18:44:43 +00:00
VERSION = "1.2.0"
2017-05-05 11:01:04 +00:00
gitreposubpath = "PowerShell/PowerShell/master"
gitreposcriptroot = " https://raw.githubusercontent.com/ $gitreposubpath /tools "
thisinstallerdistro = debian
repobased = true
gitscriptname = "installpsh-debian.psh"
2018-06-28 18:46:58 +00:00
powershellpackageid = powershell
2017-05-05 11:01:04 +00:00
2018-03-06 22:01:50 +00:00
echo ;
2017-05-05 11:01:04 +00:00
echo " *** PowerShell Core Development Environment Installer $VERSION for $thisinstallerdistro "
echo " *** Current PowerShell Core Version: $currentpshversion "
echo " *** Original script is at: $gitreposcriptroot / $gitscriptname "
echo
echo " *** Arguments used: $* "
#Verify The Installer Choice (for direct runs of this script)
lowercase( ) {
#echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
echo " $1 " | tr [ A-Z] [ a-z]
}
# Let's quit on interrupt of subcommands
trap '
trap - INT # restore default INT handler
echo "Interrupted"
kill -s INT " $$ "
' INT
if [ " ${ OS } " = = "windowsnt" ] ; then
OS = windows
DistroBasedOn = windows
elif [ " ${ OS } " = = "darwin" ] ; then
OS = osx
DistroBasedOn = osx
else
OS = ` uname`
if [ " ${ OS } " = = "SunOS" ] ; then
OS = solaris
ARCH = ` uname -p`
OSSTR = " ${ OS } ${ REV } ( ${ ARCH } `uname -v`) "
DistroBasedOn = sunos
elif [ " ${ OS } " = = "AIX" ] ; then
OSSTR = " ${ OS } `oslevel` (`oslevel -r`) "
DistroBasedOn = aix
elif [ " ${ OS } " = = "Linux" ] ; then
if [ -f /etc/redhat-release ] ; then
DistroBasedOn = 'redhat'
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
DIST = " ${ DIST } [`cat /etc/UnitedLinux-release | tr " \n " ' ' | sed s/VERSION.*//`]"
DistroBasedOn = unitedlinux
fi
OS = ` lowercase $OS `
DistroBasedOn = ` lowercase $DistroBasedOn `
fi
fi
if [ " $DistroBasedOn " != " $thisinstallerdistro " ] ; then
echo " *** This installer is only for $thisinstallerdistro and you are running $DistroBasedOn , please run \" $gitreporoot \install-powershell.sh\" to see if your distro is supported AND to auto-select the appropriate installer if it is. "
exit 0
fi
## Check requirements and prerequisites
2018-06-25 18:44:43 +00: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 11:01:04 +00:00
fi
2018-06-25 18:44:43 +00:00
SUDO = ''
if ( ( $EUID != 0 ) ) ; then
#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 11:01:04 +00:00
fi
fi
#Collect any variation details if required for this distro
2018-03-06 22:01:50 +00:00
. /etc/lsb-release
DISTRIB_ID = ` lowercase $DISTRIB_ID `
2017-05-05 11:01:04 +00: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:
#END Verify The Installer Choice
##END Check requirements and prerequisites
echo
echo " *** Installing PowerShell Core for $DistroBasedOn ... "
if ! hash curl 2>/dev/null; then
echo "curl not found, installing..."
$SUDO apt-get install -y curl
fi
2018-06-25 18:44:43 +00:00
2018-06-28 18:46:58 +00:00
if [ [ " ' $* ' " = ~ preview ] ] ; then
2018-06-25 18:44:43 +00:00
echo
2018-06-28 18:46:58 +00:00
echo "-preview was used, the latest preview release will be installed (side-by-side with your production release)"
powershellpackageid = powershell-preview
2018-06-25 18:44:43 +00:00
fi
2018-04-06 22:23:11 +00: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`
2017-05-05 11:01:04 +00:00
echo " *** Current version on git is: $currentversion , repo version may differ slightly... "
echo "*** Setting up PowerShell Core repo..."
# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | $SUDO apt-key add -
#Add the Repo
2018-12-11 22:40:38 +00:00
if [ [ " ${ DISTRIB_ID } " = "linuxmint" ] ] ; then
echo "Attempting to remap linuxmint to an appropriate ubuntu version" >& 2
LINUXMINT_VERSION = ${ DISTRIB_RELEASE }
#https://en.wikipedia.org/wiki/Linux_Mint_version_history
case ${ LINUXMINT_VERSION } in
19*)
DISTRIB_RELEASE = 18.04
; ;
18*)
DISTRIB_RELEASE = 16.04
; ;
17*)
DISTRIB_RELEASE = 14.04
; ;
*)
echo " ERROR: unsupported linuxmint version ( ${ LINUXMINT_VERSION } ). " >& 2
echo "Supported versions: 19" >& 2
echo "For additional versions open an issue or pull request at: https://github.com/powershell/powershell" >& 2
exit 1
; ;
esac
echo " Remapping linuxmint version ${ LINUXMINT_VERSION } to ubuntu version ${ DISTRIB_RELEASE } " >& 2
fi
2018-03-06 22:01:50 +00:00
case $DISTRIB_ID in
2018-12-11 22:40:38 +00:00
ubuntu| linuxmint)
2018-03-06 22:01:50 +00:00
case $DISTRIB_RELEASE in
2018-09-17 21:48:23 +00:00
18.04| 16.10| 16.04| 15.10| 14.04)
2018-03-06 22:01:50 +00:00
curl https://packages.microsoft.com/config/ubuntu/$DISTRIB_RELEASE /prod.list | $SUDO tee /etc/apt/sources.list.d/microsoft.list
; ;
*)
echo " ERROR: unsupported Ubuntu version ( $DISTRIB_RELEASE ). " >& 2
2018-09-17 21:48:23 +00:00
echo "Supported versions: 14.04, 15.10, 16.04, 16.10, 18.04." >& 2
2018-12-11 22:40:38 +00:00
echo "For additional versions open an issue or pull request at: https://github.com/powershell/powershell" >& 2
2018-03-06 22:01:50 +00:00
exit 1
; ;
esac
; ;
debian)
DISTRIB_RELEASE = ${ DISTRIB_RELEASE %%.* }
case $DISTRIB_RELEASE in
8| 9)
curl https://packages.microsoft.com/config/debian/$DISTRIB_RELEASE /prod.list | $SUDO tee /etc/apt/sources.list.d/microsoft.list
; ;
*)
echo " ERROR: unsupported Debian version ( $DISTRIB_RELEASE ). " >& 2
echo "Supported versions: 8, 9." >& 2
2018-12-11 22:40:38 +00:00
echo "For additional versions open an issue or pull request at: https://github.com/powershell/powershell" >& 2
2018-03-06 22:01:50 +00:00
exit 1
; ;
esac
; ;
*)
echo " ERROR: unsupported Debian-based distribution ( $DISTRIB_ID ). " >& 2
echo "Supported distributions: Debian, Ubuntu." >& 2
exit 1
; ;
esac
2017-05-05 11:01:04 +00:00
# Update apt-get
$SUDO apt-get update
# Install PowerShell
2018-06-28 18:46:58 +00:00
$SUDO apt-get install -y ${ powershellpackageid }
2017-05-05 11:01:04 +00:00
2017-11-03 15:47:26 +00:00
pwsh -noprofile -c ' " Congratulations! PowerShell is installed at $PSHOME .
Run ` "pwsh`" to start a PowerShell session." '
2017-05-05 11:01:04 +00: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..."
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
$SUDO mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
$SUDO sh -c 'echo "deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
$SUDO apt-get update
$SUDO apt-get install -y code
echo
echo "*** Installing VS Code PowerShell Extension"
code --install-extension ms-vscode.PowerShell
2018-06-25 18:44:43 +00: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 11:01:04 +00:00
fi
if [ [ " $repobased " = = true ] ] ; then
echo
echo "*** NOTE: Run your regular package manager update cycle to update PowerShell Core\n"
fi
2017-07-21 21:20:51 +00:00
echo "*** Install Complete"