-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.sh
executable file
·120 lines (99 loc) · 3.96 KB
/
start.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
#
# start.sh
#
# This script automates environment setup for embedded-sharepoint
IMAGE_NAME="embedded-sharepoint"
WORKDIR_MOUNT="$PWD"
DOCKERFILE_DIR="$(dirname "$0")"
DOCKERFILE_PATH="$DOCKERFILE_DIR/Dockerfile"
DOCKER_COMPOSE_FILE="docker-compose.yml"
echo "====================================================="
echo " Embedded Sharepoint Setup"
echo "====================================================="
###############################################################################
# Detect Distro
###############################################################################
if [ -f /etc/os-release ]; then
source /etc/os-release
DISTRO_ID=$ID
elif [ -f /etc/issue ]; then
# Fallback for older systems
DISTRO_ID=$(head -n1 /etc/issue | awk '{print tolower($1)}')
else
DISTRO_ID="unknown"
fi
###############################################################################
# Check if Docker is installed
###############################################################################
function install_docker_ubuntu() {
echo "[INFO] Installing Docker for Ubuntu..."
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable docker
sudo systemctl start docker
}
function install_docker_arch() {
echo "[INFO] Installing Docker for Arch..."
sudo pacman -Sy --noconfirm docker
sudo systemctl enable docker
sudo systemctl start docker
}
if ! command -v docker &> /dev/null; then
echo "[INFO] Docker not found on your system."
if [[ "$DISTRO_ID" == "ubuntu" ]]; then
install_docker_ubuntu
elif [[ "$DISTRO_ID" == "arch" ]]; then
install_docker_arch
else
echo "[WARNING] Your distro is '$DISTRO_ID', which isn't supported by this script."
echo " Please follow Docker's official instructions at:"
echo " https://docs.docker.com/get-docker/"
exit 1
fi
# Add current user to docker group
echo "[INFO] Adding '$USER' to the 'docker' group..."
sudo groupadd docker 2> /dev/null || true
sudo usermod -aG docker "$USER"
echo "[INFO] Docker installation complete."
echo " You may need to log out and log back in (or restart your shell) for the group"
echo " membership to take effect. Please do that, then re-run this script."
exit 0
else
echo "[OK] Docker is already installed."
fi
# Double-check Docker is running properly
if ! docker ps &> /dev/null; then
echo "[ERROR] Docker is installed but not running. Please start Docker \(e.g., 'sudo systemctl start docker'\)."
exit 1
fi
###############################################################################
# Run the container
###############################################################################
echo "[INFO] Running the Docker container ..."
echo " - Image: $IMAGE_NAME"
echo " - Mount: $WORKDIR_MOUNT -> /Embedded-Sharepoint"
echo "-----------------------------------------------------"
# Sets SSH_AUTH_SOCK for macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
export SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock"
fi
# Start ssh-agent
# test whether $SSH_AUTH_SOCK is valid
ssh-add -l 2>/dev/null >/dev/null
# if not valid, then start ssh-agent using $SSH_AUTH_SOCK
[ $? -ge 2 ] && ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null
docker compose -f "$DOCKER_COMPOSE_FILE" build
docker compose -f "$DOCKER_COMPOSE_FILE" run --rm dev
echo "[INFO] Container exited."