2021-10-22 15:22:10 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# SPDX-FileCopyrightText: 2020 Umbrel https://getumbrel.com
|
2022-01-28 06:52:26 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-2022 Citadel and contributors
|
2021-10-22 15:22:10 +00:00
|
|
|
#
|
2022-01-21 20:37:48 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2021-10-22 15:22:10 +00:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# Start Citadel
|
|
|
|
|
|
|
|
if [[ $UID != 0 ]]; then
|
|
|
|
echo "Citadel must be started as root"
|
|
|
|
echo "Please re-run this script as"
|
|
|
|
echo " sudo ./scripts/start"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
check_dependencies () {
|
|
|
|
for cmd in "$@"; do
|
|
|
|
if ! command -v $cmd >/dev/null 2>&1; then
|
|
|
|
echo "This script requires \"${cmd}\" to be installed"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check system's dependencies
|
|
|
|
check_dependencies readlink dirname ip docker
|
|
|
|
|
|
|
|
# Check karen's dependencies
|
|
|
|
check_dependencies fswatch
|
|
|
|
|
|
|
|
# Check OTA update scripts' dependencies
|
|
|
|
check_dependencies rsync jq curl
|
|
|
|
|
|
|
|
CITADEL_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/.."
|
|
|
|
CITADEL_LOGS="${CITADEL_ROOT}/logs"
|
|
|
|
|
|
|
|
if [[ ! -d "$CITADEL_ROOT" ]]; then
|
|
|
|
echo "Root dir does not exist '$CITADEL_ROOT'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-11-07 08:51:42 +00:00
|
|
|
# Configure Citadel if it isn't already configured
|
2021-10-22 15:22:10 +00:00
|
|
|
if [[ ! -f "${CITADEL_ROOT}/statuses/configured" ]]; then
|
|
|
|
NGINX_PORT=${NGINX_PORT:-80} NETWORK="${NETWORK:-mainnet}" "${CITADEL_ROOT}/scripts/configure"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "======================================"
|
|
|
|
echo "============= STARTING ==============="
|
|
|
|
echo "============= CITADEL ================"
|
|
|
|
echo "======================================"
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo "Setting environment variables..."
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Check Citadel OS
|
|
|
|
[[ -f "/etc/default/citadel" ]] && source "/etc/default/citadel"
|
|
|
|
if [[ -z "${CITADEL_OS:-}" ]]; then
|
|
|
|
export IS_CITADEL_OS="false"
|
|
|
|
else
|
|
|
|
export IS_CITADEL_OS="true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Whitelist device IP, hostname and hidden service for CORS
|
2022-01-02 09:10:57 +00:00
|
|
|
DEVICE_IP=$(hostname -I | awk '{print $1}') || DEVICE_IP="$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep "inet" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1)"
|
|
|
|
DEVICE_HOSTNAME="$(hostname)" || DEVICE_HOSTNAME="$(cat /etc/hostname)"
|
2021-10-22 15:22:10 +00:00
|
|
|
DEVICE_HOSTS="http://${DEVICE_IP},http://${DEVICE_HOSTNAME}.local,https://${DEVICE_HOSTNAME}.local,http://${DEVICE_HOSTNAME},https://${DEVICE_HOSTNAME}"
|
|
|
|
if [[ -f "${CITADEL_ROOT}/tor/data/web/hostname" ]]; then
|
|
|
|
hidden_service_url=$(cat "${CITADEL_ROOT}/tor/data/web/hostname")
|
|
|
|
DEVICE_HOSTS="${DEVICE_HOSTS},http://${hidden_service_url}"
|
|
|
|
fi
|
|
|
|
export DEVICE_HOSTS=$DEVICE_HOSTS
|
|
|
|
export DEVICE_HOSTNAME="${DEVICE_HOSTNAME}.local"
|
|
|
|
|
|
|
|
# Increase default Docker and Compose timeouts to 240s
|
|
|
|
# as bitcoin can take a long while to respond
|
|
|
|
export DOCKER_CLIENT_TIMEOUT=240
|
|
|
|
export COMPOSE_HTTP_TIMEOUT=240
|
|
|
|
|
|
|
|
cd "$CITADEL_ROOT"
|
|
|
|
|
|
|
|
echo "Starting karen..."
|
|
|
|
echo
|
|
|
|
./karen &>> "${CITADEL_LOGS}/karen.log" &
|
|
|
|
|
|
|
|
echo "Starting status monitors..."
|
|
|
|
pkill -f ./scripts/status-monitor || true
|
|
|
|
./scripts/status-monitor memory 60 &>> "${CITADEL_LOGS}/status-monitor.log" &
|
|
|
|
./scripts/status-monitor storage 60 &>> "${CITADEL_LOGS}/status-monitor.log" &
|
|
|
|
./scripts/status-monitor temperature 15 &>> "${CITADEL_LOGS}/status-monitor.log" &
|
|
|
|
./scripts/status-monitor uptime 15 &>> "${CITADEL_LOGS}/status-monitor.log" &
|
2022-02-02 18:31:19 +00:00
|
|
|
./scripts/status-monitor app-updates 300 &>> "${CITADEL_LOGS}/status-monitor.log" &
|
2021-10-22 15:22:10 +00:00
|
|
|
|
|
|
|
echo "Starting backup monitor..."
|
|
|
|
echo
|
|
|
|
./scripts/backup/monitor &>> "${CITADEL_LOGS}/backup-monitor.log" &
|
|
|
|
|
|
|
|
echo "Starting decoy backup trigger..."
|
|
|
|
echo
|
|
|
|
./scripts/backup/decoy-trigger &>> "${CITADEL_LOGS}/backup-decoy-trigger.log" &
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Resetting config files"
|
|
|
|
echo
|
|
|
|
./scripts/configure
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Starting Docker services..."
|
|
|
|
echo
|
|
|
|
docker compose up --detach --build --remove-orphans || {
|
|
|
|
echo "Failed to start containers"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
echo
|
|
|
|
|
2021-11-07 08:51:42 +00:00
|
|
|
# Unlock the user file on each start of Citadel to avoid issues
|
2021-10-22 15:22:10 +00:00
|
|
|
# Normally, the user file shouldn't ever be locked, if it is, something went wrong, but it could still be working
|
|
|
|
if [[ -f "${CITADEL_ROOT}/db/user.json.lock" ]]; then
|
|
|
|
echo "WARNING: The user file was locked, Citadel probably wasn't shut down properly"
|
|
|
|
rm "${CITADEL_ROOT}/db/user.json.lock"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Starting installed apps..."
|
|
|
|
echo
|
2022-02-01 17:50:59 +00:00
|
|
|
./scripts/app start installed
|
2021-10-22 15:22:10 +00:00
|
|
|
echo
|
|
|
|
|
|
|
|
echo "Citadel is now accessible at"
|
|
|
|
echo " http://${DEVICE_HOSTNAME}"
|
|
|
|
echo " http://${DEVICE_IP}"
|
|
|
|
if [[ ! -z "${hidden_service_url:-}" ]]; then
|
|
|
|
echo " http://${hidden_service_url}"
|
|
|
|
fi
|