function exit_error {
  for msg in "$@"
  do
    echo "$msg" > /dev/stderr
  done
  exit 1
}

function var_is_defined {
  for var in "$@"
  do
    test -n "${!var}" || exit_error "$var is not defined (see set-config* files)"
  done
}

function check_torbrowser_version_var {
  local tbver=$("$script_dir/../../rbm/rbm" showconf browser var/torbrowser_version)
  test "$tbver" != "$tbb_version" && exit_error "Wrong tbb_version: $tbver != $tbb_version"
  return 0
}

function check_update_responses_repository_dir {
  if test -z "$update_responses_repository_dir" || ! test -d "$update_responses_repository_dir"
  then
    cat << 'EOF' > /dev/stderr
$aus1_repository_dir is not defined, or the directory does not exist
You should clone git@gitlab.torproject.org:tpo/applications/tor-browser-update-responses.git
and set $update_responses_repository_dir in set-config.update-responses
EOF
    exit 1
  fi
}

function is_project {
  test "$1" = "$SIGNING_PROJECTNAME"
}

function generate_config {
  p1=$("$rbm" showconf browser var/project-name --target "$SIGNING_PROJECTNAME")
  p2=$("$rbm" showconf browser var/Project_Name --target "$SIGNING_PROJECTNAME")
  p3=$("$rbm" showconf browser var/ProjectName --target "$SIGNING_PROJECTNAME")
  echo 'rbm_not_available=1' > "$script_dir/set-config.generated-config"
  echo "SIGNING_PROJECTNAMES=(\"$p1\" \"$p2\" \"$p3\")" >> "$script_dir/set-config.generated-config"
}

function project-name {
   if test -n "${rbm_not_available+x}"; then
     echo "${SIGNING_PROJECTNAMES[0]}"
   else
     "$rbm" showconf browser var/project-name --target "$SIGNING_PROJECTNAME"
   fi
}

function Project_Name {
   if test -n "${rbm_not_available+x}"; then
     echo "${SIGNING_PROJECTNAMES[1]}"
   else
     "$rbm" showconf browser var/Project_Name --target "$SIGNING_PROJECTNAME"
   fi
}

function ProjectName {
   if test -n "${rbm_not_available+x}"; then
     echo "${SIGNING_PROJECTNAMES[2]}"
   else
     "$rbm" showconf browser var/ProjectName --target "$SIGNING_PROJECTNAME"
   fi
}

. "$script_dir/set-config"
