File size: 1,976 Bytes
d0bf6e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# onw AMD one-line installer for Ubuntu. In a terminal:
#   curl -fsSL https://huggingface.co/ryugyosoft/onwAMD/resolve/main/install.sh | bash
# Downloads onw AMD into ~/onw-amd (no git / hf needed) and runs setup.sh (system packages, Python environment,
# application list entry, top-bar app). Run it again to update onw.
set -e
repo="ryugyosoft/onwAMD"
dest="$HOME/onw-amd"
echo
echo "onw AMD - Ore no NPU ga konna ni ugoku wake nai (AMD Ryzen AI NPU)"
echo "Installing into $dest ..."
python3 - "$repo" "$dest" <<'PY'
import json, os, sys, time, urllib.request
repo, dest = sys.argv[1], sys.argv[2]


def fetch(url, tries=4):                      # the hub redirects to a CDN; a reset connection is retried
    for i in range(tries):
        try:
            with urllib.request.urlopen(url, timeout=60) as r:
                return r.read()
        except Exception as e:
            if i == tries - 1:
                raise
            print(f"  retrying ({e}) ...", flush=True)
            time.sleep(2 * (i + 1))


info = json.loads(fetch(f"https://huggingface.co/api/models/{repo}"))
files = [s["rfilename"] for s in info["siblings"] if s["rfilename"] != ".gitattributes"]
for f in files:
    out = os.path.join(dest, f)
    os.makedirs(os.path.dirname(out), exist_ok=True)
    data = fetch(f"https://huggingface.co/{repo}/resolve/main/{f}")
    if f.endswith((".sh", ".py", ".toml", ".txt", ".md", ".html")):
        data = data.replace(b"\r\n", b"\n")   # scripts must have Unix line endings
    with open(out, "wb") as fh:
        fh.write(data)
open(os.path.join(dest, ".onw-installed"), "w").write("installer\n")   # onw may update itself here
print(f"Downloaded {len(files)} files.")
PY
cd "$dest"
if [ -r /dev/tty ] && [ -w /dev/tty ]; then
    bash setup.sh </dev/tty                  # piped from curl: setup's questions (sudo) read the terminal
else
    bash setup.sh                            # no terminal (a script, CI): run as is
fi