Xonshiz / anime-dl

Anime-dl is a command-line program to download anime from CrunchyRoll and Funimation.
MIT License
229 stars 37 forks source link

[Feature-Request] Auto installer script. #56

Closed monoclex closed 6 years ago

monoclex commented 6 years ago

Can you make an auto installer script so we don't have to install dependencies and go through a bunch of hoops before using your software? I've made a script that does just that ( verified working on debian 9 only ), but it only works on debian.

This is the script to execute it.

wget https://www.sirjosh3917.com/cdn/anime-dl-install.sh.txt; mv anime-dl-install.sh.txt anime-dl-install.sh; chmod +x anime-dl-install.sh; ./anime-dl-install.sh

Script source code:


#Creator of script: SirJosh3917
#Creator of anime-dl: Xonshiz
#5/5/2018

#check if root
#https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root
is_root() {
    if ! [ $(id -u) = 0 ]; then
        echo "Please run this script as root."
        echo "Running \'sudo\' on this script..."

        SCRIPT_NAME=$(basename "$0")

        CMD="sudo ./${SCRIPT_NAME}"
        eval ${CMD}
        exit $?
    fi
}

#shamelessly stolen/modified from https://install.pi-hole.net
distro_check() {
    DISTRO_OS=""
    DISTRO_DEBIAN="debian"

    PKG_MANAGER=""
    PKG_INSTALL=""

    if command -v apt-get &> /dev/null; then
        DISTRO_OS=(${DISTRO_DEBIAN})
        PKG_MANAGER="apt-get"
        PKG_INSTALL="${PKG_MANAGER} --yes --no-install-recommends install"
#   elif command -v rpm &> /dev/null; then
#       if command -v dnf &> /dev/null; then
#           PKG_MANAGER="dnf"
#       elif
#           PKG_MANAGER="yum"
#       fi
    else
        echo "Your linux distro is not supporeted."
        exit
    fi

    if [ ${DISTRO_OS} == ${DISTRO_DEBIAN} ]; then
        return 0;
    else
        echo "Your linux distro either isn\'t supported, or somebody didn\'t finish coding the distro_check..."
        exit
    fi

    return 0;
}

get_distro() {
    DISTRO_DEBIAN_7=0
    DISTRO_DEBIAN_8=1
    DISTRO_DEBIAN_9=2
    RETURN=-1

    if [ ${DISTRO_OS} == ${DISTRO_DEBIAN} ]; then
        lsb_release -a > tmp_distro
        if grep "stretch" tmp_distro; then
            RETURN=${DISTRO_DEBIAN_9}
        elif grep "jessie" tmp_distro; then
                        RETURN=${DISTRO_DEBIAN_8}
                elif grep "wheezy" tmp_distro; then
                        RETURN=${DISTRO_DEBIAN_7}
        else
            echo "Version of debian not supported."
            RETURN=-1;
        fi
    fi

    rm tmp_distro
    return ${RETURN}
}

install_ffmpeg() {
    ${PKG_INSTALL} ffmpeg
}

install_mkvmerge() {
    wget -q -O - https://mkvtoolnix.download/gpg-pub-moritzbunkus.txt | sudo apt-key add -

    get_distro
    DISTRO=$?

    if [ ${DISTRO} == ${DISTRO_DEBIAN_9} ]; then
        deb https://mkvtoolnix.download/debian/ stretch main
        deb-src https://mkvtoolnix.download/debian/ stretch main 
    elif [ ${DISTRO} == ${DISTRO_DEBIAN_8} ]; then
        deb https://mkvtoolnix.download/debian/ jessie main
        deb-src https://mkvtoolnix.download/debian/ jessie main 
    elif [ ${DISTRO} == ${DISTRO_DEBIAN_8} ]; then
                deb https://mkvtoolnix.download/debian/ wheezy main
                deb-src https://mkvtoolnix.download/debian/ wheezy main
        else echo "Distro unsupported."; return 1; fi

    apt update
    ${PKG_INSTALL} mkvtoolnix
}

install_nodejs() {
    curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
    ${PKG_INSTALL} nodejs
}

install_animedl() {
    wget https://github.com/Xonshiz/anime-dl/archive/master.tar.gz
    tar -xzf master.tar.gz
    mv anime-dl-master anime-dl #rename to anime-dl
    rm master.tar.gz

    SCRIPTS_DIR="anime-dl/anime_dl/"

    #make it runnable
    chmod -R +x ${SCRIPTS_DIR}
    chmod -R 755 ${SCRIPTS_DIR}
}

install_pip() {
    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    python get-pip.py
    rm get-pip.py
}

install_dependencies() {
    pip install cfscrape #unspecified animedl dependenceis
    pip install cfscrape -U
    pip install tqdm
    pip install bs4
}

ensure_animedl_installed() {
    #find "Anime_DL downloads anime from" in the --help

    FIND="Anime_DL downloads anime from"
    SCRIPTS_DIR="anime-dl/anime_dl/"
    RETURN=1

    cd ${SCRIPTS_DIR}
    ./__main__.py --help > ../../tmp_help
    cd ..; cd ..

    if grep "${FIND}" tmp_help; then
        echo "anime-dl installed!";
        RETURN=0
    else
        echo "anime-dl not installed...";
        RETURN=1
    fi

    rm tmp_help
    return ${RETURN}
}

#make sure we're root so we can install packages

is_root

distro_check

if [ $? == 0 ]; then
    install_ffmpeg
    install_mkvmerge
    install_nodejs
    install_pip
    install_cfscrape
    install_animedl
    ensure_animedl_installed
    exit $?
else
    echo "no"
    exit
fi```
Xonshiz commented 6 years ago

Hey, this looks amazing. Could you please add the .sh file on this github repo and then update the same in the readme and send a PR? Or should I add it here myself?

monoclex commented 6 years ago

IIRC, at it's current state, it's not the greatest and I think I'll improve on it first before submitting a PR with it. I think I'll submit a PR within 48 hours with an improved version of it.

monoclex commented 6 years ago

58 Submitted PR