-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·151 lines (122 loc) · 4.82 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Set Moqui setup directory
MOQUI_SETUP_DIR="moqui"
if ! [ -x "$(command -v docker)" ]; then
echo 'Docker is not installed. Please install Docker by running...'
# Download the convenience script
echo "curl -fsSL https://get.docker.com | sh"
exit 1
else
echo 'Docker is already installed.'
fi
# Ensure that the docker daemon is running
if ! systemctl is-active --quiet docker; then
echo 'Please start Docker service by running...'
echo "systemctl start docker"
exit 1
fi
# Check if $MOQUI_SETUP_DIR exists; if not, clone the repository
if [ -n "$1" ]; then
MOQUI_SETUP_DIR="$1"
elif [ -n "$MOQUI_SETUP_DIR" ]; then
echo "Using environment variable MOQUI_SETUP_DIR: $MOQUI_SETUP_DIR"
else
read -p "Enter the directory path for Moqui setup [$MOQUI_SETUP_DIR]: " USER_INPUT < /dev/tty
# If the user didn't provide input, set a default value
if [ -z "$USER_INPUT" ]; then
if [ -d "$MOQUI_SETUP_DIR" ]; then
# Generate a random string with a prefix of 'moqui-'
RANDOM_SUFFIX=$(openssl rand -hex 4)
MOQUI_SETUP_DIR="moqui-$RANDOM_SUFFIX"
echo "Defaulting to generated directory: $MOQUI_SETUP_DIR"
fi
else
MOQUI_SETUP_DIR="$USER_INPUT"
fi
fi
# Define the download URL for the .tar.gz version of the repository
DOWNLOAD_URL="https://github.com/moqui/moqui-docker/archive/refs/heads/master.tar.gz"
# Download the tar.gz file using curl
curl -sL "$DOWNLOAD_URL" -o "$MOQUI_SETUP_DIR.tar.gz"
# Ensure the `gunzip` command is available
if ! command -v gunzip &> /dev/null; then
echo "gunzip could not be found. Please install gunzip and try again."
exit 1
fi
# Create the directory if it doesn't exist
mkdir -p "$MOQUI_SETUP_DIR"
# Use gunzip to decompress the .tar.gz file
gunzip -q "$MOQUI_SETUP_DIR.tar.gz"
# Extract the resulting .tar file to the specified directory
tar -xf "$MOQUI_SETUP_DIR.tar" -C "$MOQUI_SETUP_DIR" --strip-components 1
# Remove the downloaded .tar file after extraction
rm "$MOQUI_SETUP_DIR.tar"
cd "$MOQUI_SETUP_DIR"
echo "Moqui Docker repository has been set up in $MOQUI_SETUP_DIR."
# Load existing .env file if it exists
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
# Prompt for domain if not provided as a parameter
DOMAIN=${1:-$VIRTUAL_HOST}
if [ -n "$DOMAIN" ]; then
read -rp "Enter the domain to run Moqui: " input < /dev/tty
DOMAIN=${input:-DOMAIN}
DOMAIN=${DOMAIN:-$VIRTUAL_HOST}
else
read -rp "Enter the domain to run Moqui [$VIRTUAL_HOST]: " input < /dev/tty
DOMAIN=${input:-DOMAIN}
DOMAIN=${DOMAIN:-$VIRTUAL_HOST}
fi
# Set ACME_EMAIL to the second positional parameter or keep its current value
ACME_EMAIL=${2:-$ACME_EMAIL}
# Prompt for ACME_EMAIL if it is still empty
if [ -z "$ACME_EMAIL" ]; then
read -rp "Enter your ACME email address: " ACME_EMAIL < /dev/tty
else
read -rp "Enter your ACME email address [$ACME_EMAIL]: " input < /dev/tty
# If the user input is empty, retain the current value of ACME_EMAIL
ACME_EMAIL=${input:-$ACME_EMAIL}
fi
# Set environment variables
echo "Setting environment variables..."
export VIRTUAL_HOST="$DOMAIN"
export DEFAULT_HOST="$DOMAIN"
export DEFAULT_EMAIL="$ACME_EMAIL"
export LETSENCRYPT_TEST=true
# Set default passwords or prompt for them if not provided
if [ -z "$POSTGRES_PASSWORD" ]; then
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-$(head -c 16 /dev/random | base64)}
read -rp "Enter your PostgreSQL password [$POSTGRES_PASSWORD]: " input < /dev/tty
POSTGRES_PASSWORD=${input:-$POSTGRES_PASSWORD}
fi
if [ -z "$ENTITY_DS_CRYPT_PASS" ]; then
ENTITY_DS_CRYPT_PASS=${ENTITY_DS_CRYPT_PASS:-$(head -c 16 /dev/random | base64)}
read -rp "Enter your Entity DS Crypt password [$ENTITY_DS_CRYPT_PASS]: " input < /dev/tty
ENTITY_DS_CRYPT_PASS=${input:-$ENTITY_DS_CRYPT_PASS}
fi
if [ -z "$ELASTICSEARCH_PASSWORD" ]; then
ELASTICSEARCH_PASSWORD=${ELASTICSEARCH_PASSWORD:-$(head -c 16 /dev/random | base64)}
read -rp "Enter your Elasticsearch password [$ELASTICSEARCH_PASSWORD]: " input < /dev/tty
ELASTICSEARCH_PASSWORD=${input:-$ELASTICSEARCH_PASSWORD}
fi
MOQUI_IMAGE=${MOQUI_IMAGE:-moqui/moquidemo}
read -rp "Enter your moqui image [$MOQUI_IMAGE]: " input < /dev/tty
MOQUI_IMAGE=${input:-$MOQUI_IMAGE}
# Save the environment variables to a .env file
cat <<EOF > .env
POSTGRES_PASSWORD=$POSTGRES_PASSWORD
ENTITY_DS_CRYPT_PASS=$ENTITY_DS_CRYPT_PASS
ELASTICSEARCH_PASSWORD=$ELASTICSEARCH_PASSWORD
VIRTUAL_HOST=$VIRTUAL_HOST
DEFAULT_HOST=$DEFAULT_HOST
DEFAULT_EMAIL=$DEFAULT_EMAIL
LETSENCRYPT_TEST=$LETSENCRYPT_TEST
ACME_EMAIL=$ACME_EMAIL
MOQUI_IMAGE=$MOQUI_IMAGE
EOF
echo "Environment setup complete. Configuration saved in $MOQUI_SETUP_DIR/.env file."
# Check if there is the adequate docker image to run the docker compose
# Run ./compose-up compose/default-compose.yml
# if it fails, run ./compose-down.sh compose/default-compose.yml
./compose-up.sh compose/default-compose.yml . eclipse-temurin:11-jdk .env