commit 6899dcb66ddc3a8c88509c518901960bbc6492ab Author: dede Date: Tue Jan 17 23:37:24 2023 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24f9f8d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +data/ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4d06e97 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +--- +# source: https://nginxproxymanager.com/setup/#using-mysql-mariadb-database +version: "3" +services: + app: + image: 'jc21/nginx-proxy-manager:latest' + restart: unless-stopped + ports: + # These ports are in format : + - '80:80' # Public HTTP Port + - '443:443' # Public HTTPS Port + - '81:81' # Admin Web Port + # Add any other Stream port you want to expose + # - '21:21' # FTP + environment: + DB_MYSQL_HOST: "db" + DB_MYSQL_PORT: 3306 + DB_MYSQL_USER: ${DB_USER} + DB_MYSQL_PASSWORD: ${DB_PASSWD} + DB_MYSQL_NAME: "npm" + # Uncomment this if IPv6 is not enabled on your host + # DISABLE_IPV6: 'true' + volumes: + - ./${DATA_DIR}/data:/data + - ./${DATA_DIR}/letsencrypt:/etc/letsencrypt + depends_on: + - db + + db: + image: 'jc21/mariadb-aria:latest' + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWD} + MYSQL_DATABASE: 'npm' + MYSQL_USER: ${DB_USER} + MYSQL_PASSWORD: ${DB_PASSWD} + volumes: + - ./${DATA_DIR}/data/mysql:/var/lib/mysql diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..5b11a06 --- /dev/null +++ b/env.sample @@ -0,0 +1,7 @@ +# general +DATA_DIR=./data/ + +# database +DB_ROOT_PASSWD= +DB_PASSWD= +DB_USER=npm_user diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..141cd5d --- /dev/null +++ b/setup.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# env setup script for nginx-proxy-manager docker compose +# 2023-01-06 by dede & dany + +dir_name=$(basename "$(dirname "$0")") + +echo "$dir_name docker compose setup" +echo "> env setup for $dir_name with docker compose" + +# check for existing .env file to not break an existing setup +if [[ -f .env ]]; then + if [[ "$1" == "-f" ]]; then + echo "-f" + else + echo ".env file already exists. setup will not run."\ + "either rename/delete it first or run this script with force param like this: " + echo "$ ./${0##*/} -f" + exit 1 + fi +elif [[ ! -f env.sample ]]; then + echo "> env.sample file is missing. cannot run." + exit 2 +fi + +# create .env file +echo -e "# file generated by ${0##*/} on $(date +"%F %H:%M") by $USER\n" > .env + +# step through the list of lines and ask for each key to use default value or set value +# for each line in configfile +while read -r -u 3 line; do + + # keep blank and comment lines + if [[ -z $line ]] || [[ $line == \#* ]]; then + echo "$line" >> .env + + # handle variable lines + else + # split line by '=' into key and value + readarray -d "=" -t currvar<<< "$line" + + # preset value with default + value=${currvar[1]::-1} + + # check if there's a password to generate + if [[ ${currvar[0]} =~ (PASS|PASSWORD|PWD|PASSWD)$ ]]; then + value=$(openssl rand -base64 29 | tr -d "=+/" | cut -c1-25) + fi + + # ask for user input + echo -n "please enter value for ${currvar[0]} [$value]: " + read -r userinput + + # set userinput as new value if any + if [ -n "$userinput" ]; then + value=$userinput + fi + + # check if there's a directory to create + if [[ ${currvar[0]} =~ (DIR|DIRECTORY)$ ]]; then + if [[ ! -d $value ]]; then + echo -n "do you want to create the directory? [Y/n]: " + read -r createdir + if [[ $createdir =~ ^([yY]|)$ ]]; then + mkdir -p "$value" + echo "directory created." + fi + else + echo "directory already exists." + if [ -n "$(ls -A "$value")" ]; then + echo "WATCH OUT! the directory is NOT empty. please ensure this is intended." + fi + fi + fi + + # now append the line + echo "${currvar[0]}=$value" >> .env + + fi +done 3< env.sample