72 lines
2.2 KiB
Bash
72 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck disable=SC1091
|
|
source "${SCRIPT_DIR}/common.sh"
|
|
|
|
SYSTEMD_TEMPLATE_DIR="${SCRIPT_DIR}/systemd"
|
|
SYSTEMD_DEST_DIR="/etc/systemd/system"
|
|
|
|
render_template() {
|
|
local template_path="$1"
|
|
local output_path="$2"
|
|
|
|
sed \
|
|
-e "s|@OMNISOCKETGO_ROOT@|${OMNISOCKETGO_ROOT}|g" \
|
|
-e "s|@BLITZ_LOG_FILE@|${BLITZ_LOG_FILE}|g" \
|
|
-e "s|@BLITZ_ROS_USER@|${BLITZ_ROS_USER}|g" \
|
|
"${template_path}" > "${output_path}"
|
|
}
|
|
|
|
install_unit() {
|
|
local template_name="$1"
|
|
local temp_output
|
|
|
|
temp_output="$(mktemp)"
|
|
render_template "${SYSTEMD_TEMPLATE_DIR}/${template_name}" "${temp_output}"
|
|
install -m 0644 "${temp_output}" "${SYSTEMD_DEST_DIR}/${template_name%.in}"
|
|
rm -f "${temp_output}"
|
|
blitz_log "install" "install-unit" "success" "unit=${SYSTEMD_DEST_DIR}/${template_name%.in}" 0
|
|
}
|
|
|
|
remove_unit_if_present() {
|
|
local unit_name="$1"
|
|
local unit_path="${SYSTEMD_DEST_DIR}/${unit_name}"
|
|
|
|
if [[ ! -f "${unit_path}" ]]; then
|
|
return 0
|
|
fi
|
|
|
|
systemctl disable --now "${unit_name}" >/dev/null 2>&1 || true
|
|
rm -f "${unit_path}"
|
|
blitz_log "install" "remove-unit" "success" "unit=${unit_path}" 0
|
|
}
|
|
|
|
blitz_load_boot_env
|
|
blitz_require_root "install"
|
|
blitz_require_command install "install"
|
|
blitz_require_command systemctl "install"
|
|
|
|
mkdir -p "${SYSTEMD_DEST_DIR}"
|
|
install -d -m 0755 "$(dirname "${BLITZ_LOG_FILE}")"
|
|
touch "${BLITZ_LOG_FILE}"
|
|
chmod 0644 "${BLITZ_LOG_FILE}"
|
|
blitz_log "install" "prepare-log-file" "success" "log_file=${BLITZ_LOG_FILE}" 0
|
|
blitz_prepare_runtime_dir
|
|
blitz_prepare_run_root
|
|
|
|
install_unit "blitz-boot-gate.service.in"
|
|
install_unit "blitz-run-context.service.in"
|
|
install_unit "blitz-5g-dial.service.in"
|
|
install_unit "blitz-5g-link-logger.service.in"
|
|
install_unit "blitz-ros-receiver.service.in"
|
|
install_unit "blitz-b-side-omnid.service.in"
|
|
install_unit "blitz-watchdog.service.in"
|
|
install_unit "blitz-robot.target.in"
|
|
remove_unit_if_present "blitz-time-sync.service"
|
|
|
|
blitz_run "install" "daemon-reload" systemctl daemon-reload
|
|
blitz_run "install" "enable-target" systemctl enable blitz-robot.target
|
|
blitz_log "install" "complete" "success" "run systemctl start blitz-robot.target to launch immediately" 0
|