File size: 2,982 Bytes
1e962ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e47c081
 
1e962ea
 
 
 
 
 
 
 
 
e47c081
 
1e962ea
e4f1d27
 
 
 
1e962ea
 
 
 
 
e4f1d27
1e962ea
 
 
 
 
 
e4f1d27
1e962ea
 
 
 
 
 
 
 
 
9d28207
3aabffd
97ca32a
1e962ea
 
df9407b
1e962ea
 
 
 
9d28207
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# onw - Ore no NPU ga konna ni ugoku wake nai: install the resident top-bar app (Ubuntu).
# Installs the system pieces the indicator and the window need (AppIndicator, WebKit; asks for sudo once), creates .venv,
# installs onw + the tray, adds "onw" to the application list and starts it in the top bar.
# GNOME shows indicators through the "Ubuntu AppIndicators" extension, which Ubuntu enables by default.
set -e
cd "$(dirname "$0")"
export PYTHONUTF8=1

if ! python3 -c "import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)" 2>/dev/null; then
    echo "Python 3.10 or newer is needed (Ubuntu 22.04 and later ship it):  sudo apt install python3"
    exit 1
fi

need=""
# the window is a WebKit web view (pywebview): 4.1 on Ubuntu 24.04 and later, 4.0 before
webkit=gir1.2-webkit2-4.1
apt-cache show $webkit >/dev/null 2>&1 || webkit=gir1.2-webkit2-4.0
# wl-clipboard / xclip: "Copy the OpenAI API URL" in the top-bar menu (Wayland / X11)
for p in python3-venv python3-gi gir1.2-ayatanaappindicator3-0.1 $webkit wl-clipboard xclip; do
    dpkg -s "$p" >/dev/null 2>&1 || need="$need $p"
done
if [ -n "$need" ]; then
    echo "[setup] installing system packages:$need"
    sudo apt-get install -y $need
fi

install_onw() {
    # the bundled pip is fine (a newer pip once failed to install packages that have scripts, so it is not upgraded)
    .venv/bin/python -m pip install -e ".[tray]" \
        --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/pre-release
}
# pip ran for this pyproject.toml already (onw.deps): nothing to install. Otherwise - new packages from an update, an
# update whose pip could not finish, an older install - pip runs again (a running onw is stopped first, and started
# again at the end).
if [ ! -f .venv/bin/python ] || ! .venv/bin/python -m onw.deps check >/dev/null 2>&1; then
    if [ ! -f .venv/bin/python ]; then
        echo "[setup] creating Python environment in .venv ..."
        # system site packages: the GObject bindings for the indicator and WebKit come from apt (python3-gi)
        python3 -m venv --system-site-packages .venv
    fi
    .venv/bin/python -m onw.deps stop || true
    if ! install_onw; then
        echo "[setup] installation failed; rebuilding the Python environment once ..."
        rm -rf .venv
        python3 -m venv --system-site-packages .venv
        install_onw || exit 1
    fi
    .venv/bin/python -m onw.deps done
    echo ok > .venv/installed.txt
fi

mkdir -p ~/.local/share/applications
cat > ~/.local/share/applications/onw.desktop <<EOF
[Desktop Entry]
Type=Application
Name=onw
Comment=LLMs on the Intel NPU (俺のNPUがこんなに動くわけない)
Exec="$PWD/.venv/bin/onw" tray
Path=$PWD
Icon=$PWD/onw/web/icon.png
Terminal=false
Categories=Utility;
StartupWMClass=onw
EOF
echo "[setup] application list: onw"

echo "[start] onw is starting in the top bar (first model start: download + NPU compile) ..."
nohup .venv/bin/onw tray >/dev/null 2>&1 &