mirror of
https://github.com/containers/ramalama.git
synced 2026-02-05 06:46:39 +01:00
Replace install.py with install.sh and add rm.sh
Creating a hack/rm.sh script Want to try and install via pipx and wrote a script to remove old install. Also converted python install script back to shell, the python experience in a new mac is just not nice in comparison to bash. Signed-off-by: Eric Curtin <ecurtin@redhat.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@@ -71,13 +71,13 @@ Install RamaLama by running this one-liner (on macOS run without sudo):
|
||||
Linux:
|
||||
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/containers/ramalama/s/install.py | sudo python3
|
||||
curl -fsSL https://raw.githubusercontent.com/containers/ramalama/s/install.sh | sudo sh
|
||||
```
|
||||
|
||||
macOS:
|
||||
|
||||
```
|
||||
curl -fsSL https://raw.githubusercontent.com/containers/ramalama/s/install.py | python3
|
||||
curl -fsSL https://raw.githubusercontent.com/containers/ramalama/s/install.sh | sh
|
||||
```
|
||||
|
||||
## Hardware Support
|
||||
|
||||
141
install.py
141
install.py
@@ -1,141 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
|
||||
def cleanup(tmp):
|
||||
shutil.rmtree(tmp)
|
||||
|
||||
|
||||
def available(command):
|
||||
return shutil.which(command) is not None
|
||||
|
||||
|
||||
def nvidia_lshw():
|
||||
try:
|
||||
output = subprocess.check_output(["lshw", "-c", "display", "-numeric", "-disable", "network"], text=True)
|
||||
return "vendor: .* [10DE]" in output
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
def amd_lshw():
|
||||
try:
|
||||
output = subprocess.check_output(["lshw", "-c", "display", "-numeric", "-disable", "network"], text=True)
|
||||
return "vendor: .* [1002]" in output
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
|
||||
|
||||
def download(url, to):
|
||||
curl_cmd = [
|
||||
"curl",
|
||||
"--globoff",
|
||||
"--location",
|
||||
"--proto-default",
|
||||
"https",
|
||||
"-f",
|
||||
"-o",
|
||||
to,
|
||||
"--remote-time",
|
||||
"--retry",
|
||||
"10",
|
||||
"--retry-max-time",
|
||||
"10",
|
||||
url,
|
||||
]
|
||||
subprocess.run(curl_cmd, check=True)
|
||||
|
||||
|
||||
def check_platform():
|
||||
if sys.platform == "darwin":
|
||||
if os.geteuid() == 0:
|
||||
print("This script is intended to run as non-root on macOS")
|
||||
return 1
|
||||
if not available("brew"):
|
||||
print(
|
||||
"""
|
||||
RamaLama requires brew to complete installation. Install brew and add the
|
||||
directory containing brew to the PATH before continuing to install RamaLama
|
||||
"""
|
||||
)
|
||||
return 2
|
||||
elif sys.platform == "linux":
|
||||
if os.geteuid() != 0:
|
||||
print("This script is intended to run as root on Linux")
|
||||
return 3
|
||||
else:
|
||||
print("This script is intended to run on Linux and macOS only")
|
||||
return 4
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def install_mac_dependencies():
|
||||
subprocess.run(["pip3", "install", "huggingface_hub[cli]"], check=True)
|
||||
subprocess.run(["pip3", "install", "omlmd==0.1.5"], check=True)
|
||||
subprocess.run(["pip3", "install", "tqdm"], check=True)
|
||||
subprocess.run(["brew", "install", "llama.cpp"], check=True)
|
||||
|
||||
|
||||
def setup_ramalama(bindir, tmp_dir):
|
||||
binfile = "ramalama"
|
||||
from_file = binfile + ".py"
|
||||
host = "https://raw.githubusercontent.com"
|
||||
branch = os.getenv("BRANCH", "s")
|
||||
url = f"{host}/containers/ramalama/{branch}/{from_file}"
|
||||
to_file = os.path.join(tmp_dir, from_file)
|
||||
download(url, to_file)
|
||||
ramalama_bin = os.path.join(bindir, binfile)
|
||||
sharedirs = ["/opt/homebrew/share", "/usr/local/share", "/usr/share"]
|
||||
syspath = next((d for d in sharedirs if os.path.exists(d)), None)
|
||||
syspath += "/ramalama"
|
||||
if sys.platform == "darwin":
|
||||
install_mac_dependencies()
|
||||
|
||||
subprocess.run(["install", "-m755", "-d", syspath], check=True)
|
||||
syspath += "/ramalama"
|
||||
subprocess.run(["install", "-m755", "-d", syspath], check=True)
|
||||
subprocess.run(["install", "-m755", to_file, ramalama_bin], check=True)
|
||||
|
||||
python_files = [
|
||||
"cli.py",
|
||||
"huggingface.py",
|
||||
"model.py",
|
||||
"ollama.py",
|
||||
"common.py",
|
||||
"__init__.py",
|
||||
"oci.py",
|
||||
"version.py",
|
||||
"shortnames.py",
|
||||
]
|
||||
for i in python_files:
|
||||
url = f"{host}/containers/ramalama/{branch}/ramalama/{i}"
|
||||
download(url, to_file)
|
||||
subprocess.run(["install", "-m755", to_file, f"{syspath}/{i}"], check=True)
|
||||
|
||||
|
||||
def main():
|
||||
ret = check_platform()
|
||||
if ret:
|
||||
return ret
|
||||
|
||||
bindirs = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"]
|
||||
bindir = next((d for d in bindirs if d in os.environ["PATH"]), None)
|
||||
if bindir is None:
|
||||
print("No suitable bindir found in PATH")
|
||||
return 5
|
||||
|
||||
tmp_dir = tempfile.mkdtemp()
|
||||
try:
|
||||
setup_ramalama(bindir, tmp_dir)
|
||||
finally:
|
||||
cleanup(tmp_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
116
install.sh
Executable file
116
install.sh
Executable file
@@ -0,0 +1,116 @@
|
||||
#!/bin/bash
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$TMP" &
|
||||
}
|
||||
|
||||
available() {
|
||||
command -v "$1" >/dev/null
|
||||
}
|
||||
|
||||
nvidia_lshw() {
|
||||
lshw -c display -numeric -disable network | grep -q 'vendor: .* \[10DE\]'
|
||||
}
|
||||
|
||||
amd_lshw() {
|
||||
lshw -c display -numeric -disable network | grep -q 'vendor: .* \[1002\]'
|
||||
}
|
||||
|
||||
download() {
|
||||
curl --globoff --location --proto-default https -f -o "$2" \
|
||||
--remote-time --retry 10 --retry-max-time 10 "$1"
|
||||
}
|
||||
|
||||
check_platform() {
|
||||
if [ "$os" = "Darwin" ]; then
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "This script is intended to run as non-root on macOS"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! available "brew"; then
|
||||
echo "RamaLama requires brew to complete installation. Install brew and add the"
|
||||
echo "directory containing brew to the PATH before continuing to install RamaLama"
|
||||
return 2
|
||||
fi
|
||||
elif [ "$os" = "Linux" ]; then
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "This script is intended to run as root on Linux"
|
||||
return 3
|
||||
fi
|
||||
else
|
||||
echo "This script is intended to run on Linux and macOS only"
|
||||
return 4
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
install_mac_dependencies() {
|
||||
pipx install huggingface_hub[cli] omlmd argcomplete
|
||||
brew install llama.cpp
|
||||
}
|
||||
|
||||
setup_ramalama() {
|
||||
local binfile="ramalama"
|
||||
local from_file="${binfile}"
|
||||
local host="https://raw.githubusercontent.com"
|
||||
local branch="${BRANCH:-s}"
|
||||
local url="${host}/containers/ramalama/${branch}/bin/${from_file}"
|
||||
local to_file="${2}/${from_file}"
|
||||
download "$url" "$to_file"
|
||||
|
||||
local ramalama_bin="${1}/${binfile}"
|
||||
local sharedirs=("/opt/homebrew/share" "/usr/local/share" "/usr/share")
|
||||
local syspath
|
||||
for dir in "${sharedirs[@]}"; do
|
||||
if [ -d "$dir" ]; then
|
||||
syspath="$dir/ramalama"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$os" == "Darwin" ]; then
|
||||
install_mac_dependencies
|
||||
fi
|
||||
|
||||
install -m755 -d "$syspath"
|
||||
install -m755 "$to_file" "$ramalama_bin"
|
||||
|
||||
local python_files=("cli.py" "huggingface.py" "model.py" "ollama.py" "common.py" "__init__.py" \
|
||||
"oci.py" "version.py" "shortnames.py")
|
||||
|
||||
for i in "${python_files[@]}"; do
|
||||
url="${host}/containers/ramalama/${branch}/ramalama/${i}"
|
||||
download "$url" "$to_file"
|
||||
install -m755 "$to_file" "${syspath}/${i}"
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
set -e -o pipefail
|
||||
local os
|
||||
os="$(uname -s)"
|
||||
check_platform
|
||||
|
||||
local bindirs=("/opt/homebrew/bin" "/usr/local/bin" "/usr/bin" "/bin")
|
||||
local bindir
|
||||
for bindir in "${bindirs[@]}"; do
|
||||
if echo "$PATH" | grep -q "$bindir"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$bindir" ]; then
|
||||
echo "No suitable bindir found in PATH"
|
||||
exit 5
|
||||
fi
|
||||
|
||||
TMP="$(mktemp -d)"
|
||||
trap cleanup EXIT
|
||||
|
||||
setup_ramalama "$bindir" "$TMP"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
@@ -5,17 +5,17 @@ available() {
|
||||
}
|
||||
|
||||
mac_steps() {
|
||||
./install.py
|
||||
./install.sh
|
||||
}
|
||||
|
||||
linux_steps() {
|
||||
shellcheck -- *.sh
|
||||
if [ -n "$BRANCH" ]; then
|
||||
$maybe_sudo BRANCH=$BRANCH ./install.py
|
||||
$maybe_sudo BRANCH=$BRANCH ./install.sh
|
||||
return
|
||||
fi
|
||||
|
||||
$maybe_sudo ./install.py
|
||||
$maybe_sudo ./install.sh
|
||||
}
|
||||
|
||||
main() {
|
||||
@@ -29,7 +29,7 @@ main() {
|
||||
local os
|
||||
os="$(uname -s)"
|
||||
binfile=bin/ramalama
|
||||
chmod +x ${binfile} install.py
|
||||
chmod +x ${binfile} install.sh
|
||||
uname -a
|
||||
/usr/bin/python3 --version
|
||||
|
||||
|
||||
Reference in New Issue
Block a user