#!/bin/bash
set -e

##
## This script must match the API the temporary Steam UI updater wants of us, including this file
## Please note that this script is now deprecated! The Steam client is migrating to the new
## atomic update D-Bus API, and developers are encouraged to use `atomupd-manager`.
##

if [[ $# -eq 1 ]]; then
  case "$1" in
    "-c")
      branch=$(atomupd-manager tracked-branch)
      if [[ "$branch" == "stable" ]]; then
        echo rel
      else
        echo "$branch"
      fi
      exit 0
      ;;
    "-l")
      branches=$(atomupd-manager list-branches)
      branches=${branches/stable/rel}
      echo "$branches"
      exit 0
      ;;
    "rel")
      # The legacy stable variant was called "rel", convert it to "stable" before
      # calling atomupd-manager
      atomupd-manager switch-branch stable
      exit 0
      ;;
    "stable" | "rc" | "beta" | "bc" | "preview" | "pc" | "main" | "staging")
      atomupd-manager switch-branch "$1"
      exit 0
      ;;
  esac
fi

echo "Usage: steamos-select-branch <-c|-l|rel|rc|beta|bc|preview|pc|main>" 1>&2
