@@ -40,7 +40,7 @@ echo -e "${YELLOW}[STEP 1/6]${RESET} Verifying required files and folders..."
4040echo
4141
4242# Check for docker-compose.yaml
43- if [ ! -f " docker-compose.yaml" ]; then
43+ if [[ ! -f " docker-compose.yaml" ] ]; then
4444 echo -e " ${RED} [ERROR]${RESET} Missing 'docker-compose.yaml' file."
4545 echo " Please ensure this file is present in the root directory."
4646 exit 1
5050echo
5151
5252# Check for nginx configuration
53- if [ ! -f " $NGINX_CONF_FILE " ]; then
53+ if [[ ! -f " $NGINX_CONF_FILE " ] ]; then
5454 echo -e " ${RED} [ERROR]${RESET} Missing 'docker/etc/nginx/conf.d/default.conf' file."
5555 echo " Please ensure this file is present in the correct directory."
5656 exit 1
6060echo
6161
6262# Check for Caddyfile
63- if [ ! -f " docker/etc/caddy/Caddyfile" ]; then
63+ if [[ ! -f " docker/etc/caddy/Caddyfile" ] ]; then
6464 echo -e " ${RED} [ERROR]${RESET} Missing 'docker/etc/caddy/Caddyfile' file."
6565 echo " Please ensure this file is present in the correct directory."
6666 exit 1
7272echo
7373
7474# Check for .env.docker
75- if [ ! -f " docker/.env.docker" ]; then
75+ if [[ ! -f " docker/.env.docker" ] ]; then
7676 echo -e " ${RED} [ERROR]${RESET} Missing 'docker/.env.docker' file."
7777 echo " Please ensure this file is present in the correct directory."
7878 exit 1
7979fi
8080
8181# Create .env if it doesn't exist
82- if [ ! -f " $ENV_FILE " ]; then
82+ if [[ ! -f " $ENV_FILE " ] ]; then
8383 echo -e " ${BLUE} [INFO]${RESET} '.env' file not found. Creating from '.env.docker'..."
8484 cp " docker/.env.docker" " $ENV_FILE "
85- if [ $? -ne 0 ]; then
85+ if [[ $? -ne 0 ] ]; then
8686 echo -e " ${RED} [ERROR]${RESET} Failed to create '.env' file."
8787 exit 1
8888 fi
9393echo
9494
9595# Ensure data/app subdirectories exists
96- if [ ! -d " data/media" ] || [ ! -d " data/avatars" ] || [ ! -d " data/thumbnails" ] || [ ! -d " app" ]; then
96+ if [[ ! -d " data/media" ]] || [[ ! -d " data/avatars" ]] || [[ ! -d " data/thumbnails" ]] || [[ ! -d " app" ] ]; then
9797 echo -e " ${BLUE} [INFO]${RESET} One or more 'data/app' subdirectories are missing. Creating them..."
9898 echo
9999 mkdir -p data/media data/avatars data/thumbnails app
@@ -106,13 +106,13 @@ echo
106106# Ensure permissions are set for data directories
107107sudo chown -R 9999:9999 data app
108108sudo chmod -R 775 data app
109- if [ $? -ne 0 ]; then
109+ if [[ $? -ne 0 ] ]; then
110110 echo -e " ${RED} [ERROR]${RESET} Failed to create 'data/app' subdirectories or set permissions."
111111 exit 1
112112fi
113113
114114# Ensure logs directory exists
115- if [ ! -d " logs" ]; then
115+ if [[ ! -d " logs" ] ]; then
116116 echo -e " ${BLUE} [INFO]${RESET} Missing 'logs' directory. Creating it..."
117117 echo
118118 mkdir -p " logs/mediaServer"
@@ -121,7 +121,7 @@ if [ ! -d "logs" ]; then
121121 sudo chown -R 9999:9999 ./logs/nginx
122122 sudo chown -R 9999:9999 ./logs/mediaServer
123123 sudo chmod -R 755 logs
124- if [ $? -ne 0 ]; then
124+ if [[ $? -ne 0 ] ]; then
125125 echo -e " ${RED} [ERROR]${RESET} Failed to create 'logs' directory."
126126 exit 1
127127 fi
132132echo
133133
134134# Ensure caddy directory exists
135- if [ ! -d " caddy/data" ]; then
135+ if [[ ! -d " caddy/data" ] ]; then
136136 echo -e " ${BLUE} [INFO]${RESET} Missing 'caddy' directory. Creating it..."
137137 echo
138138 mkdir -p " caddy/data"
139139 mkdir -p " caddy/config"
140140 sudo chown -R 1000:1000 ./caddy
141- if [ $? -ne 0 ]; then
141+ if [[ $? -ne 0 ] ]; then
142142 echo -e " ${RED} [ERROR]${RESET} Failed to create 'caddy' directory."
143143 exit 1
144144 fi
154154# Get existing APP_HOST and APP_PORT or use defaults
155155CURRENT_APP_HOST=" "
156156CURRENT_APP_PORT=" "
157- if [ -f " $ENV_FILE " ]; then
157+ if [[ -f " $ENV_FILE " ] ]; then
158158 CURRENT_APP_HOST=$( grep " ^APP_HOST=" " $ENV_FILE " | sed -E ' s/^APP_HOST="?([^"]*)"?/\1/' )
159159 CURRENT_APP_PORT=$( grep " ^APP_PORT=" " $ENV_FILE " | sed -E ' s/^APP_PORT="?([^"]*)"?/\1/' )
160160fi
185185
186186# Update APP_HOST in .env file using sed
187187sed -i " s|^APP_HOST=.*|APP_HOST=\" ${APP_HOST} \" |" " $ENV_FILE "
188- if [ $? -ne 0 ]; then
188+ if [[ $? -ne 0 ] ]; then
189189 echo -e " ${RED} [ERROR]${RESET} Failed to update APP_HOST in ${ENV_FILE} ."
190190 echo " Please check the .env file format or script permissions."
191191 exit 1
@@ -198,7 +198,7 @@ ESCAPED_APP_HOST=$(echo "$APP_HOST" | sed 's/\./\\./g') # Escape dots
198198
199199sed -i " s#valid_referers 127.0.0.1, .*;#valid_referers 127.0.0.1, ${ESCAPED_APP_HOST} ;#" " $NGINX_CONF_FILE "
200200
201- if [ $? -ne 0 ]; then
201+ if [[ $? -ne 0 ] ]; then
202202 echo -e " ${RED} [ERROR]${RESET} Failed to update valid_referers in ${NGINX_CONF_FILE} ."
203203 echo " Please check the Nginx config file format or script permissions."
204204 exit 1
@@ -211,7 +211,7 @@ echo -e "${YELLOW}[STEP 3/6]${RESET} Stopping and cleaning up Existing mediaServ
211211echo
212212
213213docker compose down
214- if [ $? -ne 0 ]; then
214+ if [[ $? -ne 0 ] ]; then
215215 echo -e " ${RED} [ERROR]${RESET} Failed to bring down Docker containers."
216216 echo " Please check your Docker setup and try again."
217217 exit 1
222222echo -e " ${YELLOW} [STEP 4/6]${RESET} Pruning Docker volumes..."
223223echo
224224docker volume prune -f
225- if [ $? -ne 0 ]; then
225+ if [[ $? -ne 0 ] ]; then
226226 echo -e " ${RED} [ERROR]${RESET} Failed to prune Docker volumes."
227227 echo " Please check your Docker setup and try again."
228228 exit 1
233233echo -e " ${YELLOW} [STEP 5/6]${RESET} Pulling latest Docker images..."
234234echo
235235docker compose pull
236- if [ $? -ne 0 ]; then
236+ if [[ $? -ne 0 ] ]; then
237237 echo -e " ${RED} [ERROR]${RESET} Failed to pull Docker images."
238238 echo " Please check your internet connection and Docker setup."
239239 exit 1
249249if ! docker volume inspect " $SHARED_VOLUME_NAME " & > /dev/null; then
250250 echo -e " ${BLUE} [INFO]${RESET} Shared volume '$SHARED_VOLUME_NAME ' does not exist. Creating it..."
251251 docker volume create " $SHARED_VOLUME_NAME "
252- if [ $? -ne 0 ]; then
252+ if [[ $? -ne 0 ] ]; then
253253 echo -e " ${RED} [ERROR]${RESET} Failed to create shared volume '$SHARED_VOLUME_NAME '."
254254 echo " Please check Docker daemon status and permissions."
255255 exit 1
@@ -269,7 +269,7 @@ docker run --rm \
269269 -v " ${SHARED_VOLUME_NAME} :/shared" \
270270 alpine sh -c " mkdir -p /shared && chown -R ${VOLUME_UID} :${VOLUME_GID} /shared && chmod 775 /shared && echo 'Volume permissions set.'"
271271
272- if [ $? -ne 0 ]; then
272+ if [[ $? -ne 0 ] ]; then
273273 echo -e " ${RED} [ERROR]${RESET} Failed to set shared volume permissions."
274274 echo " Please check your Docker volume and user/group ID configurations."
275275 exit 1
279279
280280docker compose up -d
281281
282- if [ $? -ne 0 ]; then
282+ if [[ $? -ne 0 ] ]; then
283283 echo -e " ${RED} [ERROR]${RESET} Failed to build docker compose."
284284 echo " Please check your configuration."
285285 exit 1
0 commit comments