Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
!cli
!cmd
!pkg
!install
!.github
!scripts
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
ENV GOTOOLCHAIN=local
COPY --link --from=xx / /
RUN apk add --no-cache bash clang lld llvm file git git-daemon
RUN apk add --no-cache bash clang lld llvm file git git-daemon ca-certificates
WORKDIR /go/src/wpm

FROM build-base-alpine AS build-alpine
Expand Down Expand Up @@ -53,4 +53,5 @@ RUN --mount=type=bind,target=.,ro \

FROM scratch AS binary
COPY --from=build /out .
CMD [ "./wpm" ]
COPY --from=build-base-alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ENTRYPOINT [ "./wpm" ]
78 changes: 78 additions & 0 deletions install/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Usage:
# powershell -ExecutionPolicy ByPass -File install.ps1
# powershell -ExecutionPolicy ByPass -File install.ps1 -Version v1.0.0

param (
[string]$Version
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

function Show-Error { param([string]$Msg); Write-Host "error: $Msg" -ForegroundColor Red }
function Show-Success { param([string]$Msg); Write-Host "$Msg" -ForegroundColor Green }
function Show-Info { param([string]$Msg); Write-Host "$Msg" -ForegroundColor Gray }
function Show-Bold { param([string]$Msg); Write-Host "$Msg" -ForegroundColor White }

$Arch = $env:PROCESSOR_ARCHITECTURE
$Target = ""

if ($Arch -eq "AMD64") {
$Target = "windows-amd64"
} elseif ($Arch -eq "ARM64") {
$Target = "windows-arm64"
} else {
Show-Error "Unsupported architecture: $Arch"
exit 1
}

$GitHubOrg = "trywpm"
$Repo = "cli"
$ExeName = "wpm.exe"
# Install to %LocalAppData%\wpm (Standard user-level location)
$InstallDir = Join-Path $env:LOCALAPPDATA "wpm"
$ExePath = Join-Path $InstallDir $ExeName

$BaseUrl = "https://github.com/$GitHubOrg/$Repo/releases"
$BinaryName = "wpm-$Target.exe"

if ([string]::IsNullOrEmpty($Version)) {
$Uri = "$BaseUrl/latest/download/$BinaryName"
} else {
$Uri = "$BaseUrl/download/$Version/$BinaryName"
}

try {
Show-Info "Installing wpm for $Target..."

if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
}

Show-Info "Downloading from $Uri..."
Invoke-WebRequest -Uri $Uri -OutFile $ExePath

# Check if InstallDir is in the User's persistent Path
$UserPathArgs = "Path", "User"
$CurrentPath = [Environment]::GetEnvironmentVariable($UserPathArgs)

if (($CurrentPath -split ';') -notcontains $InstallDir) {
Show-Info "Adding $InstallDir to User PATH..."

# Add to persistent Registry PATH
[Environment]::SetEnvironmentVariable("Path", "$CurrentPath;$InstallDir", "User")

$env:Path += ";$InstallDir"
}

Write-Host ""
Show-Success "wpm installed to $ExePath"

Write-Host ""
Show-Info "To get started, run:"
Write-Host ""
Show-Bold " wpm --help"
} catch {
Show-Error $_.Exception.Message
exit 1
}
136 changes: 136 additions & 0 deletions install/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env bash
set -euo pipefail

# Reset
Color_Off=''

# Regular Colors
Red=''
Green=''
Dim='' # White

# Bold
Bold_White=''
Bold_Green=''

if [[ -t 1 ]]; then
# Reset
Color_Off='\033[0m' # Text Reset

# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Dim='\033[0;2m' # White

# Bold
Bold_Green='\033[1;32m' # Bold Green
Bold_White='\033[1m' # Bold White
fi

error() {
echo -e "${Red}error${Color_Off}:" "$@" >&2
exit 1
}

info() {
echo -e "${Dim}$@ ${Color_Off}"
}

info_bold() {
echo -e "${Bold_White}$@ ${Color_Off}"
}

success() {
echo -e "${Green}$@ ${Color_Off}"
}

if [[ $# -gt 1 ]]; then
error 'Usage: install.sh [version]'
fi

platform=$(uname -ms)

case $platform in
*'MINGW'* | *'CYGWIN'* | *'MSYS'* | 'Windows_NT'*)
error "Please run \`powershell -c \"irm wpm.so/install.ps1|iex\"\` to install wpm on Windows systems."
;;
esac

case $platform in
# --- macOS ---
'Darwin x86_64')
target="darwin-amd64"
;;
'Darwin arm64')
target="darwin-arm64"
;;

# --- Linux ---
'Linux x86_64')
target="linux-amd64"
;;
'Linux aarch64' | 'Linux arm64')
target="linux-arm64"
;;
'Linux armv7'*)
target="linux-arm-v7"
;;
'Linux armv6'*)
target="linux-arm-v6"
;;
'Linux ppc64le')
target="linux-ppc64le"
;;
'Linux riscv64')
target="linux-riscv64"
;;
'Linux s390x')
target="linux-s390x"
;;

# --- Unsupported ---
*)
error "Unsupported platform: $platform"
exit 1
;;
esac

if [[ $target = darwin-amd64 ]]; then
# Is this process running in Rosetta?
# redirect stderr to devnull to avoid error message when not running in Rosetta
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
target=darwin-arm64
info "Your shell is running in Rosetta 2. Downloading wpm for $target instead"
fi
fi

GITHUB=${GITHUB-"https://github.com"}

github_repo="$GITHUB/trywpm/cli"

exe_name=wpm
bin_dir="/usr/local/bin"
exe="$bin_dir/$exe_name"

if [[ $# = 0 ]]; then
wpm_uri=$github_repo/releases/latest/download/wpm-$target
else
wpm_uri=$github_repo/releases/download/$1/wpm-$target
fi

curl --fail --location --progress-bar --output "/tmp/$exe_name" "$wpm_uri" ||
error "Failed to download wpm from \"$wpm_uri\""

chmod +x "/tmp/$exe_name" ||
error 'Failed to make wpm executable'

sudo mv "/tmp/$exe_name" "$exe" ||
Comment thread
thelovekesh marked this conversation as resolved.
Resolved
error 'Failed to move extracted wpm to destination'

echo
success "wpm installed to ${Bold_Green}$exe${Color_Off}"

echo
info "To get started, run:"
echo
info_bold " wpm --help"