forked from sprintcube/docker-compose-lamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
71 lines (59 loc) · 2 KB
/
setup.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
#!/bin/bash
# Detect sudo usage
if [[ $(id -u) -ne 0 ]]; then
echo "This script requires root privileges. Please run with sudo."
exit 1
fi
# Detect the package manager
package_managers=("apt" "yum" "dnf" "pacman" "yay")
PACKAGE_MANAGER=""
for manager in "${package_managers[@]}"; do
if command -v "$manager" >/dev/null 2>&1; then
PACKAGE_MANAGER="$manager install -y git docker docker-compose"
break
fi
done
if [[ -z "$PACKAGE_MANAGER" ]]; then
echo "Unable to detect a supported package manager (apt, yum, dnf, pacman, or yay). Exiting."
exit 1
fi
# Install packages
echo "Usage: sudo bash script.sh [repository URL]"
echo "Example: sudo bash script.sh https://github.com/sprintcube/docker-compose-lamp"
# Prompt for repository URL or show help menu
if [[ $# -eq 0 ]]; then
echo "Installing necessary packages using $PACKAGE_MANAGER..."
if ! command -v docker-compose >/dev/null 2>&1; then
echo "Docker Compose is already installed. Skipping."
if ! command -v docker-compose >/dev/null 2>&1; then
echo "Docker Compose is already installed. Skipping."
if ! command -v git >/dev/null 2>&1; then
echo "Git is already installed. Skipping."
else
if ! eval "$PACKAGE_MANAGER"; then
echo "Package installation failed. Exiting."
exit 1
fi
fi
else
if ! eval "$PACKAGE_MANAGER"; then
echo "Package installation failed. Exiting."
exit 1
fi
fi
fi
echo "Enabling and starting Docker..."
systemctl enable --now docker.service docker.socket
sleep 1
REPO_URL="$1"
# Clone the repository
echo "Cloning repository..."
if [[ -z "$REPO_URL" ]]; then
echo "No repository URL provided. Exiting."
exit 1
fi
git clone "$REPO_URL" ./www
# Start Docker container using docker-compose
echo "Starting Docker container..."
docker-compose up -d
fi