iflrandevu/nginx_docker_localtest.sh

155 lines
4.7 KiB
Bash
Raw Normal View History

2023-12-21 00:37:07 +03:00
#!/bin/bash
# Nginx Docker Localtest
2023-12-21 01:58:33 +03:00
CONT_NAME="IFLRANDEVU_NGINX_LOCALTEST" # nginx docker name
MOUNT_PATH="/source" # binded mount path in nginx docker
SCRIPT_NAME="nginx_docker_localtest.sh" # name of the *this* file
### REMOTE RELEASE ###
LATEST_RELEASE="1.4.3-ifl.2"
FILE_NAME="iflrandevu-$LATEST_RELEASE.zip"
DOWNLOAD_LINK=https://git.aliberksandikci.com.tr/ifl/iflrandevu/releases/download/$LATEST_RELEASE/$FILE_NAME
CONFIG_FILE_CONTENT="""
<?php
/* ----------------------------------------------------------------------------
* IFLRandevu - Izmir Fen Lisesi Randevu Portali
*
* @package iflrandevu
* @author asandikci <contact@aliberksandikci.com.tr>
* @copyright Copyleft 2023 - 2024
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://iflpanel.com/about/iflrandevu
* @since v1.4.3
* ---------------------------------------------------------------------------- */
/**
* IFLRandevu Configuration File
*/
class Config {
// ------------------------------------------------------------------------
// GENERAL SETTINGS
// ------------------------------------------------------------------------
const BASE_URL = 'http://localhost:8000';
const LANGUAGE = 'turkish';
const DEBUG_MODE = TRUE;
// ------------------------------------------------------------------------
// DATABASE SETTINGS
// ------------------------------------------------------------------------
const DB_HOST = 'localhost';
const DB_NAME = 'iflrandevu';
const DB_USERNAME = 'root';
const DB_PASSWORD = 'root';
// ------------------------------------------------------------------------
// GOOGLE CALENDAR SYNC
// ------------------------------------------------------------------------
const GOOGLE_SYNC_FEATURE = FALSE; // Enter TRUE or FALSE
const GOOGLE_PRODUCT_NAME = '';
const GOOGLE_CLIENT_ID = '';
const GOOGLE_CLIENT_SECRET = '';
const GOOGLE_API_KEY = '';
}
/* End of file config.php */
/* Location: ./config.php */
"""
NGINX_CONFIG_FILE="""
server {
listen 80;
server_name localhost;
location / {
# alias /usr/share/nginx/html/;
root /usr/share/nginx/html/;
index index.php;
# Common parameter to increase upload size limit in conjunction with dedicated php-fpm file
# client_max_body_size 50M;
# try_files \$uri \$uri/ index.php;
# location ~ [^/]\.php(/|\$) {
# fastcgi_split_path_info ^(.+?\.php)(/.*)\$;
# fastcgi_pass unix:/var/run/php/php8.2-fpm-iflrandevu.sock;
# fastcgi_index index.php;
# include fastcgi_params;
# fastcgi_param REMOTE_USER \$remote_user;
# fastcgi_param PATH_INFO \$fastcgi_path_info;
# fastcgi_param SCRIPT_FILENAME \$request_filename;
# }
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
"""
############################
############################
2023-12-21 00:37:07 +03:00
_RED='\033[0;31m'
_NC='\033[0m \e[0m' # No Color, No Effect
if [[ $1 != "docker" ]]; then
if [[ $(pwd) != *iflrandevu ]]; then
echo "PLEASE CHANGE DIRECTORY TO \`iflrandevu/\` BEFORE STARTING SCRIPT"
exit
fi
docker stop $CONT_NAME
docker rm $CONT_NAME
echo "removed"
docker run -it -d --name "$CONT_NAME" --mount type=bind,source=".",target=/source/,readonly --publish 8000:80 nginx bash
2023-12-21 01:58:33 +03:00
echo -e "RUN SCRIPT: \`${_RED}bash $MOUNT_PATH/$SCRIPT_NAME docker${_NC}\`"
2023-12-21 00:37:07 +03:00
docker attach $CONT_NAME --detach-keys="ctrl-k"
echo "EXIT"
exit
2023-12-21 01:58:33 +03:00
elif [[ $1 == "attach" ]]; then
docker start $CONT_NAME
docker attach $CONT_NAME --detach-keys="ctrl-k"
2023-12-21 00:37:07 +03:00
elif [[ $1 == "docker" ]]; then
2023-12-21 01:58:33 +03:00
2023-12-21 00:37:07 +03:00
apt update
2023-12-21 01:58:33 +03:00
apt install nano exa tree wget unzip less -y
2023-12-21 00:37:07 +03:00
cd /usr/share/nginx/html
2023-12-21 01:58:33 +03:00
# rm -f "50x.html"
2023-12-21 00:37:07 +03:00
rm -f "index.html"
2023-12-21 01:58:33 +03:00
if [[ $2 == "local" ]]; then
cp -r /source/build/* /usr/share/nginx/html/
elif [[ $2 == "remote" ]]; then
wget $DOWNLOAD_LINK
unzip $FILE_NAME
mv $FILE_NAME ../
else
echo -e "${_RED}use docker local or docker remote${_NC}"
fi
### CONFIGURATIONS ###
apt install php php-fpm -y
apt install mariadb-server -y
service mariadb start
mysql -u root -e "create database iflrandevu"
echo -e "$CONFIG_FILE_CONTENT" >"config.php"
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
chmod 770 storage
2023-12-21 00:37:07 +03:00
2023-12-21 01:58:33 +03:00
service nginx start
service nginx status
service nginx restart
echo -e "${_RED}DONE! - OPEN localhost:8000 TO TEST${_NC}"
2023-12-21 00:37:07 +03:00
fi
2023-12-21 01:58:33 +03:00
# TODO Docker compose to run with /docker/build/docker.sh container together