-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·84 lines (72 loc) · 2.89 KB
/
run.sh
File metadata and controls
executable file
·84 lines (72 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -euo pipefail
echo "Starting SmartThings HomeKit Bridge container..."
# Configuration
REGISTRY="docker.revealedpreferences.com"
IMAGE_NAME="smartthings-homekit-bridge"
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:latest" # Using local test image
CONTAINER_NAME="smartthings-homekit-bridge"
# Port configuration (avoiding conflicts with Homebridge on 51826)
WEB_PORT="${WEB_PORT:-3000}"
HAP_PORT="${HAP_PORT:-52826}" # Use 52826 to avoid conflict with Homebridge (51826)
# Stop and remove existing container if running
if docker ps -a --format 'table {{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Stopping existing container..."
docker stop ${CONTAINER_NAME} || true
echo "Removing existing container..."
docker rm ${CONTAINER_NAME} || true
fi
docker pull ${FULL_IMAGE} || true
# Create data directory for persistent storage if it doesn't exist
DATA_DIR="${HOME}/.smartthings-bridge"
mkdir -p "${DATA_DIR}"
mkdir -p "${DATA_DIR}/persist"
# Set permissions to allow container user (UID 1001) to write
# This makes the directories world-writable which allows the container user to write
chmod 777 "${DATA_DIR}"
chmod 777 "${DATA_DIR}/persist"
# Build docker run command with conditional volume mounts
# Detect OS and use appropriate networking
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Detected macOS - using port mapping instead of host networking"
DOCKER_CMD="docker run -d \
--name ${CONTAINER_NAME} \
--restart=unless-stopped \
-p ${WEB_PORT}:${WEB_PORT} \
-p ${HAP_PORT}:${HAP_PORT} \
-e HAP_PORT=${HAP_PORT} \
-e WEB_PORT=${WEB_PORT} \
-v \"${DATA_DIR}:/app/data\" \
-v \"${DATA_DIR}/persist:/app/persist\""
else
echo "Using host network mode for mDNS advertisement (Linux)"
DOCKER_CMD="docker run -d \
--name ${CONTAINER_NAME} \
--restart=unless-stopped \
--network=host \
-e HAP_PORT=${HAP_PORT} \
-e WEB_PORT=${WEB_PORT} \
-v \"${DATA_DIR}:/app/data\" \
-v \"${DATA_DIR}/persist:/app/persist\""
fi
# Add .env file mount if file exists
if [ -f "${PWD}/.env" ]; then
DOCKER_CMD="${DOCKER_CMD} -v \"${PWD}/.env:/app/.env:ro\""
echo "Found .env file - mounting into container"
else
echo "Warning: .env file not found - you may need to set environment variables manually"
fi
DOCKER_CMD="${DOCKER_CMD} ${FULL_IMAGE}"
echo "Starting new container..."
eval ${DOCKER_CMD}
echo "Container started successfully!"
echo "Web interface available at: http://localhost:${WEB_PORT}"
echo "HomeKit bridge running on port: ${HAP_PORT}"
echo "Container name: ${CONTAINER_NAME}"
echo "Data directory: ${DATA_DIR}"
echo ""
echo "Note: Using port ${HAP_PORT} to avoid conflict with Homebridge (port 51826)"
echo "To customize ports: WEB_PORT=3001 HAP_PORT=52827 ./run.sh"
echo ""
echo "To view logs: docker logs -f ${CONTAINER_NAME}"
echo "To stop: docker stop ${CONTAINER_NAME}"