| #!/bin/bash |
| # Copyright 2015 The Vanadium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style |
| # license that can be found in the LICENSE file. |
| |
| # Functions for starting the Sensor Log daemon and required services with |
| # appropriate blessings. Expected to be run with V23_CREDENTIALS or through |
| # an agent. |
| |
| set -eu |
| |
| function kill_child_processes() { |
| kill -TERM -- -"${BASHPID}" || true |
| sleep 1 |
| kill -KILL -- -"${BASHPID}" || true |
| } |
| export -f kill_child_processes |
| |
| function name_to_blessing() { |
| local -r CHAIN_SEPARATOR='/' |
| sed -e "s,/,${CHAIN_SEPARATOR},g" <<< "$@" |
| } |
| export -f name_to_blessing |
| |
| function run_mounttabled() { |
| local -r BLESSNAME="$1" |
| local -r NAME="$2" |
| local -r IPADDR_PORT="$3" |
| "${JIRI_ROOT}"/release/go/bin/vbecome -name="$(name_to_blessing "${BLESSNAME}/sl/mounttabled/${NAME}")" \ |
| "${JIRI_ROOT}"/release/go/bin/mounttabled -v23.tcp.address "${IPADDR_PORT}" \ |
| & |
| sleep 1 |
| } |
| export -f run_mounttabled |
| |
| function run_syncbased() { |
| local -r BLESSNAME="$1" |
| local -r MT="$2" |
| local -r NAME="$3" |
| local -r TMPDIR="$4" |
| local -r DEF_BLESSING_ROOT="$("${JIRI_ROOT}"/release/go/bin/principal dump -s | cut -d ' ' -f 1 | cut -d ',' -f 1)" |
| local -r DEF_BLESSING_RUNNER="$(name_to_blessing "${DEF_BLESSING_ROOT}/${BLESSNAME}/sl/${NAME}")" |
| # Everyone can Resolve to be able to join the syncgroup. |
| echo "$DEF_BLESSING_RUNNER" |
| local -r PERMISSIONS_LITERAL="{\ |
| \"Admin\":{\"In\":[\"${DEF_BLESSING_RUNNER}\"]}, \ |
| \"Read\":{\"In\":[\"${DEF_BLESSING_RUNNER}\"]}, \ |
| \"Write\":{\"In\":[\"${DEF_BLESSING_RUNNER}\"]}, \ |
| \"Debug\":{\"In\":[\"${DEF_BLESSING_RUNNER}\"]}, \ |
| \"Resolve\":{\"In\":[\"...\"]} \ |
| }" |
| "${JIRI_ROOT}"/release/go/bin/vbecome -name="$(name_to_blessing "${BLESSNAME}/sl/syncbased/${NAME}")" \ |
| "${JIRI_ROOT}"/release/go/bin/syncbased -v23.namespace.root "${MT}" \ |
| -name "syncbased/${NAME}" -engine leveldb -root-dir "${TMPDIR}/syncbased/${NAME}" \ |
| -v23.permissions.literal="${PERMISSIONS_LITERAL}" \ |
| & |
| sleep 1 |
| } |
| export -f run_syncbased |
| |
| function run_measured() { |
| local -r BLESSNAME="$1" |
| local -r MT="$2" |
| local -r NAME="$3" |
| local -r TMPDIR="$4" |
| run_syncbased "${BLESSNAME}" "${MT}" "measured/${NAME}" "${TMPDIR}" |
| "${JIRI_ROOT}"/release/go/bin/vbecome -name="$(name_to_blessing "${BLESSNAME}/sl/measured/${NAME}")" \ |
| "${JIRI_ROOT}"/experimental/projects/sensorlog_lite/bin/measured -v23.namespace.root "${MT}" \ |
| -service "syncbased/measured/${NAME}" -alsologtostderr \ |
| & |
| sleep 1 |
| } |
| export -f run_measured |