Skip to content

Commit

Permalink
feat: improve toggle-nvidia just command
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalOughtness committed Apr 5, 2024
1 parent 7ace438 commit cb05841
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Binary file added build/ublue-os-just/.40-nvidia.just.kate-swp
Binary file not shown.
35 changes: 32 additions & 3 deletions build/ublue-os-just/40-nvidia.just
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,44 @@ configure-nvidia ACTION="prompt":
fi

# Switch between Nvidia image and NVK
toggle-nvk:
toggle-nvidia ACTION="prompt":
#!/usr/bin/bash
CURRENT_IMAGE=$(rpm-ostree status -b --json | jq -r '.deployments[0]."container-image-reference"' | sed -E 's/^.+\/(.+:.+)$/\1/')
CURRENT_URI=$(rpm-ostree status -b --json | jq -r '.deployments[0]."container-image-reference"' | sed -E 's/^(.+\/).+:.+$/\1/')
NEW_IMAGE=$CURRENT_IMAGE
if [[ "$CURRENT_IMAGE" =~ "nvidia" ]]; then
NEW_IMAGE=${CURRENT_IMAGE/-nvidia/}
IS_CURRENTLY_NVIDIA=true
echo "Current nvidia driver: Nvidia (From Nvidia Inc, Proprietary)"
else
NEW_IMAGE=${CURRENT_IMAGE/:/-nvidia:}
IS_CURRENTLY_NVIDIA=false
echo "Current nvidia driver: NVK (Open Source, MESA)"
fi
OPTION={{ ACTION }}
if [ "$OPTION" == "prompt" ]; then
echo "${bold}Enable or Disable Nvidia driver${normal}"
echo 'What would you like to do?'
OPTION=$(ugum choose "Enable" "Disable")
elif [ "$OPTION" == "help" ]; then
echo "Usage: ujust toggle-nvidia <option>"
echo " <option>: Specify the quick option - 'enable' or 'disable'"
echo " Use 'enable' to Enable the proprietary Nvidia driver from Nvidia Inc (reboot required)."
echo " Use 'disable' to Enable the open source Nvidia driver (reboot required)."
exit 0
fi
if [ "$OPTION" == "Enable" ] || [ "${OPTION,,}" == "enable" ]; then
if $IS_CURRENTLY_NVIDIA; then
echo "Proprietary nvidia drivers are already enabled."
exit 0
else
NEW_IMAGE=${CURRENT_IMAGE/:/-nvidia:}
fi
elif [ "$OPTION" == "Disable" ] || [ "${OPTION,,}" == "disable" ]; then
if ! $IS_CURRENTLY_NVIDIA; then
echo "Proprietary nvidia drivers are already disabled."
exit 0
else
NEW_IMAGE=${CURRENT_IMAGE/-nvidia/}
fi
fi
echo "Rebasing to ${NEW_IMAGE}"
rpm-ostree rebase ${CURRENT_URI}${NEW_IMAGE}
Expand Down

0 comments on commit cb05841

Please sign in to comment.