Free.vps.vc 访问GitHub资源出错 用GithubProxy代理 用sed修改脚本内容

问题

Free.vps.vc 访问GitHub资源出错


--update

修改后

bash <(curl -L https://github.crazypeace.workers.dev/https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | perl -pe "$(curl -L https://github.crazypeace.workers.dev/https://github.com/crazypeace/gh-proxy/raw/master/perl-pe-para)")


解决思路

用 GitHub Proxy 代理

source: https://github.com/hunshcn/gh-proxy

要么fork一份脚本,自己修改添加gh-proxy,如下文教程

如何设置自定义gh-proxy参数使用我的warp脚本

要么就把脚本下载到本地,然后修改脚本。有手搓和sed命令替换两条路。

手搓方法

1. 自己搭 或者 使用现成的 GitHub Proxy.

以 https://github.crazypeace.workers.dev/ 为例

2. 在你的 GitHub 资源 url 的前面加上 GitHub Proxy 的 url 

如:

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh)

修改为

bash <(curl -L https://github.crazypeace.workers.dev/https://github.com/crazypeace/v2ray_wss/raw/main/install.sh)

3. 如果你的资源是一个脚本,而这个脚本里面访问了GitHub资源

3.1 那么你可以先 wget 下来

wget https://github.crazypeace.workers.dev/https://github.com/crazypeace/v2ray_wss/raw/main/install.sh

这里下载下来的是文件名是 install.sh

3.2 然后修改脚本内容,把访问 GitHub 资源的部分也加上 GitHub Proxy 代理。

修改前

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --version 4.45.2

修改后

bash <(curl -L https://github.crazypeace.workers.dev/https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --version 4.45.2 

3.3 然后再用 chmod +x 和 bash 去调用你的脚本

3.4 进一步的,如果这个脚本内部又调用了GitHub上的脚本,你需要递归的操作

如,这里有一个 bash 和 curl 联用方式调用 GitHub上的脚本

bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --version 4.45.2

那么需要把这个 .sh 脚本文件也wget下来再修改内容,再执行。


用 sed 命令

1. 用sed修改脚本内容,给GitHub资源加上Proxy

1.1 在脚本内全部的GitHub资源的前面加上 GitHub Proxy

修改前

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh)

修改后

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed 's/\(http.*github[^/]*\/\)/https:\/\/github.crazypeace.workers.dev\/\1/g')

1.2. 用sed -E 参数

不需要转义括号了,看起来清爽一点(也就一点点,哈哈)

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E 's/(http.*github[^/]*\/)/https:\/\/github.crazypeace.workers.dev\/\1/g')

1.3 把分隔符从 / 换为 #, 又清爽一点

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E 's#(http.*github[^/]*/)#https://github.crazypeace.workers.dev/\1#g')

1.4 将sed -E的参数放到 GitHub上

例如,把上一步的sed参数保存在GitHub上 https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para1

那么命令继续进化为:

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para1)" )

到此为止,我们还只是将脚本上用到的GitHub资源加上 GitHub Proxy. 

2. 如果脚本内部调用了其它脚本

* 注, 只针对 bash 和 url 联用的形式。类似于 
bash <(curl https://xxx.sh)

有些人喜欢写成先 wget 然后 运行,这种情况本文不讨论。

2.1 在内部脚本的后面加上这么一段来处理脚本内调用到GitHub资源
 | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para1)"

那么命令为:

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E 's#(curl.*\.sh)([^/])#\1 | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para1)" \2#g')

2.2 将sed -E的参数放到 GitHub上
例如,把上一步的sed参数保存在GitHub上 https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para2

那么命令继续进化为:

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para2)" )

3. 套娃递归

3.1 将前面两段合并起来

sed的命令合并,中间用“;”号分开连接。

那么命令继续进化为:

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E 's#(curl.*\.sh)([^/])#\1 | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para1)" \2#g; s#(http.*github[^/]*/)#https://github.crazypeace.workers.dev/\1#g')

3.2 我们把 sed -E 的参数放到 GitHub 上 https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para

并且递归调用。

https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para 的内容为:

s#(curl.*\.sh)([^/])#\1 | sed -E "$(curl -L https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para)" \2#g; s#(http.*github[^/]*/)#https://github.crazypeace.workers.dev/\1#g


总结

使用时的用法为:

修改前

bash <(curl -L https://github.com/crazypeace/v2ray_wss/raw/main/install.sh)

修改后

bash <(curl -L https://github.crazypeace.workers.dev/https://github.com/crazypeace/v2ray_wss/raw/main/install.sh | sed -E "$(curl -L https://github.crazypeace.workers.dev/https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para)")


拓展一下思维,如果warp脚本里面是使用的 bash url 联用的方式的话,如果VPS的网络不能访问Github。例如:

修改前

bash <(curl -fsSL https://raw.githubusercontent.com/P3TERX/warp.sh/main/warp.sh) 4

修改后

bash <(curl -fsSL https://github.crazypeace.workers.dev/https://raw.githubusercontent.com/P3TERX/warp.sh/main/warp.sh | sed -E "$(curl -L https://github.crazypeace.workers.dev/https://github.com/crazypeace/gh-proxy/raw/master/sed-E-para)") 4

评论

The Hot3 in Last 30 Days

无服务器 自建短链服务 Url-Shorten-Worker 完整的部署教程

ClouDNS .asia免费域名 托管到CloudFlare开CDN白嫖Websocket WS通道翻墙 / desec.io