---
# The directory to install the executable for code-server
code_server_bin_dir: "{{ code_server_install_prefix }}/bin"

# code-server before v3 is a single file binary, code-server since v3 is a directory of files.
# code_server_dir is only used for v3+
code_server_dir: "{{ '/opt/code-server' if code_server_major|int >= 3 else '' }}"

# The directory to install code-server systemd service file
code_server_service_dir: "{{ code_server_install_prefix }}/lib/systemd/system"

# URL prefix for downloading code-server
code_server_url_prefix: https://github.com/cdr/code-server/releases/download

# code_server_ver without v prefix
code_server_cleaned_ver: "{{ code_server_ver | regex_replace('^v', '') }}"

# code_server_short_ver removes vscode version
# 2.1692-vsc1.39.2 -> 2.1692
# 3.0.0 -> 3.0.0
code_server_short_ver: "{{ code_server_cleaned_ver | regex_replace('-.+', '') }}"

# Whether we need to download code-server for fresh install or upgrade.
# Note that code-server release tag has a 'v' prefix since v3.3.0,
# while `code-server --version` never outputs the 'v' prefix.
code_server_download_needed: >-
  {{ not code_server_exists.stat.exists
  or code_server_version.stdout != code_server_cleaned_ver }}

# The subdirectory under URL prefix containing code-server artifacts
code_server_download_dir: "{{ 'v' if code_server_cleaned_ver is version('3.3.0', '>=') else '' }}{{ code_server_short_ver if code_server_short_ver is version('2.1698', '>=') else code_server_cleaned_ver }}"

# The major version of code-server in string
code_server_major: "{{ code_server_cleaned_ver.split('.')[0] }}"

# The architecture of code-server as used in download URL
code_server_arch: "{% if code_server_cleaned_ver is version('3.3.0', '>=') %}amd64{% elif code_server_major != '1' %}x86_64{% else %}x64{% endif %}"

# The build-up final .tar.gz url for code-server
code_server_tar_url: "{{ code_server_url_prefix }}/{{ code_server_download_dir }}/code-server{{ '-' if code_server_major|int >= 3 else '' }}{{ code_server_cleaned_ver }}-linux-{{ code_server_arch }}.tar.gz"

# The data directory of code-server
code_server_data_dir_abs: "{{ code_server_data_dir | expanduser }}"

# Whether to configure service.
# This will be set to yes in tasks unless `--skip-tags service` specified.
code_server_configure_service: no
