-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (127 loc) · 5.09 KB
/
Copy pathMakefile
File metadata and controls
135 lines (127 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
.PHONY: all install install-dev deps build-deb build-rpm package-all
# Default target - build release binary
all:
cargo build --release
# Install release version and grant the CAP_NET_ADMIN file capability.
# akon runs as your user (keyring intact); the only privilege it needs is
# CAP_NET_ADMIN for the TUN device + netlink route setup. No openconnect, no
# passwordless sudo.
install: all
@echo "Installing akon..."
sudo install -m 755 target/release/akon /usr/local/bin/akon
@echo "✓ Installed to /usr/local/bin/akon"
@echo ""
@echo "Removing any legacy passwordless-sudo config from older akon versions..."
@sudo rm -f /etc/sudoers.d/akon 2>/dev/null || true
@echo "Granting CAP_NET_ADMIN to the akon binary (setcap)..."
@if ! command -v setcap &> /dev/null; then \
echo "ERROR: 'setcap' not found. Install libcap:"; \
echo " Ubuntu/Debian: sudo apt install libcap2-bin"; \
echo " RHEL/Fedora: sudo dnf install libcap"; \
exit 1; \
fi
sudo setcap cap_net_admin+ep /usr/local/bin/akon
@echo "✓ Granted cap_net_admin+ep to /usr/local/bin/akon"
@echo ""
@echo "Installing polkit rule so VPN DNS applies without password prompts..."
sudo install -d -m 755 /usr/share/polkit-1/rules.d
sudo install -m 644 packaging/polkit/49-akon-resolved-dns.rules /usr/share/polkit-1/rules.d/49-akon-resolved-dns.rules
@echo "✓ Installed /usr/share/polkit-1/rules.d/49-akon-resolved-dns.rules"
@echo ""
@echo "Installation complete! Run akon as your normal user (no sudo):"
@echo " akon setup"
@echo " akon vpn on"
# Remove akon, its capability, and the polkit rule.
.PHONY: uninstall
uninstall:
@echo "Removing akon..."
sudo rm -f /usr/local/bin/akon
sudo rm -f /usr/share/polkit-1/rules.d/49-akon-resolved-dns.rules
sudo rm -f /etc/sudoers.d/akon 2>/dev/null || true
@echo "✓ Removed akon, polkit rule, and any legacy sudoers config"
# Install development version for debugging
install-dev:
cargo build
@echo "Installing debug akon..."
sudo install -m 755 target/debug/akon /usr/local/bin/akon-dev
@echo "✓ Installed to /usr/local/bin/akon-dev"
@echo ""
@echo "You can now run:"
@echo " akon-dev setup"
.PHONY: deps
# Install system dependencies for building/running akon on common Linux runners.
# Supports Ubuntu/Debian (apt) and Fedora/RHEL (dnf/yum). If sudo is not available
# or the distro is not detected, the target will print the manual commands to run.
deps:
@echo "Checking system for package manager and distro..."
@sh -c '\
if [ -f /etc/os-release ]; then . /etc/os-release; fi; \
SUDO=""; if [ "$$(id -u)" -ne 0 ]; then \
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi; \
fi; \
if [ -n "$$SUDO" ]; then \
echo "Using sudo to install packages"; \
fi; \
case "$$ID" in \
ubuntu|debian|linuxmint|pop) \
if [ -z "$$SUDO" ]; then \
echo "Detected $$ID (Ubuntu/Debian)."; \
echo "Run as root or ensure 'sudo' is available and re-run:"; \
echo " sudo apt-get update && sudo apt-get install -y libcap2-bin libdbus-1-dev pkg-config"; \
exit 0; \
fi; \
echo "Installing libcap (setcap), dbus dev, and pkg-config (apt)..."; \
$$SUDO apt-get update && $$SUDO apt-get install -y libcap2-bin libdbus-1-dev pkg-config; \
;; \
fedora|rhel|centos) \
if [ -z "$$SUDO" ]; then \
echo "Detected $$ID (Fedora/RHEL)."; \
echo "Run as root or ensure 'sudo' is available and re-run:"; \
echo " sudo dnf install -y libcap dbus-devel pkgconf-pkg-config"; \
exit 0; \
fi; \
echo "Installing libcap (setcap), dbus dev, and pkg-config (dnf/yum)..."; \
if command -v dnf >/dev/null 2>&1; then \
$$SUDO dnf install -y libcap dbus-devel pkgconf-pkg-config; \
else \
$$SUDO yum install -y libcap dbus-devel pkgconf-pkg-config; \
fi; \
;; \
*) \
echo "Could not detect a supported distro (ID=$$ID)."; \
echo "Please run one of the following commands manually depending on your distro:"; \
echo " Ubuntu/Debian: sudo apt-get update && sudo apt-get install -y libcap2-bin libdbus-1-dev pkg-config"; \
echo " Fedora/RHEL: sudo dnf install -y libcap dbus-devel pkgconf-pkg-config"; \
exit 0; \
;; \
esac'
# Build .deb package for Ubuntu/Debian
build-deb: all
@echo "Building .deb package..."
@if ! command -v cargo-deb &> /dev/null; then \
echo "Installing cargo-deb..."; \
cargo install cargo-deb; \
fi
cargo deb --no-build
@echo "✓ Package created: $$(ls -1 target/debian/*.deb | tail -1)"
@echo ""
@echo "Install with:"
@echo " sudo dpkg -i $$(ls -1 target/debian/*.deb | tail -1)"
# Build .rpm package for Fedora/RHEL
build-rpm: all
@echo "Building .rpm package..."
@if ! command -v cargo-generate-rpm &> /dev/null; then \
echo "Installing cargo-generate-rpm..."; \
cargo install cargo-generate-rpm; \
fi
cargo generate-rpm
@echo "✓ Package created: $$(ls -1 target/generate-rpm/*.rpm | tail -1)"
@echo ""
@echo "Install with:"
@echo " sudo rpm -i $$(ls -1 target/generate-rpm/*.rpm | tail -1)"
# Build both packages
package-all: build-deb build-rpm
@echo ""
@echo "All packages built successfully!"
@echo "DEB: $$(ls -1 target/debian/*.deb | tail -1)"
@echo "RPM: $$(ls -1 target/generate-rpm/*.rpm | tail -1)"