#!/bin/bash

# Root level functions requiring password for mx-packageinstaller

repo_sync() {
    pacman -Sy --noconfirm
}


copy_log() {
    echo -e "-----------------------------------------------------------\nMXPI SESSION\n-----------------------------------------------------------\n" >> /var/log/mxpi.log.old
    cat /var/log/mxpi.log >> /var/log/mxpi.log.old
    mv /tmp/mxpi.log /var/log
}

flatpak_add_repos() {
    flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
    flatpak remote-add --if-not-exists --subset=verified flathub-verified https://flathub.org/repo/flathub.flatpakrepo
}

flatpak_add_repos_user() {
    flatpak --user remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
    flatpak --user remote-add --if-not-exists --subset=verified flathub-verified https://flathub.org/repo/flathub.flatpakrepo
}

main() {
case "$1" in
    repo_sync)
        repo_sync;;
    copy_log)
        copy_log;;
    flatpak_add_repos)
        flatpak_add_repos;;
    flatpak_add_repos_user)
        flatpak_add_repos_user;;
esac
}

main "$@"
