gistfile1.txt
· 1.8 KiB · Text
Raw
#!/usr/bin/env bash
set -e
WGCTL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DATA_DIR="/etc/wireguard/.wgctl"
echo "Installing wgctl..."
install::dependencies
install::make_structure
install::daemon_logs
install::symlink
install::wgctl_service
install_ulogd
install::create_config
echo "wgctl installed successfully!"
function install::symlink() {
ln -sf /etc/wireguard/wgctl/wgctl /usr/local/bin/wgctl
}
function install::dependencies() {
apt install -y wireguard ulogd2 ulogd2-json python3 qrencode
}
function install::make_structure() {
mkdir -p "${DATA_DIR}"/{rules,groups,blocks,meta,daemon}
}
function install::daemon_logs() {
touch "${DATA_DIR}/daemon/fw_events.log"
chown ulog:ulog "${DATA_DIR}/daemon/fw_events.log"
echo '{}' > "${DATA_DIR}/daemon/watchlist.json"
echo '{}' > "${DATA_DIR}/daemon/endpoint_cache.json"
}
function install::wgctl_service() {
# Install systemd service
cp "${WGCTL_DIR}/install/wgctl-monitor.service" /etc/systemd/system/
systemctl daemon-reload
systemctl enable wgctl-monitor
systemctl start wgctl-monitor
}
function install::ulogd() {
# Install ulogd config
cp "${WGCTL_DIR}/install/ulogd.conf" /etc/ulogd.conf
systemctl restart ulogd2
}
function install::create_config() {
if [[ ! -f "${DATA_DIR}/wgctl.conf" ]]; then
install::create_example_config
cp "${WGCTL_DIR}/install/wgctl.conf.example" "${DATA_DIR}/wgctl.conf"
echo " Created ${DATA_DIR}/wgctl.conf — edit with your settings"
fi
}
function install::create_example_config() {
cat > /etc/wireguard/wgctl/install/wgctl.conf.example << 'EOF'
# wgctl configuration
# Copy to /etc/wireguard/.wgctl/wgctl.conf and edit
WG_INTERFACE=wg0
WG_ENDPOINT=wg.yourdomain.com:51820
WG_DNS=10.0.0.103
WG_LISTEN_PORT=51820
WG_SUBNET=10.1.0.0/16
WG_LAN=10.0.0.0/24
EOF
}
| 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 | } |