#!/bin/sh

SC_COMMAND="$0 $@"
SC_LIB=${SC_LIB:-/usr/lib/sc}
. $SC_LIB/setup-env

show_welcome_header

[ $# -lt 1 ] && fatal_log "usage: $0 <command>"
command=$1
shift

case $command in
install-dotfiles)
    [ -d "$HOME/.dotfiles" ] && fatal_log "dotfiles already exist"
    LOGI installing dotfiles...
    git clone https://git.saluco.nl/strix/dotfiles $HOME/.dotfiles
    cd $HOME/.dotfiles
    ./dot a
    ;;
run)
    if [ -z "$@" ]; then
        if command -v zsh >/dev/null; then
            zsh
        elif command -v bash >/dev/null; then
            bash
        else
            sh
        fi
    else
        $@
    fi
    ;;

pm)
    . $SC_LIB/pm
    case $1 in
        upgrade) pm_upgrade_packages ;;
        install) shift; pm_install_packages $@ ;;
        remove) shift; pm_remove_packages $@ ;;        
    esac
    ;;
eval) 
    LOGD "evaluating: $@..."
    $@ 
    ;;
check) exit 0 ;;
*) fatal_log "invalid command" ;;
esac