59fc774f08
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
23 lines
1.1 KiB
Bash
Executable File
23 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# bj-keymedia-worker — демон обработки запросов установки ключа (host namespace).
|
|
REQDIR=/var/lib/bj/keymedia-requests
|
|
getf(){ python3 -c "import json;print(json.load(open('$1')).get('$2',''))" 2>/dev/null; }
|
|
process_one(){
|
|
local req="$1" id res action staging profile tdev tmnt extra out
|
|
id=$(basename "$req" .req); res="$REQDIR/$id.res"
|
|
action=$(getf "$req" action); staging=$(getf "$req" staging); profile=$(getf "$req" profile)
|
|
tdev=$(getf "$req" target_dev); tmnt=$(getf "$req" target_mnt); extra=$(getf "$req" extra)
|
|
rm -f "$req"
|
|
case "$action" in
|
|
quikexport-*) out=$(BJ_EXTRA="$extra" /usr/local/sbin/bj-quikexport-admin "${action#quikexport-}" "$staging" 2>&1) ;;
|
|
*) out=$(BJ_TARGET_DEV="$tdev" BJ_TARGET_MNT="$tmnt" BJ_EXTRA="$extra" /usr/local/sbin/bj-keymedia-install "$action" "$staging" "$profile" 2>&1) ;;
|
|
esac
|
|
printf '%s' "$out" > "$res.tmp"; chown bj:bj "$res.tmp" 2>/dev/null
|
|
mv -f "$res.tmp" "$res"
|
|
}
|
|
shopt -s nullglob
|
|
while true; do
|
|
for req in "$REQDIR"/*.req; do process_one "$req"; done
|
|
sleep 1
|
|
done
|