#!/bin/bash
# -------------------------------------------------------------------
# Copyright (C) 2014 by Intevation GmbH
# Author(s):
# Sascha Wilde <wilde@intevation.de>

# This program is free software under the GNU GPL (>=v2)
# Read the file COPYING coming with the software for details.
# -------------------------------------------------------------------

ME=`basename "$0"`

declare -A codenames=(
  [1.1]="buzz"
  [1.2]="rex"
  [1.3]="bo"
  [2.0]="hamm"
  [2.1]="slink"
  [2.2]="potato"
  [3.0]="woody"
  [3.1]="sarge"
  [4.0]="etch"
  [5.0]="lenny"
  [6.0]="squeeze"
  [7]="wheezy"
  [8]="jessie"
  [9]="stretch"
  [10]="buster"
  [11]="bullseye"
  [12]="bookworm"
  [13]="trixie"
  [14]="forky"
)

usage()
{
  cat <<EOF
$ME [USER@]HOST

Display version including code name of Distro on remote HOST.

EOF
}

fatal()
{
  echo >&2 "$1"
  exit 23
}

[ $# -eq 1 ] || { usage ; exit 1 ; }

version=`ssh $1 "[ -f /etc/debian_version ] && cat /etc/debian_version"`
[ "$version" ] || fatal "Could not fetch Debian version file."

codename=${codenames[${version:0:3}]}
[ "$codename" ] || codename="${codenames[${version/\.*/}]}"

echo "Debian $version $codename"
