v0.5.0: installers retry each download and normalise line endings
Browse files- install.ps1 +14 -2
- install.sh +21 -4
install.ps1
CHANGED
|
@@ -9,13 +9,25 @@ $dest = Join-Path $env:LOCALAPPDATA "onw"
|
|
| 9 |
Write-Host ""
|
| 10 |
Write-Host "onw - Ore no NPU ga konna ni ugoku wake nai"
|
| 11 |
Write-Host "Installing into $dest ..."
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
foreach ($s in $info.siblings) {
|
| 14 |
$f = $s.rfilename
|
| 15 |
if ($f -eq ".gitattributes") { continue }
|
| 16 |
$out = Join-Path $dest ($f -replace "/", "\")
|
| 17 |
New-Item -ItemType Directory -Force -Path (Split-Path $out) | Out-Null
|
| 18 |
-
|
| 19 |
}
|
| 20 |
Write-Host "Downloaded $($info.siblings.Count - 1) files. Starting setup (Python, packages, Start menu, tray) ..."
|
| 21 |
Start-Process -FilePath (Join-Path $dest "setup.bat") -WorkingDirectory $dest
|
|
|
|
| 9 |
Write-Host ""
|
| 10 |
Write-Host "onw - Ore no NPU ga konna ni ugoku wake nai"
|
| 11 |
Write-Host "Installing into $dest ..."
|
| 12 |
+
function Get-WithRetry($uri, $out) {
|
| 13 |
+
for ($i = 1; $i -le 4; $i++) {
|
| 14 |
+
try {
|
| 15 |
+
if ($out) { Invoke-WebRequest -UseBasicParsing -Uri $uri -OutFile $out; return }
|
| 16 |
+
return Invoke-RestMethod $uri
|
| 17 |
+
} catch {
|
| 18 |
+
if ($i -eq 4) { throw }
|
| 19 |
+
Write-Host " retrying ($($_.Exception.Message)) ..."
|
| 20 |
+
Start-Sleep -Seconds (2 * $i)
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
$info = Get-WithRetry "https://huggingface.co/api/models/$repo" $null
|
| 25 |
foreach ($s in $info.siblings) {
|
| 26 |
$f = $s.rfilename
|
| 27 |
if ($f -eq ".gitattributes") { continue }
|
| 28 |
$out = Join-Path $dest ($f -replace "/", "\")
|
| 29 |
New-Item -ItemType Directory -Force -Path (Split-Path $out) | Out-Null
|
| 30 |
+
Get-WithRetry "https://huggingface.co/$repo/resolve/main/$f" $out
|
| 31 |
}
|
| 32 |
Write-Host "Downloaded $($info.siblings.Count - 1) files. Starting setup (Python, packages, Start menu, tray) ..."
|
| 33 |
Start-Process -FilePath (Join-Path $dest "setup.bat") -WorkingDirectory $dest
|
install.sh
CHANGED
|
@@ -10,16 +10,33 @@ echo
|
|
| 10 |
echo "onw - Ore no NPU ga konna ni ugoku wake nai"
|
| 11 |
echo "Installing into $dest ..."
|
| 12 |
python3 - "$repo" "$dest" <<'PY'
|
| 13 |
-
import json, os, sys, urllib.request
|
| 14 |
repo, dest = sys.argv[1], sys.argv[2]
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
files = [s["rfilename"] for s in info["siblings"] if s["rfilename"] != ".gitattributes"]
|
| 17 |
for f in files:
|
| 18 |
out = os.path.join(dest, f)
|
| 19 |
os.makedirs(os.path.dirname(out), exist_ok=True)
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
print(f"Downloaded {len(files)} files.")
|
| 22 |
PY
|
| 23 |
cd "$dest"
|
| 24 |
-
sed -i 's/\r$//' setup.sh start.sh # in case a file was saved with Windows line endings
|
| 25 |
bash setup.sh </dev/tty
|
|
|
|
| 10 |
echo "onw - Ore no NPU ga konna ni ugoku wake nai"
|
| 11 |
echo "Installing into $dest ..."
|
| 12 |
python3 - "$repo" "$dest" <<'PY'
|
| 13 |
+
import json, os, sys, time, urllib.request
|
| 14 |
repo, dest = sys.argv[1], sys.argv[2]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def fetch(url, tries=4): # the hub redirects to a CDN; a reset connection is retried
|
| 18 |
+
for i in range(tries):
|
| 19 |
+
try:
|
| 20 |
+
with urllib.request.urlopen(url, timeout=60) as r:
|
| 21 |
+
return r.read()
|
| 22 |
+
except Exception as e:
|
| 23 |
+
if i == tries - 1:
|
| 24 |
+
raise
|
| 25 |
+
print(f" retrying ({e}) ...", flush=True)
|
| 26 |
+
time.sleep(2 * (i + 1))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
info = json.loads(fetch(f"https://huggingface.co/api/models/{repo}"))
|
| 30 |
files = [s["rfilename"] for s in info["siblings"] if s["rfilename"] != ".gitattributes"]
|
| 31 |
for f in files:
|
| 32 |
out = os.path.join(dest, f)
|
| 33 |
os.makedirs(os.path.dirname(out), exist_ok=True)
|
| 34 |
+
data = fetch(f"https://huggingface.co/{repo}/resolve/main/{f}")
|
| 35 |
+
if f.endswith((".sh", ".py", ".toml", ".txt", ".md", ".html")):
|
| 36 |
+
data = data.replace(b"\r\n", b"\n") # scripts must have Unix line endings
|
| 37 |
+
with open(out, "wb") as fh:
|
| 38 |
+
fh.write(data)
|
| 39 |
print(f"Downloaded {len(files)} files.")
|
| 40 |
PY
|
| 41 |
cd "$dest"
|
|
|
|
| 42 |
bash setup.sh </dev/tty
|