Skip to content

Instantly share code, notes, and snippets.

@kesslerdev
Last active January 19, 2019 14:32
Show Gist options
  • Save kesslerdev/9803173550cf5bce4f94c0b6b80e064d to your computer and use it in GitHub Desktop.
Save kesslerdev/9803173550cf5bce4f94c0b6b80e064d to your computer and use it in GitHub Desktop.
execute remote powershell

use this onliner for installing Ubuntu on Windows 10 (WSL)

. { Invoke-WebRequest -useb https://gist.githubusercontent.com/kesslerdev/9803173550cf5bce4f94c0b6b80e064d/raw/install.ps1 } | Invoke-Expression

and when bash is available,

curl -o- https://gist.githubusercontent.com/kesslerdev/9803173550cf5bce4f94c0b6b80e064d/raw/install.sh | bash
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Relaunch as an elevated process:
Start-Process powershell.exe ". { Invoke-WebRequest -useb https://gist.githubusercontent.com/kesslerdev/9803173550cf5bce4f94c0b6b80e064d/raw/install.ps1 } | Invoke-Expression" -Verb RunAs
exit
}
# enable WSL
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux;
Start-Process wslconfig.exe /u Ubuntu;
Remove-Item C:\Distros\Ubuntu -Force;
# install ubuntu 1804
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.zip -UseBasicParsing;
Expand-Archive Ubuntu.zip C:\Distros\Ubuntu;
Start-Process C:\Distros\Ubuntu\ubuntu.exe;
#!/usr/bin/env bash
if grep -q Microsoft /proc/version; then
echo "Ubuntu on Windows (WSL)"
WSL=1
else
echo "native Linux"
fi
read -s -r -p "Enter Password for sudo: " sudoPW
echo
## git
if ! [ -e ~/.ssh/id_rsa ]; then
EMAIL="[email protected]"
GIT_SSH="https://github.com/settings/ssh/new"
ssh-keygen -t rsa -b 4096 -C "$EMAIL" -f ~/.ssh/id_rsa -q -N ""
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
if [ -n "$WSL" ]; then
clip.exe < ~/.ssh/id_rsa.pub
explorer.exe "$GIT_SSH"
else
echo "$sudoPW" | sudo -S apt-get install -y xclip
xclip -sel clip < ~/.ssh/id_rsa.pub # or cat
xdg-open "$GIT_SSH"
fi
git config --global user.name "Kessler dev"
git config --global user.email "$EMAIL"
fi
## fish
if ! hash fish 2>/dev/null; then
echo "$sudoPW" | sudo -S apt-add-repository -y ppa:fish-shell/release-2
echo "$sudoPW" | sudo -S apt-get update
echo "$sudoPW" | sudo -S apt-get install -y fish
fi
if ! [ -d ~/.local/share/omf ]; then
bash -c "curl -L https://get.oh-my.fish | fish"
fi
if ! [ -d ~/.local/share/omf/themes/bobthefish ]; then
fish -c "omf install bobthefish"
fi
FONT_URI="https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/FiraMono/Regular/complete/Fura%20Mono%20Regular%20Nerd%20Font%20Complete%20Mono.otf?raw=true"
if [ -n "$WSL" ]; then
if ! [ -e /mnt/c/Fura-Mono-Regular.otf ]; then
echo "$sudoPW" | curl -L "$FONT_URI" -o /mnt/c/Fura-Mono-Regular.otf
explorer.exe "c:\Fura-Mono-Regular.otf"
fi
else
if ! [ -e /usr/local/share/fonts/Fura-Mono-Regular.otf ]; then
echo "$sudoPW" | sudo -S mkdir -p /usr/local/share/fonts
echo "$sudoPW" | sudo -S curl -L "$FONT_URI" -o /usr/local/share/fonts/Fura-Mono-Regular.otf
gsettings set org.gnome.desktop.interface monospace-font-name 'FuraMono Nerd Font Mono 11'
fi
fi
if ! [ -d ~/.nvm ]; then
bash -c "PROFILE=/dev/null curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash"
sed -i -e 's/\. "\$NVM_DIR\/nvm\.sh"/\. "\$NVM_DIR\/nvm\.sh" "--no-use"/g' ~/.bashrc
export NVM_DIR="$HOME/.nvm"
# shellcheck source=/dev/null
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install node
NODE_PATH=$(dirname "$(command -v node)")
echo "PATH=\"$NODE_PATH:\$PATH\"" >> ~/.profile
npm install -g yarn
### add yarn global to bashprofile
cat <<EOT >> ~/.profile
# set PATH so it includes yarn bin if it exists
if [ -d "\$HOME/.yarn/bin" ] ; then
PATH="\$HOME/.yarn/bin:\$PATH"
fi
EOT
### global yarn
yarn global add serverless
fi
## python
if ! hash pip 2>/dev/null; then
echo "$sudoPW" | sudo -S apt-get install -y python
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py --user
rm get-pip.py
fi
if ! hash aws 2>/dev/null; then
pip install awscli --upgrade --user
mkdir -p ~/.aws
cat <<EOT > ~/.aws/config
[default]
output = json
region = eu-central-1
EOT
AWS_CONSOLE="https://console.aws.amazon.com/"
if [ -n "$WSL" ]; then
explorer.exe "$AWS_CONSOLE"
else
xdg-open "$AWS_CONSOLE"
fi
fi
if ! hash java 2>/dev/null; then
## java
echo "$sudoPW" | sudo -S apt-get install -y default-jre
### add java to bashprofile
cat <<EOT >> ~/.profile
# set JAVA
export JAVA_HOME="/usr/lib/jvm/default-java"
export PATH=\$JAVA_HOME/bin:\$PATH
EOT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment