-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
local-app/python-tools/build-ansible-distribution/manage_uv.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/bin/bash | ||
|
|
||
| THIS=$(basename $0 .sh) | ||
| VERSION="1.0.0" | ||
|
|
||
| # --- Configuration --- | ||
| BASE_DIR="${1:-/apps/uv}" | ||
| CACHE_DIR="$BASE_DIR/cache" | ||
| PYTHON_INST_DIR="$BASE_DIR/share" | ||
| BIN_DIR="$BASE_DIR/bin" | ||
| OWNER="root" | ||
| GROUP="root" | ||
| UMASK="022" | ||
|
|
||
| # Version to install (defaulting to latest if not provided) | ||
| UV_VERSION=$(curl -s https://api.github.com/repos/astral-sh/uv/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | ||
| # --------------------- | ||
|
|
||
| echo "Installing/Updating uv to version $UV_VERSION in $BASE_DIR..." | ||
|
|
||
| # 1. Create Directory Structure | ||
| umask $UMASK | ||
| mkdir -p "$BASE_DIR/$UV_VERSION" "$CACHE_DIR" "$PYTHON_INST_DIR" "$BIN_DIR" | ||
| chown -R $(OWNER):$(GROUP) "$BASE_DIR" | ||
|
|
||
| # 2. Download and Extract uv | ||
| TEMP_DIR=$(mktemp -d) | ||
| curl -LsSf https://github.com/astral-sh/uv/releases/download/$UV_VERSION/uv-x86_64-unknown-linux-musl.tar.gz | tar -xz -C "$TEMP_DIR" | ||
|
|
||
| # Move binaries to versioned directory | ||
| mv "$TEMP_DIR"/uv-x86_64-unknown-linux-musl/uv* "$BASE_DIR/$UV_VERSION/" | ||
| rm -rf "$TEMP_DIR" | ||
|
|
||
| # 3. Update Symlinks to Current | ||
| ln -snf "$BASE_DIR/$UV_VERSION/uv" "$BIN_DIR/uv" | ||
| ln -snf "$BASE_DIR/$UV_VERSION/uvx" "$BIN_DIR/uvx" | ||
|
|
||
| # 4. Create Environment Configuration File | ||
| cat <<EOF > "$BASE_DIR/uv_env.sh" | ||
| # uv Environment Configuration | ||
| export PATH="$BIN_DIR:\$PATH" | ||
| export SSL_CERT_FILE=/etc/pki/tls/certs/ca-bundle.crt | ||
| export UV_PYTHON_INSTALL_DIR="$PYTHON_INST_DIR" | ||
| export UV_CACHE_DIR="$CACHE_DIR" | ||
| export UV_LINK_MODE=copy | ||
| export UV_NATIVE_TLS=true | ||
| # Use managed python by default | ||
| export UV_PYTHON_PREFERENCE=managed | ||
| EOF | ||
|
|
||
| # 5. Create profile.d entry | ||
| sudo cat <<EOF | sudo tee /etc/profile.d/uv.sh > /dev/null | ||
| # Load uv settings for all users | ||
| source "$BASE_DIR/uv_env.sh" | ||
| EOF | ||
|
|
||
| echo "------------------------------------------------" | ||
| echo "uv $UV_VERSION installed successfully." | ||
| echo "Binaries: $BASE_DIR/$UV_VERSION" | ||
| echo "Current Link: $BIN_DIR/uv" | ||
| echo "Toolchains: $PYTHON_INST_DIR" | ||
| echo "--------------------" | ||
| echo "Run 'source $BASE_DIR/uv_env.sh' to use immediately." |