From d50ce2c777263bd93261ac4c9d5c91972cdadf1f Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 10 Feb 2024 01:33:48 +0000 Subject: [PATCH] Improves platform installation scripts --- scripts/.funcs.cmds.inc.sh | 35 +++-------------------------------- scripts/install_mt4.sh | 19 +++---------------- scripts/install_mt5.sh | 18 +++--------------- scripts/options.txt | 2 +- scripts/provision.sh | 2 +- scripts/run_backtest.sh | 4 ++-- 6 files changed, 13 insertions(+), 67 deletions(-) diff --git a/scripts/.funcs.cmds.inc.sh b/scripts/.funcs.cmds.inc.sh index 52c00f10..5c9ffd18 100644 --- a/scripts/.funcs.cmds.inc.sh +++ b/scripts/.funcs.cmds.inc.sh @@ -210,10 +210,10 @@ filever() } # Install platform. -# Usage: install_mt [ver/4/5/v4.0.0.1260/v5.0.0.2361] (dest) +# Usage: install_mt [ver/4/5] (dest) install_mt() { - type jq wget unzip > /dev/null + type jq wget > /dev/null local mt_ver=${1:-$MT_VER} local dir_dest=${2:-$WINE_PATH} dir_dest=${dir_dest:-$HOME} @@ -222,43 +222,14 @@ install_mt() 4) . "$CWD"/install_mt4.sh ;; - 4x) - . "$CWD"/install_mt4x.sh - ;; 5) . "$CWD"/install_mt5.sh ;; - 4.0.0.* | 5.0.0.*) - [ ! -d "$dir_dest" ] && mkdir $VFLAG -p "$dir_dest" - [ ! -w "$dir_dest" ] && { - echo "ERROR: Destination folder not writable!" - (id && stat "$dir_dest") >&2 - exit 1 - } - cd "$dir_dest" - header=$([ -n "${GITHUB_API_TOKEN}" ] && echo "Authorization: Bearer ${GITHUB_API_TOKEN}" || echo "") - mt_releases_json="$(curl -H "Content-Type: application/json; $header" -s https://api.github.com/repos/${REPO_MT-"EA31337/MT-Platforms"}/releases)" - jq ".[]" <<< "$mt_releases_json" > /dev/null || true # Test JSON syntax. - mapfile -t mt_releases_list < <(jq -r '.[]["tag_name"]' <<< "$mt_releases_json") - if [[ " ${mt_releases_list[*]} " =~ ${mt_ver} ]]; then - mt_release_url=$(jq -r '.[]|select(.tag_name == "'${mt_ver}'")["assets"][0]["browser_download_url"]' <<< "$mt_releases_json") - wget -nv -c "$mt_release_url" - (unzip -ou "mt-$mt_ver.zip" && rm $VFLAG "mt-$mt_ver.zip") 1>&2 - clean_bt . '*' - else - echo "Error: Cannot find supported platform version. Supported: ${mt_releases_list[@]}" >&2 - if [ -z "${mt_releases_list[*]}" ]; then - echo "Error: Empty release list!" - echo $mt_releases_json - fi - fi - cd - &> /dev/null - ;; *) if [ -z "$MT_VER" ]; then echo "Error: Platform not specified!" >&2 else - echo "Error: Not supported platform version ($MT_VER). Supported: 4, 4x, 4.0.0.x, 5 or 5.0.0.x." >&2 + echo "Error: Not supported platform version ($MT_VER). Supported: 4, 5." >&2 fi exit 1 ;; diff --git a/scripts/install_mt4.sh b/scripts/install_mt4.sh index 7eb434f1..e2b75680 100755 --- a/scripts/install_mt4.sh +++ b/scripts/install_mt4.sh @@ -6,6 +6,7 @@ CWD="$( cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" 2> /dev/null pwd -P )" +type ansible > /dev/null type winetricks > /dev/null # Load variables. @@ -20,23 +21,9 @@ curl -s ifconfig.me/all.json . "$CWD/.funcs.inc.sh" . "$CWD/.funcs.cmds.inc.sh" -# Activates display. -echo "Configuring display..." >&2 -set_display - -# Updates Wine configuration. -echo "Updating configuration..." >&2 -wineboot -u - -echo "Installing winhttp..." >&2 -winetricks -q winhttp - -echo "Installing .NET..." >&2 -winetricks -q dotnet472 - echo "Installing platform..." >&2 -#winetricks -q -v mt4 -winetricks -q "$CWD"/verb/install_mt4.verb +ansible-playbook -c local -e metatrader_version=4 +\ -i "localhost," /opt/ansible/install-platform.yml -v . "$CWD"/.vars.inc.sh if [ -n "$TERMINAL5_DIR" ]; then diff --git a/scripts/install_mt5.sh b/scripts/install_mt5.sh index 4a9e946d..ddef05a8 100755 --- a/scripts/install_mt5.sh +++ b/scripts/install_mt5.sh @@ -6,6 +6,7 @@ CWD="$( cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" 2> /dev/null pwd -P )" +type ansible > /dev/null type winetricks > /dev/null # Load variables. @@ -20,22 +21,9 @@ curl -s ifconfig.me/all.json . "$CWD/.funcs.inc.sh" . "$CWD/.funcs.cmds.inc.sh" -# Activates display. -echo "Configuring display..." >&2 -set_display - -# Updates Wine configuration. -echo "Updating configuration..." >&2 -wineboot -u - -echo "Installing winhttp..." >&2 -winetricks -q winhttp - -echo "Installing .NET..." >&2 -winetricks -q dotnet472 - echo "Installing platform..." >&2 -winetricks -q "$CWD"/verb/install_mt5.verb +ansible-playbook -c local -e metatrader_version=5 +\ -i "localhost," /opt/ansible/install-platform.yml -v . "$CWD"/.vars.inc.sh if [ -n "$TERMINAL5_DIR" ]; then diff --git a/scripts/options.txt b/scripts/options.txt index 863f6b9f..f7ad9958 100644 --- a/scripts/options.txt +++ b/scripts/options.txt @@ -60,7 +60,7 @@ Supported options: Specifies range of months in each year to test. Default: 1-12. Variable (uint/string): BT_MONTHS -M (version) - Specifies version of MetaTrader to use for the test (e.g. 4, 4x, 5, 4.0.0.1010). Default: 4.0.0.1010 + Specifies version of MetaTrader to use for the test (e.g. 4, 5). Default: 4 Variable (string): MT_VER -o Runs test in optimization mode. diff --git a/scripts/provision.sh b/scripts/provision.sh index 607f96d0..ed71d253 100755 --- a/scripts/provision.sh +++ b/scripts/provision.sh @@ -154,7 +154,7 @@ case "$(uname -s)" in # Install other CLI tools. apt-get install -qq less binutils coreutils moreutils # Common CLI utils. - apt-get install -qq cabextract zip unzip p7zip-full # Compression tools. + apt-get install -qq cabextract zip p7zip-full # Compression tools. apt-get install -qq git links tree pv bc # Required commands. apt-get install -qq realpath || true # Install realpath if available. apt-get install -qq html2text jq # Required parsers. diff --git a/scripts/run_backtest.sh b/scripts/run_backtest.sh index 1494c66c..f049c0d8 100755 --- a/scripts/run_backtest.sh +++ b/scripts/run_backtest.sh @@ -219,8 +219,8 @@ while getopts $ARGS arg; do MT_VER=5 ;; - M) # Specify version of MetaTrader (e.g. 4, 4x, 5, 4.0.0.1010). - MT_VER=${OPTARG:-4.0.0.1010} + M) # Specify version of MetaTrader (e.g. 4, 5). + MT_VER=${OPTARG:-4} ;; v) # Verbose mode.