Script clean up, automation improvements, documentation

This commit is contained in:
Marwolf
2018-08-13 12:23:55 -04:00
parent b74975670d
commit 7b6fe9c460
7 changed files with 188 additions and 109 deletions

14
.env Normal file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Ghost
URL=http://localhost
# Nginx
NGINX_HOST=localhost
# MySQL
MYSQL_DATABASE=test
MYSQL_ROOT_USER=root
MYSQL_ROOT_PASSWORD=root
MYSQL_USER=dev
MYSQL_PASSWORD=dev

2
.gitignore vendored
View File

@@ -12,7 +12,7 @@ Game
Wiki
# Database
data
data/
# SSL Certs
etc/ssl/

View File

@@ -1,26 +0,0 @@
#!/bin/bash
# Pull
echo "Pulling updates from repositories."
sudo git pull
cd Game
sudo git pull
cd ..
cd Website
sudo git pull
cd ..
echo ""
echo ""
# Manual edits
echo "Manual java file edits are next. Press enter to begin."
read next
sudo nano Game/client/src/org/openrsc/client/Config.java
sudo nano Game/Launcher/src/Main.java
sudo nano Run_Production_Linux_Game_Server.sh
sudo nano Game/server/config/config.xml
echo ""
echo ""
echo "Ready to execute Run_Production_Linux_Game_Server.sh"
echo ""
echo ""

View File

@@ -1,3 +1,5 @@
include .env
MYSQL_DUMPS_DIR=./data/db
start:
@@ -55,40 +57,40 @@ logs:
backup:
@sudo mkdir -p $(MYSQL_DUMPS_DIR)
@$(shell sudo chmod -R 777 $(MYSQL_DUMPS_DIR))
@docker exec $(shell docker-compose ps -q mysqldb) mysqldump --all-databases -u"root" -p"root" > $(MYSQL_DUMPS_DIR)/db.sql 2>/dev/null
@docker exec $(shell docker-compose ps -q mysqldb) mysqldump --all-databases -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" > $(MYSQL_DUMPS_DIR)/db.sql 2>/dev/null
backup-windows:
@docker exec -i mysql mysqldump --all-databases -u"root" -p"root" > $(MYSQL_DUMPS_DIR)/db.sql
@docker exec -i mysql mysqldump --all-databases -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" > $(MYSQL_DUMPS_DIR)/db.sql
restore:
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < $(MYSQL_DUMPS_DIR)/db.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < $(MYSQL_DUMPS_DIR)/db.sql 2>/dev/null
restore-windows:
@docker exec -i mysql mysql -u"root" -p"root" < $(MYSQL_DUMPS_DIR)/db.sql
@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < $(MYSQL_DUMPS_DIR)/db.sql
import-game:
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < Game/Databases/openrsc_config.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < Game/Databases/openrsc_logs.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < Game/Databases/openrsc.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < Game/Databases/openrsc_tools.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc_config.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc_logs.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc_tools.sql 2>/dev/null
import-website:
#@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < Website/openrsc_forum.sql 2>/dev/null
#@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Website/openrsc_forum.sql 2>/dev/null
import-wiki:
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"root" -p"root" < Website/Wiki/openrsc_wiki.sql 2>/dev/null
@docker exec -i $(shell docker-compose ps -q mysqldb) mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Website/Wiki/openrsc_wiki.sql 2>/dev/null
import-windows-game:
@docker exec -i mysql mysql -u"root" -p"root" < Game/Databases/openrsc_logs.sql
@docker exec -i mysql mysql -u"root" -p"root" < Game/Databases/openrsc_config.sql
@docker exec -i mysql mysql -u"root" -p"root" < Game/Databases/openrsc.sql
@docker exec -i mysql mysql -u"root" -p"root" < Game/Databases/openrsc_tools.sql
@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc_logs.sql
@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc_config.sql
@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc.sql
@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Game/Databases/openrsc_tools.sql
import-windows-website:
#@docker exec -i mysql mysql -u"root" -p"root" < Website/openrsc_forum.sql
#@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Website/openrsc_forum.sql
import-windows-wiki:
@docker exec -i mysql mysql -u"root" -p"root" < Website/Wiki/openrsc_wiki.sql
@docker exec -i mysql mysql -u"$(MYSQL_ROOT_USER)" -p"$(MYSQL_ROOT_PASSWORD)" < Website/Wiki/openrsc_wiki.sql
flush:
@$(shell rm -rf Website && rm -rf Game)

View File

@@ -46,7 +46,7 @@ ___
* Mac OS X High Sierra
* Ubuntu Linux 18.04 (or a derivative like Mint Linux)
* Ubuntu Linux 16.04 and above (or a derivative like Mint Linux)
* Fedora Linux 28
@@ -95,8 +95,8 @@ ___
2. Open your favorite browser:
* [http://localhost](http://localhost) (username: Marwolf, password: malware)
* [http://localhost:9000](http://localhost:9000) PHPMyAdmin (username: root, password: root)
* [http://localhost](http://localhost)
* [http://localhost:9000](http://localhost:9000) PHPMyAdmin (default username: root, password: root)
* [http://localhost:8080](http://localhost:8080) Apache Tomcat webserver, used to serve files over HTTP
3. Start the game's Docker containers, then run the game server and client:
@@ -128,17 +128,8 @@ ___
```sh
Windows: "Restore_Game_Database_Backup_Windows.cmd"
```
6. View the game's Docker container logs:
```sh
./View_Docker_Container_Logs_Linux_Mac.sh
```
```sh
Windows: "View_Docker_Container_Logs_Windows.cmd"
```
7. Stop the game's Docker containers and shut down the game server:
6. Stop the game's Docker containers and shut down the game server:
```sh
Mac/Linux: ./Stop-Game-Linux_Mac.sh
@@ -153,38 +144,35 @@ ___
## Steps to Host on a VPS <a name="vps"></a>
You will need to edit:
* Execute "Setup_Linux_Mac.sh"
#### Docker-Compose.xml Ghost URL
* Follow the steps to install needed programs
* The main website is running through Ghost Blog. Scroll to the bottom of Docker-Compose.xml (located in the root of the Docker-Home repository folder) and edit this line with your hostname / IP: "url: 'http://localhost' #change this!"
* You will need to reload all docker containers. Shortcut command: "sudo make stop && sudo make start"
* Nginx has a hostname reference for localhost at the top of the file. It can be safely left alone.
* Select "2. Deployment for a publicly hosted server"
* You will be prompted to edit specific files. Below is how to do each:
#### PHPMyAdmin MariaDB SQL users
* Create a new user in PHPMyAdmin, grant permissions, remove existing users.
* Create a new user in PHPMyAdmin, grant it all permissions, remove pre-existing users.
* Use % for the host associated with the user. Docker containers get fresh IPs, the setup script configures firewall to block external access to MariaDB and the Docker container for MariaDB is bound to localhost.
* Use % for the host associated with the new user. Docker containers do not have static IP addresses and we are using the PHPMyAdmin Docker container to connect to the MariaDB Docker container. Each has a unique internally assigned IP address that is not localhost. The Docker container port of tcp/3306 for MariaDB is bound to the server as localhost so there should be no threat of external connections.
#### Launcher main.java
#### .env
* Edit: "/Docker-Home/Game/Launcher/src/Main.java"
* This is located in "Docker-Home/.env"
* Replace with your domain / IP: "private static String Domain = "localhost";"
* The main website is running through Ghost CMS. For the section starting with # Ghost:
* Compile and copy result from "/Docker-Home/Game/Launcher/dist/Open_RSC_Launcher.jar" to "/Docker-Home/Website/downloads/Open_RSC_Launcher.jar"
* Edit: "URL=http://localhost"
#### Client config.java
* You will need to reload all docker containers. Shortcut command: "sudo make stop && sudo make start"
* Edit: "/Docker-Home/Game/client/src/org/openrsc/client/Config.java"
* Nginx has a hostname reference for localhost as "NGINX_HOST=localhost" under the # Nginx section. It can be safely left alone at this time.
* Replace with your domain / IP: public static String IP = "localhost";
* For the section starting with # MySQL:
* Compile and compress "/Docker-Home/Game/Launcher/dist/Open_RSC_Launcher.jar" as "/Docker-Home/Game/Launcher/dist/client.zip" then copy "/Docker-Home/Game/Launcher/dist/client.zip" to "/Docker-Home/Website/downloads/client.zip"
* Set the username and password that have been granted root privileges in MariaDB SQL that you just created in the previous step with PHPMyAdmin where it reads "MYSQL_ROOT_USER=root" and "MYSQL_ROOT_PASSWORD=root"
#### Server config.xml
@@ -194,22 +182,30 @@ You will need to edit:
* Replace with your newly created SQL user pass: <entry key="dbpass">root</entry>
#### Website downloads/hashes.txt
* Edit: /Docker-Home/Website/downloads/hashes.txt
* Replace with updated md5sum hashes of client.zip and cache.zip (likely you only will replace client.zip's hash)
* Obtain MD5sum via command: "md5sum *.zip"
### Website config import:
* Visit http://localhost/ghost
* Login with admin@openrsc.com / malwareinfection
* If it wants to set up a first user, go for it.
* Click on "Labs"
* If it already has Open RSC news articles, login with admin@openrsc.com / malwareinfection
* Click "Browse" beside "Import content" and select ""/Docker-Home/website_backup.json"
* Either way, click on "Labs" once logged in
* Click "Browse" beside "Import content" and select ""/Docker-Home/website_backup.json"
#### Run_Production_Linux_Game_Server.sh
* Compiles client, launcher, and server.
* Copies "Docker-Home/Game/client/cache.zip" to "Docker-Home/Website/downloads/cache.zip"
* Copies "Docker-Home/Game/Launcher/Open_RSC_Launcher.jar" to "Docker-Home/Website/downloads/Open_RSC_Launcher.jar"
* Compresses then copies "Docker-Home/Game/client/client.zip" to "Docker-Home/Website/downloads/client.zip"
* Md5sums client.zip and cache.zip in "Docker-Home/Website/" and outputs to hashes.txt
* Starts the game server in a detached screen console. Access via "screen -r", return via "Ctrl + A + D", exit via "Ctrl + C"
[Return to top](#top)

View File

@@ -15,6 +15,9 @@ Choices:
${RED}1${NC} - Install for me!
${RED}2${NC} - Im all set, continue! (default)"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read install
# OS Selection ===================================================>
@@ -28,6 +31,9 @@ if [ "$install" == "1" ]; then
echo "${RED}4${NC} - Mac OS High Sierra"
echo "${RED}5${NC} - Other"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read os
# Ubuntu OS ===================================================>
@@ -75,6 +81,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - No, install it for me!"
echo "${RED}2${NC} - Yes"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read docker
# Ubuntu Docker ===================================================>
@@ -113,6 +122,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - Install for me!"
echo "${RED}2${NC} - Im all set"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read java
# Ubuntu Java ===================================================>
@@ -152,6 +164,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - Install for me!"
echo "${RED}2${NC} - Im all set"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read java
# Fedora Java ===================================================>
@@ -179,6 +194,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - No, install it for me!"
echo "${RED}2${NC} - Yes"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read docker
# Fedora Docker ===================================================>
@@ -246,6 +264,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - Install for me!"
echo "${RED}2${NC} - Im all set"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read java
# CentOS 7 Java ===================================================>
@@ -273,6 +294,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - No, install it for me!"
echo "${RED}2${NC} - Yes"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read docker
# CentOS 7 Docker ===================================================>
@@ -312,6 +336,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - No, install it for me!"
echo "${RED}2${NC} - Yes"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read brew
# Mac Brew ===================================================>
@@ -333,6 +360,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - Install for me!"
echo "${RED}2${NC} - Im all set"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read java
# Mac Java ===================================================>
@@ -349,6 +379,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - No, install it for me!"
echo "${RED}2${NC} - Yes"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read docker
# Mac Docker ===================================================>
@@ -387,6 +420,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - No, install it for me!"
echo "${RED}2${NC} - Yes"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read docker
# Other OS Docker ===================================================>
@@ -407,6 +443,9 @@ if [ "$install" == "1" ]; then
echo "${RED}1${NC} - Install for me!"
echo "${RED}2${NC} - Im all set"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read java
# Other OS Java ===================================================>
@@ -435,21 +474,24 @@ echo ""
sudo git pull
echo ""
echo ""
echo ""
clear
echo "${RED}Open RSC Installer:${NC}
An easy to run RSC private server using Docker magic.
Choices:
${RED}1${NC} - Set up for single player
${RED}2${NC} - Deployment for a publicly hosted server"
echo "
Which of the above do you want? Type 1, 2, or 3, and press enter."
${RED}2${NC} - Deployment for a publicly hosted server
${RED}3${NC} - Backup all SQL databases
${RED}4${NC} - Restore all SQL databases
"
echo ""
echo "Which of the above do you wish to do? Type the choice number and press enter."
echo ""
echo ""
read choice
# Selection ===================================================>
# 1. Single player RSC game ===================================================>
# 1. Set up for single player ===================================================>
if [ "$choice" == "1" ]; then
clear
echo "You have picked ${GREEN}Set up for single player!${NC}"
@@ -482,12 +524,12 @@ if [ "$choice" == "1" ]; then
echo "Open RSC setup complete!"
echo ""
exit
# 1. Single player RSC game <===================================================
# 1. Set up for single player <===================================================
# 2. Game + Website + PHPMyAdmin ===================================================>
# 2. Deployment for a publicly hosted server ===================================================>
elif [ "$choice" == "2" ]; then
clear
echo "You have picked ${GREEN}Deployment for a publicly hosted server!${NC}"
echo "You have picked ${GREEN}deployment for a publicly hosted server!${NC}"
echo ""
echo ""
echo "Starting up the Docker containers and stopping any existing ones."
@@ -515,10 +557,63 @@ elif [ "$choice" == "2" ]; then
sudo make import-game
echo ""
echo ""
echo "Open RSC setup complete!"
echo "Creating a backup of your current databases as \"Docker-Home/data/db/db.sql\""
echo ""
exit
# 2. Game + Website + PHPMyAdmin <===================================================
sudo make backup
echo ""
echo ""
echo "Next is manual file editing for the website domain and SQL user/pass."
echo ""
echo "(Use Ctrl + X to save each file when done editing) - Press enter when ready."
read next
sudo nano .env
sudo nano Game/client/src/org/openrsc/client/Config.java
sudo nano Game/Launcher/src/Main.java
sudo nano Run_Production_Linux_Game_Server.sh
sudo nano Game/server/config/config.xml
echo ""
echo ""
echo "File edits complete. Restarting Docker containers."
echo ""
sudo make stop && sudo make start
echo ""
echo ""
echo "Ready to launch \"Run_Production_Linux_Game_Server.sh\" - Press enter when ready."
echo ""
echo ""
read next
./Run_Production_Linux_Game_Server.sh
# 2. Deployment for a publicly hosted server <===================================================
# 3. Backup ===================================================>
elif [ "$choice" == "3" ]; then
echo "You have picked ${GREEN}backup all SQL databases!${NC}"
echo ""
echo ""
sudo make backup
echo ""
echo ""
echo "Done! - Press enter to return back to the menu."
echo ""
read
./Setup_Linux_Mac.sh
# 3. Backup <===================================================
# 4. Restore ===================================================>
elif [ "$choice" == "4" ]; then
echo "You have picked ${GREEN}restore all SQL databases!${NC}"
echo ""
echo ""
sudo make restore
echo ""
echo ""
echo "Done! - Press enter to return back to the menu."
echo ""
read
./Setup_Linux_Mac.sh
# 4. Restore <===================================================
else
echo ""

View File

@@ -16,7 +16,7 @@ services:
- "80:80"
- "443:443"
environment:
- NGINX_HOST=localhost
- NGINX_HOST=${NGINX_HOST}
command: /bin/sh -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
restart: always
depends_on:
@@ -55,11 +55,14 @@ services:
image: mariadb:10.3.8
container_name: mysql
restart: always
env_file:
- ".env"
environment:
- MYSQL_DATABASE=test
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=dev
- MYSQL_PASSWORD=dev
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_ROOT_USER=${MYSQL_ROOT_USER}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- "127.0.0.1:3306:3306"
volumes:
@@ -102,17 +105,12 @@ services:
- "./etc/ghost:/var/lib/ghost/content"
depends_on:
- nginx
env_file:
- ".env"
environment:
NODE_ENV: production
privacy__useUpdateCheck: 0
url: 'http://localhost' #change this!
#mail__from: OpenRSC Emailer <openrsc.emailer@gmail.com>
#mail__transport: SMTP
#mail__transport__options__host: smtp.gmail.com
#mail__transport__options__secureConnection: 1
#mail__transport__options__port: 465
#mail__transport__options__auth_user: openrsc.emailer@gmail.com
#mail__transport__options__auth_pass: OFF
url: ${URL}
# logging:
# driver: splunk
# options: