sharex-php-uploader/docker/start.sh

59 lines
1.8 KiB
Bash
Raw Normal View History

2023-07-07 23:16:13 +00:00
#!/bin/sh
2023-07-07 23:34:15 +00:00
# TODO: add all the other fallback values for the other variables
2023-07-07 23:16:13 +00:00
if [ -z "$MAX_UPLOAD_SIZE" ]; then
2023-07-04 16:23:14 +00:00
MAX_UPLOAD_SIZE="8M" # Default fallback value
2023-07-07 23:34:15 +00:00
echo "MAX_UPLOAD_SIZE was not set, using default value of ${MAX_UPLOAD_SIZE}"
2023-07-04 16:23:14 +00:00
fi
2023-07-04 15:51:11 +00:00
echo "Checking if upload script exists in /var/www/html"
if [ -f "/var/www/html/upload.php" ]; then
2023-07-07 23:16:13 +00:00
echo "Upload script was found, ignoring copy."
2023-07-04 15:46:10 +00:00
else
2023-07-07 23:16:13 +00:00
cp /tmp/upload.php /var/www/html
echo "Upload script was not found, copying it."
2023-07-04 15:46:10 +00:00
fi
2024-02-25 17:37:58 +00:00
echo "Checking if default index.html exists in /var/www/html"
if [ -f "/var/www/html/index.html" ]; then
echo "Upload script was found, ignoring copy."
else
cp /tmp/index.html /var/www/html
echo "Default index.html was not found, copying it."
fi
2023-07-05 00:49:59 +00:00
# Letting php know that we are running in docker
2023-07-07 23:16:13 +00:00
echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf
echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf
2023-07-05 23:23:22 +00:00
2023-07-07 23:32:46 +00:00
# Create the directory for PHP socket
mkdir -p /run/php
2023-07-07 23:24:42 +00:00
# Set php-fpm to listen on socket
2023-07-07 23:30:33 +00:00
touch /run/php/php.sock
2023-07-07 23:28:33 +00:00
sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf
2023-07-07 23:24:42 +00:00
2023-07-04 16:32:14 +00:00
echo "Setting permissions for upload script"
chmod 777 /var/www/html/upload.php
2023-07-04 16:22:22 +00:00
echo "Setting max upload size to ${MAX_UPLOAD_SIZE}"
2023-07-04 16:42:02 +00:00
# Set max upload size for php
2023-07-07 23:16:13 +00:00
sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
2023-07-04 16:22:22 +00:00
2023-07-04 16:42:02 +00:00
# Set max upload size for nginx
sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf
2023-07-07 22:43:14 +00:00
function start() {
echo "Starting PHP & Nginx"
2023-07-07 23:19:15 +00:00
php-fpm81 &&
2023-07-07 23:35:47 +00:00
chmod 777 /run/php/php.sock &&
2023-10-13 18:44:24 +00:00
/usr/local/sbin/nginx -g 'daemon off;'
2023-07-07 22:43:14 +00:00
}
# Start Nginx and retry if it fails
until start; do
echo "Nginx failed to start, retrying in 5 seconds..."
sleep 5
done