Skip to content

Instantly share code, notes, and snippets.

@bedilbek
Created October 22, 2022 11:09
Show Gist options
  • Select an option

  • Save bedilbek/a1c31e5c00bb6a5824e1e7dec5a1a772 to your computer and use it in GitHub Desktop.

Select an option

Save bedilbek/a1c31e5c00bb6a5824e1e7dec5a1a772 to your computer and use it in GitHub Desktop.
Cuda Changer Bash script
#!/bin/bash
set -e
INSTALL_DIR="/usr/local"
TARGET_VERSION=${1}
default_info () {
echo "The following cuda installations have been found (in '${INSTALL_DIR}'):"
available_cudas=$(ls -a "${INSTALL_DIR}" | grep "cuda-" | sed 's/cuda-//')
#echo $available_cudas
for available_cuda in $available_cudas
do
if [ ${INSTALL_DIR}/cuda-$available_cuda == $(realpath $INSTALL_DIR/cuda) ]
then
echo "$available_cuda *"
else
echo "$available_cuda"
fi
done
}
if [[ -z ${TARGET_VERSION} ]]; then
default_info
set +e
exit
elif [[ ! -d "${INSTALL_DIR}/cuda-${TARGET_VERSION}" ]]; then
echo "No installation of CUDA ${TARGET_VERSION} has been found!"
default_info
set +e
exit
fi
cuda_path="${INSTALL_DIR}/cuda-${TARGET_VERSION}"
if [[ -d "${INSTALL_DIR}/cuda" ]]; then
sudo unlink "${INSTALL_DIR}/cuda"
fi
sudo ln -s "${cuda_path}" "${INSTALL_DIR}/cuda"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment