|
1 | 1 | #!/bin/bash
|
2 | 2 | set -o pipefail
|
3 |
| -SSH='timeout -k 1 11 sshpass -p 12345 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/run/ssh_control:%h:%p:%r -o ControlPersist=15s -o ServerAliveInterval=3 -o ServerAliveCountMax=2 root@10.5.0.10 ' |
| 3 | + |
| 4 | +# Configuration |
| 5 | +REMOTE_IP="10.5.0.10" |
| 6 | +SSH_PASS="12345" |
| 7 | +CACHE_DIR="/tmp/gsmenu_cache" |
| 8 | +CACHE_TTL=10 # seconds |
| 9 | +MAJESTIC_YAML="/etc/majestic.yaml" |
| 10 | +WFB_YAML="/etc/wfb.yaml" |
| 11 | + |
| 12 | +# SSH command setup |
| 13 | +SSH="timeout -k 1 11 sshpass -p $SSH_PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/run/ssh_control:%h:%p:%r -o ControlPersist=15s -o ServerAliveInterval=3 -o ServerAliveCountMax=2 root@$REMOTE_IP" |
| 14 | + |
| 15 | +# Create cache directory if it doesn't exist |
| 16 | +mkdir -p "$CACHE_DIR" |
| 17 | + |
| 18 | +# Function to refresh cached files |
| 19 | +refresh_cache() { |
| 20 | + local current_time=$(date +%s) |
| 21 | + local last_refresh=$((current_time - CACHE_TTL)) |
| 22 | + |
| 23 | + # Check if we need to refresh |
| 24 | + if [[ ! -f "$CACHE_DIR/last_refresh" ]] || [[ $(cat "$CACHE_DIR/last_refresh") -lt $last_refresh ]]; then |
| 25 | + # Copy the YAML configuration files |
| 26 | + $SSH "cat $MAJESTIC_YAML" > "$CACHE_DIR/majestic.yaml" 2>/dev/null |
| 27 | + $SSH "cat $WFB_YAML" > "$CACHE_DIR/wfb.yaml" 2>/dev/null |
| 28 | + |
| 29 | + # Update refresh timestamp |
| 30 | + echo "$current_time" > "$CACHE_DIR/last_refresh" |
| 31 | + fi |
| 32 | +} |
| 33 | + |
| 34 | +# Function to get value from majestic.yaml using yaml-cli |
| 35 | +get_majestic_value() { |
| 36 | + local key="$1" |
| 37 | + yaml-cli -i "$CACHE_DIR/majestic.yaml" -g "$key" 2>/dev/null |
| 38 | +} |
| 39 | + |
| 40 | +# Function to get value from wfb.yaml using yaml-cli |
| 41 | +get_wfb_value() { |
| 42 | + local key="$1" |
| 43 | + yaml-cli -i "$CACHE_DIR/wfb.yaml" -g "$key" 2>/dev/null |
| 44 | +} |
| 45 | + |
| 46 | +# Refresh cache for get |
| 47 | +case "$1" in |
| 48 | + "get air"*) |
| 49 | + refresh_cache |
| 50 | + ;; |
| 51 | +esac |
4 | 52 |
|
5 | 53 | case "$@" in
|
6 | 54 | "values air wfbng mcs_index")
|
@@ -83,64 +131,64 @@ case "$@" in
|
83 | 131 | ;;
|
84 | 132 |
|
85 | 133 | "get air camera mirror")
|
86 |
| - [ "true" = $($SSH cli -g .image.mirror) ] && echo 1 || echo 0 |
| 134 | + [ "$(get_majestic_value '.image.mirror')" = "true" ] && echo 1 || echo 0 |
87 | 135 | ;;
|
88 | 136 | "get air camera flip")
|
89 |
| - [ "true" = $($SSH cli -g .image.flip) ] && echo 1 || echo 0 |
| 137 | + [ "$(get_majestic_value '.image.flip')" = "true" ] && echo 1 || echo 0 |
90 | 138 | ;;
|
91 | 139 | "get air camera contrast")
|
92 |
| - $SSH cli -g .image.contrast |
| 140 | + get_majestic_value '.image.contrast' |
93 | 141 | ;;
|
94 | 142 | "get air camera hue")
|
95 |
| - $SSH cli -g .image.hue |
| 143 | + get_majestic_value '.image.hue' |
96 | 144 | ;;
|
97 | 145 | "get air camera saturation")
|
98 |
| - $SSH cli -g .image.saturation |
| 146 | + get_majestic_value '.image.saturation' |
99 | 147 | ;;
|
100 | 148 | "get air camera luminace")
|
101 |
| - $SSH cli -g .image.luminance |
| 149 | + get_majestic_value '.image.luminance' |
102 | 150 | ;;
|
103 | 151 | "get air camera size")
|
104 |
| - $SSH cli -g .video0.size |
| 152 | + get_majestic_value '.video0.size' |
105 | 153 | ;;
|
106 | 154 | "get air camera fps")
|
107 |
| - $SSH cli -g .video0.fps |
| 155 | + get_majestic_value '.video0.fps' |
108 | 156 | ;;
|
109 | 157 | "get air camera bitrate")
|
110 |
| - $SSH cli -g .video0.bitrate |
| 158 | + get_majestic_value '.video0.bitrate' |
111 | 159 | ;;
|
112 | 160 | "get air camera codec")
|
113 |
| - $SSH cli -g .video0.codec |
| 161 | + get_majestic_value '.video0.codec' |
114 | 162 | ;;
|
115 | 163 | "get air camera gopsize")
|
116 |
| - $SSH cli -g .video0.gopSize |
| 164 | + get_majestic_value '.video0.gopSize' |
117 | 165 | ;;
|
118 | 166 | "get air camera rc_mode")
|
119 |
| - $SSH cli -g .video0.rcMode |
| 167 | + get_majestic_value '.video0.rcMode' |
120 | 168 | ;;
|
121 | 169 | "get air camera rec_enable")
|
122 |
| - [ "true" = $($SSH cli -g .records.enabled) ] && echo 1 || echo 0 |
| 170 | + [ "$(get_majestic_value '.records.enabled')" = "true" ] && echo 1 || echo 0 |
123 | 171 | ;;
|
124 | 172 | "get air camera rec_split")
|
125 |
| - $SSH cli -g .records.split |
| 173 | + get_majestic_value '.records.split' |
126 | 174 | ;;
|
127 | 175 | "get air camera rec_maxusage")
|
128 |
| - $SSH cli -g .records.maxUsage |
| 176 | + get_majestic_value '.records.maxUsage' |
129 | 177 | ;;
|
130 | 178 | "get air camera exposure")
|
131 |
| - $SSH cli -g .isp.exposure |
| 179 | + get_majestic_value '.isp.exposure' |
132 | 180 | ;;
|
133 | 181 | "get air camera antiflicker")
|
134 |
| - $SSH cli -g .isp.antiFlicker |
| 182 | + get_majestic_value '.isp.antiFlicker' |
135 | 183 | ;;
|
136 | 184 | "get air camera sensor_file")
|
137 |
| - $SSH cli -g .isp.sensorConfig |
| 185 | + get_majestic_value '.isp.sensorConfig' |
138 | 186 | ;;
|
139 | 187 | "get air camera fpv_enable")
|
140 |
| - $SSH cli -g .fpv.enabled | grep -q true && echo 1 || echo 0 |
| 188 | + get_majestic_value '.fpv.enabled' | grep -q true && echo 1 || echo 0 |
141 | 189 | ;;
|
142 | 190 | "get air camera noiselevel")
|
143 |
| - $SSH cli -g .fpv.noiseLevel |
| 191 | + get_majestic_value '.fpv.noiseLevel' |
144 | 192 | ;;
|
145 | 193 |
|
146 | 194 | "set air camera mirror"*)
|
@@ -261,32 +309,32 @@ case "$@" in
|
261 | 309 | ;;
|
262 | 310 |
|
263 | 311 | "get air wfbng power")
|
264 |
| - $SSH wifibroadcast cli -g .wireless.txpower |
| 312 | + get_wfb_value '.wireless.txpower' |
265 | 313 | ;;
|
266 | 314 | "get air wfbng air_channel")
|
267 |
| - channel=$($SSH wifibroadcast cli -g .wireless.channel | tr -d '\n') |
268 |
| - iw list | grep "\[$channel\]" | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | sort -n | uniq | tr -d '\n' |
| 315 | + channel=$(get_wfb_value '.wireless.channel' | tr -d '\n') |
| 316 | + iw list | grep "\[$channel\]" | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | sort -n | uniq | tr -d '\n' |
269 | 317 | ;;
|
270 | 318 | "get air wfbng width")
|
271 |
| - $SSH wifibroadcast cli -g .wireless.width |
| 319 | + get_wfb_value '.wireless.width' |
272 | 320 | ;;
|
273 | 321 | "get air wfbng mcs_index")
|
274 |
| - $SSH wifibroadcast cli -g .broadcast.mcs_index |
| 322 | + get_wfb_value '.broadcast.mcs_index' |
275 | 323 | ;;
|
276 | 324 | "get air wfbng stbc")
|
277 |
| - $SSH wifibroadcast cli -g .broadcast.stbc |
| 325 | + get_wfb_value '.broadcast.stbc' |
278 | 326 | ;;
|
279 | 327 | "get air wfbng ldpc")
|
280 |
| - $SSH wifibroadcast cli -g .broadcast.ldpc |
| 328 | + get_wfb_value '.broadcast.ldpc' |
281 | 329 | ;;
|
282 | 330 | "get air wfbng fec_k")
|
283 |
| - $SSH wifibroadcast cli -g .broadcast.fec_k |
| 331 | + get_wfb_value '.broadcast.fec_k' |
284 | 332 | ;;
|
285 | 333 | "get air wfbng fec_n")
|
286 |
| - $SSH wifibroadcast cli -g .broadcast.fec_n |
| 334 | + get_wfb_value '.broadcast.fec_n' |
287 | 335 | ;;
|
288 | 336 | "get air wfbng mlink")
|
289 |
| - $SSH wifibroadcast cli -g .wireless.mlink |
| 337 | + get_wfb_value '.wireless.mlink' |
290 | 338 | ;;
|
291 | 339 | "get air wfbng adaptivelink")
|
292 | 340 | $SSH grep ^alink_drone /etc/rc.local | grep -q 'alink_drone' && echo 1 || echo 0
|
|
0 commit comments