diff --git a/config/backups.cfg b/config/backups.cfg index a719d60..7bd3a4b 100644 --- a/config/backups.cfg +++ b/config/backups.cfg @@ -1,3 +1,3 @@ # /sample/folder/ /data/appdata/gitea/ -/data/projects/ +/data/appdata/wordpress/wp-content/ diff --git a/config/cron.cfg b/config/cron.cfg index 83be812..4d1af51 100644 --- a/config/cron.cfg +++ b/config/cron.cfg @@ -1,2 +1 @@ -0 8 * * * ./data/backup/all.sh -# 0 9 * * * ./data/backup/remote-backup.sh \ No newline at end of file +0 8 * * * /data/server-origin/cron.sh diff --git a/cron.sh b/cron.sh new file mode 100644 index 0000000..e8d5e2a --- /dev/null +++ b/cron.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ "$(id -u)" != "0" ]; then + echo -e "\033[31mThis script requires superuser rights\033[0m" + exit 0 +fi + +trap 'echo -e "\033[31mcron.sh: Something went wrong\033[0m"; exit 1' ERR +set -e + +export DEBIAN_FRONTEND=noninteractive + +cd /data/backup +bash files-all.sh +bash postgres-all.sh +bash mariadb-all.sh + +trap - ERR +echo "All cron tasks completed successfully" \ No newline at end of file diff --git a/run-checkerwars.sh b/install-checkerwars.sh similarity index 100% rename from run-checkerwars.sh rename to install-checkerwars.sh diff --git a/install.sh b/install.sh index e5f024f..0ba752e 100644 --- a/install.sh +++ b/install.sh @@ -1,19 +1,10 @@ #!/bin/bash -#SECRETS_STORE=/data/secrets/secrets.env -GIT_SSH_DOMAIN=rozenlab.com -GIT_USER=leo -PGUSER=admin -PGDATABASE=postgres -LETSENCRYPT_EMAIL=426742@gmail.com -TRAEFIKLOGLEVEL=DEBUG # / INFO / ERROR -ADMINEMAIL=426742@gmail.com STARTDIR=server-origin -SSHPORT=2525 if [ "$(id -u)" != "0" ]; then - echo "This script requires superuser rights. Running with sudo..." - exec sudo "$0" "$@" + echo -e "\033[31mThis script requires superuser rights.\033[0m" + exit 0 fi if [ -z "$1" ]; then @@ -21,95 +12,106 @@ if [ -z "$1" ]; then exit 1 fi -#if [ -f $SECRETS_STORE ]; then -# source $SECRETS_STORE -#fi - -trap 'echo -e "\033[31minstall.sh: Something went wrong\033[0m"; exit 1' EXIT +trap 'echo -e "\033[31minstall.sh: Something went wrong\033[0m"; exit 1' ERR set -e export DEBIAN_FRONTEND=noninteractive DOMAIN=$1 -#$SERVER_TYPE=dev +SECRETS_PATH=/data/secrets/$DOMAIN/$DOMAIN.env +source $SECRETS_PATH -#mkdir -p /data -#chown usradmin:usradmin /data -#chmod 770 /data - -#cd /data -#git clone git@$GIT_SSH_DOMAIN:$GIT_USER/utils.git cd /data/utils -#bash init-server.sh - echo "Install docker..." bash init-docker.sh echo "Creating docker network proxynet..." docker network create proxynet -# SSH config: -#bash ssh-port.sh $SSHPORT -#ssh-keygen -t ed25519 -C "$ADMINEMAIL" - -#echo "Init cron list..." -#bash cron-list.sh - -# create global environment vars: +echo "create global environment vars..." bash global-env.sh SERVER_DOMAIN $DOMAIN -bash global-env.sh POSTGRES_USER $PGUSER -bash global-env.sh POSTGRES_DB $PGDATABASE -bash global-env.sh TRAEFIK_LOG_LEVEL $TRAEFIKLOGLEVEL bash global-env.sh ADMIN_EMAIL $ADMINEMAIL bash global-env.sh SRV_START_DIR $STARTDIR echo "Init cron list..." -bash cron-list.sh - -#bash global-env.sh SERVER_TYPE $SERVER_TYPE +sudo bash cron-list.sh +echo "Clone backup.git..." cd /data git clone git@$GIT_SSH_DOMAIN:$GIT_USER/backup.git - +echo "Install traefik..." cd /data/utils -#bash env-gen.sh LE_EMAIL "$LETSENCRYPT_EMAIL" - +bash global-env.sh TRAEFIK_LOG_LEVEL $TRAEFIKLOGLEVEL +cd /data git clone git@$GIT_SSH_DOMAIN:$GIT_USER/traefik.git cd traefik sudo docker compose up -d - +echo "Install postgres..." cd /data/utils +bash global-env.sh POSTGRES_USER admin +bash global-env.sh POSTGRES_DB postgres bash env-gen.sh POSTGRES_PASSWORD - cd /data git clone git@$GIT_SSH_DOMAIN:$GIT_USER/postgres.git cd postgres sudo docker compose up -d -# pgadmin install: +echo "Install pgadmin..." mkdir -p /data/appdata/pgadmin chown -R 5050:5050 /data/appdata/pgadmin +cd /data/utils +bash env-gen.sh PGADMIN_DEFAULT_PASSWORD cd /data git clone git@$GIT_SSH_DOMAIN:$GIT_USER/pgadmin.git cd pgadmin sudo docker compose up -d -ln -s /data/blog-frontend/main /data/www -cd /data -git clone git@$GIT_SSH_DOMAIN:$GIT_USER/nginx-main.git -cd nginx-main -sudo docker compose up -d - -cd /data -git clone git@$GIT_SSH_DOMAIN:$GIT_USER/gitea.git -cd gitea +echo "Install gitea..." cd /data/utils bash env-gen.sh GITEA__database__PASSWD bash init-db.sh gitea $GITEA__database__PASSWD +cd /data +git clone git@$GIT_SSH_DOMAIN:$GIT_USER/gitea.git +cd gitea sudo docker compose up -d +echo "Install mariadb..." +cd /data/utils +bash global-env.sh MARIADB_USER admin +bash global-env.sh MARIADB_DB mariadb +bash env-gen.sh MARIADB_ROOT_PASSWORD +MARIADBPASSWORD=$(pwgen -s 20 1); +bash env-gen.sh MARIADB_PASSWORD $MARIADBPASSWORD +bash env-gen.sh WORDPRESS_DB_PASSWORD $MARIADBPASSWORD +bash env-gen.sh WP_ADMIN_PASSWORD +cd /data +git clone git@$GIT_SSH_DOMAIN:$GIT_USER/mariadb.git +cd mariadb +sudo docker compose up -d -trap - EXIT +echo "Install blog-wp..." +cd /data +git clone git@$GIT_SSH_DOMAIN:$GIT_USER/blog-wp.git +cd blog-wp +sudo docker compose up -d + +echo "Await 10s before blog-wp-install..." +sleep 10 + +echo "Install blog-wp-install..." +cd /data +git clone git@$GIT_SSH_DOMAIN:$GIT_USER/blog-wp-install.git +cd blog-wp-install +sudo docker bash install.sh + +echo "Install tetris..." +cd /data +git clone git@$GIT_SSH_DOMAIN:$GIT_USER/tetris.git +cd tetris +sudo docker compose build +sudo docker compose up -d + +trap - ERR echo "Install server-origin complete" \ No newline at end of file diff --git a/push-all.sh b/push-all.sh new file mode 100644 index 0000000..7c31f6f --- /dev/null +++ b/push-all.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +echo "Auto push all dependences..." + +echo "push install..." +cd /data/install +git add -A +git commit -m autocommit +git push install main + +echo "push server-origin..." +cd /data/server-origin +git add -A +git commit -m autocommit +git push server-origin main + +echo "push utils..." +cd /data/utils +git add -A +git commit -m autocommit +git push utils main + +echo "push backup..." +cd /data/backup +git add -A +git commit -m autocommit +git push backup main + +echo "push traefik..." +cd /data/traefik +git add -A +git commit -m autocommit +git push traefik main + + +echo "push postgres..." +cd /data/postgres +git add -A +git commit -m autocommit +git push postgres main + +echo "push pgadmin..." +cd /data/pgadmin +git add -A +git commit -m autocommit +git push pgadmin main + +echo "push gitea..." +cd /data/gitea +git add -A +git commit -m autocommit +git push gitea main + +echo "push gitea-init..." +cd /data/gitea-init +git add -A +git commit -m autocommit +git push gitea-init main + + +echo "push mariadb..." +cd /data/mariadb +git add -A +git commit -m autocommit +git push mariadb main + +echo "push blog-wp..." +cd /data/blog-wp +git add -A +git commit -m autocommit +git push blog-wp main + +echo "push blog-wp-install..." +cd /data/blog-wp-install +git add -A +git commit -m autocommit +git push blog-wp-install main + + +echo "push tetris..." +cd /data/tetris +git add -A +git commit -m autocommit +git push tetris main \ No newline at end of file