Skip to content

Commit 9f396b2

Browse files
committed
Update installers
1 parent 9f83a02 commit 9f396b2

File tree

7 files changed

+163
-62
lines changed

7 files changed

+163
-62
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
create_release:
10-
name: Create release
10+
name: Create Release
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
@@ -29,8 +29,16 @@ jobs:
2929
release_name: ${{ steps.tags.outputs.tag }}
3030
draft: false
3131
prerelease: false
32+
- name: Upload install.bat
33+
uses: svenstaro/upload-release-action@v2
34+
with:
35+
repo_token: ${{ secrets.GITHUB_TOKEN }}
36+
file: install.bat
37+
asset_name: install.bat
38+
tag: ${{ github.ref }}
39+
overwrite: true
3240
publish_binaries:
33-
name: Release Go Binary
41+
name: Release Binary
3442
runs-on: ubuntu-latest
3543
strategy:
3644
matrix:
@@ -57,3 +65,5 @@ jobs:
5765
asset_name: codegame-cli-${{matrix.goos}}-${{matrix.goarch}}
5866
extra_files: LICENSE README.md
5967
release_tag: ${{ steps.tags.outputs.tag }}
68+
ldflags: -X "main.version=${{ steps.tags.outputs.tag }}"
69+
md5sum: false

README.md

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -146,71 +146,32 @@ codegame help <cmd>
146146

147147
### Windows
148148

149-
1. Open the Start menu
150-
2. Search for `powershell`
151-
3. Hit `Run as Administrator`
152-
4. Paste the following commands and hit enter:
149+
[Download](https://github.com/code-game-project/codegame-cli/releases/latest/download/install.bat) and execute `install.bat`.
153150

154-
#### Install
151+
### macOS/Linux
155152

156-
```powershell
157-
Invoke-WebRequest -Uri "https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-windows-amd64.zip" -OutFile "C:\Program Files\codegame-cli.zip"
158-
Expand-Archive -LiteralPath "C:\Program Files\codegame-cli.zip" -DestinationPath "C:\Program Files\codegame-cli"
159-
rm "C:\Program Files\codegame-cli.zip"
160-
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value "$((Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path);C:\Program Files\codegame-cli"
161-
```
162-
163-
**IMPORTANT:** Please reboot for the installation to take effect.
164-
165-
#### Update
166-
167-
```powershell
168-
rm -r -fo "C:\Program Files\codegame-cli"
169-
Invoke-WebRequest -Uri "https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-windows-amd64.zip" -OutFile "C:\Program Files\codegame-cli.zip"
170-
Expand-Archive -LiteralPath "C:\Program Files\codegame-cli.zip" -DestinationPath "C:\Program Files\codegame-cli"
171-
rm "C:\Program Files\codegame-cli.zip"
172-
```
153+
Paste one of the following commands into a terminal window:
173154

174-
### macOS
175-
176-
Open the Terminal application, paste the command for your architecture and hit enter.
177-
178-
To update, simply run the command again.
179-
180-
#### x86_64
155+
#### curl
181156

182-
```
183-
curl -L https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-darwin-amd64.tar.gz | tar -xz codegame && sudo mv codegame /usr/local/bin
157+
```bash
158+
curl -L https://raw.githubusercontent.com/code-game-project/codegame-cli/main/install.sh | bash
184159
```
185160

186-
#### ARM64
161+
#### wget (in case curl is not installed)
187162

188-
```
189-
curl -L https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-darwin-arm64.tar.gz | tar -xz codegame && sudo mv codegame /usr/local/bin
163+
```bash
164+
wget -q --show-progress https://raw.githubusercontent.com/code-game-project/codegame-cli/main/install.sh -O- | bash
190165
```
191166

192-
### Linux
167+
## Uninstallation
193168

194-
Open a terminal, paste the command for your architecture and hit enter.
169+
To remove codegame-cli from your system run:
195170

196-
To update, simply run the command again.
197-
198-
#### x86_64
199-
200-
```
201-
curl -L https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-linux-amd64.tar.gz | tar -xz codegame && sudo mv codegame /usr/local/bin
171+
```bash
172+
codegame uninstall
202173
```
203174

204-
#### ARM64
205-
206-
```
207-
curl -L https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-linux-arm64.tar.gz | tar -xz codegame && sudo mv codegame /usr/local/bin
208-
```
209-
210-
### Other
211-
212-
You can download a prebuilt binary file for your operating system on the [releases](https://github.com/code-game-project/codegame-cli/releases) page.
213-
214175
### Compiling from source
215176

216177
#### Prerequisites
@@ -220,7 +181,7 @@ You can download a prebuilt binary file for your operating system on the [releas
220181
```
221182
git clone https://github.com/code-game-project/codegame-cli.git
222183
cd codegame-cli
223-
go build .
184+
go build -o codegame .
224185
```
225186

226187
## Modules

cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ var rootCmd = &cobra.Command{
1616
}
1717

1818
func Execute(version string) {
19-
rootCmd.SetVersionTemplate(`codegame-cli v{{.Version}}
19+
rootCmd.SetVersionTemplate(`codegame-cli {{.Version}}
2020
`)
2121
rootCmd.Version = version
22+
rootCmd.InitDefaultVersionFlag()
2223
err := rootCmd.Execute()
2324
if err != nil {
2425
os.Exit(1)

install.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
echo Downloading latest installer...
3+
Powershell.exe -Command "iwr -useb https://raw.githubusercontent.com/code-game-project/codegame-cli/main/install.ps1 | iex"
4+
pause

install.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
if ((Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyEnable) {
2+
$proxy = (Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').ProxyServer
3+
$env:HTTP_PROXY = $proxy
4+
$env:HTTPS_PROXY = $proxy
5+
Write-Host "Using proxy: $proxy"
6+
}
7+
8+
Write-Host "Installing codegame-cli..."
9+
10+
$InstallDir = "$HOME\AppData\Local\Programs\codegame-cli"
11+
if (!($InstallDir | Test-Path)) {
12+
New-Item -ItemType "directory" -Path $InstallDir
13+
[System.Environment]::SetEnvironmentVariable("PATH",[System.Environment]::GetEnvironmentVariable("PATH","USER") + ";" + $InstallDir,"USER")
14+
15+
Write-Host "Refreshing environment variables..."
16+
$HWND_BROADCAST = [intptr]0xffff;
17+
$WM_SETTINGCHANGE = 0x1a;
18+
$result = [uintptr]::zero
19+
if (-not ("win32.nativemethods" -As [type])) {
20+
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
21+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
22+
public static extern IntPtr SendMessageTimeout(
23+
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
24+
uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
25+
"@
26+
}
27+
[void]([win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [uintptr]::Zero, "Environment", 2, 5000, [ref]$result))
28+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
29+
} else {
30+
rm -r $InstallDir
31+
New-Item -ItemType "directory" -Path $InstallDir
32+
}
33+
34+
$TempDir = [System.IO.Path]::GetTempPath()
35+
cd $TempDir
36+
37+
Invoke-WebRequest -Uri https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-windows-amd64.zip -OutFile codegame-cli.zip
38+
Expand-Archive -LiteralPath codegame-cli.zip -DestinationPath $InstallDir
39+
rm codegame-cli.zip
40+
41+
Write-Host "Done." -ForegroundColor Green

install.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
echo "Installing codegame-cli..."
4+
5+
cd /tmp
6+
7+
rm -f "codegame-cli.tar.gz"
8+
9+
os=$(uname)
10+
arch=$(uname -m)
11+
12+
download () {
13+
if hash wget 2>/dev/null; then
14+
wget -q --show-progress https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-$1-$2.tar.gz -O codegame-cli.tar.gz || exit 1
15+
elif hash curl 2>/dev/null; then
16+
curl -L https://github.com/code-game-project/codegame-cli/releases/latest/download/codegame-cli-$1-$2.tar.gz > codegame-cli.tar.gz || exit 1
17+
else
18+
echo "Please install either wget or curl."
19+
exit 1
20+
fi
21+
}
22+
23+
shopt -s nocasematch
24+
25+
if [[ $os == *"linux"* ]]; then
26+
if [[ $arch == *"x86"* ]]; then
27+
echo "Detected OS: Linux x86_64"
28+
download "linux" "amd64"
29+
elif [[ $arch == *"aarch64"* ]]; then
30+
echo "Detected OS: Linux ARM64"
31+
download "linux" "arm64"
32+
elif [[ $arch == *"arm"* ]]; then
33+
echo "Detected OS: Linux ARM64"
34+
download "linux" "arm64"
35+
else
36+
echo "Detected OS: $os $arch"
37+
echo "Your architecture is not supported by this installer."
38+
exit 1
39+
fi
40+
elif [[ $os == *"darwin"* ]]; then
41+
if [[ $arch == *"x86"* ]]; then
42+
echo "Detected OS: macOS x86_64"
43+
download "darwin" "amd64"
44+
elif [[ $arch == *"aarch64"* ]]; then
45+
echo "Detected OS: macOS ARM64"
46+
download "darwin" "arm64"
47+
elif [[ $arch == *"arm"* ]]; then
48+
echo "Detected OS: macOS ARM64"
49+
download "darwin" "arm64"
50+
else
51+
echo "Detected OS: $os $arch"
52+
echo "Your architecture is not supported by this installer."
53+
exit 1
54+
fi
55+
else
56+
echo "Detected OS: $os $arch"
57+
echo "Your OS is not supported by this installer."
58+
exit 1
59+
fi
60+
61+
if [[ :$PATH: == *:"$HOME/.local/bin":* ]] ; then
62+
echo "Installing binaries into ~/.local/bin..."
63+
mkdir -p $HOME/.local/bin || exit 1
64+
if test -f /usr/local/bin/codegame; then
65+
echo "Removing old version in /usr/local/bin..."
66+
sudo rm -f /usr/local/bin/codegame
67+
fi
68+
tar -xzf codegame-cli.tar.gz codegame && mv codegame $HOME/.local/bin || exit 1
69+
else
70+
echo "Installing binaries into /usr/local/bin..."
71+
sudo mkdir -p /usr/local/bin || exit 1
72+
if test -f $HOME/.local/bin/codegame; then
73+
echo "Removing old version in ~/.local/bin..."
74+
rm -f $HOME/.local/bin/codegame
75+
fi
76+
tar -xzf codegame-cli.tar.gz codegame && sudo mv codegame /usr/local/bin || exit 1
77+
fi
78+
79+
rm codegame-cli.tar.gz
80+
81+
echo "Done."

main.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@ import (
2020
"github.com/code-game-project/codegame-cli/cmd"
2121
)
2222

23-
const Version = "0.8.0"
23+
const version = "dev"
2424

2525
func main() {
2626
checkVersion()
27-
cmd.Execute(Version)
27+
cmd.Execute(version)
2828
}
2929

3030
// checkVersion prints a warning, if there is a newer version of codegame-cli available.
3131
// On macOS and linux the user is offered to update automatically.
3232
func checkVersion() {
33+
if version == "dev" {
34+
return
35+
}
36+
3337
latest, err := getLatestVersion()
3438
if err != nil {
3539
return
3640
}
3741

38-
currentMajor, currentMinor, currentPatch, err := semver.ParseVersion(Version)
42+
currentMajor, currentMinor, currentPatch, err := semver.ParseVersion(version)
3943
if err != nil {
4044
return
4145
}
@@ -54,7 +58,7 @@ func checkVersion() {
5458
if codegameErr == nil && !cgBin.IsDir() && shErr == nil && sudoErr == nil && curlErr == nil && tarErr == nil && (runtime.GOOS == "darwin" || runtime.GOOS == "linux") {
5559
update()
5660
} else {
57-
cli.Warn("You are using an old version of codegame-cli (v%s).\nUpdate to the latest version (v%s): https://github.com/code-game-project/codegame-cli#installation", Version, latest)
61+
cli.Warn("You are using an old version of codegame-cli (%s).\nUpdate to the latest version (%s): https://github.com/code-game-project/codegame-cli#installation", version, latest)
5862
}
5963
}
6064
}
@@ -96,7 +100,6 @@ func getLatestVersion() (string, error) {
96100
if err != nil {
97101
return "", err
98102
}
99-
version := strings.TrimPrefix(tag, "v")
100103
os.WriteFile(filepath.Join(cacheDir, "latest_version"), []byte(fmt.Sprintf("%d\n%s", time.Now().Unix(), version)), 0o644)
101-
return version, nil
104+
return tag, nil
102105
}

0 commit comments

Comments
 (0)