Last active
August 19, 2023 22:23
-
-
Save wd/e0bc83b33ce63506a9bdbc3b81658c52 to your computer and use it in GitHub Desktop.
路由器梅林固件上面使用 v2ray 的方案
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"log": { | |
"loglevel": "none" | |
}, | |
"inbound": { | |
"port": 23456, | |
"listen": "127.0.0.1", | |
"protocol": "socks", | |
"settings": { | |
"udp": true | |
} | |
}, | |
"inboundDetour": | |
[{ | |
"port": 3333, | |
"listen": "0.0.0.0", | |
"protocol": "dokodemo-door", | |
"settings": { | |
"network": "tcp,udp", | |
"followRedirect": true | |
} | |
}], | |
"outbound": { | |
"protocol": "vmess", | |
"settings": { | |
"vnext": [ | |
{ | |
"address": "这里输入你的服务器信息", | |
"port": 443, | |
"users": [ | |
{ | |
"id": "这里输入你的id,其他配置根据你需要配置", | |
"alterId": 64, | |
"security": "auto" | |
} | |
] | |
} | |
] | |
}, | |
"streamSettings": | |
{ | |
"network": "tcp", | |
"security": "tls", | |
"tlsSettings": { "allowInsecure": true } | |
} | |
}, | |
"policy": { | |
"levels": { | |
"0": {"uplinkOnly": 0} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CUR_VER="" | |
NEW_VER="" | |
ARCH="" | |
VDIS="arm" | |
ZIPFILE="/tmp/v2ray/v2ray.zip" | |
V2RAY_DIR="/jffs/v2ray" | |
CMD_INSTALL="" | |
CMD_UPDATE="" | |
SOFTWARE_UPDATED=0 | |
#######color code######## | |
RED="31m" | |
GREEN="32m" | |
YELLOW="33m" | |
BLUE="36m" | |
sysArch(){ | |
ARCH=$(uname -m) | |
if [[ "$ARCH" == "i686" ]] || [[ "$ARCH" == "i386" ]]; then | |
VDIS="32" | |
elif [[ "$ARCH" == *"armv7"* ]] || [[ "$ARCH" == "armv6l" ]]; then | |
VDIS="arm" | |
elif [[ "$ARCH" == *"armv8"* ]] || [[ "$ARCH" == "aarch64" ]]; then | |
VDIS="arm64" | |
elif [[ "$ARCH" == *"mips64le"* ]]; then | |
VDIS="mips64le" | |
elif [[ "$ARCH" == *"mips64"* ]]; then | |
VDIS="mips64" | |
elif [[ "$ARCH" == *"mipsle"* ]]; then | |
VDIS="mipsle" | |
elif [[ "$ARCH" == *"mips"* ]]; then | |
VDIS="mips" | |
elif [[ "$ARCH" == *"s390x"* ]]; then | |
VDIS="s390x" | |
fi | |
return 0 | |
} | |
colorEcho(){ | |
COLOR=$1 | |
echo -e "\033[${COLOR}${@:2}\033[0m" | |
} | |
downloadV2Ray(){ | |
rm -rf /tmp/v2ray | |
mkdir -p /tmp/v2ray | |
colorEcho ${BLUE} "Downloading V2Ray." | |
DOWNLOAD_LINK="https://github.com/v2ray/v2ray-core/releases/download/${NEW_VER}/v2ray-linux-${VDIS}.zip" | |
curl -L -H "Cache-Control: no-cache" -o ${ZIPFILE} ${DOWNLOAD_LINK} | |
if [ $? != 0 ];then | |
colorEcho ${RED} "Failed to download! Please check your network or try again." | |
exit 1 | |
fi | |
return 0 | |
} | |
installSoftware(){ | |
COMPONENT=$1 | |
if [[ -n `command -v $COMPONENT` ]]; then | |
return 0 | |
fi | |
getPMT | |
if [[ $? -eq 1 ]]; then | |
colorEcho $YELLOW "The system package manager tool isn't APT or YUM, please install ${COMPONENT} manually." | |
exit | |
fi | |
colorEcho $GREEN "Installing $COMPONENT" | |
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then | |
colorEcho ${BLUE} "Updating software repo" | |
$CMD_UPDATE | |
SOFTWARE_UPDATED=1 | |
fi | |
colorEcho ${BLUE} "Installing ${COMPONENT}" | |
$CMD_INSTALL $COMPONENT | |
if [[ $? -ne 0 ]]; then | |
colorEcho ${RED} "Install ${COMPONENT} fail, please install it manually." | |
exit | |
fi | |
return 0 | |
} | |
extract(){ | |
colorEcho ${BLUE}"Extracting V2Ray package to /tmp/v2ray." | |
mkdir -p /tmp/v2ray | |
unzip $1 -d "/tmp/v2ray/" | |
if [[ $? -ne 0 ]]; then | |
colorEcho ${RED} "Extracting V2Ray faile!" | |
exit | |
fi | |
return 0 | |
} | |
# 1: new V2Ray. 0: no | |
getVersion(){ | |
CUR_VER=`$V2RAY_DIR/v2ray -version 2>/dev/null | head -n 1 | cut -d " " -f2` | |
TAG_URL="https://api.github.com/repos/v2ray/v2ray-core/releases/latest" | |
NEW_VER=`curl ${PROXY} -s ${TAG_URL} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4` | |
if [[ $? -ne 0 ]] || [[ $NEW_VER == "" ]]; then | |
colorEcho ${RED} "Network error! Please check your network or try again." | |
exit | |
elif [[ "$NEW_VER" != "$CUR_VER" ]];then | |
return 1 | |
fi | |
return 0 | |
} | |
copyFile() { | |
NAME=$1 | |
MANDATE=$2 | |
ERROR=`cp "/tmp/v2ray/v2ray-${NEW_VER}-linux-${VDIS}/${NAME}" "$V2RAY_DIR/${NAME}"` | |
if [[ $? -ne 0 ]]; then | |
colorEcho ${YELLOW} "${ERROR}" | |
if [ "$MANDATE" = true ]; then | |
exit | |
fi | |
fi | |
} | |
installV2Ray(){ | |
# Install V2Ray binary to $V2RAY_DIR | |
mkdir -p $V2RAY_DIR | |
copyFile v2ray true | |
makeExecutable v2ray | |
copyFile v2ctl false | |
makeExecutable v2ctl | |
copyFile geoip.dat false | |
copyFile geosite.dat false | |
return 0 | |
} | |
makeExecutable() { | |
chmod +x "$V2RAY_DIR/$1" | |
} | |
updateWatchDog() { | |
colorEcho ${GREEN} "Update v2ray_watchdog.sh" | |
echo "IyEvYmluL3NoCgp2MnJheT0nL2pmZnMvdjJyYXkvdjJyYXknCgppc192MnJheV9hbGl2ZSgpIHsKICAgIHYycmF5X2NvdW50PWBwcyAtdyB8Z3JlcCAnL2pmZnMvdjJyYXkvdjJyYXknfGdyZXAgLXYgZ3JlcHxncmVwIC12IHdhdGNoZG9nfHdjIC1sYAogICAgaWYgWyAiJHYycmF5X2NvdW50IiAtZXEgMSBdO3RoZW4KICAgICAgICByZXR1cm4gMCAgIyB3b3JrIG9rCiAgICBlbHNlCiAgICAgICAgcmV0dXJuIDEKICAgIGZpCn0KCnJlc3RhcnRfdjJyYXkoKSB7CiAgICBraWxsYWxsIHYycmF5ID4vZGV2L251bGwgMj4mMQogICAgJHYycmF5ICYKICAgIGVjaG8gJCQgPiAvdG1wL3YycmF5LnBpZAp9CgpzdG9wX3NzKCkgewogICAga2lsbGFsbCBzcy1sb2NhbCA+L2Rldi9udWxsIDI+JjEKICAgIGtpbGxhbGwgc3MtcmVkaXIgPi9kZXYvbnVsbCAyPiYxCn0KCm1haW4oKXsKICAgIGlzX3YycmF5X2FsaXZlCiAgICBpZiBbICIkPyIgLW5lIDAgXTt0aGVuCiAgICAgICAgc3RvcF9zcwogICAgICAgIHJlc3RhcnRfdjJyYXkKICAgICAgICBlY2hvICJ2MnJheSByZXN0YXJ0IGF0ICIkKGRhdGUpID4+IC90bXAvdjJyYXkubG9nCiAgICBmaQp9CgptYWluCg==" > /tmp/dog.in | |
base64 -d /tmp/dog.in > "$V2RAY_DIR/v2ray_watchdog.sh" | |
rm /tmp/dog.in | |
} | |
main() { | |
# dowload via network and extract | |
updateWatchDog | |
getVersion | |
if [[ $? == 0 ]]; then | |
colorEcho ${GREEN} "Lastest version ${NEW_VER} is already installed." | |
exit | |
else | |
colorEcho ${BLUE} "Installing V2Ray ${NEW_VER} on ${ARCH}" | |
downloadV2Ray | |
extract ${ZIPFILE} | |
fi | |
installV2Ray | |
colorEcho ${GREEN} "V2Ray ${NEW_VER} is installed." | |
rm -rf /tmp/v2ray | |
return 0 | |
} | |
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 修改 /jffs/scripts/nat-start 和 /jffs/scripts/wan-start 都增加一行 cron 的配置,定时跑 watchdog 检查服务 | |
# 注意:下面的 admin 需要改成你自己的用户名 | |
grep -q 'v2ray_watchdog.sh' /var/spool/cron/crontabs/admin || echo "*/5 * * * * /bin/sh /jffs/v2ray/v2ray_watchdog.sh" >> /var/spool/cron/crontabs/admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
v2ray='/jffs/v2ray/v2ray' # v2ray 的所有文件放到 /jffs/v2ray 下面 | |
is_v2ray_alive() { | |
v2ray_count=`ps -w |grep '/jffs/v2ray/v2ray'|grep -v grep|grep -v watchdog|wc -l` | |
if [ "$v2ray_count" -eq 1 ];then | |
return 0 # work ok | |
else | |
return 1 | |
fi | |
} | |
restart_v2ray() { | |
killall v2ray >/dev/null 2>&1 | |
$v2ray & | |
echo $$ > /tmp/v2ray.pid | |
} | |
stop_ss() { | |
killall ss-local >/dev/null 2>&1 | |
killall ss-redir >/dev/null 2>&1 | |
} | |
main(){ | |
is_v2ray_alive #判断 v2ray 是不是还活着 | |
if [ "$?" -ne 0 ];then | |
stop_ss # 停止 ss 相关进程,因为我们会用 v2ray 代替他 | |
restart_v2ray # 启动 v2ray | |
echo "v2ray restart at "$(date) >> /tmp/v2ray.log | |
fi | |
} | |
main |
大佬可否做一个独立版的安装包啊?完全没理解为何你(似乎)连独立的插件控制页面都做出来了,为何还需要通过ss补丁的方式安装?
现在可否更新xray或者v2fly内核?另外你博客里说的奔溃了自动重启插件似乎被你删了?谢谢
不是已经有官方插件了吗?别用这个了吧。我好久不用 merlin 和 v2ray 了。
😅啊?!有官方的吗?我是想跑服务端的,梅林我只找到ssserver和fancyss。但是fancyss是客户端的。看了下你的代码,似乎是跑v2ray然后可以自定义config.json?所以可以当成服务器用?(所以你说的替换ss是指替换ss客户端啊?)
这个基于 kooshare 梅林固件的,你可以去看看他们有没有 v2ray 支持。我记得是有了的。
看过了,没有。。。或许是谁在论坛上发布的吧😅。。。就是没找到v2ray,xray之类的插件。整个github感觉你的最接近了。。。
https://github.com/koolshare/armsoft
https://github.com/orgs/koolshare/repositories
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
arm 似乎有 arm, armv7, arm64,我看 v2ray 提供了 arm 和 arm64 版本,是不是都试试看?我这跑没问题的,不用自己编译。
我的是 AC86u,
uname -a
输出如下v2ray -version
输出