Skip to content

Commit

Permalink
Improves platform installation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Feb 10, 2024
1 parent 6a43cef commit d50ce2c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 67 deletions.
35 changes: 3 additions & 32 deletions scripts/.funcs.cmds.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
;;
Expand Down
19 changes: 3 additions & 16 deletions scripts/install_mt4.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
18 changes: 3 additions & 15 deletions scripts/install_mt5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions scripts/run_backtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d50ce2c

Please sign in to comment.