Rewrite of bash system

+ Implemented new dashboard menu
+ some fixes for db_assembler
+ new module installation process with version check via json files
+ some fixes to modules installer
+ implemented simple crossplatform worldserver and authserver restarters
+ new compiler script
+ client data downloader (beta)
+ various other fixes
This commit is contained in:
Yehonal
2018-07-15 22:40:49 +02:00
parent 07a451e140
commit 85388901cf
38 changed files with 2179 additions and 163 deletions

View File

@@ -0,0 +1,23 @@
function registerHooks() { hwc_event_register_hooks "$@"; }
function runHooks() { hwc_event_run_hooks "$@"; }
source "$AC_PATH_CONF/config.sh.dist" # "hack" to avoid missing conf variables
if [ -f "$AC_PATH_CONF/config.sh" ]; then
source "$AC_PATH_CONF/config.sh" # should overwrite previous
else
echo "NOTICE: file <$AC_PATH_CONF/config.sh> has not been found, you should create and configure it."
fi
#
# Load modules
#
for entry in "$AC_PATH_MODULES/"*/include.sh
do
if [ -e $entry ]; then
source $entry
fi
done
ACORE_VERSION=$("$AC_PATH_DEPS/jsonpath/JSONPath.sh" -f $AC_PATH_ROOT/acore.json -b '$.version')

View File

@@ -11,25 +11,5 @@ source "$AC_PATH_SHARED/defines.sh"
source "$AC_PATH_DEPS/hw-core/bash-lib-event/src/hooks.sh"
source "$AC_PATH_SHARED/common.sh"
function registerHooks() { hwc_event_register_hooks "$@"; }
function runHooks() { hwc_event_run_hooks "$@"; }
source "$AC_PATH_CONF/config.sh.dist" # "hack" to avoid missing conf variables
if [ -f "$AC_PATH_CONF/config.sh" ]; then
source "$AC_PATH_CONF/config.sh" # should overwrite previous
else
echo "NOTICE: file <$AC_PATH_CONF/config.sh> has not been found, you should create and configure it."
fi
#
# Load modules
#
for entry in "$AC_PATH_MODULES/"*/include.sh
do
if [ -e $entry ]; then
source $entry
fi
done

View File

@@ -1,5 +0,0 @@
#!/usr/bin/env bash
CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash "$CURRENT_PATH/compiler.sh" 1

View File

@@ -1,5 +0,0 @@
#!/usr/bin/env bash
CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash "$CURRENT_PATH/compiler.sh" 2

View File

@@ -1,5 +0,0 @@
#!/usr/bin/env bash
CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash "$CURRENT_PATH/compiler.sh" 3

View File

@@ -4,41 +4,67 @@ CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_PATH/includes/includes.sh"
function all() {
comp_clean
comp_configure
comp_build
}
function run_option() {
if test "${comp_functions[$1-1]+'test'}"; then
re='^[0-9]+$'
if [[ $1 =~ $re ]] && test "${comp_functions[$1-1]+'test'}"; then
${comp_functions[$1-1]}
elif [ -n "$(type -t comp_$1)" ] && [ "$(type -t comp_$1)" = function ]; then
fun="comp_$1"
$fun
else
echo "invalid option"
fi
echo "invalid option, use --help option for the commands list"
fi
}
comp_options=("Clean" "Configure" "Build" "All")
comp_functions=("comp_clean" "comp_configure" "comp_build" "all")
function comp_quit() {
exit 0
}
comp_options=(
"build: Configure and compile"
"clean: Clean build files"
"configure: Run CMake"
"compile: Compile only"
"all: clean, configure and compile"
"quit: Close this menu")
comp_functions=(
"comp_build"
"comp_clean"
"comp_configure"
"comp_compile"
"comp_all"
"comp_quit")
PS3='[ Please enter your choice ]: '
runHooks "ON_AFTER_OPTIONS" #you can create your custom options
# push exit after custom options
comp_options+=('Exit')
comp_functions+=('exit 0')
function _switch() {
_reply="$1"
_opt="$2"
# run option directly if specified in argument
[ ! -z $1 ] && run_option $1 && exit 0
PS3='[ Please enter your choice ]: '
select opt in "${comp_options[@]}"
do
case $opt in
'Exit')
break
case $_reply in
""|"--help")
echo "Available commands:"
printf '%s\n' "${options[@]}"
;;
*)
run_option $REPLY
run_option $_reply $_opt
;;
esac
}
while true
do
# run option directly if specified in argument
[ ! -z $1 ] && _switch $@
[ ! -z $1 ] && exit 0
select opt in "${comp_options[@]}"
do
echo "==== ACORE COMPILER ===="
_switch $REPLY
break;
done
done

View File

@@ -39,7 +39,7 @@ function comp_configure() {
}
function comp_build() {
function comp_compile() {
[ $MTHREADS == 0 ] && MTHREADS=`grep -c ^processor /proc/cpuinfo` && MTHREADS=$(($MTHREADS + 2))
echo "Using $MTHREADS threads"
@@ -55,3 +55,13 @@ function comp_build() {
runHooks "ON_AFTER_BUILD"
}
function comp_build() {
comp_configure
comp_build
}
function comp_all() {
comp_clean
comp_build
}

View File

@@ -6,56 +6,70 @@ source "$CURRENT_PATH/includes/includes.sh"
cmdopt=$1
while true
do
echo "===== DB ASSEMBLER MENU ====="
PS3='Please enter your choice: '
PS3='[Please enter your choice]: '
options=(
"Assemble ALL" "Assemble only bases" "Assemble only updates" "Assemble only customs"
"Quit"
"Assemble & import ALL" "Assemble & import only bases" "Assemble & import only updates" "Assemble & import only customs"
"all: Assemble all" # 1
"bases: Assemble only bases" # 2
"updates: Assemble only updates" # 3
"customs: Assemble only customs" # 4
"import-all: Assemble & Import all" # 5
"import-bases: Assemble & Import only bases" # 6
"import-updates: Assemble & Import only updates" # 7
"import-customs: Assemble & Import only customs" # 8
"quit: Exit from this menu" # 9
)
function _switch() {
case $1 in
"Assemble ALL")
_reply="$1"
_opt="$2"
case $_reply in
""|"all"|"1")
dbasm_run true true true
;;
"Assemble only bases")
""|"bases"|"2")
dbasm_run true false false
;;
"Assemble only updates")
""|"updates"|"3")
dbasm_run false true false
;;
"Assemble only customs")
""|"customs"|"4")
dbasm_run false false true
;;
"Assemble & import ALL")
""|"import-all"|"5")
dbasm_import true true true
;;
"Assemble & import only bases")
""|"import-bases"|"6")
dbasm_import true false false
;;
"Assemble & import only updates")
""|"import-updates"|"7")
dbasm_import false true false
;;
"Assemble & import only customs")
""|"import-customs"|"8")
dbasm_import false false true
;;
"Quit")
""|"quit"|"9")
echo "Goodbye!"
exit
;;
*) echo invalid option;;
""|"--help")
echo "Available commands:"
printf '%s\n' "${options[@]}"
;;
*) echo "invalid option, use --help option for the commands list";;
esac
}
# run option directly if specified in argument
[ ! -z $1 ] && _switch "${options[$cmdopt-1]}" && exit 0
select opt in "${options[@]}"
while true
do
_switch "$opt"
break
done
# run option directly if specified in argument
[ ! -z $1 ] && _switch $@
[ ! -z $1 ] && exit 0
select opt in "${options[@]}"
do
echo "===== DB ASSEMBLER MENU ====="
_switch $REPLY
break
done
done

View File

@@ -44,10 +44,6 @@ function inst_cleanCompile() {
inst_compile
}
function inst_assembleDb {
dbasm_import true true true
}
function inst_allInOne() {
inst_configureOS
inst_updateRepo
@@ -55,19 +51,66 @@ function inst_allInOne() {
inst_assembleDb
}
function inst_getVersionBranch() {
local res="master"
local v="not-defined"
local MODULE_MAJOR=0
local MODULE_MINOR=0
local MODULE_PATCH=0
local MODULE_SPECIAL=0;
local ACV_MAJOR=0
local ACV_MINOR=0
local ACV_PATCH=0
local ACV_SPECIAL=0;
local curldata=$(curl -f --silent -H 'Cache-Control: no-cache' "$1" || echo "{}")
local parsed=$(echo "$curldata" | "$AC_PATH_DEPS/jsonpath/JSONPath.sh" -b '$.compatibility.*.[version,branch]')
semverParseInto "$ACORE_VERSION" ACV_MAJOR ACV_MINOR ACV_PATCH ACV_SPECIAL
if [[ ! -z "$parsed" ]]; then
readarray -t vers < <(echo "$parsed")
local idx
res="none"
# since we've the pair version,branch alternated in not associative and one-dimensional
# array, we've to simulate the association with length/2 trick
for idx in `seq 0 $((${#vers[*]}/2-1))`; do
semverParseInto "${vers[idx*2]}" MODULE_MAJOR MODULE_MINOR MODULE_PATCH MODULE_SPECIAL
if [[ $MODULE_MAJOR -eq $ACV_MAJOR && $MODULE_MINOR -le $ACV_MINOR ]]; then
res="${vers[idx*2+1]}"
v="${vers[idx*2]}"
fi
done
fi
echo "$v" "$res"
}
function inst_module_search {
search=""
local res="$1"
local idx=0;
if [ -z "$1" ]; then
echo "Type what to search or leave blank for full list"
read -p "Insert name: " res
search="+$res"
fi
echo "Searching ..."
local search="+$res"
echo "Searching $res..."
echo "";
for i in `curl -s "https://api.github.com/search/repositories?q=org%3Aazerothcore${search}+fork%3Atrue+topic%3Acore-module+sort%3Astars&type=" | grep \"name\" | cut -d ':' -f 2-3|tr -d '",'`; do
echo "-> $i";
readarray -t MODS < <(curl --silent "https://api.github.com/search/repositories?q=org%3Aazerothcore${search}+fork%3Atrue+topic%3Acore-module+sort%3Astars&type=" \
| "$AC_PATH_DEPS/jsonpath/JSONPath.sh" -b '$.items.*.name')
while (( ${#MODS[@]} > idx )); do
mod="${MODS[idx++]}"
read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/azerothcore/$mod/master/acore-module.json")
if [[ "$b" != "none" ]]; then
echo "-> $mod (tested with AC v$v)"
else
echo "-> $mod (no revision available for AC v$AC_VERSION, it could not work!)"
fi
done
echo "";
@@ -75,30 +118,50 @@ function inst_module_search {
}
function inst_module_install {
local res
if [ -z "$1" ]; then
echo "Type the name of the module to install"
read -p "Insert name: " res
else
res="$1"
fi
git clone "https://github.com/azerothcore/$res" "$AC_PATH_ROOT/modules/$res" && echo "Done, please re-run compiling and db assembly. Read instruction on module repository for more information"
read v b < <(inst_getVersionBranch "https://raw.githubusercontent.com/azerothcore/$res/master/acore-module.json")
if [[ "$b" != "none" ]]; then
Joiner:add_repo "https://github.com/azerothcore/$res" "$res" "$b" && echo "Done, please re-run compiling and db assembly. Read instruction on module repository for more information"
else
echo "Cannot install $res module: it doesn't exists or no version compatible with AC v$ACORE_VERSION are available"
fi
echo "";
echo "";
}
function inst_module_update {
local res;
local _tmp;
local branch;
local p;
if [ -z "$1" ]; then
echo "Type the name of the module to update"
read -p "Insert name: " res
else
res="$1"
fi
cd "$AC_PATH_ROOT/modules/$res"
_tmp=$PWD
#git reset --hard master
#git clean -f
git pull origin master && echo "Done"
if [ -d "$J_PATH_MODULES/$res/" ]; then
cd "$J_PATH_MODULES/$res/"
branch=`git rev-parse --abbrev-ref HEAD`
cd "../../"
Joiner:upd_repo "https://github.com/azerothcore/$res" "$res" "$branch" && echo "Done, please re-run compiling and db assembly" || echo "Cannot update"
cd $_tmp
else
echo "Cannot update! Path doesn't exist"
fi;
echo "";
echo "";
@@ -108,10 +171,29 @@ function inst_module_remove {
if [ -z "$1" ]; then
echo "Type the name of the module to remove"
read -p "Insert name: " res
else
res="$1"
fi
rm -rf "$AC_PATH_ROOT/modules/$res" && echo "Done"
Joiner:remove "$res" && echo "Done, please re-run compiling" || echo "Cannot remove"
echo "";
echo "";
}
function inst_simple_restarter {
echo "Running $1 in background..."
bash "$AC_PATH_APPS/startup-scripts/simple-restarter" "$BINPATH" "$1" &
}
function inst_download_client_data {
path="$BINPATH/data"
if [ -e "$path/.git/" ]; then
# if exists , update
git --git-dir="$path/.git/" rev-parse && git --git-dir="$path/.git/" pull origin master | grep 'Already up-to-date.' && changed="no"
else
# otherwise clone
git clone "https://github.com/wowgaming/client-data" -c advice.detachedHead=0 -b master --depth=1 $path
fi
}

View File

@@ -1,9 +1,31 @@
CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
[[ ${INSTALLER_GUARDYVAR:-} -eq 1 ]] && return || readonly INSTALLER_GUARDYVAR=1 # include it once
CURRENT_PATH=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd )
source "$CURRENT_PATH/../../bash_shared/includes.sh"
AC_PATH_INSTALLER="$AC_PATH_APPS/installer"
J_VER_REQ="v0.8.3"
J_PATH="$AC_PATH_APPS/drassil/joiner"
J_PATH_MODULES="$AC_PATH_MODULES"
#install/update and include joiner
if [ ! -d "$J_PATH/.git" ]; then
git clone https://github.com/drassil/joiner "$J_PATH" -b master
git --git-dir="$J_PATH/.git/" --work-tree="$J_PATH/" reset --hard "$J_VER_REQ"
else
# legacy code, with new rev of joiner the update process is internally handled
_cur_branch=`git --git-dir="$J_PATH/.git/" --work-tree="$J_PATH/" rev-parse --abbrev-ref HEAD`
_cur_ver=`git --git-dir="$J_PATH/.git/" --work-tree="$J_PATH/" name-rev --tags --name-only $_cur_branch`
if [ "$_cur_ver" != "$J_VER_REQ" ]; then
git --git-dir="$J_PATH/.git" --work-tree="$J_PATH/" rev-parse && git --git-dir="$J_PATH/.git" --work-tree="$J_PATH/" fetch --tags origin master --quiet
git --git-dir="$J_PATH/.git/" --work-tree="$J_PATH/" reset --hard "$J_VER_REQ"
fi
fi
source "$AC_PATH_APPS/drassil/joiner/joiner.sh"
if [ -f "$AC_PATH_INSTALLER/config.sh" ]; then
source "$AC_PATH_INSTALLER/config.sh" # should overwrite previous
fi
@@ -11,4 +33,6 @@ fi
source "$AC_PATH_APPS/compiler/includes/includes.sh"
source "$AC_PATH_APPS/db_assembler/includes/includes.sh"
source "$AC_PATH_DEPS/semver_bash/semver.sh"
source "$AC_PATH_INSTALLER/includes/functions.sh"

View File

@@ -4,75 +4,90 @@ CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_PATH/includes/includes.sh"
cmdopt=$1
while true
do
echo "===== INSTALLER SCRIPT ====="
PS3='Please enter your choice: '
PS3='[Please enter your choice]: '
options=(
"First Installation" "Configure OS dep" "Update Repository" "Reset & Clean Repository"
"Compile" "Clean & Compile" "Assemble & Import DB" "Module Search" "Module Install" "Module Update" "Module Remove"
"Sub Menu >> Compiler" "Sub Menu >> DB Assembler"
"Quit"
"init (i): First Installation" # 1
"install-deps (d): Configure OS dep" # 2
"pull (u): Update Repository" # 3
"reset (r): Reset & Clean Repository" # 4
"compiler (c): Run compiler tool" # 5
"db-assembler (a): Run db assembler tool" # 6
"module-search (ms): Module Search by keyword" # 7
"module-install (mi): Module Install by name" # 8
"module-update (mu): Module Update by name" # 9
"module-remove: (mr): Module Remove by name" # 10
"client-data: (gd): download client data from github repository (beta)" # 11
"run-worldserver (rw): execute a simple restarter for worldserver" # 12
"run-authserver (ra): execute a simple restarter for authserver" # 13
"quit: Exit from this menu" # 14
)
function _switch() {
case $1 in
"First Installation")
_reply="$1"
_opt="$2"
case $_reply in
""|"i"|"init"|"1")
inst_allInOne
;;
"Configure OS dep")
""|"d"|"install-deps"|"2")
inst_configureOS
;;
"Update Repository")
""|"u"|"pull"|"3")
inst_updateRepo
;;
"Reset & Clean Repository")
""|"r"|"reset"|"4")
inst_resetRepo
;;
"Compile")
inst_compile
""|"c"|"compiler"|"5")
bash "$AC_PATH_APPS/compiler/compiler.sh" $_opt
;;
"Clean & Compile")
inst_cleanCompile
""|"a"|"db-assembler"|"6")
bash "$AC_PATH_APPS/db_assembler/db_assembler.sh" $_opt
;;
"Assemble & Import DB")
inst_assembleDb
""|"ms"|"module-search"|"7")
inst_module_search "$_opt"
;;
"Module Search")
inst_module_search $2
""|"mi"|"module-install"|"8")
inst_module_install "$_opt"
;;
"Module Install")
inst_module_install $2
""|"mu"|"module-update"|"9")
inst_module_update "$_opt"
;;
"Module Update")
inst_module_update $2
""|"mr"|"module-remove"|"10")
inst_module_remove "$_opt"
;;
"Module Remove")
inst_module_remove $2
""|"gd"|"client-data"|"11")
inst_download_client_data
;;
"Sub Menu >> Compiler")
bash "$AC_PATH_APPS/compiler/compiler.sh"
""|"rw"|"run-worldserver"|"12")
inst_simple_restarter worldserver
;;
"Sub Menu >> DB Assembler")
bash "$AC_PATH_APPS/db_assembler/db_assembler.sh"
""|"ra"|"run-authserver"|"13")
inst_simple_restarter authserver
;;
"Quit")
""|"quit"|"14")
echo "Goodbye!"
exit
;;
*) echo invalid option;;
""|"--help")
echo "Available commands:"
printf '%s\n' "${options[@]}"
;;
*) echo "invalid option, use --help option for the commands list";;
esac
}
# run option directly if specified in argument
[ ! -z $1 ] && _switch "${options[$cmdopt-1]}"
[ ! -z $1 ] && exit 0
select opt in "${options[@]}"
while true
do
_switch "$opt"
break
done
# run option directly if specified in argument
[ ! -z $1 ] && _switch $@ # old method: "${options[$cmdopt-1]}"
[ ! -z $1 ] && exit 0
select opt in "${options[@]}"
do
echo "==== ACORE DASHBOARD ===="
_switch $REPLY
break
done
done

View File

@@ -0,0 +1,9 @@
#PARAMETER 1: directory
#PARAMETER 2: binary file
_bin_path=$1
_bin_file=$2
while true
do
cd "$_bin_path" && "./$_bin_file" &>/dev/null; echo "$_bin_file crashed (?), restarting..."
done