Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions tools/install-powershell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,14 @@ else
PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/system-release ] ; then
DistroBasedOn='redhat'
DIST=`cat /etc/system-release |sed s/\ release.*//`
PSUEDONAME=`cat /etc/system-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/system-release | sed s/.*release\ // | sed s/\ .*//`
if [[ $DIST == *"Amazon Linux"* ]] ; then
DistroBasedOn='amazonlinux'
else
DistroBasedOn='redhat'
fi
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn='suse'
PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
Expand Down Expand Up @@ -130,7 +134,7 @@ if [[ "'$*'" =~ appimage ]] ; then
echo "Pulling it from \"$gitreposcriptroot/appimage.sh\""
bash <(wget -qO- $gitreposcriptroot/appimage.sh) $@
fi
elif [ "$DistroBasedOn" == "redhat" ] || [ "$DistroBasedOn" == "debian" ] || [ "$DistroBasedOn" == "osx" ] || [ "$DistroBasedOn" == "suse" ]; then
elif [ "$DistroBasedOn" == "redhat" ] || [ "$DistroBasedOn" == "debian" ] || [ "$DistroBasedOn" == "osx" ] || [ "$DistroBasedOn" == "suse" ] || [ "$DistroBasedOn" == "amazonlinux" ]; then
echo "Configuring PowerShell Core Enviornment for: $DistroBasedOn $DIST $REV"
if [ -f $SCRIPTFOLDER/installpsh-$DistroBasedOn.sh ]; then
#Script files were copied local - use them
Expand Down
221 changes: 221 additions & 0 deletions tools/installpsh-amazonlinux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
#!/bin/bash

#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
#bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-amazonlinux.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-amazonlinux.sh) <ARGUMENTS>

#Usage - if you do not have the ability to run scripts directly from the web,
# 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

#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution


VERSION="1.1.2"
gitreposubpath="PowerShell/PowerShell/master"
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
thisinstallerdistro=amazonlinux
repobased=false
gitscriptname="installpsh-amazonlinux.psh"

echo
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: $*"
echo

# Let's quit on interrupt of subcommands
trap '
trap - INT # restore default INT handler
echo "Interrupted"
kill -s INT "$$"
' INT

lowercase(){
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}

OS=`lowercase \`uname\``
KERNEL=`uname -r`
MACH=`uname -m`

if [ "${OS}" == "windowsnt" ]; then
OS=windows
DistroBasedOn=windows
SCRIPTFOLDER=$(dirname $(readlink -f $0))
elif [ "${OS}" == "darwin" ]; then
OS=osx
DistroBasedOn=osx
# readlink doesn't work the same on macOS
SCRIPTFOLDER=$(dirname $0)
else
SCRIPTFOLDER=$(dirname $(readlink -f $0))
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'
DIST=`cat /etc/redhat-release |sed s/\ release.*//`
PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/system-release ] ; then
DIST=`cat /etc/system-release |sed s/\ release.*//`
PSUEDONAME=`cat /etc/system-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/system-release | sed s/.*release\ // | sed s/\ .*//`
if [[ $DIST == *"Amazon Linux"* ]] ; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code to check current OS and DistroBasedOn is different from other installsh- scripts targeting other Linux distros. Are you going to unify them all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it could be done, it's not absolutely necessary so I tacked toward minimal changes to anything I wasn't going to unit test before doing the PR. install-powershell.sh needs it to correctly call installpsh-amazonlinux.sh and then installpsh-amazonlinux.sh needs it to validate the correct installer. None of the others need the amazonlinux piece - but I can also understand keeping this bit of code the same. I don't currently have the bandwidth to test if I change the others.

Let me know what you think we should do with this and then I'll do one update and include the other two items you mentioned in this PR.

Copy link
Member

@daxian-dbw daxian-dbw Nov 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. I'm fine with the current change.
It would be more consistent if this piece of code can be unified, but that can be done in separate PRs. #closed

DistroBasedOn='amazonlinux'
else
DistroBasedOn='redhat'
fi
elif [ -f /etc/SuSE-release ] ; then
DistroBasedOn='suse'
PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
REV=`cat /etc/SuSE-release | grep 'VERSION' | sed s/.*=\ //`
elif [ -f /etc/mandrake-release ] ; then
DistroBasedOn='mandrake'
PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
elif [ -f /etc/debian_version ] ; then
DistroBasedOn='debian'
DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'`
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
fi
if [ -f /etc/UnitedLinux-release ] ; then
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
fi
OS=`lowercase $OS`
DistroBasedOn=`lowercase $DistroBasedOn`
readonly OS
readonly DIST
readonly DistroBasedOn
readonly PSUEDONAME
readonly REV
readonly KERNEL
readonly MACH
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

#Only do SUDO if we are not root
SUDO=''
if (( $EUID != 0 )); then
SUDO='sudo'
fi

#Check that sudo is available
if [[ "$SUDO" -eq "sudo" ]]; then

$SUDO -v
if [ $? -ne 0 ]; then
echo "ERROR: You must either be root or be able to use sudo" >&2
exit 5
fi
fi

#Collect any variation details if required for this distro

#END Verify The Installer Choice

echo
echo "*** Installing prerequisites for PowerShell Core..."
$SUDO yum install -y \
curl \
libunwind \
libicu \
libcurl \
openssl \
libuuid.x86_64 \
&& yum clean all

##END Check requirements and prerequisites

echo
echo "*** Installing PowerShell Core for $DistroBasedOn..."
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//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

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

echo "Installing PowerShell to /opt/microsoft/powershell/$release in overwrite mode"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add this line to installpsh-suse.sh too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this comment and the one below, they are about adding the ehco message to the same place in installpsh-suse.sh. Making this change won't need additional tests as it's just adding a log message. Could you please do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is made, squashed and pushed - but this PR is now showing as "closed" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DarwinJS The timeline of this PR shows that you closed it ... But I see you already opened a new PR.

## 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

## 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

pwsh -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME.
Run `"pwsh`" to start a PowerShell session."'

success=$?

if [[ "$success" != 0 ]]; then
echo "ERROR: PowerShell failed to install!" >&2
exit "$success"
fi

if [[ "'$*'" =~ includeide ]] ; then
echo
echo "Amazon Linux does not have a desktop manager to support vscode, ignoring -includeide"
fi

if [[ "'$*'" =~ -interactivetesting ]] ; then
echo
echo "Amazon Linux does not have a desktop manager to support vscode, ignoring -includeide"
fi

if [[ "$repobased" == true ]] ; then
echo "*** NOTE: Run your regular package manager update cycle to update PowerShell Core"
else
echo "*** NOTE: Re-run this script to update PowerShell Core"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be added to installpsh-suse.sh too.

fi
echo "*** Install Complete"
4 changes: 2 additions & 2 deletions tools/installpsh-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
#bash <(wget -O - https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/pshcoredevenv-debian.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
#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>

#Usage - if you do not have the ability to run scripts directly from the web,
# pull all files in this repo folder and execute, this script
Expand Down
4 changes: 2 additions & 2 deletions tools/installpsh-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
#bash <(wget -O - https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/pshcoredevenv-debian.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
#bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-osx.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-osx.sh) <ARGUMENTS>

#Usage - if you do not have the ability to run scripts directly from the web,
# pull all files in this repo folder and execute, this script
Expand Down
6 changes: 3 additions & 3 deletions tools/installpsh-redhat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
#bash <(wget -O - https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/pshcoredevenv-debian.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
#bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-redhat.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/installpsh-redhat.sh) <ARGUMENTS>

#Usage - if you do not have the ability to run scripts directly from the web,
# pull all files in this repo folder and execute, this script
Expand Down Expand Up @@ -144,7 +144,7 @@ if [[ "'$*'" =~ includeide ]] ; then
echo "*** Installing VS Code PowerShell IDE..."
echo "*** Setting up VS Code repo..."
$SUDO rpm --import https://packages.microsoft.com/keys/microsoft.asc
$SUDO sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
$SUDO sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
yum check-update
$SUDO yum install -y code

Expand Down
6 changes: 3 additions & 3 deletions tools/installpsh-suse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#Companion code for the blog https://cloudywindows.com
#call this code direction from the web with:
#bash <(wget -O - https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/pshcoredevenv-debian.sh) ARGUMENTS
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
#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>

#Usage - if you do not have the ability to run scripts directly from the web,
# pull all files in this repo folder and execute, this script
Expand Down Expand Up @@ -169,7 +169,7 @@ $SUDO tar zxf $package -C /opt/microsoft/powershell/$release
## 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 -s /opt/microsoft/powershell/$release/pwsh $pwshlink
$SUDO ln -sfn /opt/microsoft/powershell/$release/pwsh $pwshlink

## Add the symbolic link path to /etc/shells
if [ ! -f /etc/shells ] ; then
Expand Down