forked from ItzNotABug/ghosler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-install.sh
executable file
·62 lines (49 loc) · 1.98 KB
/
docker-install.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
#!/bin/bash
# Define color codes
NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD_GREEN='\033[1;32m'
# Set default values
DEFAULT_PORT=2369
DEFAULT_CONTAINER_NAME="ghosler"
echo ""
echo -e "${BOLD_GREEN}Note: If you are UPDATING, use the same PORT & CONTAINER NAME!${NC}"
echo ""
# Prompt for port number with default
echo -e "${GREEN}Provide a port for Ghosler [Default: $DEFAULT_PORT]${NC} : "
read -r PORT
PORT=${PORT:-$DEFAULT_PORT}
# Prompt for container name with default
echo -e "${GREEN}Provide a name for Ghosler Container [Default: $DEFAULT_CONTAINER_NAME]${NC} : "
read -r CONTAINER_NAME
CONTAINER_NAME=${CONTAINER_NAME:-$DEFAULT_CONTAINER_NAME}
# Fetch the releases from GitHub API
releases=$(curl -s "https://api.github.com/repos/itznotabug/ghosler/releases")
# latest version
LATEST_VERSION=""
# Loop through each line in the releases
while read -r line; do
# Check if the line contains "tag_name" and LATEST_VERSION is not set
if [[ $line == *"tag_name"* && -z $LATEST_VERSION ]]; then
# Extract the version from the line
LATEST_VERSION=$(echo "$line" | cut -d '"' -f 4)
break
fi
done <<< "$releases"
# Check if a version was found
if [[ -z "$LATEST_VERSION" ]]; then
LATEST_VERSION="0.94" # default to the docker supported version.
fi
echo -e "${GREEN}Starting Ghosler Docker installation...${NC}"
echo ""
# Stop the container silently if it's running in case of an update.
docker stop "$CONTAINER_NAME" > /dev/null 2>&1
# Run the container with latest version.
if ! docker run --rm --name "$CONTAINER_NAME" -d -p "$PORT":2369 -v "${CONTAINER_NAME}"-logs:/usr/src/app/.logs -v "${CONTAINER_NAME}"-analytics:/usr/src/app/files -v "${CONTAINER_NAME}"-configuration:/usr/src/app/configuration itznotabug/ghosler:"${LATEST_VERSION}"; then
echo ""
echo -e "${RED}Error: Failed to start Ghosler. Please check the Docker logs for more details.${NC}" >&2
exit 1
fi
echo ""
echo -e "${GREEN}Ghosler has been successfully installed and started.${NC}"