core: 添加 frpc 内网穿透

This commit is contained in:
bin456789 2025-04-28 23:18:27 +08:00
parent 3f1d5ce9fa
commit bbf78e6d9a
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
13 changed files with 397 additions and 27 deletions

View File

@ -8,9 +8,13 @@ charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
[windows.xml] [{windows.xml,windows-*.xml}]
end_of_line = crlf end_of_line = crlf
[windows-frpc.xml]
charset = utf-16-le
indent_size = 2
[*.{bat,cmd,ps1}] [*.{bat,cmd,ps1}]
end_of_line = crlf end_of_line = crlf

View File

@ -34,7 +34,7 @@ The system requirements for the target system are as follows:
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.18, 3.19, 3.20, 3.21 | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.18, 3.19, 3.20, 3.21 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | Rolling | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://canonical-subiquity.readthedocs-hosted.com/en/latest/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.04 | 512 MB \* | 2 GB | | <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.04 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB |
@ -42,7 +42,7 @@ The system requirements for the target system are as follows:
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 41, 42 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 41, 42 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.03 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.03 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, Tumbleweed (Rolling) | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, Tumbleweed (Rolling) | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 GB | | <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 24.11 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | Rolling | 512 MB | 5 GB | | <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | Rolling | 512 MB | 5 GB |
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB | | <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | Rolling | 512 MB | 5 GB |
| <img width="16" height="16" src="https://aosc.io/assets/distros/aosc-os.svg" /> AOSC OS | Rolling | 512 MB | 5 GB | | <img width="16" height="16" src="https://aosc.io/assets/distros/aosc-os.svg" /> AOSC OS | Rolling | 512 MB | 5 GB |
@ -160,6 +160,7 @@ bash reinstall.sh anolis 7|8|23
- `--ssh-key C:\path\to\public_key` - `--ssh-key C:\path\to\public_key`
- `--ssh-port PORT` Change the SSH port (for log observation during installation and for the new system) - `--ssh-port PORT` Change the SSH port (for log observation during installation and for the new system)
- `--web-port PORT` Change the Web port (for log observation during installation) - `--web-port PORT` Change the Web port (for log observation during installation)
- `--frpc-toml /path/to/frpc.toml` Add frpc for intranet tunneling
- `--hold 2` Prevent reboot after installation completes, allowing SSH login to modify system content; the system is mounted at `/os` (this feature is not supported on Debian/Kali). - `--hold 2` Prevent reboot after installation completes, allowing SSH login to modify system content; the system is mounted at `/os` (this feature is not supported on Debian/Kali).
> [!TIP] > [!TIP]
@ -212,10 +213,11 @@ bash reinstall.sh dd --img "https://example.com/xxx.xz"
#### Optional parameters #### Optional parameters
- `--allow-ping` Allow ping responses (DD Windows only) - `--allow-ping` Configure Windows Firewall to Allow Ping Responses (DD Windows only)
- `--rdp-port PORT` Change RDP port (DD Windows only) - `--rdp-port PORT` Change RDP port (DD Windows only)
- `--ssh-port PORT` Change SSH port (for log observation during installation) - `--ssh-port PORT` Change SSH port (for log observation during installation)
- `--web-port PORT` Change Web port (for log observation during installation) - `--web-port PORT` Change Web port (for log observation during installation)
- `--frpc-toml /path/to/frpc.toml` Add frpc for intranet tunneling (DD Windows only)
- `--hold 2` Prevent reboot after the DD process finishes, allowing SSH login to modify system content. The Windows system will be mounted at `/os`, but Linux systems will **NOT** be automatically mounted. - `--hold 2` Prevent reboot after the DD process finishes, allowing SSH login to modify system content. The Windows system will be mounted at `/os`, but Linux systems will **NOT** be automatically mounted.
> [!TIP] > [!TIP]
@ -245,6 +247,7 @@ bash reinstall.sh alpine --hold=1
- `--ssh-key gitlab:your_username` - `--ssh-key gitlab:your_username`
- `--ssh-key /path/to/public_key` - `--ssh-key /path/to/public_key`
- `--ssh-key C:\path\to\public_key` - `--ssh-key C:\path\to\public_key`
- `--frpc-toml /path/to/frpc.toml` Add frpc for intranet tunneling
### Feature 4: Reboot to <img width="16" height="16" src="https://netboot.xyz/img/favicon.ico" /> netboot.xyz ### Feature 4: Reboot to <img width="16" height="16" src="https://netboot.xyz/img/favicon.ico" /> netboot.xyz
@ -384,13 +387,14 @@ bash reinstall.sh windows \
#### Optional parameters #### Optional parameters
- `--password PASSWORD` Set Password - `--password PASSWORD` Set Password
- `--allow-ping` Configures the Windows firewall to allow ping requests - `--allow-ping` Configure Windows Firewall to Allow Ping Responses
- `--rdp-port PORT` Change RDP port - `--rdp-port PORT` Change RDP port
- `--ssh-port PORT` Change SSH port (for log observation during installation) - `--ssh-port PORT` Change SSH port (for log observation during installation)
- `--web-port PORT` Change Web port (for log observation during installation) - `--web-port PORT` Change Web port (for log observation during installation)
- `--add-driver INF_OR_DIR` Add additional driver, specifying .inf path, or the folder contains .inf file. - `--add-driver INF_OR_DIR` Add additional driver, specifying .inf path, or the folder contains .inf file.
- The driver must be downloaded locally first. - The driver must be downloaded locally first.
- This parameter can be set multiple times to add different driver. - This parameter can be set multiple times to add different driver.
- `--frpc-toml /path/to/frpc.toml` Add frpc for intranet tunneling
- `--hold 2` Allow SSH connections for modifying the disk content before rebooting into the official Windows installation program, with the disk mounted at `/os`. - `--hold 2` Allow SSH connections for modifying the disk content before rebooting into the official Windows installation program, with the disk mounted at `/os`.
#### The following drivers will automatic download and install as needed, without the need for manual addition #### The following drivers will automatic download and install as needed, without the need for manual addition

View File

@ -34,7 +34,7 @@
| <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.18, 3.19, 3.20, 3.21 | 256 MB | 1 GB | | <img width="16" height="16" src="https://www.alpinelinux.org/alpine-logo.ico" /> Alpine | 3.18, 3.19, 3.20, 3.21 | 256 MB | 1 GB |
| <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://www.debian.org/favicon.ico" /> Debian | 9, 10, 11, 12 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ | | <img width="16" height="16" src="https://github.com/bin456789/reinstall/assets/7548515/f74b3d5b-085f-4df3-bcc9-8a9bd80bb16d" /> Kali | 滚动 | 256 MB | 1 ~ 1.5 GB ^ |
| <img width="16" height="16" src="https://canonical-subiquity.readthedocs-hosted.com/en/latest/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.04 | 512 MB \* | 2 GB | | <img width="16" height="16" src="https://documentation.ubuntu.com/server/_static/favicon.png" /> Ubuntu | 16.04 LTS - 24.04 LTS, 25.04 | 512 MB \* | 2 GB |
| <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://img.alicdn.com/imgextra/i1/O1CN01oJnJZg1yK4RzI4Rx2_!!6000000006559-2-tps-118-118.png" /> Anolis | 7, 8, 23 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.redhat.com/favicon.ico" /> RHEL &nbsp;<img width="16" height="16" src="https://almalinux.org/fav/favicon.ico" /> AlmaLinux &nbsp;<img width="16" height="16" src="https://rockylinux.org/favicon.png" /> Rocky &nbsp;<img width="16" height="16" src="https://www.oracle.com/asset/web/favicons/favicon-32.png" /> Oracle | 8, 9 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://opencloudos.org/qq.ico" /> OpenCloudOS | 8, 9, Stream 23 | 512 MB \* | 5 GB |
@ -42,7 +42,7 @@
| <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 41, 42 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://fedoraproject.org/favicon.ico" /> Fedora | 41, 42 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.03 | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://www.openeuler.org/favicon.ico" /> openEuler | 20.03 LTS - 24.03 LTS, 25.03 | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, Tumbleweed (滚动) | 512 MB \* | 5 GB | | <img width="16" height="16" src="https://static.opensuse.org/favicon.ico" /> openSUSE | Leap 15.6, Tumbleweed (滚动) | 512 MB \* | 5 GB |
| <img width="16" height="16" src="https://github.com/user-attachments/assets/99a542b6-6482-4086-addf-f192c06fef73" /> NixOS | 24.11 | 512 MB | 5 GB | | <img width="16" height="16" src="https://nixos.org/favicon.svg" /> NixOS | 24.11 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | 滚动 | 512 MB | 5 GB | | <img width="16" height="16" src="https://archlinux.org/static/favicon.png" /> Arch | 滚动 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB | | <img width="16" height="16" src="https://www.gentoo.org/assets/img/logo/gentoo-g.png" /> Gentoo | 滚动 | 512 MB | 5 GB |
| <img width="16" height="16" src="https://aosc.io/assets/distros/aosc-os.svg" /> 安同 OS | 滚动 | 512 MB | 5 GB | | <img width="16" height="16" src="https://aosc.io/assets/distros/aosc-os.svg" /> 安同 OS | 滚动 | 512 MB | 5 GB |
@ -160,6 +160,7 @@ bash reinstall.sh anolis 7|8|23
- `--ssh-key C:\path\to\public_key` - `--ssh-key C:\path\to\public_key`
- `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用,也作用于新系统) - `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用,也作用于新系统)
- `--web-port PORT` 修改 Web 端口(安装期间观察日志用) - `--web-port PORT` 修改 Web 端口(安装期间观察日志用)
- `--frpc-toml /path/to/frpc.toml` 添加 frpc 内网穿透
- `--hold 2` 安装结束后不重启,此时可以 SSH 登录修改系统内容,系统挂载在 `/os` (此功能不支持 Debian/Kali) - `--hold 2` 安装结束后不重启,此时可以 SSH 登录修改系统内容,系统挂载在 `/os` (此功能不支持 Debian/Kali)
> [!TIP] > [!TIP]
@ -212,10 +213,11 @@ bash reinstall.sh dd --img "https://example.com/xxx.xz"
#### 可选参数 #### 可选参数
- `--allow-ping` 允许被 Ping (仅限 DD Windows) - `--allow-ping` 设置 Windows 防火墙允许被 Ping (仅限 DD Windows)
- `--rdp-port PORT` 修改 RDP 端口 (仅限 DD Windows) - `--rdp-port PORT` 修改 RDP 端口 (仅限 DD Windows)
- `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用) - `--ssh-port PORT` 修改 SSH 端口(安装期间观察日志用)
- `--web-port PORT` 修改 Web 端口(安装期间观察日志用) - `--web-port PORT` 修改 Web 端口(安装期间观察日志用)
- `--frpc-toml /path/to/frpc.toml` 添加 frpc 内网穿透(仅限 DD Windows
- `--hold 2` DD 结束后不重启,此时可以 SSH 登录修改系统内容Windows 系统会挂载在 `/os`Linux 系统**不会**自动挂载 - `--hold 2` DD 结束后不重启,此时可以 SSH 登录修改系统内容Windows 系统会挂载在 `/os`Linux 系统**不会**自动挂载
> [!TIP] > [!TIP]
@ -245,6 +247,7 @@ bash reinstall.sh alpine --hold=1
- `--ssh-key gitlab:your_username` - `--ssh-key gitlab:your_username`
- `--ssh-key /path/to/public_key` - `--ssh-key /path/to/public_key`
- `--ssh-key C:\path\to\public_key` - `--ssh-key C:\path\to\public_key`
- `--frpc-toml /path/to/frpc.toml` 添加 frpc 内网穿透
### 功能 4: 重启到 <img width="16" height="16" src="https://netboot.xyz/img/favicon.ico" /> netboot.xyz ### 功能 4: 重启到 <img width="16" height="16" src="https://netboot.xyz/img/favicon.ico" /> netboot.xyz
@ -391,6 +394,7 @@ bash reinstall.sh windows \
- `--add-driver INF_OR_DIR` 添加额外驱动,填写 .inf 路径,或者 .inf 所在的文件夹 - `--add-driver INF_OR_DIR` 添加额外驱动,填写 .inf 路径,或者 .inf 所在的文件夹
- 需先下载驱动到本地 - 需先下载驱动到本地
- 可多次设置该参数以添加不同的驱动 - 可多次设置该参数以添加不同的驱动
- `--frpc-toml /path/to/frpc.toml` 添加 frpc 内网穿透
- `--hold 2` 在进入 Windows 官方安装程序之前,可以 SSH 登录修改硬盘内容,硬盘挂载在 `/os` - `--hold 2` 在进入 Windows 官方安装程序之前,可以 SSH 登录修改硬盘内容,硬盘挂载在 `/os`
#### 以下驱动会自动按需下载安装,无需手动添加 #### 以下驱动会自动按需下载安装,无需手动添加

View File

@ -164,6 +164,7 @@ d-i partman/early_command string true; \
# kali ssh 默认关闭 # kali ssh 默认关闭
# 另一种方法处理 cloudcone # 另一种方法处理 cloudcone
# if [ "$link_grub_dir" = 1 ]; then mkdir /target/boot/grub2; echo 'chainloader (hd0)+1' >/target/boot/grub2/grub.cfg; fi; \ # if [ "$link_grub_dir" = 1 ]; then mkdir /target/boot/grub2; echo 'chainloader (hd0)+1' >/target/boot/grub2/grub.cfg; fi; \
# debian 9 tar 不支持 --strip-components
d-i preseed/late_command string true; \ d-i preseed/late_command string true; \
for str in $(grep -wo "extra_[^ ]*" /proc/cmdline | sed 's/^extra_//'); do eval "$str"; done; \ for str in $(grep -wo "extra_[^ ]*" /proc/cmdline | sed 's/^extra_//'); do eval "$str"; done; \
@ -186,6 +187,22 @@ d-i preseed/late_command string true; \
echo "Port $ssh_port" >>/target/etc/ssh/sshd_config; \ echo "Port $ssh_port" >>/target/etc/ssh/sshd_config; \
fi; \ fi; \
if [ -s /configs/frpc.toml ]; then \
url=$(sh /get-frpc-url.sh linux); \
basename=$(echo "$url" | sed 's,.*/,,' | sed 's,\.tar\.gz,,'); \
mkdir -p /target/usr/local/bin; \
mkdir -p /target/usr/local/etc/frpc; \
for i in {1..5}; do \
wget -O /target/frpc.tar.gz "$url" && break; \
done; \
tar xzf /target/frpc.tar.gz "$basename/frpc" -O >/target/usr/local/bin/frpc; \
rm -f /target/frpc.tar.gzx; \
chmod a+x /target/usr/local/bin/frpc; \
cp /configs/frpc.toml /target/usr/local/etc/frpc/; \
cp /frpc.service /target/etc/systemd/system/; \
in-target systemctl enable frpc; \
fi; \
cp /fix-eth-name.sh /target/; \ cp /fix-eth-name.sh /target/; \
cp /fix-eth-name.service /target/etc/systemd/system/; \ cp /fix-eth-name.service /target/etc/systemd/system/; \
in-target systemctl enable fix-eth-name in-target systemctl enable fix-eth-name

24
frpc-example.toml Normal file
View File

@ -0,0 +1,24 @@
serverAddr = "YOUR_FRP_SERVER_IP"
serverPort = 7000
auth.token = "YOUR_FRP_TOKEN"
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 2222
[[proxies]]
name = "rdp_tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3389
remotePort = 33890
[[proxies]]
name = "rdp_udp"
type = "udp"
localIP = "127.0.0.1"
localPort = 3389
remotePort = 33890

17
frpc.service Normal file
View File

@ -0,0 +1,17 @@
# https://github.com/archlinuxcn/repo/blob/master/archlinuxcn/frp/frpc.service
[Unit]
Description=Frp Client Service
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/frpc -c /usr/local/etc/frpc/frpc.toml
ExecReload=/usr/local/bin/frpc reload -c /usr/local/etc/frpc/frpc.toml
[Install]
WantedBy=multi-user.target

96
get-frpc-url.sh Normal file
View File

@ -0,0 +1,96 @@
#!/bin/ash
# shellcheck shell=dash
# trans.sh/debian.cfg 共用此脚本
# debian 9 不支持 set -E
set -e
is_in_china() {
grep -q 1 /dev/netconf/*/is_in_china
}
is_ipv6_only() {
! grep -q 1 /dev/netconf/eth*/ipv4_has_internet
}
get_frpc_url() {
# 传入 windows 或者 linux
local os_type=$1
local nt_ver=$2
is_need_old_version() {
[ "$nt_ver" = "6.0" ] || [ "$nt_ver" = "6.1" ]
}
version=$(
if is_need_old_version; then
echo 0.54.0
else
# debian 11 initrd 没有 xargs awk
# debian 12 initrd 没有 xargs
# github 不支持 ipv6
if is_in_china || is_ipv6_only; then
wget -O- https://mirrors.nju.edu.cn/github-release/fatedier/frp/LatestRelease/frp_sha256_checksums.txt |
grep -m1 frp_ | cut -d_ -f2
else
# https://api.github.com/repos/fatedier/frp/releases/latest 有请求次数限制
# root@localhost:~# wget --spider -S https://github.com/fatedier/frp/releases/latest 2>&1 | grep Location:
# Location: https://github.com/fatedier/frp/releases/tag/v0.62.0
# Location: https://github.com/fatedier/frp/releases/tag/v0.62.0 [following] # 原版 wget 多了这行
wget --spider -S https://github.com/fatedier/frp/releases/latest 2>&1 |
grep -m1 '^ Location:' | sed 's,.*/tag/v,,'
fi
fi
)
if [ -z "$version" ]; then
echo 'cannot find version'
return 1
fi
suffix=$(
case "$os_type" in
linux) echo tar.gz ;;
windows) echo zip ;;
esac
)
mirror=$(
# nju 没有 win7 用的旧版
# github 不支持 ipv6
# jsdelivr 不支持 github releases 文件
if is_ipv6_only; then
if is_need_old_version; then
echo 'NOT_SUPPORT'
return 1
else
echo https://mirrors.nju.edu.cn/github-release/fatedier/frp
fi
else
if is_in_china; then
if is_need_old_version; then
echo https://github.com/fatedier/frp/releases/download
else
echo https://mirrors.nju.edu.cn/github-release/fatedier/frp
fi
else
echo https://github.com/fatedier/frp/releases/download
fi
fi
)
arch=$(
case "$(uname -m)" in
x86_64) echo amd64 ;;
aarch64) echo arm64 ;;
esac
)
filename=frp_${version}_${os_type}_${arch}.$suffix
echo "${mirror}/v${version}/${filename}"
}
get_frpc_url "$@"

View File

@ -1,6 +1,6 @@
#!/bin/ash #!/bin/ash
# shellcheck shell=dash # shellcheck shell=dash
# alpine / debian initrd 共用此脚本 # alpine/debian initrd 共用此脚本
# accept_ra 接收 RA + 自动配置网关 # accept_ra 接收 RA + 自动配置网关
# autoconf 自动配置地址,依赖 accept_ra # autoconf 自动配置地址,依赖 accept_ra
@ -288,6 +288,9 @@ fi
echo "Configuring $ethx ($mac_addr)..." echo "Configuring $ethx ($mac_addr)..."
# 不开启 lo 则 frp 无法连接 127.0.0.1 22
ip link set dev lo up
# 开启 ethx # 开启 ethx
ip link set dev "$ethx" up ip link set dev "$ethx" up
sleep 1 sleep 1

View File

@ -69,12 +69,17 @@ Usage: $reinstall_____ anolis 7|8|23
windows --image-name="windows xxx yyy" --iso="http://xxx.com/xxx.iso" windows --image-name="windows xxx yyy" --iso="http://xxx.com/xxx.iso"
netboot.xyz netboot.xyz
Options: [--password PASSWORD] Options: For Linux/Windows:
[--ssh-key KEY] [--password PASSWORD]
[--ssh-port PORT] [--ssh-key KEY]
[--rdp-port PORT] [--ssh-port PORT]
[--web-port PORT] [--web-port PORT]
[--frpc-toml TOML]
For Windows Only:
[--allow-ping] [--allow-ping]
[--rdp-port PORT]
[--add-driver INF_OR_DIR]
Manual: https://github.com/bin456789/reinstall Manual: https://github.com/bin456789/reinstall
@ -3148,11 +3153,15 @@ EOF
curl -LO "$confhome/fix-eth-name.sh" curl -LO "$confhome/fix-eth-name.sh"
curl -LO "$confhome/fix-eth-name.service" curl -LO "$confhome/fix-eth-name.service"
# 最近 kali initrd 删除了原版 wget # 有段时间 kali initrd 删除了原版 wget
# 但 initrd 的 busybox wget 又不支持 https # 但 initrd 的 busybox wget 又不支持 https
# 因此改成在这里下载 # 因此改成在这里下载
curl -LO "$confhome/get-xda.sh" curl -LO "$confhome/get-xda.sh"
curl -LO "$confhome/ttys.sh" curl -LO "$confhome/ttys.sh"
if [ -n "$frpc_config" ]; then
curl -LO "$confhome/get-frpc-url.sh"
curl -LO "$confhome/frpc.service"
fi
# 可以节省一点内存? # 可以节省一点内存?
echo 'export DEBCONF_DROP_TRANSLATIONS=1' | echo 'export DEBCONF_DROP_TRANSLATIONS=1' |
@ -3522,6 +3531,9 @@ This script is outdated, please download reinstall.sh again.
else else
save_password $initrd_dir/configs save_password $initrd_dir/configs
fi fi
if [ -n "$frpc_config" ]; then
cat "$frpc_config" >$initrd_dir/configs/frpc.toml
fi
if is_distro_like_debian $nextos_distro; then if is_distro_like_debian $nextos_distro; then
mod_initrd_debian_kali mod_initrd_debian_kali
@ -3690,6 +3702,7 @@ for o in ci installer debug minimal allow-ping force-cn help \
web-port: http-port: \ web-port: http-port: \
allow-ping: \ allow-ping: \
commit: \ commit: \
frpc-conf: frpc-config: frpc-toml: \
force: \ force: \
force-old-windows-setup:; do force-old-windows-setup:; do
[ -n "$long_opts" ] && long_opts+=, [ -n "$long_opts" ] && long_opts+=,
@ -3744,6 +3757,25 @@ while true; do
error_and_exit "Invalid $1 value: $2" error_and_exit "Invalid $1 value: $2"
fi fi
hold=$2 hold=$2
shift 2
;;
--frpc-conf | --frpc-config | --frpc-toml)
[ -n "$2" ] || error_and_exit "Need value for $1"
# windows 路径转换
frpc_config=$(get_unix_path "$2")
# alpine busybox 不支持 readlink -m
# readlink -m /asfsafasfsaf/fasf
# 因此需要先判断路径是否存在
if ! [ -f "$frpc_config" ]; then
error_and_exit "Not a toml file: $2"
fi
# 转为绝对路径
frpc_config=$(readlink -f "$frpc_config")
shift 2 shift 2
;; ;;
--force) --force)

136
trans.sh
View File

@ -331,7 +331,7 @@ get_ttys() {
find_xda() { find_xda() {
# 出错后再运行脚本,硬盘可能已经格式化,之前记录的分区表 id 无效 # 出错后再运行脚本,硬盘可能已经格式化,之前记录的分区表 id 无效
# 因此找到 xda 后要保存 xda 到 /config/xda # 因此找到 xda 后要保存 xda 到 /configs/xda
# 先读取之前保存的 # 先读取之前保存的
if xda=$(get_config xda 2>/dev/null) && [ -n "$xda" ]; then if xda=$(get_config xda 2>/dev/null) && [ -n "$xda" ]; then
@ -1401,6 +1401,15 @@ install_alpine() {
chmod +x /os/etc/init.d/fix-eth-name chmod +x /os/etc/init.d/fix-eth-name
chroot /os rc-update add fix-eth-name boot chroot /os rc-update add fix-eth-name boot
# 安装 frpc
if [ -s /configs/frpc.toml ]; then
chroot /os apk add frp
# chroot rc-update add 默认添加到 sysinit
# 但不加 chroot 默认添加到 default
chroot /os rc-update add frpc boot
cp /configs/frpc.toml /os/etc/frp/frpc.toml
fi
# 安装固件微码会触发 grub-probe # 安装固件微码会触发 grub-probe
# 如果没挂载会报错 # 如果没挂载会报错
# Executing grub-2.12-r5.trigger # Executing grub-2.12-r5.trigger
@ -1480,7 +1489,8 @@ install_nixos() {
show_nixos_config() { show_nixos_config() {
echo echo
cat -n /os/etc/nixos/configuration.nix # 过滤 frp auth.token
cat -n /os/etc/nixos/configuration.nix | grep -Fv 'auth.token'
echo echo
cat -n /os/etc/nixos/hardware-configuration.nix cat -n /os/etc/nixos/hardware-configuration.nix
echo echo
@ -1549,7 +1559,7 @@ install_nixos() {
sh=https://nixos.org/nix/install sh=https://nixos.org/nix/install
fi fi
apk add xz apk add xz
wget -O- "$sh" | sh -s -- --no-channel-add wget -O- "$sh" | sh -s -- --no-daemon --no-channel-add
apk del xz apk del xz
# shellcheck source=/dev/null # shellcheck source=/dev/null
. /root/.nix-profile/etc/profile.d/nix.sh . /root/.nix-profile/etc/profile.d/nix.sh
@ -1605,6 +1615,22 @@ $(del_comment_lines </configs/ssh_keys | del_empty_lines | quote_line | add_spac
nix_ssh_ports="services.openssh.ports = [ $ssh_port ];" nix_ssh_ports="services.openssh.ports = [ $ssh_port ];"
fi fi
# 虽然是原始 frpc.toml (string) 转成 toml 类型,再转成最终使用的 frpc.toml (string)
# 但是可以避免原始 frpc.toml 有错误导致失联
if [ -s /configs/frpc.toml ]; then
nix_frpc=$(
cat <<EOF
services.frp = {
enable = true;
role = "client";
settings = builtins.fromTOML ''
$(del_comment_lines </configs/frpc.toml | add_space 4)
'';
};
EOF
)
fi
# TODO: 准确匹配网卡,添加 udev 或者直接配置 networkd 匹配 mac # TODO: 准确匹配网卡,添加 udev 或者直接配置 networkd 匹配 mac
create_nixos_network_config /tmp/nixos_network_config.nix create_nixos_network_config /tmp/nixos_network_config.nix
@ -1617,6 +1643,7 @@ boot.kernelParams = [ $(get_ttys console= | quote_word) ];
services.openssh.enable = true; services.openssh.enable = true;
$nix_ssh_keys_or_PermitRootLogin $nix_ssh_keys_or_PermitRootLogin
$nix_ssh_ports $nix_ssh_ports
$nix_frpc
$(cat /tmp/nixos_network_config.nix) $(cat /tmp/nixos_network_config.nix)
################################################### ###################################################
EOF EOF
@ -1698,14 +1725,12 @@ EOF
show_nixos_config show_nixos_config
} }
add_fix_eth_name_systemd_service() { add_systemd_service() {
os_dir=$1 local os_dir=$1
local service_name=$2
# 无需执行 systemctl daemon-reload download "$confhome/$service_name.service" "$os_dir/etc/systemd/system/$service_name.service"
# 因为 chroot 下执行会提示 Running in chroot, ignoring command 'daemon-reload' chroot "$os_dir" systemctl enable "$service_name.service"
download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh"
download "$confhome/fix-eth-name.service" "$os_dir/etc/systemd/system/fix-eth-name.service"
chroot "$os_dir" systemctl enable fix-eth-name
# aosc 首次开机会执行 preset-all # aosc 首次开机会执行 preset-all
# 因此需要设置 fix-eth-name 的 preset 状态 # 因此需要设置 fix-eth-name 的 preset 状态
@ -1714,9 +1739,46 @@ add_fix_eth_name_systemd_service() {
# 可能是 /usr/lib/systemd/system-preset/ 或者 /lib/systemd/system-preset/ # 可能是 /usr/lib/systemd/system-preset/ 或者 /lib/systemd/system-preset/
if [ -d "$os_dir/usr/lib/systemd/system-preset" ]; then if [ -d "$os_dir/usr/lib/systemd/system-preset" ]; then
echo 'enable fix-eth-name.service' >"$os_dir/usr/lib/systemd/system-preset/01-fix-eth-name.preset" echo "enable $service_name.service" >"$os_dir/usr/lib/systemd/system-preset/01-$service_name.preset"
else else
echo 'enable fix-eth-name.service' >"$os_dir/lib/systemd/system-preset/01-fix-eth-name.preset" echo "enable $service_name.service" >"$os_dir/lib/systemd/system-preset/01-$service_name.preset"
fi
}
add_fix_eth_name_systemd_service() {
local os_dir=$1
# 无需执行 systemctl daemon-reload
# 因为 chroot 下执行会提示 Running in chroot, ignoring command 'daemon-reload'
download "$confhome/fix-eth-name.sh" "$os_dir/fix-eth-name.sh"
add_systemd_service "$os_dir" fix-eth-name
}
get_frpc_url() {
wget "$confhome/get-frpc-url.sh" -O- | sh -s "$@"
}
add_frpc_systemd_service_if_need() {
local os_dir=$1
if [ -s /configs/frpc.toml ]; then
mkdir -p "$os_dir/usr/local/bin"
mkdir -p "$os_dir/usr/local/etc/frpc"
# 下载 frpc
# 注意下载的 frpc owner 不是 root:root
frpc_url=$(get_frpc_url linux)
basename=$(echo "$frpc_url" | awk -F/ '{print $NF}' | sed 's/\.tar\.gz//')
download "$frpc_url" "$os_dir/frpc.tar.gz"
tar xzf "$os_dir/frpc.tar.gz" "$basename/frpc" -O >"$os_dir/usr/local/bin/frpc"
rm -f "$os_dir/frpc.tar.gz"
chmod a+x "$os_dir/usr/local/bin/frpc"
# frpc conf
cp /configs/frpc.toml "$os_dir/usr/local/etc/frpc/frpc.toml"
# 添加服务
add_systemd_service "$os_dir" frpc
fi fi
} }
@ -1775,6 +1837,9 @@ basic_init() {
# 即使开了 net.ifnames=0 也需要 # 即使开了 net.ifnames=0 也需要
# 因为 alpine live 和目标系统的网卡顺序可能不同 # 因为 alpine live 和目标系统的网卡顺序可能不同
add_fix_eth_name_systemd_service $os_dir add_fix_eth_name_systemd_service $os_dir
# frpc
add_frpc_systemd_service_if_need $os_dir
} }
install_arch_gentoo_aosc() { install_arch_gentoo_aosc() {
@ -2841,6 +2906,28 @@ modify_windows() {
bats="$bats windows-set-netconf-$ethx.bat" bats="$bats windows-set-netconf-$ethx.bat"
done done
# 5 frp
if [ -s /configs/frpc.toml ]; then
# 好像 win7 无法运行 frpc暂时不管
windows_arch=$(get_windows_arch_from_windows_drive "$os_dir" | to_lower)
if [ "$windows_arch" = amd64 ] || [ "$windows_arch" = arm64 ]; then
mkdir -p "$os_dir/frpc/"
url=$(get_frpc_url windows "$nt_ver")
download "$url" $os_dir/frpc/frpc.zip
# -j 去除文件夹
# -C 筛选文件时不区分大小写,但 busybox zip 不支持
unzip -o -j "$os_dir/frpc/frpc.zip" '*/frpc.exe' -d "$os_dir/frpc/"
rm -f "$os_dir/frpc/frpc.zip"
cp -f /configs/frpc.toml "$os_dir/frpc/frpc.toml"
download "$confhome/windows-frpc.xml" "$os_dir/frpc/frpc.xml"
download "$confhome/windows-frpc.bat" "$os_dir/frpc/frpc.bat"
download "$confhome/windows-frpc-workaround.bat" "$os_dir/frpc/frpc-workaround.bat"
bats="$bats frpc\frpc.bat"
else
warn "$windows_arch Not Support frpc"
fi
fi
if $use_gpo; then if $use_gpo; then
# 使用组策略 # 使用组策略
scripts_ini=$(get_path_in_correct_case $os_dir/Windows/System32/GroupPolicy/Machine/Scripts/scripts.ini) scripts_ini=$(get_path_in_correct_case $os_dir/Windows/System32/GroupPolicy/Machine/Scripts/scripts.ini)
@ -2911,6 +2998,9 @@ EOF
# cat 可以保留权限 # cat 可以保留权限
cat $setup_complete_mod >$setup_complete cat $setup_complete_mod >$setup_complete
# 查看最终内容
cat -n $setup_complete
fi fi
} }
@ -5268,6 +5358,16 @@ get_installation_type_from_windows_drive() {
apk del hivex apk del hivex
} }
get_windows_arch_from_windows_drive() {
local os_dir=$1
apk add hivex
hive=$(find_file_ignore_case $os_dir/Windows/System32/config/SYSTEM)
# 没有 CurrentControlSet
hivexget $hive 'ControlSet001\Control\Session Manager\Environment' PROCESSOR_ARCHITECTURE
apk del hivex
}
install_windows() { install_windows() {
get_wim_prop() { get_wim_prop() {
wim=$1 wim=$1
@ -6866,6 +6966,18 @@ else
printf '\nyes' | setup-sshd printf '\nyes' | setup-sshd
fi fi
# 设置 frpc
# 并防止重复运行
if [ -s /configs/frpc.toml ] && ! pidof frpc >/dev/null; then
info 'run frpc'
add_community_repo
apk add frp
while true; do
frpc -c /configs/frpc.toml || true
sleep 5
done &
fi
# shellcheck disable=SC2154 # shellcheck disable=SC2154
if [ "$hold" = 1 ]; then if [ "$hold" = 1 ]; then
if is_run_from_locald; then if is_run_from_locald; then

View File

@ -0,0 +1,18 @@
@echo off
mode con cp select=437 >nul
rem 如果找到 LOCAL SERVICE 运行的 frpc则结束 SYSTEM 运行的 frpc
rem 如果没找到 frpc则运行 frpc本脚本是用 SYSTEM 运行,好像无法 runas "NT AUTHORITY\LOCAL SERVICE"
rem tasklist 返回值始终为 0因此需要用 findstr
:loop
tasklist /FI "IMAGENAME eq frpc.exe" /FI "USERNAME eq NT AUTHORITY\LOCAL SERVICE" | findstr /I "frpc.exe" && goto :kill_system_frpc
tasklist /FI "IMAGENAME eq frpc.exe" | findstr /I "frpc.exe" || start %SystemDrive%\frpc\frpc.exe -c %SystemDrive%\frpc\frpc.toml
timeout 5
goto :loop
:kill_system_frpc
taskkill /F /T /FI "IMAGENAME eq frpc.exe" /FI "USERNAME eq NT AUTHORITY\SYSTEM"
del "%~f0"

39
windows-frpc.bat Normal file
View File

@ -0,0 +1,39 @@
@echo off
mode con cp select=437 >nul
rem Windows Deferder 会误报,因此要添加白名单
powershell -ExecutionPolicy Bypass -Command "Add-MpPreference -ExclusionPath '%SystemDrive%\frpc\frpc.exe'"
rem ---------- DEBUG ----------
rem 检查服务状态
rem sc query Schedule >%SystemDrive%\x.txt 2>&1
rem 启用日志
rem wevtutil set-log Microsoft-Windows-TaskScheduler/Operational /enabled:true
rem ---------- DEBUG ----------
rem 创建计划任务并立即运行
schtasks /Create /TN "frpc" /XML "%SystemDrive%\frpc\frpc.xml"
schtasks /Run /TN "frpc"
del "%SystemDrive%\frpc\frpc.xml"
rem win11 在首次登录后计划任务才生效
rem 即使手动重启,计划任务也没有运行
rem 如果 10 秒内有 frpc 进程,则代表计划任务已经生效,不需要首次登录
rem 如果 10 秒后也没有 frpc 进程,则需要运行 frpc-workaround.bat
for /L %%i in (1,1,10) do (
timeout 1
tasklist /FI "IMAGENAME eq frpc.exe" | find /I "frpc.exe" && (
del "%SystemDrive%\frpc\frpc-workaround.bat"
goto :end
)
)
rem 后台运行 frpc-workaround.bat
rem 需要加 cmd /c不然 frpc-workaround.bat 结束后有 cmd 窗口残留
start cmd /c "%SystemDrive%\frpc\frpc-workaround.bat"
:end
rem 删除此脚本
del "%~f0"

BIN
windows-frpc.xml Normal file

Binary file not shown.