一个用 Go 语言写的脚本路由器(例如快捷拉取执行自用脚本)
突然发现用 PHP 顺带路由一下也不错
这个项目是我突发奇想折腾出来的,当时玩的虚拟机实在太多了,一个一个的改东西太麻烦了,于是索性自己手搓了一个Shell
后来发现GitHub上已经有大佬写好现成的了……
不过练练手也不错
Note
怀念vs8.top,这个域名被注册局暂停解析了,目前域名托管商也没办法申诉,原因是重定向滥用,所以暂时换成了k7s.top
简短的一句话命令,如果系统上没有 bash 的话,可以使用 sh 或者 zsh 等等 shell 代替,使用 sh 执行可能有部分命令用不了
bash <(curl k7s.top)或者使用 wget :
bash <(wget -qO- k7s.top)对于 sudo 提升的权限
sudo bash -c "$(curl -fsSL k7s.top)"更通用的方法
curl -fsSL k7s.top -o main.sh
chmod +x main.sh
bash main.sh[root@localhost ~] bash <(curl -sL k7s.top)
请输入选项:
-1. 执行快捷菜单(一些实用功能)
1. 执行arch.sh脚本(查看架构)
2. 执行install.sh脚本(没写)
3. 执行update.sh脚本(没写)
4. 执行uninstall.sh脚本(没写)
5. 一键换清华源setup_sources.sh(支持多种发行版)
-1
请输入选项:
1. 一键关闭SELinux(redhat系Linux需要)
2. 一键允许root用户连接ssh
3. 一键设置vi-tiny可以使用插入(Debian最小化安装可能出现的问题)
1
/usr/sbin/setenforce: SELinux is disabled
[root@localhost ~] bash <(curl -sSL k7s.top)
请输入选项:
-1. 执行快捷菜单(一些实用功能)
1. 执行arch.sh脚本(查看架构)
2. 执行install.sh脚本(没写)
3. 执行update.sh脚本(没写)
4. 执行uninstall.sh脚本(没写)
5. 一键换清华源setup_sources.sh(支持多种发行版)
5
Supported Linux distributions:(Only the official original version is supported)
1. Ubuntu 22.04 LTS
2. Debian 12
3. CentOS 7
4. Fedora 30
5. OpenBSD
6. Alpine
7. Arch Linux
8. openSUSE Tumbleweed
9. openSUSE Leap 15.3
Enter your Linux distribution choice: 3
Setting up sources for CentOS 7...
已加载插件:fastestmirror
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/8): extras/7/x86_64/filelists_db | 303 kB 00:00:00
(2/8): extras/7/x86_64/primary_db | 250 kB 00:00:00
(3/8): extras/7/x86_64/other_db | 150 kB 00:00:00
(4/8): base/7/x86_64/other_db | 2.6 MB 00:00:01
(5/8): base/7/x86_64/filelists_db | 7.2 MB 00:00:01
(6/8): updates/7/x86_64/primary_db | 22 MB 00:00:03
(7/8): updates/7/x86_64/other_db | 1.4 MB 00:00:00
(8/8): updates/7/x86_64/filelists_db | 12 MB 00:00:04
元数据缓存已建立
Source setup completed.
frps
# token 配置
bash <(curl k7s.top/frps.sh)
# oidc 配置
# bash <(curl k7s.top/frps-oidc.sh)
# 统一配置(实验)
# bash <(curl k7s.top/frps-unified.sh) -y --auth token --mirror ghfast
# auth 可选 token oidc, mirror 可选 ghfast, github, gitee(暂未支持)对于需要加速下载的情况可以替换链接为镜像地址,例如 https://github.com/fatedier/frp/releases/download/ 替换为 https://ghfast.top/https://github.com/fatedier/frp/releases/download/
frpc
bash <(curl k7s.top/frpc.sh)卸载 frps
systemctl stop frps
systemctl disable frps
rm -rf /usr/local/bin/frps
rm -rf /etc/frp/frps.toml卸载 frpc
systemctl stop frpc
systemctl disable frpc
rm -rf /usr/local/bin/frpc
rm -rf /etc/frp/frpc.toml编译成二进制文件
go build -o script-router main.go然后运行
./script-router
# 可以指定地址和端口
./script-router -addr 0.0.0.0:8080可以根据需要配置反向代理
使用 systemd 管理脚本路由器
cat >/etc/systemd/system/Script-Router.service <<EOF
[Unit]
Description=Script-Router service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/Script-Router -addr 0.0.0.0:28789
Restart=always
WorkingDirectory=/root/Script-Router/
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable Script-Router
systemctl start Script-Router
# 查看状态
systemctl status Script-Router
# 查看日志
journalctl -u Script-Router -f
# upload shell script to Workdirectory
curl http://localhost:28789
# 卸载
#systemctl stop Script-Router
#systemctl disable Script-Router
#rm -f /etc/systemd/system/Script-Router.service参考