zoukankan      html  css  js  c++  java
  • github git clone 下载提速 一键脚本

    # github 下载提速 一键脚本, 目前只支持 ubuntu (理论上装了 bash 的机器都支持)

    ## 依赖命令:

      curl

      egrep

      sed

    ### 大概原理:

    爬取 github 的真实 ip 地址, 并写入 hosts 文件

    ### 建议使用 sudo 运行, 因为要修改 /etc/hosts 文件

    ## 脚本源码:

    #!/bin/bash
    #
    # 功能:这个脚本是为了更新 github.com 的ip 并插入到 /etc/hosts 文件中, 以完成 git clone 的加速
    # 作者: David Zhang
    # Ver: 0.1
    # 重要: 本脚本需要使用到 root 权限!如不信任可以 ctrl + c 打断运行
    set -e
    echo '重要: 本脚本需要使用到 root 权限!建议使用 sudo 运行! 如不信任可以 ctrl + c 打断运行...'
    echo 'zsh 下 egrep 会失效,请切换到 bash 下运行!'
    
    GITHUBIP=`curl https://github.com.ipaddress.com/ |egrep -o '<th>IP Address</th><td><ul class="comma-separated"><li>'[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+ | egrep  -o [0-9]+[.][0-9]+[.][0-9]+[.][0-9]+`
    
    echo '获取到 github ip: ';echo $GITHUBIP
    
    FASTLYIP=`curl https://fastly.net.ipaddress.com/github.global.ssl.fastly.net |egrep -o '<th>IP Address</th><td><ul class="comma-separated"><li>'[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+ | egrep  -o [0-9]+[.][0-9]+[.][0-9]+[.][0-9]+`
    
    echo '获取到 github.global.ssl.fastly ip: ';echo $FASTLYIP
    
    CODELOADIP=`curl https://github.com.ipaddress.com/codeload.github.com |egrep -o '<th>IP Address</th><td><ul class="comma-separated"><li>'[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+ | egrep  -o [0-9]+[.][0-9]+[.][0-9]+[.][0-9]+`
    
    echo '获取到 codeload.github.com ip: ';echo $CODELOADIP
    
    cp /etc/hosts ~/hosts.tmp;
    
    sed -i '/github/d' ~/hosts.tmp;
    
    echo '## github 加速用 hosts ##' >> ~/hosts.tmp
    echo $GITHUBIP ' github.com' >> ~/hosts.tmp;
    echo $FASTLYIP ' github.global.ssl.fastly.net' >> ~/hosts.tmp
    echo $CODELOADIP ' codeload.github.com' >> ~/hosts.tmp
    
    cp /etc/hosts{,.bak}
    cp ~/hosts.tmp /etc/hosts
    rm ~/hosts.tmp
    
    echo 'done'
    echo 'Now you got hosts like this:'
    
    cat /etc/hosts

    ## 喜欢请点赞哦

  • 相关阅读:
    Spring-data-jpa 笔记(一)
    grpc详解 java版
    快速入门正则表达式
    异常的处理
    一位资深程序员大牛给予Java初学者的学习路线建议
    this用法
    静态代码块与非静态代码块
    类的成员变量--构造器
    Java并发机制及锁的实现原理
    JAVA内存模型
  • 原文地址:https://www.cnblogs.com/gettolive/p/11898231.html
Copyright © 2011-2022 走看看