mirror of https://github.com/lukechilds/umbrel.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
4.1 KiB
140 lines
4.1 KiB
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Start Umbrel
|
|
|
|
if [[ $UID != 0 ]]; then
|
|
echo "Umbrel 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 docker-compose
|
|
|
|
# Check karen's dependencies
|
|
check_dependencies fswatch
|
|
|
|
# Check OTA update scripts' dependencies
|
|
check_dependencies rsync jq curl
|
|
|
|
UMBREL_ROOT="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))/.."
|
|
UMBREL_LOGS="${UMBREL_ROOT}/logs"
|
|
|
|
set_status="${UMBREL_ROOT}/scripts/umbrel-os/status-server/set-status"
|
|
|
|
$set_status umbrel started
|
|
|
|
if [[ ! -d "$UMBREL_ROOT" ]]; then
|
|
echo "Root dir does not exist '$UMBREL_ROOT'"
|
|
$set_status umbrel errored umbrel-root-missing
|
|
exit 1
|
|
fi
|
|
|
|
# Configure Umbrel if it isn't already configured
|
|
if [[ ! -f "${UMBREL_ROOT}/statuses/configured" ]]; then
|
|
NGINX_PORT=${NGINX_PORT:-80} NETWORK="${NETWORK:-mainnet}" "${UMBREL_ROOT}/scripts/configure"
|
|
fi
|
|
|
|
echo
|
|
echo "======================================"
|
|
echo "============= STARTING ==============="
|
|
echo "============== UMBREL ================"
|
|
echo "======================================"
|
|
echo
|
|
|
|
echo "Setting environment variables..."
|
|
echo
|
|
|
|
# Check Umbrel OS
|
|
[[ -f "/etc/default/umbrel" ]] && source "/etc/default/umbrel"
|
|
if [[ -z "${UMBREL_OS:-}" ]]; then
|
|
export IS_UMBREL_OS="false"
|
|
else
|
|
export IS_UMBREL_OS="true"
|
|
fi
|
|
|
|
# Whitelist device IP, hostname and hidden service for CORS
|
|
DEVICE_IP="$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')"
|
|
DEVICE_HOSTNAME="$(hostname)"
|
|
DEVICE_HOSTS="http://${DEVICE_IP},http://${DEVICE_HOSTNAME}.local,https://${DEVICE_HOSTNAME}.local,http://${DEVICE_HOSTNAME},https://${DEVICE_HOSTNAME}"
|
|
if [[ -f "${UMBREL_ROOT}/tor/data/web/hostname" ]]; then
|
|
hidden_service_url=$(cat "${UMBREL_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 "$UMBREL_ROOT"
|
|
|
|
echo "Starting karen..."
|
|
echo
|
|
./karen &>> "${UMBREL_LOGS}/karen.log" &
|
|
|
|
echo "Starting status monitors..."
|
|
pkill -f ./scripts/status-monitor || true
|
|
./scripts/status-monitor memory 60 &>> "${UMBREL_LOGS}/status-monitor.log" &
|
|
./scripts/status-monitor storage 60 &>> "${UMBREL_LOGS}/status-monitor.log" &
|
|
./scripts/status-monitor temperature 15 &>> "${UMBREL_LOGS}/status-monitor.log" &
|
|
./scripts/status-monitor uptime 15 &>> "${UMBREL_LOGS}/status-monitor.log" &
|
|
|
|
echo "Starting memory monitor..."
|
|
echo
|
|
./scripts/memory-monitor &>> "${UMBREL_LOGS}/memory-monitor.log" &
|
|
|
|
echo "Starting backup monitor..."
|
|
echo
|
|
./scripts/backup/monitor &>> "${UMBREL_LOGS}/backup-monitor.log" &
|
|
|
|
echo "Starting decoy backup trigger..."
|
|
echo
|
|
./scripts/backup/decoy-trigger &>> "${UMBREL_LOGS}/backup-decoy-trigger.log" &
|
|
|
|
echo
|
|
echo "Starting Docker services..."
|
|
echo
|
|
docker-compose up --detach --build --remove-orphans || {
|
|
echo "Failed to start containers"
|
|
$set_status umbrel errored docker-failed
|
|
exit 1
|
|
}
|
|
echo
|
|
|
|
echo "Removing status server iptables entry..."
|
|
"${UMBREL_ROOT}/scripts/umbrel-os/status-server/setup-iptables" --delete
|
|
|
|
echo
|
|
echo "Starting installed apps..."
|
|
echo
|
|
# Unlock the user file on each start of Umbrel to avoid issues
|
|
# Normally, the user file shouldn't ever be locked, if it is, something went wrong, but it could still be working
|
|
if [[ -f "${UMBREL_ROOT}/db/user.json.lock" ]]; then
|
|
echo "WARNING: The user file was locked, Umbrel probably wasn't shut down properly"
|
|
rm "${UMBREL_ROOT}/db/user.json.lock"
|
|
fi
|
|
"${UMBREL_ROOT}/scripts/app" start installed
|
|
echo
|
|
|
|
echo "Umbrel is now accessible at"
|
|
echo " http://${DEVICE_HOSTNAME}"
|
|
echo " http://${DEVICE_IP}"
|
|
if [[ ! -z "${hidden_service_url:-}" ]]; then
|
|
echo " http://${hidden_service_url}"
|
|
fi
|
|
|
|
$set_status umbrel completed
|
|
|