#!/bin/bash

borgInstall()
{
    if command -v borg >/dev/null 2>&1; then
        local v
        v=$(borg --version 2>/dev/null | head -1)
        isNotice "BorgBackup already installed ($v)"
        return 0
    fi

    isHeader "Installing BorgBackup"
    if command -v apt-get >/dev/null 2>&1; then
        runSystem apt-get install -y borgbackup && return 0
    elif command -v dnf >/dev/null 2>&1; then
        runSystem dnf install -y borgbackup && return 0
    elif command -v pacman >/dev/null 2>&1; then
        runSystem pacman -S --noconfirm borg && return 0
    fi

    isError "Could not install BorgBackup — no supported package manager found."
    isNotice "Install manually (https://borgbackup.readthedocs.io/) and re-run 'libreportal backup location init'."
    return 1
}
