github备份脚本

Gayhub被微软收购了,从网上找了一个备份脚本,还是有备无患下吧。

原地址https://blog.csdn.net/guguant/article/details/78204912

    #!/bin/bash
    # tool
    # auto backup all repositories from github
    if [[ $# -eq 0 ]] || [[ $1 = "-h" ]];then
        echo -e "\033[31m--------------------------------------------------------\033[0m"
        echo "Usage1: $0 URL"
        echo "   e.g: $0 https://github.com/Guguant?tab=repositories"
        echo ""
        echo "Usage2: $0 Username Page"
        echo "   e.g: $0 Guguant 1"
        echo -e "\033[31m--------------------------------------------------------\033[0m"
        exit 1;
    fi

    url=""
    username=""
    if [ $# == 1 ];then
        url="https://github.com/knickersgod?tab=repositories"
        username=${url%\?*}
        username=${username##*/}
    else
        username=$1
        url="https://github.com/${username}?page=${2}&tab=repositories"
    fi

    patten1="a href=\"/"${username}"/"
    r_path=`curl "${url}" | grep "${patten1}"`

    # get repositories url path
    path_head="https://github.com/"
    for p in ${r_path}
    do
        if [[ $p =~ "href" ]];then
            p=${p#*/}
            p=${p%\"*}

            p=${path_head}${p}
            echo -e "\033[33m ====== Download ====================\033[0m"
            echo -e "\033[32m $p \033[0m"
            git clone ${p}
            echo -e "\033[33m ====== $p has been Finished =================\033[0m"
        fi
    done

使用方法:

sh ./git.sh https://github.com/YOURUSERNAME?tab=repositories

0

Related Posts

Comments

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.