From 1620931318e0c19dfbe72e1e95580e99698db24d Mon Sep 17 00:00:00 2001 From: notepadguyOfficial Date: Tue, 11 Feb 2025 16:06:15 +0800 Subject: [PATCH] Add initial setup for Azerothcore with Docker and environment configuration --- .gitignore | 4 + README.md | 156 ++++++++++++++++++++++- setup-docker-wsl.sh | 28 +++++ setup.sh | 159 ++++++++++++++++++++++++ sqldump.sh | 29 +++++ src/.env | 25 ++++ src/docker-compose.override.yml | 10 ++ src/sql/acore_auth/update_realmlist.sql | 3 + start_stop_acore.sh | 23 ++++ uninstall.sh | 26 ++++ 10 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 setup-docker-wsl.sh create mode 100644 setup.sh create mode 100644 sqldump.sh create mode 100644 src/.env create mode 100644 src/docker-compose.override.yml create mode 100644 src/sql/acore_auth/update_realmlist.sql create mode 100644 start_stop_acore.sh create mode 100644 uninstall.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f88dbee --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +azerothcore-wotlk +wotlk/* +sql_dumps/*/*.sql +sql_dumps/*/*.*filepart \ No newline at end of file diff --git a/README.md b/README.md index 07ffe3b..b9c339f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,154 @@ -# WSL-Debian-Docker-Azerothcore-Playerbots-Installation -A Compilation Guide of Installing Azerothcore on WSL (Debian) with Docker Containers +# WSL Debian Docker Azerothcore-Playerbots Installation + +## Table of Contents + +- [Requirements](#requirements) +- [Git Cloning](#gitcloning) +- [WSL Installation](#wslinstallation) +- [Docker Installation](#dockerinstallation) +- [Azerothcore-Playerbots Introduction](#azerothcore-playerbots) +- [AzerothCore Bot Installation](#azerothcorebotinstallation) + +## Requirements + - wsl2 + +## Git Cloning +1. Clone Repository: + ```cmd + git clone https://github.com/notepadguyOfficial/Debian-Docker-Azerothcore-Playerbot.git + ``` + +## WSL Installation +1. Open cmd/Powershell and run this command: + ```cmd + wsl --insall -d Debian + ``` + +2. Once Installed, Export the a backup to the desired location: + ```cmd + wsl --export Debian C:\Example + ``` + or + ```cmd + wsl --export Debian D:\Example + ``` + +3. Unregister the Original Debian Image from WSL: + ```cmd + wsl --unregister Debian + ``` + +4. Import it back into your chosen location: + ```cmd + wsl --import Debian C:\Debian C:\Example\Debian.tar --version 2 + ``` + or + ```cmd + wsl --import Debian D:\Debian D:\Example\Debian.tar --version 2 + ``` + + - (Optional) Delete the .tar file to free space: + ```cmd + Remove-Item D:\Example\Debian.tar + ``` +5. Launch Debian: + ```cmd + wsl -d Debian + ``` + +## Docker Installation +1. see [Git Cloning](#gitcloning) + +2. Run WSL via cmd/Powershell: + ```cmd + wsl -d Debian + ``` + +3. Navigate to repository: + ```cmd + cd /mnt/c/to-your-clones-repository-directory + ``` + or if you cloned the repository in another drive: + ```cmd + cd /mnt/d/to-your-clones-repository-directory + ``` + +4. run the sh file: + ```cmd + ./setup-docker-wsl.sh + ``` + + - (!Note) If you run the script but with error, This usually means Windows-style line endings instead of the Unix-style. + To fix this run this command + ```cmd + sudo apt install dos2unix + + #then + + dos2unix *.sh + + #final command + + chmod +x *.sh + ``` + +5. wait until done then restart wsl: + ```cmd + wsl --shutdown + ``` + then start the wsl service again + ``` + wsl -d Debian + ``` + +## Azerothcore-Playerbot +Includes: + - MariaDB-Client (This is only client and will install only if you dont have the mysql command...) + - Docker (Will install if Docker is not installed.) + - Azeroth Core - Playerbots branch + - mod-playerbots + - mod-aoe-loot (optional) + - mod-learn-spells (optional) + - mod-fireworks-on-level (optional) + - mod-individual-progression (optional) + +### Update + - To update and get the latest versions, you can run `./uninstall.sh` without deleting the volumes and run `./setup.sh` again. It will prompt you if you want to delete the volumes. + + - You can add modules to the `setup.sh` file by scrolling to the "install_mod" section and add the entries you'd like. Or you could do it manually by putting the modules folders into the `azerothcore-wotlk/modules` folder. `setup.sh` will automatically add the sql. See + + - Running `setup.sh` will not install anything over again unless you delete a modules folder or the `azerothcore-wotlk` folder before. You can run it if you only want to install new modules youve added, it will skip if you already downloaded the repos. + +- If you delete modules, remember to run `clear_custom_sql.sh` first and remove the respective tables in the db. + +## AzerothCore Bot Installation +1. Run Setup sh Script: + ```cmd + ./setup.sh + ``` + +2. choose if you want to install modules besides the given one. + - (Optional) You can edit `setup.sh` to add another modules + +3. Wait for docker to install the images. + +4. If no error then attach to ac-worldserver by running this command: + ```cmd + docker attach ac-worldserver + ``` + (!Note) You can dettach from attached service by pressing `ctrl+p` and `ctrl+q`. + +5. Create Azerothcore Account + ```cmd + account create + ``` + +6. Find WSL IP Address + ```cmd + ip addr show eth0 + ``` + (!Important) when connecting to database or game use the wsl ip address. + +7. Edit your `\Data\enUS\realmlist.wtf` and type in the ip address you get in the end of installing..." set realmlist dockerhost_ip 192.168.48.2 " + +8. Run the Game and your done. \ No newline at end of file diff --git a/setup-docker-wsl.sh b/setup-docker-wsl.sh new file mode 100644 index 0000000..2dfb04d --- /dev/null +++ b/setup-docker-wsl.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +sudo apt-get update +sudo apt-get dist-upgrade +sudo apt-get install ca-certificates curl wget gnupg lsb-release apt-transport-https + +wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O /tmp/packages-microsoft-prod.deb +sudo dpkg -i /tmp/packages-microsoft-prod.deb +rm /tmp/packages-microsoft-prod.deb + +sudo wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg +sudo chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg +echo -e "deb https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main +deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/wsl-transdebian.list > /dev/null + +sudo apt-get update +sudo apt-get install systemd-genie + +curl https://get.docker.com | sh + +sudo usermod -aG docker $USER + +sudo curl -L "https://github.com/docker/compose/releases/download/2.32.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +sudo chmod +x /usr/local/bin/docker-compose + +echo "genie -i" >> ~/.bashrc + +exit \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..72ed4aa --- /dev/null +++ b/setup.sh @@ -0,0 +1,159 @@ +#!/bin/bash + +function ask_user() { + read -p "$1 (y/n): " choice + case "$choice" in + y|Y ) return 0;; + * ) return 1;; + esac +} + +sed -i "s|^TZ=.*$|TZ=$(cat /etc/timezone)|" src/.env + +sudo apt update + +if ! command -v mysql &> /dev/null +then + echo "MySQL client is not installed. Installing mariadb-client now..." + sudo apt install -y mariadb-client +else + echo "MySQL client is already installed." +fi + +if ! command -v docker &> /dev/null +then + echo "Docker is not installed. Installing Docker now..." + sudo apt-get install ca-certificates curl + sudo install -m 0755 -d /etc/apt/keyrings + sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + sudo chmod a+r /etc/apt/keyrings/docker.asc + + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update + sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + sudo usermod -aG docker $USER + echo "::NOTE::" + echo "Added your user to docker group to manage docker without root." + echo "Log out and back in and rerun setup.sh." + exit 1; +else + echo "Docker is already installed." +fi + +if [ -d "azerothcore-wotlk" ]; then + destination_dir="data/sql/custom" + + world=$destination_dir"/db_world/" + chars=$destination_dir"/db_characters/" + auth=$destination_dir"/db_auth/" + + cd azerothcore-wotlk + + rm -rf $world/*.sql + rm -rf $chars/*.sql + rm -rf $auth/*.sql + + cd .. + + cp src/.env azerothcore-wotlk/ + cp src/*.yml azerothcore-wotlk/ + cd azerothcore-wotlk +else + if ask_user "Download and install AzerothCore Playerbots?"; then + git clone https://github.com/liyunfan1223/azerothcore-wotlk.git --branch=Playerbot + cp src/.env azerothcore-wotlk/ + cp src/*.yml azerothcore-wotlk/ + cd azerothcore-wotlk/modules + git clone https://github.com/liyunfan1223/mod-playerbots.git --branch=master + cd .. + else + echo "Aborting..." + exit 1 + fi +fi + +if ask_user "Install modules?"; then + + cd modules + + function install_mod() { + local mod_name=$1 + local repo_url=$2 + + if [ -d "${mod_name}" ]; then + echo "${mod_name} exists. Skipping..." + else + if ask_user "Install ${mod_name}?"; then + git clone "${repo_url}" + fi + fi + } + + install_mod "mod-aoe-loot" "https://github.com/azerothcore/mod-aoe-loot.git" + install_mod "mod-learn-spells" "https://github.com/noisiver/mod-learnspells.git" + install_mod "mod-fireworks-on-level" "https://github.com/azerothcore/mod-fireworks-on-level.git" + install_mod "mod-individual-progression" "https://github.com/ZhengPeiRu21/mod-individual-progression.git" + install_mod "mod-junk-to-gold" "https://github.com/notepadguyOfficial/mod-junk-to-gold.git" + install_mod "mod-dungeon-respawn" "https://github.com/notepadguyOfficial/DungeonRespawn.git" + cd .. + +fi + + +docker compose up -d --build + +cd .. + +sudo chown -R 1000:1000 wotlk + +custom_sql_dir="src/sql" +auth="acore_auth" +world="acore_world" +chars="acore_characters" + +ip_address=$(hostname -I | awk '{print $1}') + +temp_sql_file="/tmp/temp_custom_sql.sql" + +function execute_sql() { + local db_name=$1 + local sql_files=("$custom_sql_dir/$db_name"/*.sql) + + if [ -e "${sql_files[0]}" ]; then + for custom_sql_file in "${sql_files[@]}"; do + echo "Executing $custom_sql_file" + temp_sql_file=$(mktemp) + if [[ "$(basename "$custom_sql_file")" == "update_realmlist.sql" ]]; then + sed -e "s/{{IP_ADDRESS}}/$ip_address/g" "$custom_sql_file" > "$temp_sql_file" + else + cp "$custom_sql_file" "$temp_sql_file" + fi + mysql -h "$ip_address" -uroot -ppassword "$db_name" < "$temp_sql_file" + done + else + echo "No SQL files found in $custom_sql_dir/$db_name, skipping..." + fi +} + +echo "Running custom SQL files..." +execute_sql "$auth" +execute_sql "$world" +execute_sql "$chars" + +rm "$temp_sql_file" + +echo "" +echo "NOTE:" +echo "" +echo "!!! If ac-db-import failed, run 'sudo chown -R 1000:1000 wotlk' and './setup.sh' again !!!" +echo "" +echo "1. Execute 'docker attach ac-worldserver'" +echo "2. 'account create username password' creates an account." +echo "3. 'account set gmlevel username 3 -1' sets the account as gm for all servers." +echo "4. Ctrl+p Ctrl+q will take you out of the world console." +echo "5. Edit your gameclients realmlist.wtf and set it to $ip_address." +echo "6. Now login to wow with 3.3.5a client!" +echo "7. All config files are copied into the wotlk folder created with setup.sh." diff --git a/sqldump.sh b/sqldump.sh new file mode 100644 index 0000000..ab956ea --- /dev/null +++ b/sqldump.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +read -sp "Enter mysql password: " password +echo "" + +function ask_user() { + read -p "$1 (recover/backup): " choice + case "$choice" in + recover|Recover ) + read -p "Enter the date to recover (YYYY-MM-DD): " recover_date + mysql -h127.0.0.1 -P3306 -uroot -p$password acore_auth < ./sql_dumps/acore_auth/acore_auth-$recover_date.sql + mysql -h127.0.0.1 -P3306 -uroot -p$password acore_characters < ./sql_dumps/acore_characters/acore_characters-$recover_date.sql + mysql -h127.0.0.1 -P3306 -uroot -p$password acore_world < ./sql_dumps/acore_world/acore_world-$recover_date.sql + mysql -h127.0.0.1 -P3306 -uroot -p$password acore_playerbots < ./sql_dumps/acore_playerbots/acore_playerbots-$recover_date.sql + docker restart ac-worldserver + ;; + backup|Backup ) + if [[ ! -d sql_dumps ]]; then + mkdir -p sql_dumps/acore_auth sql_dumps/acore_characters sql_dumps/acore_world sql_dumps/acore_playerbots + fi + mysqldump -h127.0.0.1 -P3306 -uroot -p$password acore_auth > ./sql_dumps/acore_auth/acore_auth-$(date +%F).sql + mysqldump -h127.0.0.1 -P3306 -uroot -p$password acore_characters > ./sql_dumps/acore_characters/acore_characters-$(date +%F).sql + mysqldump -h127.0.0.1 -P3306 -uroot -p$password acore_world > ./sql_dumps/acore_world/acore_world-$(date +%F).sql + mysqldump -h127.0.0.1 -P3306 -uroot -p$password acore_playerbots > ./sql_dumps/acore_playerbots/acore_playerbots-$(date +%F).sql + ;; + esac +} + +ask_user 'Type recover or backup.' diff --git a/src/.env b/src/.env new file mode 100644 index 0000000..cca99cd --- /dev/null +++ b/src/.env @@ -0,0 +1,25 @@ + +# +# Create a .env file in the root folder and use the following +# variables to configure your docker compose +# + +DOCKER_AC_ENV_FILE= + +DOCKER_VOL_ROOT= +DOCKER_VOL_CONF= +DOCKER_VOL_ETC=../wotlk/etc +DOCKER_VOL_LOGS=../wotlk/logs +DOCKER_VOL_DATA= + +DOCKER_WORLD_EXTERNAL_PORT= +DOCKER_SOAP_EXTERNAL_PORT= +DOCKER_AUTH_EXTERNAL_PORT= +DOCKER_DB_EXTERNAL_PORT= +DOCKER_DB_ROOT_PASSWORD=root + +DOCKER_USER=acore +DOCKER_USER_ID=1000 +DOCKER_GROUP_ID=1000 + +TZ=Europe/Oslo \ No newline at end of file diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml new file mode 100644 index 0000000..a57ac07 --- /dev/null +++ b/src/docker-compose.override.yml @@ -0,0 +1,10 @@ +services: + ac-database: + environment: + TZ: ${TZ} + + ac-worldserver: + environment: + TZ: ${TZ} + volumes: + - ./modules:/azerothcore/modules:rw \ No newline at end of file diff --git a/src/sql/acore_auth/update_realmlist.sql b/src/sql/acore_auth/update_realmlist.sql new file mode 100644 index 0000000..52ef7aa --- /dev/null +++ b/src/sql/acore_auth/update_realmlist.sql @@ -0,0 +1,3 @@ +USE acore_auth; +SELECT * FROM realmlist; +UPDATE realmlist SET address='{{IP_ADDRESS}}'; \ No newline at end of file diff --git a/start_stop_acore.sh b/start_stop_acore.sh new file mode 100644 index 0000000..28e3301 --- /dev/null +++ b/start_stop_acore.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +manage_docker_containers() { + containers=("ac-worldserver" "ac-authserver" "ac-database") + + all_running=true + for container in "${containers[@]}"; do + if ! docker ps --format '{{.Names}}' | grep -q "^${container}$"; then + all_running=false + break + fi + done + + if $all_running; then + echo "Stopping containers: ${containers[*]}" + docker stop "${containers[@]}" + else + echo "Starting containers: ${containers[*]}" + docker start "${containers[@]}" + fi +} + +manage_docker_containers \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..2523a5d --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +function ask_user() { + read -p "$1 (y/n): " choice + case "$choice" in + y|Y ) return 0;; + * ) return 1;; + esac +} + +if ask_user "This will uninstall azerothcore, continue?"; then + + cd azerothcore-wotlk + + docker compose down + docker image prune -a + if ask_user "Delete volumes? If you keep the volumes, a reinstall will only update."; then + docker system prune -a + docker volume rm azerothcore-wotlk_ac-client-data + docker volume rm azerothcore-wotlk_ac-database + fi + + cd .. && rm -rf azerothcore-wotlk wotlk/* + + exit 0 +fi \ No newline at end of file