Skip to content

Commit b70a179

Browse files
committed
feat: install scripts (sh + powershell)
1 parent a8dbac6 commit b70a179

File tree

3 files changed

+171
-3
lines changed

3 files changed

+171
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ Wokwi Simulation API command line interface.
66

77
Download the latest release from the [GitHub Releases page](https://github.com/wokwi/wokwi-cli/releases/latest). Rename the file to `wokwi-cli` (or `wokwi-cli.exe` on Windows), and put it in your `PATH`.
88

9-
On Linux (x64), the CLI can be installed using the following commands:
9+
On Linux and macOS, you can also install the CLI using the following command:
1010

1111
```bash
12-
sudo wget -O /usr/local/bin/wokwi-cli https://github.com/wokwi/wokwi-cli/releases/latest/download/wokwi-cli-linuxstatic-x64
13-
sudo chmod +x /usr/local/bin/wokwi-cli
12+
curl -L https://wokwi.com/ci/install.sh | sh
13+
```
14+
15+
And on Windows:
16+
17+
```powershell
18+
iwr https://wokwi.com/ci/install.ps1 -useb | iex
1419
```
1520

1621
## Usage

scripts/install.ps1

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env pwsh
2+
# Based on Flyctl installer.
3+
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
4+
# TODO(everyone): Keep this script simple and easily auditable.
5+
6+
$ErrorActionPreference = 'Stop'
7+
8+
$Version = if ($v) {
9+
$v
10+
}
11+
elseif ($args.Length -eq 1) {
12+
$args.Get(0)
13+
}
14+
else {
15+
"latest"
16+
}
17+
18+
$WokwiInstall = $env:WOKWI_INSTALL
19+
$BinDir = if ($WokwiInstall) {
20+
"$WokwiInstall\bin"
21+
}
22+
else {
23+
"$Home\.wokwi\bin"
24+
}
25+
26+
$TempExe = "$BinDir\wokwi-cli.exe.new"
27+
$WokwiCLIExe = "$BinDir\wokwi-cli.exe"
28+
29+
# GitHub require TLS 1.2
30+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
31+
32+
# Determine the URL for downloading wokwi-cli
33+
$WokwiUri = if ($Version -eq "latest") {
34+
"https://github.com/wokwi/wokwi-cli/releases/latest/download/wokwi-cli-win-x64.exe"
35+
}
36+
else {
37+
"https://github.com/wokwi/wokwi-cli/releases/download/v$Version/wokwi-cli-win-x64.exe"
38+
}
39+
40+
# Check if the URL is valid
41+
try {
42+
Invoke-WebRequest $WokwiUri -Method Head -UseBasicParsing | Out-Null
43+
}
44+
catch {
45+
$StatusCode = $_.Exception.Response.StatusCode.value__
46+
if ($StatusCode -eq 404) {
47+
Write-Error "Unable to find a wokwi-cli release on GitHub for version: $Version - see https://github.com/wokwi/wokwi-cli/releases for all versions"
48+
Exit 1
49+
}
50+
else {
51+
$Request = $_.Exception
52+
Write-Error "Error while fetching releases: $Request"
53+
Exit 1
54+
}
55+
}
56+
57+
if (!(Test-Path $BinDir)) {
58+
New-Item $BinDir -ItemType Directory | Out-Null
59+
}
60+
61+
$prevProgressPreference = $ProgressPreference
62+
try {
63+
# Invoke-WebRequest on older powershell versions has severe transfer
64+
# performance issues due to progress bar rendering - the screen updates
65+
# end up throttling the download itself. Disable progress on these older
66+
# versions.
67+
if ($PSVersionTable.PSVersion.Major -lt 7) {
68+
Write-Output "Downloading wokwi-cli..."
69+
$ProgressPreference = "SilentlyContinue"
70+
}
71+
72+
Invoke-WebRequest $WokwiUri -OutFile $TempExe -UseBasicParsing
73+
}
74+
finally {
75+
$ProgressPreference = $prevProgressPreference
76+
}
77+
78+
if (Test-Path $WokwiCLIExe) {
79+
Remove-Item $WokwiCLIExe
80+
}
81+
Copy-Item $TempExe $WokwiCLIExe
82+
Remove-Item $TempExe
83+
84+
$User = [EnvironmentVariableTarget]::User
85+
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
86+
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
87+
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
88+
$Env:Path += ";$BinDir"
89+
}
90+
91+
Write-Output "wokwi-cli was installed successfully to $WokwiCLIExe"
92+
Write-Output "Run 'wokwi-cli --help' to get started"
93+
Write-Output ""
94+
Write-Output "Stuck? Join our Discord at https://wokwi.com/discord"

scripts/install.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh
2+
# Based on Flyctl installer.
3+
# Based on Deno installer: Copyright 2019 the Deno authors. All rights reserved. MIT license.
4+
# TODO(everyone): Keep this script simple and easily auditable.
5+
6+
set -e
7+
8+
main() {
9+
os=$(uname -s)
10+
arch=$(uname -m)
11+
version=${1:-latest}
12+
13+
# Map to the expected values for the URLs
14+
case "$os" in
15+
Darwin) os="macos" ;;
16+
Linux) os="linuxstatic" ;;
17+
*) echo "Unsupported OS: $os"; exit 1 ;;
18+
esac
19+
20+
case "$arch" in
21+
x86_64) arch="x64" ;;
22+
arm64) ;;
23+
*) echo "Unsupported architecture: $arch"; exit 1 ;;
24+
esac
25+
26+
# URL based on detected values and version
27+
if [ "$version" = "latest" ]; then
28+
wokwi_cli_uri="https://github.com/wokwi/wokwi-cli/releases/latest/download/wokwi-cli-$os-$arch"
29+
else
30+
wokwi_cli_uri="https://github.com/wokwi/wokwi-cli/releases/download/v$version/wokwi-cli-$os-$arch"
31+
fi
32+
33+
wokwi_cli_install="${WOKWI_CLI_INSTALL:-$HOME/.wokwi}"
34+
35+
bin_dir="$wokwi_cli_install/bin"
36+
tmp_dir="$wokwi_cli_install/tmp"
37+
exe="$bin_dir/wokwi-cli"
38+
39+
mkdir -p "$bin_dir"
40+
mkdir -p "$tmp_dir"
41+
42+
curl -q --fail --location --progress-bar --output "$tmp_dir/wokwi-cli" "$wokwi_cli_uri"
43+
chmod +x "$tmp_dir/wokwi-cli"
44+
45+
# atomically rename into place:
46+
mv "$tmp_dir/wokwi-cli" "$exe"
47+
48+
mkdir -p "$HOME/bin"
49+
ln -s -f "$exe" "$HOME/bin/wokwi-cli"
50+
51+
echo "wokwi-cli was installed successfully to $HOME/bin/wokwi-cli"
52+
53+
if command -v wokwi-cli >/dev/null; then
54+
echo "Run 'wokwi-cli --help' to get started"
55+
else
56+
case $SHELL in
57+
/bin/zsh) shell_profile="$HOME/.zshrc" ;;
58+
*) shell_profile="$HOME/.bashrc" ;;
59+
esac
60+
echo "export PATH=\"$HOME/bin:\$PATH\"" >> "$shell_profile"
61+
echo "Path updated! You may need to restart your shell or run 'source $shell_profile' to refresh your PATH."
62+
echo "Run '$exe --help' to get started"
63+
fi
64+
65+
echo
66+
echo "Stuck? Join our Discord at https://wokwi.com/discord"
67+
}
68+
69+
main "$1"

0 commit comments

Comments
 (0)