Skip to content

Instantly share code, notes, and snippets.

@jhelgert
Created April 9, 2025 15:58
Show Gist options
  • Save jhelgert/33a3c6d319f6ed60b767de6285cc78d8 to your computer and use it in GitHub Desktop.
Save jhelgert/33a3c6d319f6ed60b767de6285cc78d8 to your computer and use it in GitHub Desktop.
[Bash] Simple script to install or update uv and uvx on your unraid server without loosing it after a reboot.
#!/usr/bin/bash
# Copy this script to /boot/custom/ and make sure you have the following lines in
# your /boot/config/go file to install all binaries on your usb stick during boot:
# for binary in $(ls /boot/custom/bin/); do
# cp -f /boot/custom/bin/$binary /usr/local/bin/$binary
# chmod 0755 /usr/local/bin/$binary
# done
# get the newest installer script (-L to follow any redirects, -s silent)
curl -L -s -o /tmp/uv_install.sh https://astral.sh/uv/install.sh
# check the uv version of the installer script and our local version
UV_VERSION=$(cat /tmp/uv_install.sh | grep -m 1 "APP_VERSION" | grep -oE '(\.|[0-9]+)+')
UV_VERSION_INSTALLED=$((uv --version 2>/dev/null || echo "_ None") | awk '{print $2}')
if [ $UV_VERSION = $UV_VERSION_INSTALLED ]; then
printf "Newest version (%s) already installed. No need to upgrade.\n" $UV_VERSION
rm /tmp/uv_install.sh
exit 0
fi
# download the newest uv/uvx and install it locally into /root/.local/bin
printf "New version %s available (currently installed: %s). Updating it.\n" $UV_VERSION $UV_VERSION_INSTALLED
sh /tmp/uv_install.sh > /dev/null 2>&1
# copy the newest version to the usb stick and install it to '/usr/local/bin/'
printf "Copying on usb stick and installing to '/usr/local/bin'.\n"
cp -f /root/.local/bin/{uv,uvx} /boot/custom/bin/
cp -f /root/.local/bin/{uv,uvx} /usr/local/bin/
chmod 0755 /usr/local/bin/{uv,uvx}
# cleanup: removing the locally installed binaries
printf "Cleanup. Removing the locally installed binaries from the uv installer script.\n"
rm -f /root/.local/bin/{uv,uvx}
rm /tmp/uv_installer.sh
printf "Done.\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment