2023-12-22 23:44:48 +03:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# Nginx Docker Localtest
|
|
|
|
|
|
2024-01-01 22:27:04 +03:00
|
|
|
|
CONT_NAME="MAKETRANDEVU_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
|
2023-12-22 23:44:48 +03:00
|
|
|
|
DEBUG="FALSE"
|
|
|
|
|
|
|
|
|
|
### REMOTE RELEASE ###
|
2024-01-09 23:47:14 +03:00
|
|
|
|
LATEST_RELEASE="1.5.0-RC2"
|
2024-01-01 01:14:38 +03:00
|
|
|
|
FILE_NAME="maketrandevu-$LATEST_RELEASE.zip"
|
|
|
|
|
DOWNLOAD_LINK=https://git.aliberksandikci.com.tr/maket/maketrandevu/releases/download/$LATEST_RELEASE/$FILE_NAME
|
2023-12-22 23:44:48 +03:00
|
|
|
|
|
|
|
|
|
WEB_ROOT_FOLDER="/usr/share/nginx/html/"
|
|
|
|
|
|
|
|
|
|
############################
|
|
|
|
|
############################
|
|
|
|
|
|
|
|
|
|
_RED='\033[0;31m'
|
|
|
|
|
_NC='\033[0m \e[0m' # No Color, No Effect
|
|
|
|
|
|
|
|
|
|
HELP="""
|
|
|
|
|
Usage:
|
|
|
|
|
dock [command] [subcommand]
|
|
|
|
|
|
|
|
|
|
COMMANDS:
|
|
|
|
|
${_RED}ini:${_NC} initialize dock command
|
2024-01-01 01:14:38 +03:00
|
|
|
|
install: install maketrandevu
|
2023-12-22 23:44:48 +03:00
|
|
|
|
local: get from local /source/
|
|
|
|
|
remote: get from git service
|
|
|
|
|
reconf : reconfigure configs
|
|
|
|
|
debug: change application debug status [ON / OFF]
|
|
|
|
|
restart: restart services (nginx, mariadb, php-fpm)
|
|
|
|
|
update: update source files with new build on /source/
|
|
|
|
|
status: see current webserver status
|
|
|
|
|
help : see this help text
|
|
|
|
|
|
2024-01-01 22:27:04 +03:00
|
|
|
|
BUNDLE COMMANDS:
|
|
|
|
|
complete-restart: update + reconf + restart + reconf
|
|
|
|
|
|
|
|
|
|
EXTERNAL COMMANDS: (without dock keyword)
|
|
|
|
|
root: move to root web folder
|
|
|
|
|
|
2023-12-22 23:44:48 +03:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
CONFIG_FILE_CONTENT="""
|
|
|
|
|
<?php
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2024-01-01 11:37:50 +03:00
|
|
|
|
* MaketRandevu - MAKET Randevu Portalı
|
2023-12-22 23:44:48 +03:00
|
|
|
|
*
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* @package maketrandevu
|
2023-12-22 23:44:48 +03:00
|
|
|
|
* @author asandikci <contact@aliberksandikci.com.tr>
|
|
|
|
|
* @copyright Copyleft 2023 - 2024
|
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* @link https://iflpanel.com/about/maketrandevu
|
2023-12-22 23:44:48 +03:00
|
|
|
|
* @since v1.4.3
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* Maket Randevu Configuration File
|
2023-12-22 23:44:48 +03:00
|
|
|
|
*/
|
|
|
|
|
class Config {
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
// GENERAL SETTINGS
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const BASE_URL = 'http://localhost:8000';
|
|
|
|
|
const LANGUAGE = 'turkish';
|
|
|
|
|
const DEBUG_MODE = $DEBUG;
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
// DATABASE SETTINGS
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const DB_HOST = 'localhost';
|
2024-01-01 01:14:38 +03:00
|
|
|
|
const DB_NAME = 'maketrandevu';
|
2023-12-22 23:44:48 +03:00
|
|
|
|
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:8000;
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
alias $WEB_ROOT_FOLDER;
|
|
|
|
|
#root $WEB_ROOT_FOLDER;
|
|
|
|
|
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)(/.*)\$;
|
2024-01-01 01:14:38 +03:00
|
|
|
|
fastcgi_pass unix:/var/run/php/php8.2-fpm-maketrandevu.sock;
|
2023-12-22 23:44:48 +03:00
|
|
|
|
|
|
|
|
|
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 $WEB_ROOT_FOLDER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PHP_FPM_CONFIG_FILE="""
|
2024-01-01 01:14:38 +03:00
|
|
|
|
[maketrandevu]
|
2023-12-22 23:44:48 +03:00
|
|
|
|
|
2024-01-01 01:14:38 +03:00
|
|
|
|
user = maketrandevu
|
|
|
|
|
group = maketrandevu
|
2023-12-22 23:44:48 +03:00
|
|
|
|
|
|
|
|
|
chdir = /usr/share/nginx/html
|
|
|
|
|
|
2024-01-01 01:14:38 +03:00
|
|
|
|
listen = /var/run/php/php8.2-fpm-maketrandevu.sock
|
2023-12-22 23:44:48 +03:00
|
|
|
|
listen.owner = nginx
|
|
|
|
|
listen.group = nginx
|
|
|
|
|
listen.mode = 0660
|
|
|
|
|
|
|
|
|
|
pm = ondemand
|
|
|
|
|
pm.max_children = 8
|
|
|
|
|
pm.max_requests = 500
|
|
|
|
|
request_terminate_timeout = 1d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pm.process_idle_timeout = 10s
|
|
|
|
|
|
|
|
|
|
; Additional php.ini defines, specific to this pool of workers.
|
|
|
|
|
|
|
|
|
|
php_admin_value[upload_max_filesize] = 50M
|
|
|
|
|
php_admin_value[post_max_size] = 50M
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
_exit() {
|
|
|
|
|
echo
|
|
|
|
|
echo
|
|
|
|
|
echo -e "${_RED}exiting...${_NC}"
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_status() {
|
|
|
|
|
set +x
|
|
|
|
|
echo
|
|
|
|
|
echo
|
|
|
|
|
echo "----------------------------------"
|
|
|
|
|
echo -e "${_RED}SYSTEM STATUS HEAD${_NC}"
|
|
|
|
|
echo "----------------------------------"
|
|
|
|
|
service nginx status
|
|
|
|
|
service mariadb status
|
|
|
|
|
service php8.2-fpm status
|
|
|
|
|
echo "----------------------------------"
|
|
|
|
|
echo -e "${_RED}SYSTEM STATUS HEAD${_NC}"
|
|
|
|
|
echo "----------------------------------"
|
|
|
|
|
echo
|
|
|
|
|
echo
|
|
|
|
|
set -x
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [[ $# -eq 0 ]]; then
|
2024-01-01 11:37:50 +03:00
|
|
|
|
if [[ $(pwd) != *MaketRandevu ]]; then
|
|
|
|
|
echo "PLEASE CHANGE DIRECTORY TO \`MaketRandevu/\` BEFORE STARTING SCRIPT"
|
2023-12-22 23:44:48 +03:00
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
# TODO silmeden önce onay iste!
|
|
|
|
|
|
|
|
|
|
echo -e "${_RED}CONTAINER WILL BE REMOVED !!!${_NC} (10)"
|
|
|
|
|
sleep 10
|
|
|
|
|
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
|
|
|
|
|
echo -e "RUN SCRIPT: \`${_RED}bash $MOUNT_PATH/$SCRIPT_NAME docker ini${_NC}\`"
|
|
|
|
|
docker attach $CONT_NAME --detach-keys="ctrl-k"
|
|
|
|
|
_exit
|
|
|
|
|
|
|
|
|
|
elif [[ $1 == "attach" ]]; then
|
|
|
|
|
if [ -n "$(docker ps -f "name=$CONT_NAME" -f "status=running" -q)" ]; then
|
|
|
|
|
echo "the container is already running!"
|
|
|
|
|
else
|
|
|
|
|
docker start $CONT_NAME
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
docker attach $CONT_NAME --detach-keys="ctrl-k"
|
|
|
|
|
|
|
|
|
|
elif [[ $1 == "docker" ]]; then
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
|
|
if [[ $2 == "ini" ]]; then
|
|
|
|
|
echo "alias dock=\"bash /source/$SCRIPT_NAME docker\"" >>/root/.bashrc
|
|
|
|
|
echo "alias root=\"cd $WEB_ROOT_FOLDER\"" >>/root/.bashrc
|
|
|
|
|
sleep 1
|
|
|
|
|
exec bash
|
|
|
|
|
|
|
|
|
|
elif [[ $2 == "debug" ]]; then
|
|
|
|
|
case "$3" in
|
|
|
|
|
["oO"]["nN"] | ["tT"]["rR"]["uU"]["eE"] | 1) sed -i "s/\(DEBUG_MODE * = *\).*/\1TRUE;/" "$WEB_ROOT_FOLDER/config.php" ;;
|
|
|
|
|
["oO"]["fF"]["fF"] | ["fF"]["aA"]["lL"]["sS"]["eE"] | 0) sed -i "s/\(DEBUG_MODE * = *\).*/\1FALSE;/" "$WEB_ROOT_FOLDER/config.php" ;;
|
|
|
|
|
*) echo -e "$_RED please input ON or OFF $_NC" ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
elif [[ $2 == "restart" ]]; then
|
|
|
|
|
service mariadb restart
|
|
|
|
|
sleep 3
|
|
|
|
|
service php8.2-fpm restart
|
|
|
|
|
sleep 3
|
|
|
|
|
service nginx restart
|
|
|
|
|
|
|
|
|
|
_status
|
|
|
|
|
|
|
|
|
|
elif [[ $2 == "reconf" ]]; then
|
|
|
|
|
|
|
|
|
|
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_FOLDER/config.php"
|
|
|
|
|
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
|
2024-01-01 01:14:38 +03:00
|
|
|
|
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/maketrandevu.conf"
|
2023-12-22 23:44:48 +03:00
|
|
|
|
echo RECONFIGURED
|
|
|
|
|
echo
|
|
|
|
|
_exit
|
2024-01-01 22:27:04 +03:00
|
|
|
|
elif [[ $2 == "complete-restart" ]]; then
|
|
|
|
|
echo "updating sources!"
|
|
|
|
|
rsync -a --progress /source/build/ $WEB_ROOT_FOLDER --exclude config.php --exclude storage
|
|
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
|
|
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_FOLDER/config.php"
|
|
|
|
|
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
|
|
|
|
|
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/maketrandevu.conf"
|
|
|
|
|
echo RECONFIGURED
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
service mariadb restart
|
|
|
|
|
sleep 3
|
|
|
|
|
service php8.2-fpm restart
|
|
|
|
|
sleep 3
|
|
|
|
|
service nginx restart
|
|
|
|
|
|
|
|
|
|
_status
|
|
|
|
|
|
|
|
|
|
|
2023-12-22 23:44:48 +03:00
|
|
|
|
elif [[ $2 == "update" ]]; then
|
|
|
|
|
echo "updating sources!"
|
|
|
|
|
rsync -a --progress /source/build/ $WEB_ROOT_FOLDER --exclude config.php --exclude storage
|
|
|
|
|
elif [[ $2 == "status" ]]; then
|
|
|
|
|
_status
|
|
|
|
|
|
|
|
|
|
elif [[ $2 == "install" ]]; then
|
|
|
|
|
if [[ $# -eq 2 || ! ($3 == "local" || $3 == "remote") ]]; then
|
|
|
|
|
echo -e "use $_RED dock install local $NC or $_RED dock install remote"
|
|
|
|
|
_exit
|
|
|
|
|
fi
|
|
|
|
|
sleep 1
|
|
|
|
|
apt update
|
|
|
|
|
apt install nano exa tree wget unzip less rsync -y
|
|
|
|
|
rm -rf $WEB_ROOT_FOLDER
|
|
|
|
|
mkdir -p $WEB_ROOT_FOLDER
|
2024-01-01 01:14:38 +03:00
|
|
|
|
cd $WEB_ROOT_FOLDER || exit
|
2023-12-22 23:44:48 +03:00
|
|
|
|
if [[ $3 == "local" ]]; then
|
|
|
|
|
cp -r /source/build/* $WEB_ROOT_FOLDER/
|
|
|
|
|
elif [[ $3 == "remote" ]]; then
|
|
|
|
|
wget "$DOWNLOAD_LINK"
|
|
|
|
|
sleep 3
|
|
|
|
|
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 php-mysql -y
|
|
|
|
|
service mariadb start
|
2024-01-01 01:14:38 +03:00
|
|
|
|
mysql -u root -e "create database maketrandevu"
|
2023-12-22 23:44:48 +03:00
|
|
|
|
mysql -u root -e "set password for root@localhost = password('root');"
|
|
|
|
|
echo -e "$CONFIG_FILE_CONTENT" >"$WEB_ROOT_FOLDER/config.php"
|
|
|
|
|
echo -e "$NGINX_CONFIG_FILE" >"/etc/nginx/conf.d/default.conf"
|
2024-01-01 01:14:38 +03:00
|
|
|
|
echo -e "$PHP_FPM_CONFIG_FILE" >"/etc/php/8.2/fpm/pool.d/maketrandevu.conf"
|
|
|
|
|
groupadd maketrandevu
|
|
|
|
|
useradd -g maketrandevu maketrandevu
|
|
|
|
|
cd $WEB_ROOT_FOLDER || exit
|
|
|
|
|
chown maketrandevu:nginx -R .
|
2023-12-22 23:44:48 +03:00
|
|
|
|
chmod 770 storage
|
|
|
|
|
|
|
|
|
|
service php8.2-fpm start
|
|
|
|
|
service nginx start
|
|
|
|
|
service nginx status
|
|
|
|
|
service nginx restart
|
|
|
|
|
echo -e "${_RED}DONE! - OPEN localhost:8000 TO TEST${_NC}"
|
|
|
|
|
elif [[ $2 == "help" ]]; then
|
|
|
|
|
echo -e "$HELP!"
|
|
|
|
|
else
|
|
|
|
|
echo -e "$_RED ! COMMAND NOT FOUND ! $_NC"
|
|
|
|
|
echo
|
|
|
|
|
echo -e "$HELP"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
echo -e "$_RED ! COMMAND NOT FOUND ! $_NC"
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# TODO Docker compose to run with /docker/build/docker.sh container together
|