Skip to content

Commit c31f274

Browse files
DarwinJSTravisEz13
authored andcommitted
install-powershell.sh
updating for pull request comments OSX Install script updated to use repositories Using TR, use curl rather than wget since we ensured it is on the system Update comments in install-powershell.sh install-powershell.sh
1 parent 4df979a commit c31f274

5 files changed

Lines changed: 847 additions & 0 deletions

File tree

tools/install-powershell.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash
2+
3+
#Companion code for the blog https://cloudywindows.com
4+
5+
#call this code direction from the web with:
6+
#bash <(wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
7+
#wget -O - https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh | bash -s <ARGUMENTS>
8+
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
9+
10+
11+
#Usage - if you do not have the ability to run scripts directly from the web,
12+
# pull all files in this repo folder and execute, this script
13+
# automatically prefers local copies of sub-scripts
14+
15+
#Completely automated install requires a root account or sudo with a password requirement
16+
17+
#Switches
18+
# -includeide - the script is being run headless, do not perform actions that require response from the console
19+
# -interactivetesting - 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
20+
# -appimage - does appimage instead of native install
21+
22+
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
23+
24+
VERSION="1.1.0"
25+
gitreposubpath="PowerShell/PowerShell/master"
26+
gitreposubpath="darwinjs/PowerShell/feature/install-powershell.sh"
27+
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
28+
gitscriptname="install-powershell.psh"
29+
30+
echo "Get-PowerShell Core MASTER Installer Version $VERSION"
31+
echo "Installs PowerShell Core and Optional The Development Environment"
32+
echo " Original script is at: $gitreposcriptroot\$gitscriptname"
33+
34+
echo "Arguments used: $*"
35+
echo ""
36+
37+
# Let's quit on interrupt of subcommands
38+
trap '
39+
trap - INT # restore default INT handler
40+
echo "Interrupted"
41+
kill -s INT "$$"
42+
' INT
43+
44+
lowercase(){
45+
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
46+
}
47+
48+
OS=`lowercase \`uname\``
49+
KERNEL=`uname -r`
50+
MACH=`uname -m`
51+
52+
if [ "${OS}" == "windowsnt" ]; then
53+
OS=windows
54+
DistroBasedOn=windows
55+
elif [ "${OS}" == "darwin" ]; then
56+
OS=osx
57+
DistroBasedOn=osx
58+
else
59+
OS=`uname`
60+
if [ "${OS}" == "SunOS" ] ; then
61+
OS=solaris
62+
ARCH=`uname -p`
63+
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
64+
DistroBasedOn=sunos
65+
elif [ "${OS}" == "AIX" ] ; then
66+
OSSTR="${OS} `oslevel` (`oslevel -r`)"
67+
DistroBasedOn=aix
68+
elif [ "${OS}" == "Linux" ] ; then
69+
if [ -f /etc/redhat-release ] ; then
70+
DistroBasedOn='redhat'
71+
DIST=`cat /etc/redhat-release |sed s/\ release.*//`
72+
PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
73+
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
74+
elif [ -f /etc/SuSE-release ] ; then
75+
DistroBasedOn='suse'
76+
PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
77+
REV=`cat /etc/SuSE-release | grep 'VERSION' | sed s/.*=\ //`
78+
elif [ -f /etc/mandrake-release ] ; then
79+
DistroBasedOn='mandrake'
80+
PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
81+
REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
82+
elif [ -f /etc/debian_version ] ; then
83+
DistroBasedOn='debian'
84+
DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
85+
PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'`
86+
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
87+
fi
88+
if [ -f /etc/UnitedLinux-release ] ; then
89+
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
90+
fi
91+
OS=`lowercase $OS`
92+
DistroBasedOn=`lowercase $DistroBasedOn`
93+
readonly OS
94+
readonly DIST
95+
readonly DistroBasedOn
96+
readonly PSUEDONAME
97+
readonly REV
98+
readonly KERNEL
99+
readonly MACH
100+
fi
101+
102+
fi
103+
104+
echo "Operating System Details:"
105+
echo " OS: $OS"
106+
echo " DIST: $DIST"
107+
echo " DistroBasedOn: $DistroBasedOn"
108+
echo " PSUEDONAME: $PSUEDONAME"
109+
echo " REV: $REV"
110+
echo " KERNEL: $KERNEL"
111+
echo " MACH: $MACH"
112+
113+
SCRIPTFOLDER=$(dirname $(readlink -f $0))
114+
115+
if [[ "'$*'" =~ appimage ]] ; then
116+
if [ -f $SCRIPTFOLDER/appimage.sh ]; then
117+
#Script files were copied local - use them
118+
. $SCRIPTFOLDER/appimage.sh
119+
else
120+
#Script files are not local - pull from remote
121+
echo "Could not find \"appimage.sh\" next to this script..."
122+
echo "Pulling it from \"$gitreposcriptroot/appimage.sh\""
123+
bash <(wget -qO- $gitreposcriptroot/appimage.sh) $@
124+
fi
125+
elif [ "$DistroBasedOn" == "redhat" ] || [ "$DistroBasedOn" == "debian" ] || [ "$DistroBasedOn" == "osx" ] || [ "$DistroBasedOn" == "suse" ]; then
126+
echo "Configuring PowerShell Core Enviornment for: $DistroBasedOn $DIST $REV"
127+
if [ -f $SCRIPTFOLDER/installpsh-$DistroBasedOn.sh ]; then
128+
#Script files were copied local - use them
129+
. $SCRIPTFOLDER/installpsh-$DistroBasedOn.sh
130+
else
131+
#Script files are not local - pull from remote
132+
echo "Could not find \"installpsh-$DistroBasedOn.sh\" next to this script..."
133+
echo "Pulling it from \"$gitreposcriptroot/installpsh-$DistroBasedOn.sh\""
134+
bash <(wget -qO- $gitreposcriptroot/installpsh-$DistroBasedOn.sh) $@
135+
fi
136+
else
137+
echo "Sorry, your operating system is based on $DistroBasedOn and is not supported by PowerShell Core or this installer at this time."
138+
fi
139+

tools/installpsh-debian.sh

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/bin/bash
2+
3+
#Companion code for the blog https://cloudywindows.com
4+
#call this code direction from the web with:
5+
#bash <(wget -O - https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/pshcoredevenv-debian.sh) ARGUMENTS
6+
#bash <(curl -s https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.sh) <ARGUMENTS>
7+
8+
#Usage - if you do not have the ability to run scripts directly from the web,
9+
# pull all files in this repo folder and execute, this script
10+
# automatically prefers local copies of sub-scripts
11+
12+
#Completely automated install requires a root account or sudo with a password requirement
13+
14+
#Switches
15+
# -includeide - the script is being run headless, do not perform actions that require response from the console
16+
# -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
17+
18+
#gitrepo paths are overrideable to run from your own fork or branch for testing or private distribution
19+
20+
21+
VERSION="1.1.2"
22+
gitreposubpath="PowerShell/PowerShell/master"
23+
gitreposubpath="darwinjs/PowerShell/feature/install-powershell.sh"
24+
gitreposcriptroot="https://raw.githubusercontent.com/$gitreposubpath/tools"
25+
thisinstallerdistro=debian
26+
repobased=true
27+
gitscriptname="installpsh-debian.psh"
28+
29+
echo ;
30+
echo "*** PowerShell Core Development Environment Installer $VERSION for $thisinstallerdistro"
31+
echo "*** Current PowerShell Core Version: $currentpshversion"
32+
echo "*** Original script is at: $gitreposcriptroot/$gitscriptname"
33+
echo
34+
echo "*** Arguments used: $*"
35+
36+
#Verify The Installer Choice (for direct runs of this script)
37+
lowercase(){
38+
#echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
39+
echo "$1" | tr [A-Z] [a-z]
40+
}
41+
42+
# Let's quit on interrupt of subcommands
43+
trap '
44+
trap - INT # restore default INT handler
45+
echo "Interrupted"
46+
kill -s INT "$$"
47+
' INT
48+
49+
if [ "${OS}" == "windowsnt" ]; then
50+
OS=windows
51+
DistroBasedOn=windows
52+
elif [ "${OS}" == "darwin" ]; then
53+
OS=osx
54+
DistroBasedOn=osx
55+
else
56+
OS=`uname`
57+
if [ "${OS}" == "SunOS" ] ; then
58+
OS=solaris
59+
ARCH=`uname -p`
60+
OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
61+
DistroBasedOn=sunos
62+
elif [ "${OS}" == "AIX" ] ; then
63+
OSSTR="${OS} `oslevel` (`oslevel -r`)"
64+
DistroBasedOn=aix
65+
elif [ "${OS}" == "Linux" ] ; then
66+
if [ -f /etc/redhat-release ] ; then
67+
DistroBasedOn='redhat'
68+
elif [ -f /etc/SuSE-release ] ; then
69+
DistroBasedOn='suse'
70+
elif [ -f /etc/mandrake-release ] ; then
71+
DistroBasedOn='mandrake'
72+
elif [ -f /etc/debian_version ] ; then
73+
DistroBasedOn='debian'
74+
fi
75+
if [ -f /etc/UnitedLinux-release ] ; then
76+
DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
77+
DistroBasedOn=unitedlinux
78+
fi
79+
OS=`lowercase $OS`
80+
DistroBasedOn=`lowercase $DistroBasedOn`
81+
fi
82+
fi
83+
84+
if [ "$DistroBasedOn" != "$thisinstallerdistro" ]; then
85+
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."
86+
exit 0
87+
fi
88+
89+
## Check requirements and prerequisites
90+
91+
#Only do SUDO if we are not root
92+
SUDO=''
93+
if (( $EUID != 0 )); then
94+
SUDO='sudo'
95+
fi
96+
97+
#Check that sudo is available
98+
if [[ "$SUDO" -eq "sudo" ]]; then
99+
100+
$SUDO -v
101+
if [ $? -ne 0 ]; then
102+
echo "ERROR: You must either be root or be able to use sudo" >&2
103+
exit 5
104+
fi
105+
fi
106+
107+
#Collect any variation details if required for this distro
108+
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
109+
#END Collect any variation details if required for this distro
110+
111+
#If there are known incompatible versions of this distro, put the test, message and script exit here:
112+
113+
#END Verify The Installer Choice
114+
115+
##END Check requirements and prerequisites
116+
117+
echo
118+
echo "*** Installing PowerShell Core for $DistroBasedOn..."
119+
if ! hash curl 2>/dev/null; then
120+
echo "curl not found, installing..."
121+
$SUDO apt-get install -y curl
122+
fi
123+
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`
124+
125+
echo "*** Current version on git is: $currentversion, repo version may differ slightly..."
126+
echo "*** Setting up PowerShell Core repo..."
127+
# Import the public repository GPG keys
128+
curl https://packages.microsoft.com/keys/microsoft.asc | $SUDO apt-key add -
129+
#Add the Repo
130+
curl https://packages.microsoft.com/config/ubuntu/$REV/prod.list | $SUDO tee /etc/apt/sources.list.d/microsoft.list
131+
# Update apt-get
132+
$SUDO apt-get update
133+
# Install PowerShell
134+
$SUDO apt-get install -y powershell
135+
136+
powershell -noprofile -c '"Congratulations! PowerShell is installed at $PSHOME"'
137+
success=$?
138+
139+
if [[ "$success" != 0 ]]; then
140+
echo "ERROR: PowerShell failed to install!" >&2
141+
exit "$success"
142+
fi
143+
144+
if [[ "'$*'" =~ includeide ]] ; then
145+
echo
146+
echo "*** Installing VS Code PowerShell IDE..."
147+
echo "*** Setting up VS Code repo..."
148+
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
149+
$SUDO mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
150+
$SUDO sh -c 'echo "deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
151+
$SUDO apt-get update
152+
$SUDO apt-get install -y code
153+
154+
echo
155+
echo "*** Installing VS Code PowerShell Extension"
156+
code --install-extension ms-vscode.PowerShell
157+
fi
158+
159+
if [[ "'$*'" =~ -interactivetesting ]] ; then
160+
echo "*** Loading test code in VS Code"
161+
curl -O ./testpowershell.ps1 https://raw.githubusercontent.com/DarwinJS/CloudyWindowsAutomationCode/master/pshcoredevenv/testpowershell.ps1
162+
code ./testpowershell.ps1
163+
fi
164+
165+
if [[ "$repobased" == true ]] ; then
166+
echo
167+
echo "*** NOTE: Run your regular package manager update cycle to update PowerShell Core\n"
168+
fi
169+
echo "*** Install Complete"

0 commit comments

Comments
 (0)