Skip to content

Commit ccadcce

Browse files
authored
chore: remove header plumbing from install scripts (#46)
1 parent 9c6ee8f commit ccadcce

3 files changed

Lines changed: 10 additions & 34 deletions

File tree

.github/workflows/test-install.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v6
1616
- shell: bash
17-
env:
18-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1917
run: |
2018
INSTALL_DIR="$HOME/.loops-test"
2119
sh install.sh latest "$INSTALL_DIR"
@@ -34,8 +32,6 @@ jobs:
3432
steps:
3533
- uses: actions/checkout@v6
3634
- shell: pwsh
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3935
run: |
4036
$InstallDir = "$env:TEMP\loops-test"
4137
.\install.ps1 -InstallDir $InstallDir

install.ps1

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@ $Arch = switch ($env:PROCESSOR_ARCHITECTURE) {
1818
default { throw "Unsupported architecture: $env:PROCESSOR_ARCHITECTURE" }
1919
}
2020

21-
$AuthHeader = @{}
22-
if ($env:GITHUB_TOKEN) {
23-
$AuthHeader["Authorization"] = "Bearer $env:GITHUB_TOKEN"
24-
}
25-
2621
function Get-GithubRelease {
2722
param([string]$Repo, [string]$Version)
2823
$url = if ($Version -eq "latest") {
2924
"https://api.github.com/repos/$Repo/releases/latest"
3025
} else {
3126
"https://api.github.com/repos/$Repo/releases/tags/$Version"
3227
}
33-
$response = Invoke-RestMethod -Uri $url -Headers $AuthHeader
28+
$response = Invoke-RestMethod -Uri $url
3429
return $response.tag_name
3530
}
3631

@@ -61,8 +56,8 @@ $tmpDir = Join-Path $env:TEMP ([System.IO.Path]::GetRandomFileName())
6156
New-Item -ItemType Directory -Path $tmpDir | Out-Null
6257

6358
try {
64-
Invoke-WebRequest -Uri $downloadUrl -OutFile "$tmpDir\$archiveName" -Headers $AuthHeader
65-
Invoke-WebRequest -Uri $checksumsUrl -OutFile "$tmpDir\$checksumsName" -Headers $AuthHeader
59+
Invoke-WebRequest -Uri $downloadUrl -OutFile "$tmpDir\$archiveName"
60+
Invoke-WebRequest -Uri $checksumsUrl -OutFile "$tmpDir\$checksumsName"
6661

6762
Confirm-Checksum -FilePath "$tmpDir\$archiveName" -ChecksumsPath "$tmpDir\$checksumsName"
6863

install.sh

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ echoerr() {
1414
github_release() {
1515
owner_repo=$1
1616
version=$2
17-
header=$3
1817
test -z "$version" && version="latest"
1918
if [ "$version" = "latest" ]; then
2019
giturl="https://api.github.com/repos/${owner_repo}/releases/latest"
2120
else
2221
giturl="https://api.github.com/repos/${owner_repo}/releases/tags/${version}"
2322
fi
24-
json=$(http_copy "$giturl" "$header")
23+
json=$(http_copy "$giturl")
2524
test -z "$json" && return 1
2625
version=$(echo "$json" | tr -s '\n' ' ' | sed 's/.*"tag_name": *"//' | sed 's/".*//')
2726
test -z "$version" && return 1
@@ -31,12 +30,7 @@ github_release() {
3130
http_download_curl() {
3231
local_file=$1
3332
source_url=$2
34-
header=$3
35-
if [ -z "$header" ]; then
36-
code=$(curl -w '%{http_code}' -sL --proto '=https' --tlsv1.2 -o "$local_file" "$source_url")
37-
else
38-
code=$(curl -w '%{http_code}' -sL --proto '=https' --tlsv1.2 -H "$header" -o "$local_file" "$source_url")
39-
fi
33+
code=$(curl -w '%{http_code}' -sL --proto '=https' --tlsv1.2 -o "$local_file" "$source_url")
4034
if [ "$code" != "200" ]; then
4135
log_debug "http_download_curl received HTTP status $code"
4236
return 1
@@ -47,12 +41,7 @@ http_download_curl() {
4741
http_download_wget() {
4842
local_file=$1
4943
source_url=$2
50-
header=$3
51-
if [ -z "$header" ]; then
52-
wget -q -O "$local_file" "$source_url"
53-
else
54-
wget -q --header "$header" -O "$local_file" "$source_url"
55-
fi
44+
wget -q -O "$local_file" "$source_url"
5645
}
5746

5847
http_download() {
@@ -70,7 +59,7 @@ http_download() {
7059

7160
http_copy() {
7261
tmp=$(mktemp)
73-
http_download "${tmp}" "$1" "$2" || return 1
62+
http_download "${tmp}" "$1" || return 1
7463
body=$(cat "$tmp")
7564
rm -f "${tmp}"
7665
echo "$body"
@@ -222,11 +211,7 @@ TAG="${1-latest}"
222211
INSTALL_DIR="${2-$HOME/.local/bin}"
223212
PROJ_NAME="loops_cli"
224213
SHORT_BIN_NAME="loops"
225-
AUTH_HEADER=""
226-
if [ -n "$GITHUB_TOKEN" ]; then
227-
AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}"
228-
fi
229-
GH_RELEASE=$(github_release "$GH_REPO" "$TAG" "$AUTH_HEADER")
214+
GH_RELEASE=$(github_release "$GH_REPO" "$TAG")
230215
if [ "$OS" = "windows" ]; then
231216
GH_RELEASE_FILENAME="${PROJ_NAME}_${OS}_${ARCH}.zip"
232217
else
@@ -239,11 +224,11 @@ CHECKSUMS_URL="${GH_ASSETS_URL}/${GH_RELEASE}/${CHECKSUMS_FILENAME}"
239224

240225
execute() {
241226
TMPDIR=$(mktemp -d)
242-
if ! http_download "${TMPDIR}/${GH_RELEASE_FILENAME}" "$DOWNLOAD_URL" "$AUTH_HEADER"; then
227+
if ! http_download "${TMPDIR}/${GH_RELEASE_FILENAME}" "$DOWNLOAD_URL"; then
243228
log_err "Failed to download $DOWNLOAD_URL"
244229
return 1
245230
fi
246-
if ! http_download "${TMPDIR}/${CHECKSUMS_FILENAME}" "$CHECKSUMS_URL" "$AUTH_HEADER"; then
231+
if ! http_download "${TMPDIR}/${CHECKSUMS_FILENAME}" "$CHECKSUMS_URL"; then
247232
log_err "Failed to download checksums from $CHECKSUMS_URL"
248233
return 1
249234
fi

0 commit comments

Comments
 (0)