Skip to content

Commit 292627e

Browse files
authored
Add install scripts (#148)
1 parent 1f696d6 commit 292627e

File tree

4 files changed

+218
-2
lines changed

4 files changed

+218
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
!cli
1919
!cmd
2020
!pkg
21+
!install
2122
!.github
2223
!scripts

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
1515
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-base-alpine
1616
ENV GOTOOLCHAIN=local
1717
COPY --link --from=xx / /
18-
RUN apk add --no-cache bash clang lld llvm file git git-daemon
18+
RUN apk add --no-cache bash clang lld llvm file git git-daemon ca-certificates
1919
WORKDIR /go/src/wpm
2020

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

5454
FROM scratch AS binary
5555
COPY --from=build /out .
56-
CMD [ "./wpm" ]
56+
COPY --from=build-base-alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
57+
ENTRYPOINT [ "./wpm" ]

install/install.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Usage:
2+
# powershell -ExecutionPolicy ByPass -File install.ps1
3+
# powershell -ExecutionPolicy ByPass -File install.ps1 -Version v1.0.0
4+
5+
param (
6+
[string]$Version
7+
)
8+
9+
$ErrorActionPreference = 'Stop'
10+
Set-StrictMode -Version Latest
11+
12+
function Show-Error { param([string]$Msg); Write-Host "error: $Msg" -ForegroundColor Red }
13+
function Show-Success { param([string]$Msg); Write-Host "$Msg" -ForegroundColor Green }
14+
function Show-Info { param([string]$Msg); Write-Host "$Msg" -ForegroundColor Gray }
15+
function Show-Bold { param([string]$Msg); Write-Host "$Msg" -ForegroundColor White }
16+
17+
$Arch = $env:PROCESSOR_ARCHITECTURE
18+
$Target = ""
19+
20+
if ($Arch -eq "AMD64") {
21+
$Target = "windows-amd64"
22+
} elseif ($Arch -eq "ARM64") {
23+
$Target = "windows-arm64"
24+
} else {
25+
Show-Error "Unsupported architecture: $Arch"
26+
exit 1
27+
}
28+
29+
$GitHubOrg = "trywpm"
30+
$Repo = "cli"
31+
$ExeName = "wpm.exe"
32+
# Install to %LocalAppData%\wpm (Standard user-level location)
33+
$InstallDir = Join-Path $env:LOCALAPPDATA "wpm"
34+
$ExePath = Join-Path $InstallDir $ExeName
35+
36+
$BaseUrl = "https://github.com/$GitHubOrg/$Repo/releases"
37+
$BinaryName = "wpm-$Target.exe"
38+
39+
if ([string]::IsNullOrEmpty($Version)) {
40+
$Uri = "$BaseUrl/latest/download/$BinaryName"
41+
} else {
42+
$Uri = "$BaseUrl/download/$Version/$BinaryName"
43+
}
44+
45+
try {
46+
Show-Info "Installing wpm for $Target..."
47+
48+
if (-not (Test-Path $InstallDir)) {
49+
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
50+
}
51+
52+
Show-Info "Downloading from $Uri..."
53+
Invoke-WebRequest -Uri $Uri -OutFile $ExePath
54+
55+
# Check if InstallDir is in the User's persistent Path
56+
$UserPathArgs = "Path", "User"
57+
$CurrentPath = [Environment]::GetEnvironmentVariable($UserPathArgs)
58+
59+
if (($CurrentPath -split ';') -notcontains $InstallDir) {
60+
Show-Info "Adding $InstallDir to User PATH..."
61+
62+
# Add to persistent Registry PATH
63+
[Environment]::SetEnvironmentVariable("Path", "$CurrentPath;$InstallDir", "User")
64+
65+
$env:Path += ";$InstallDir"
66+
}
67+
68+
Write-Host ""
69+
Show-Success "wpm installed to $ExePath"
70+
71+
Write-Host ""
72+
Show-Info "To get started, run:"
73+
Write-Host ""
74+
Show-Bold " wpm --help"
75+
} catch {
76+
Show-Error $_.Exception.Message
77+
exit 1
78+
}

install/install.sh

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Reset
5+
Color_Off=''
6+
7+
# Regular Colors
8+
Red=''
9+
Green=''
10+
Dim='' # White
11+
12+
# Bold
13+
Bold_White=''
14+
Bold_Green=''
15+
16+
if [[ -t 1 ]]; then
17+
# Reset
18+
Color_Off='\033[0m' # Text Reset
19+
20+
# Regular Colors
21+
Red='\033[0;31m' # Red
22+
Green='\033[0;32m' # Green
23+
Dim='\033[0;2m' # White
24+
25+
# Bold
26+
Bold_Green='\033[1;32m' # Bold Green
27+
Bold_White='\033[1m' # Bold White
28+
fi
29+
30+
error() {
31+
echo -e "${Red}error${Color_Off}:" "$@" >&2
32+
exit 1
33+
}
34+
35+
info() {
36+
echo -e "${Dim}$@ ${Color_Off}"
37+
}
38+
39+
info_bold() {
40+
echo -e "${Bold_White}$@ ${Color_Off}"
41+
}
42+
43+
success() {
44+
echo -e "${Green}$@ ${Color_Off}"
45+
}
46+
47+
if [[ $# -gt 1 ]]; then
48+
error 'Usage: install.sh [version]'
49+
fi
50+
51+
platform=$(uname -ms)
52+
53+
case $platform in
54+
*'MINGW'* | *'CYGWIN'* | *'MSYS'* | 'Windows_NT'*)
55+
error "Please run \`powershell -c \"irm wpm.so/install.ps1|iex\"\` to install wpm on Windows systems."
56+
;;
57+
esac
58+
59+
case $platform in
60+
# --- macOS ---
61+
'Darwin x86_64')
62+
target="darwin-amd64"
63+
;;
64+
'Darwin arm64')
65+
target="darwin-arm64"
66+
;;
67+
68+
# --- Linux ---
69+
'Linux x86_64')
70+
target="linux-amd64"
71+
;;
72+
'Linux aarch64' | 'Linux arm64')
73+
target="linux-arm64"
74+
;;
75+
'Linux armv7'*)
76+
target="linux-arm-v7"
77+
;;
78+
'Linux armv6'*)
79+
target="linux-arm-v6"
80+
;;
81+
'Linux ppc64le')
82+
target="linux-ppc64le"
83+
;;
84+
'Linux riscv64')
85+
target="linux-riscv64"
86+
;;
87+
'Linux s390x')
88+
target="linux-s390x"
89+
;;
90+
91+
# --- Unsupported ---
92+
*)
93+
error "Unsupported platform: $platform"
94+
exit 1
95+
;;
96+
esac
97+
98+
if [[ $target = darwin-amd64 ]]; then
99+
# Is this process running in Rosetta?
100+
# redirect stderr to devnull to avoid error message when not running in Rosetta
101+
if [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; then
102+
target=darwin-arm64
103+
info "Your shell is running in Rosetta 2. Downloading wpm for $target instead"
104+
fi
105+
fi
106+
107+
GITHUB=${GITHUB-"https://github.com"}
108+
109+
github_repo="$GITHUB/trywpm/cli"
110+
111+
exe_name=wpm
112+
bin_dir="/usr/local/bin"
113+
exe="$bin_dir/$exe_name"
114+
115+
if [[ $# = 0 ]]; then
116+
wpm_uri=$github_repo/releases/latest/download/wpm-$target
117+
else
118+
wpm_uri=$github_repo/releases/download/$1/wpm-$target
119+
fi
120+
121+
curl --fail --location --progress-bar --output "/tmp/$exe_name" "$wpm_uri" ||
122+
error "Failed to download wpm from \"$wpm_uri\""
123+
124+
chmod +x "/tmp/$exe_name" ||
125+
error 'Failed to make wpm executable'
126+
127+
sudo mv "/tmp/$exe_name" "$exe" ||
128+
error 'Failed to move extracted wpm to destination'
129+
130+
echo
131+
success "wpm installed to ${Bold_Green}$exe${Color_Off}"
132+
133+
echo
134+
info "To get started, run:"
135+
echo
136+
info_bold " wpm --help"

0 commit comments

Comments
 (0)