最後活躍 1 month ago

nuno 已修改 1 month ago. 還原成這個修訂版本

1 file changed, 73 insertions

gistfile1.txt(檔案已創建)

@@ -0,0 +1,73 @@
1 + #!/usr/bin/env bash
2 + set -e
3 +
4 + WGCTL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5 + DATA_DIR="/etc/wireguard/.wgctl"
6 +
7 + echo "Installing wgctl..."
8 +
9 + install::dependencies
10 + install::make_structure
11 + install::daemon_logs
12 + install::symlink
13 + install::wgctl_service
14 + install_ulogd
15 + install::create_config
16 +
17 + echo "wgctl installed successfully!"
18 +
19 + function install::symlink() {
20 + ln -sf /etc/wireguard/wgctl/wgctl /usr/local/bin/wgctl
21 + }
22 +
23 + function install::dependencies() {
24 + apt install -y wireguard ulogd2 ulogd2-json python3 qrencode
25 + }
26 +
27 + function install::make_structure() {
28 + mkdir -p "${DATA_DIR}"/{rules,groups,blocks,meta,daemon}
29 + }
30 +
31 + function install::daemon_logs() {
32 + touch "${DATA_DIR}/daemon/fw_events.log"
33 + chown ulog:ulog "${DATA_DIR}/daemon/fw_events.log"
34 +
35 + echo '{}' > "${DATA_DIR}/daemon/watchlist.json"
36 + echo '{}' > "${DATA_DIR}/daemon/endpoint_cache.json"
37 + }
38 +
39 + function install::wgctl_service() {
40 + # Install systemd service
41 + cp "${WGCTL_DIR}/install/wgctl-monitor.service" /etc/systemd/system/
42 + systemctl daemon-reload
43 + systemctl enable wgctl-monitor
44 + systemctl start wgctl-monitor
45 + }
46 +
47 + function install::ulogd() {
48 + # Install ulogd config
49 + cp "${WGCTL_DIR}/install/ulogd.conf" /etc/ulogd.conf
50 + systemctl restart ulogd2
51 + }
52 +
53 + function install::create_config() {
54 + if [[ ! -f "${DATA_DIR}/wgctl.conf" ]]; then
55 + install::create_example_config
56 + cp "${WGCTL_DIR}/install/wgctl.conf.example" "${DATA_DIR}/wgctl.conf"
57 + echo " Created ${DATA_DIR}/wgctl.conf — edit with your settings"
58 + fi
59 + }
60 +
61 + function install::create_example_config() {
62 + cat > /etc/wireguard/wgctl/install/wgctl.conf.example << 'EOF'
63 + # wgctl configuration
64 + # Copy to /etc/wireguard/.wgctl/wgctl.conf and edit
65 +
66 + WG_INTERFACE=wg0
67 + WG_ENDPOINT=wg.yourdomain.com:51820
68 + WG_DNS=10.0.0.103
69 + WG_LISTEN_PORT=51820
70 + WG_SUBNET=10.1.0.0/16
71 + WG_LAN=10.0.0.0/24
72 + EOF
73 + }
上一頁 下一頁