Skip to content

Commit e09b216

Browse files
authored
core: tools.func - add uv setup (#4129)
1 parent 5825dfa commit e09b216

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

misc/tools.func

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,3 +756,60 @@ import_local_ip() {
756756

757757
export LOCAL_IP
758758
}
759+
760+
function setup_uv() {
761+
msg_info "Checking uv installation..."
762+
763+
UV_BIN="/usr/local/bin/uv"
764+
TMP_DIR=$(mktemp -d)
765+
ARCH=$(uname -m)
766+
767+
if [[ "$ARCH" == "x86_64" ]]; then
768+
UV_TAR="uv-x86_64-unknown-linux-gnu.tar.gz"
769+
elif [[ "$ARCH" == "aarch64" ]]; then
770+
UV_TAR="uv-aarch64-unknown-linux-gnu.tar.gz"
771+
else
772+
msg_error "Unsupported architecture: $ARCH"
773+
rm -rf "$TMP_DIR"
774+
return 1
775+
fi
776+
777+
# get current github version
778+
LATEST_VERSION=$(curl -s https://api.github.com/repos/astral-sh/uv/releases/latest | grep '"tag_name":' | cut -d '"' -f4 | sed 's/^v//')
779+
if [[ -z "$LATEST_VERSION" ]]; then
780+
msg_error "Could not fetch latest uv version from GitHub."
781+
rm -rf "$TMP_DIR"
782+
return 1
783+
fi
784+
785+
# check if uv exists
786+
if [[ -x "$UV_BIN" ]]; then
787+
INSTALLED_VERSION=$($UV_BIN -V | awk '{print $2}')
788+
if [[ "$INSTALLED_VERSION" == "$LATEST_VERSION" ]]; then
789+
msg_ok "uv is already at the latest version ($INSTALLED_VERSION)"
790+
rm -rf "$TMP_DIR"
791+
# set path
792+
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
793+
export PATH="/usr/local/bin:$PATH"
794+
fi
795+
return 0
796+
else
797+
msg_info "Updating uv from $INSTALLED_VERSION to $LATEST_VERSION"
798+
fi
799+
else
800+
msg_info "uv not found. Installing version $LATEST_VERSION"
801+
fi
802+
803+
# install or update uv
804+
curl -fsSL "https://github.com/astral-sh/uv/releases/latest/download/${UV_TAR}" -o "$TMP_DIR/uv.tar.gz"
805+
tar -xzf "$TMP_DIR/uv.tar.gz" -C "$TMP_DIR"
806+
install -m 755 "$TMP_DIR"/*/uv "$UV_BIN"
807+
rm -rf "$TMP_DIR"
808+
809+
# set path
810+
if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then
811+
export PATH="/usr/local/bin:$PATH"
812+
fi
813+
814+
msg_ok "uv installed/updated to $LATEST_VERSION"
815+
}

0 commit comments

Comments
 (0)