Остання активність 1 month ago

nuno ревизій цього gist 1 month ago. До ревизії

1 file changed, 94 insertions

context.sh(файл створено)

@@ -0,0 +1,94 @@
1 + #!/usr/bin/env bash
2 +
3 + # ============================================
4 + # Static Context — resolved once at source time
5 + # ============================================
6 +
7 + _CTX_WG="/etc/wireguard"
8 + _CTX_WGCTL="/etc/wireguard/wgctl"
9 + _CTX_CLIENTS="${_CTX_WG}/clients"
10 +
11 + # ── Directory layout ──────────────────────────────────
12 + # .wgctl/
13 + # config/ ← wgctl.json, display.json
14 + # data/ ← all persistent data (rules, identities, etc.)
15 + # daemon/ ← runtime files (logs, caches)
16 +
17 + _CTX_WGCTL_ARTIFACT="${_CTX_WG}/.wgctl"
18 + _CTX_CONFIG="${_CTX_WGCTL_ARTIFACT}/config"
19 + _CTX_DATA="${_CTX_WGCTL_ARTIFACT}/data"
20 + _CTX_DAEMON="${_CTX_WGCTL_ARTIFACT}/daemon"
21 +
22 + # ── Data subdirs ──────────────────────────────────────
23 + _CTX_RULES="${_CTX_DATA}/rules"
24 + _CTX_RULES_BASE="${_CTX_RULES}/base"
25 + _CTX_GROUPS="${_CTX_DATA}/groups"
26 + _CTX_BLOCKS="${_CTX_DATA}/blocks"
27 + _CTX_META="${_CTX_DATA}/meta"
28 + _CTX_IDENTITY="${_CTX_DATA}/identities"
29 + _CTX_PEER_HISTORY="${_CTX_DATA}/peer-history"
30 +
31 + # ── Data files ────────────────────────────────────────
32 + _CTX_NET="${_CTX_DATA}/services.json"
33 + _CTX_HOSTS="${_CTX_DATA}/hosts.json"
34 + _CTX_SUBNETS="${_CTX_DATA}/subnets.json"
35 + _CTX_POLICIES="${_CTX_DATA}/policies.json"
36 +
37 + # ── Config files ──────────────────────────────────────
38 + _CTX_CONFIG_FILE="${_CTX_CONFIG}/wgctl.json"
39 +
40 + # ============================================
41 + # Accessors
42 + # ============================================
43 +
44 + function ctx::wg() { echo "$_CTX_WG"; }
45 + function ctx::clients() { echo "$_CTX_CLIENTS"; }
46 +
47 + # Top-level dirs
48 + function ctx::wgctl() { echo "$_CTX_WGCTL_ARTIFACT"; } # needs to change to ctx::wgctl_artifact or ctx::artifact
49 + function ctx::config() { echo "$_CTX_CONFIG"; }
50 + function ctx::data() { echo "$_CTX_DATA"; }
51 + function ctx::daemon() { echo "$_CTX_DAEMON"; }
52 +
53 + # Data subdirs
54 + function ctx::rules() { echo "$_CTX_RULES"; }
55 + function ctx::rules::base() { echo "$_CTX_RULES_BASE"; }
56 + function ctx::groups() { echo "$_CTX_GROUPS"; }
57 + function ctx::blocks() { echo "$_CTX_BLOCKS"; }
58 + function ctx::meta() { echo "$_CTX_META"; }
59 + function ctx::identities() { echo "$_CTX_IDENTITY"; }
60 + function ctx::peer_history() { echo "$_CTX_PEER_HISTORY"; }
61 +
62 + # Data files
63 + function ctx::net() { echo "$_CTX_NET"; }
64 + function ctx::hosts() { echo "$_CTX_HOSTS"; }
65 + function ctx::subnets() { echo "$_CTX_SUBNETS"; }
66 + function ctx::policies() { echo "$_CTX_POLICIES"; }
67 +
68 + # Config files
69 + function ctx::config_file() { echo "$_CTX_CONFIG_FILE"; }
70 + function ctx::display() { echo "${_CTX_CONFIG}/display.json"; }
71 +
72 + # Daemon files
73 + function ctx::events_log() { echo "${_CTX_DAEMON}/events.log"; }
74 + function ctx::fw_events_log() { echo "${_CTX_DAEMON}/fw_events.log"; }
75 + function ctx::endpoint_cache() { echo "${_CTX_DAEMON}/endpoint_cache.json"; }
76 + function ctx::accept_events_log() { echo "${_CTX_DAEMON}/accept_events.log"; }
77 +
78 + # Tool paths
79 + function ctx::json_helper() { echo "${_CTX_WGCTL}/core/json_helper.py"; }
80 + function ctx::monitor_script() { echo "${_CTX_WGCTL}/daemon/wgctl-monitor.py"; }
81 + function ctx::lib() { echo "${_CTX_WGCTL}/core/lib"; }
82 +
83 + function ctx::block_history() { echo "${_CTX_DATA}/block-history"; }
84 +
85 + # ============================================
86 + # Path Helpers
87 + # ============================================
88 +
89 + function ctx::client::path() { local IFS="/"; echo "$_CTX_CLIENTS/$*"; }
90 + function ctx::meta::path() { local IFS="/"; echo "$_CTX_META/$*"; }
91 + function ctx::identity::path() { local IFS="/"; echo "$_CTX_IDENTITY/$*"; }
92 + function ctx::block::path() { local IFS="/"; echo "$_CTX_BLOCKS/$*"; }
93 + function ctx::group::path() { local IFS="/"; echo "$_CTX_GROUPS/$*"; }
94 + function ctx::rule::path() { local IFS="/"; echo "$_CTX_RULES/$*"; }
Новіше Пізніше