#!/bin/sh

# avoid [[ which is not POSIX sh.
if test "$#" != 1 ; then
    echo "$0 requires an argument."
    exit 1
fi

if test ! -f "$1" ; then
    echo "file does not exist: $1"
    exit 1
fi

if command -v icafe &> /dev/null; then
    icafe commit $1 < /dev/tty
elif command -v $HOME/.icafe/bin/icafe &> /dev/null; then
    $HOME/.icafe/bin/icafe commit $1 < /dev/tty
else
    # Check if $RANDOM is defined
    if test -n "$RANDOM"; then
        # Generate a random number between 1 and 5 using the $RANDOM variable
        rand=$((1 + $RANDOM % 5))
    else
        # Generate a random number between 1 and 5 using the date command
        rand=$((1 + $(date +%s) % 5))
    fi

    if [ "$rand" == "5" ]; then
        echo ""
        echo ":) 推荐安装「智能绑卡助手」，让找卡绑卡更简单: https://icafe-cli.now.baidu-int.com/"
        echo ""
    fi
    exit 0
fi

exit 0
