#!/bin/sh -e

print_keyring_help() {
    printf "==> run: 'pacman-key --populate archlinuxarm'\n"
    printf "\n"
}

add_repo() {
    r="$1" c="$2"
    printf "\n" #>> /etc/pacman.conf
    printf "%s\n" "${c}[$r]" #>> /etc/pacman.conf
    printf "%s\n" "${c}Include = /etc/pacman.d/mirrorlist-archlinuxarm" #>> /etc/pacman.conf
    printf "\n" #>> /etc/pacman.conf
}

has_testing=0
has_stable=0
has_alarm=0

for repo in $(pacman-conf -l); do
    case "$repo" in
        extra-testing|system-gremlins|world-gremlins) has_testing=1 ;;
        world) has_stable=1 ;;
        armtix) has_alarm=1 ;;
    esac
done

print_repo_help() {
    printf "==> Add the arch repos in pacman.conf:\n"

    if [ "$has_testing" -eq 1 ]; then
        add_repo 'extra-testing'
    else
        add_repo 'extra-testing' '#'
    fi
    if [ "$has_stable" -eq 1 ]; then
        add_repo "extra"
    fi
    if [ "has_alarm" -eq 1 ]; then
        add_repo "alarm"
    else
        add_repo "alarm" '#'
    fi
}

print_repo_help

print_keyring_help
