#!/usr/bin/env bash
# Punt d'entrada: només check-update consulta la xarxa.
set -euo pipefail
source_dir=$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")")
version=$(cat -- "$source_dir/VERSION")
if [[ ! $version =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
    printf "Versió de FileNest invàlida.\n" >&2; exit 1
fi
if [[ ${1-} == --version || ${1-} == check-update ]]; then
    if [[ $# != 1 ]]; then printf "Arguments incorrectes.\n" >&2; exit 2; fi
    if [[ $1 == --version ]]; then printf "filenest %s\n" "$version"; exit; fi
    # shellcheck source=lib/updates.sh
    source "$source_dir/lib/updates.sh"
    check_update
    exit
fi
# shellcheck source=lib/gestio.sh
source "$source_dir/lib/gestio.sh"
main "$@"
