Forked from guillemcanal/Microsoft.PowerShell_profile.ps1
Created
February 23, 2022 22:14
-
-
Save c0ns0le/107756636f31c43efd1193c43d09fef7 to your computer and use it in GitHub Desktop.
Boxstarter Install Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Open an elevated PowerShell prompt and set execution policy | |
# Set-ExecutionPolicy Unrestricted -Force | |
# Step 2: Install Boxstarter | |
# . { iwr -useb https://boxstarter.org/bootstrapper.ps1 } | iex; Get-Boxstarter -Force | |
# Step 3: Store your user credential (select your username name and provide your password in the dialog box) | |
# $cred=Get-Credential | |
# Step 4: Run the script | |
# Install-BoxstarterPackage -PackageName "https://gist.githubusercontent.com/guillemcanal/441cf4f0bf5da4ee7b84d778911eabba/raw/boxstarter.ps1" -Credential $cred | |
#--- Check Windows version --- | |
if ([Environment]::OSVersion.Version.Major -ne 10) { | |
Write-Error 'Upgrade to Windows 10 before running this script' | |
Exit | |
} | |
#--- Windows Update --- | |
Enable-UAC | |
Enable-MicrosoftUpdate | |
Install-WindowsUpdate -AcceptEula | |
#--- Check Windows Revision --- | |
if ((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ReleaseId -lt 2004) { | |
Write-Error 'You need to run Windows Update and install Feature Updates to at least version 2004' | |
Exit | |
} | |
#--- Termporarily disable --- | |
Disable-MicrosoftUpdate | |
Disable-UAC | |
#--- Windows Subsystems/Features --- | |
choco install -y Microsoft-Windows-Subsystem-Linux -source windowsfeatures | |
choco install -y VirtualMachinePlatform -source windowsfeatures | |
refreshenv | |
#--- Fonts | |
choco install -y cascadiacode | |
#--- Apps --- | |
choco install -y ` | |
wsl-alpine ` | |
firefox ` | |
docker-desktop ` | |
visualstudiocode ` | |
jetbrainstoolbox ` | |
microsoft-windows-terminal ` | |
starship ` | |
mkcert ` | |
sharex ` | |
spotify ` | |
wpd ` | |
vlc ` | |
qbittorrent ` | |
7zip ` | |
gsudo ` | |
googledrive | |
refreshenv | |
#--- Install WSL2 Kernel--- | |
$wslUpdateSource = "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" | |
$wslMsiArgs = @( | |
'/i', | |
$wslUpdateSource, | |
'/quiet', | |
'/norestart' | |
) | |
Start-Process -FilePath msiexec -ArgumentList $wslMsiArgs -NoNewWindow -Wait | |
#--- Setup WSL2 --- | |
wsl --set-default Alpine | |
wsl --set-version Alpine 2 | |
wsl --user root exec ` | |
sh -c '$(wget -O- https://gist.githubusercontent.com/guillemcanal/441cf4f0bf5da4ee7b84d778911eabba/raw/create-default-user.sh)' | |
wsl --user root exec ` | |
sh -c '$(wget -O- https://gist.githubusercontent.com/guillemcanal/441cf4f0bf5da4ee7b84d778911eabba/raw/glibc-install.sh)' | |
#--- Configure Powsershell --- | |
if(!(Test-Path -Path $profile)) { | |
New-item -type file -force $profile | |
} | |
Invoke-WebRequest ` | |
-Uri "https://gist.github.com/guillemcanal/441cf4f0bf5da4ee7b84d778911eabba/raw/Microsoft.PowerShell_profile.ps1" ` | |
-OutFile $profile | |
#--- Restore Temporary Settings --- | |
Enable-UAC | |
Enable-MicrosoftUpdate | |
Install-WindowsUpdate -AcceptEula | |
refreshenv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
set -ex | |
main() { | |
local USERNAME="user" | |
local PASSWORD="changeme" | |
apk -U add sudo vim git zsh curl libstdc++ | |
getent group sudo 1> /dev/null || { | |
addgroup -g 99 sudo | |
echo '%sudo ALL=(ALL) NOPASSWD: ALL' | sudo EDITOR='tee -a' visudo | |
} | |
id -u $USERNAME || { | |
adduser -u 1000 -D -s /bin/zsh $USERNAME | |
usermod -aG sudo $USERNAME | |
yes $PASSWORD | passwd $USERNAME | |
} | |
test -d "/home/$USERNAME/.oh-my-zsh" || { | |
su - $USERNAME -c 'sh -c "RUNZSH=no $(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' | |
} | |
Alpine.exe config --default-user $USERNAME | |
} | |
main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
set -e | |
get_latest_release_version() { | |
curl --silent "https://api.github.com/repos/$1/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | |
} | |
package_installed() { | |
apk info -vv | grep "$1" 1> /dev/null | |
} | |
main() { | |
local GITHUB_PROJECT="sgerrand/alpine-pkg-glibc" | |
local VERSION="$(get_latest_release_version "$GITHUB_PROJECT")" | |
local RELEASE_PUBKEY_PATH="/etc/apk/keys/sgerrand.rsa.pub" | |
local RELEASE_PATH="https://github.com/sgerrand/alpine-pkg-glibc/releases/download/$VERSION" | |
local DEFAULT_LANG="en_US" | |
[ -f "$RELEASE_PUBKEY_PATH" ] || { | |
sudo wget -q -O $RELEASE_PUBKEY_PATH https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub | |
} | |
package_installed glibc-$VERSION || { | |
sudo curl -s -OL $RELEASE_PATH/glibc-$VERSION.apk | |
sudo apk add glibc-$VERSION.apk | |
} | |
package_installed glibc-bin-$VERSION || { | |
sudo curl -s -OL $RELEASE_PATH/glibc-bin-${VERSION}.apk | |
sudo apk add glibc-bin-$VERSION.apk | |
} | |
package_installed glibc-i18n-$VERSION || { | |
sudo curl -s -OL $RELEASE_PATH/glibc-i18n-$VERSION.apk | |
sudo apk add glibc-i18n-$VERSION.apk | |
sudo /usr/glibc-compat/bin/localedef -i $DEFAULT_LANG -f UTF-8 $DEFAULT_LANG.UTF-8 | |
} | |
} | |
main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Styling | |
# Import-Module posh-git | |
# Import-Module oh-my-posh | |
# Set-Theme Robbyrussell | |
# See: https://github.com/felixrieseberg/windows-development-environment | |
# Increase history | |
$MaximumHistoryCount = 10000 | |
# Produce UTF-8 by default | |
$PSDefaultParameterValues["Out-File:Encoding"]="utf8" | |
# Show selection menu for tab | |
Set-PSReadlineKeyHandler -Chord Tab -Function MenuComplete | |
# Use Starship shell | |
$Env:STARSHIP_CONFIG = "$Env:USERPROFILE\.starship.toml" | |
Invoke-Expression (&starship init powershell) | |
# Go to the Alpine directory | |
function wsla { | |
Set-Location '\\wsl$\Alpine\home\gcanal' | |
} | |
function wsll { | |
wsl -l -v | |
} | |
function wsls { | |
wsl --shutdown | |
} | |
# Helper Functions | |
####################################################### | |
function reload-profile { | |
& $profile | |
} | |
function find-file($name) { | |
ls -recurse -filter "*${name}*" -ErrorAction SilentlyContinue | foreach { | |
$place_path = $_.directory | |
echo "${place_path}\${_}" | |
} | |
} | |
function print-path { | |
($Env:Path).Split(";") | |
} | |
function unzip ($file) { | |
$dirname = (Get-Item $file).Basename | |
echo("Extracting", $file, "to", $dirname) | |
New-Item -Force -ItemType directory -Path $dirname | |
expand-archive $file -OutputPath $dirname -ShowProgress | |
} | |
# Unixlike commands | |
####################################################### | |
function which($name) | |
{ | |
(Get-Command $name).Path | |
} | |
function df { | |
get-volume | |
} | |
function sed($file, $find, $replace){ | |
(Get-Content $file).replace("$find", $replace) | Set-Content $file | |
} | |
function sed-recursive($filePattern, $find, $replace) { | |
$files = ls . "$filePattern" -rec | |
foreach ($file in $files) { | |
(Get-Content $file.PSPath) | | |
Foreach-Object { $_ -replace "$find", "$replace" } | | |
Set-Content $file.PSPath | |
} | |
} | |
function grep($regex, $dir) { | |
if ( $dir ) { | |
ls $dir | select-string $regex | |
return | |
} | |
$input | select-string $regex | |
} | |
function grepv($regex) { | |
$input | ? { !$_.Contains($regex) } | |
} | |
function export($name, $value) { | |
set-item -force -path "env:$name" -value $value; | |
} | |
function pkill($name) { | |
ps $name -ErrorAction SilentlyContinue | kill | |
} | |
function pgrep($name) { | |
ps $name | |
} | |
function touch($file) { | |
"" | Out-File $file -Encoding ASCII | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment