2020-03-22 19:38:03 +01:00
|
|
|
#!/usr/bin/env bash
|
2020-03-29 14:32:34 +02:00
|
|
|
set -eu
|
2020-03-22 19:38:03 +01:00
|
|
|
|
|
|
|
wine_window_stage1=""
|
|
|
|
wine_window_stage2=""
|
|
|
|
wine_window_stage3=""
|
|
|
|
wine_window_stage4=""
|
|
|
|
wine_window_stage5=""
|
|
|
|
wine_window_stage6=""
|
|
|
|
wine_window_stage7=""
|
|
|
|
installer_window=""
|
|
|
|
eula_window=""
|
|
|
|
cdkey_window=""
|
|
|
|
location_window=""
|
|
|
|
installation_window=""
|
|
|
|
shortcut_window=""
|
|
|
|
registration_window=""
|
|
|
|
|
|
|
|
XAUTHORITY=$(pwd)/xauth
|
|
|
|
DISPLAY=""
|
|
|
|
|
|
|
|
function list_wine_windows {
|
2020-03-29 14:32:34 +02:00
|
|
|
local array=""
|
|
|
|
set +eu
|
|
|
|
while [ "${array}" = "" ]; do
|
|
|
|
sleep 5
|
|
|
|
array=($(xdotool search --class wine))
|
|
|
|
done
|
|
|
|
set -eu
|
|
|
|
echo ${array[@]}
|
2020-03-22 19:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function last_wine_window {
|
2020-03-29 14:32:34 +02:00
|
|
|
local array=($@)
|
|
|
|
echo ${array[$((${#array[@]}-1))]}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initialize_openbox {
|
|
|
|
xvfb-run -a -f ${XAUTHORITY} openbox --sync &
|
|
|
|
while [ "${DISPLAY}" = "" ]; do
|
|
|
|
DISPLAY=$(ps aux | awk '{if($1 == "'$(whoami)'") print $0}' | grep Xvfb\ :[0-9]* | grep -v grep | grep -o Xvfb\ :[0-9]* | awk '{print $2}')
|
2020-03-22 19:38:03 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-03-29 14:32:34 +02:00
|
|
|
function create_wine_prefix {
|
|
|
|
wine systeminfo
|
2020-03-22 19:38:03 +01:00
|
|
|
}
|
|
|
|
|
2020-03-29 14:32:34 +02:00
|
|
|
function start_roc_installer {
|
|
|
|
initialize_openbox
|
|
|
|
create_wine_prefix
|
|
|
|
pushd ${WAR3ROC_CDROM_ROOT}
|
|
|
|
wine install.exe &
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_tft_installer {
|
|
|
|
pushd ${WAR3TFT_CDROM_ROOT}
|
|
|
|
wine install.exe &
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
function begin_install {
|
2020-03-22 19:38:03 +01:00
|
|
|
wine_window_stage1=($(list_wine_windows))
|
|
|
|
installer_window=$(last_wine_window ${wine_window_stage1[@]})
|
|
|
|
# Initiate installation
|
|
|
|
xdotool windowactivate --sync ${installer_window} key W
|
2020-03-29 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function accept_eula {
|
2020-03-22 19:38:03 +01:00
|
|
|
wine_window_stage2=($(list_wine_windows))
|
|
|
|
eula_window=$(last_wine_window ${wine_window_stage2[@]})
|
|
|
|
xdotool windowactivate --sync ${eula_window} key A
|
2020-03-29 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function pass_roc_cdkey_prompt {
|
2020-03-22 19:38:03 +01:00
|
|
|
wine_window_stage3=($(list_wine_windows))
|
|
|
|
cdkey_window=$(last_wine_window ${wine_window_stage3[@]})
|
|
|
|
# Input Gentoo as the owner
|
|
|
|
for i in G e n t o o; do
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key $i
|
|
|
|
done
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key Tab
|
|
|
|
# Input CDKEY
|
2020-03-29 14:32:34 +02:00
|
|
|
for (( i=0; i<${#WAR3ROC_CDKEY}; i++ )); do
|
|
|
|
if [ "${WAR3ROC_CDKEY:$i:1}" != "-" ]; then
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key ${WAR3ROC_CDKEY:$i:1}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key Tab
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key KP_Enter
|
|
|
|
}
|
|
|
|
|
|
|
|
function pass_tft_cdkey_prompt {
|
|
|
|
wine_window_stage3=($(list_wine_windows))
|
|
|
|
cdkey_window=$(last_wine_window ${wine_window_stage3[@]})
|
|
|
|
# Input CDKEY
|
|
|
|
for (( i=0; i<${#WAR3TFT_CDKEY}; i++ )); do
|
|
|
|
if [ "${WAR3TFT_CDKEY:$i:1}" != "-" ]; then
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key ${WAR3TFT_CDKEY:$i:1}
|
2020-03-22 19:38:03 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key Tab
|
|
|
|
xdotool windowactivate --sync ${cdkey_window} key KP_Enter
|
2020-03-29 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function input_location {
|
2020-03-22 19:38:03 +01:00
|
|
|
# Input location
|
|
|
|
wine_window_stage4=($(list_wine_windows))
|
|
|
|
location_window=$(last_wine_window ${wine_window_stage4[@]})
|
2020-03-29 14:32:34 +02:00
|
|
|
set +e
|
2020-03-22 19:38:03 +01:00
|
|
|
xdotool windowactivate --sync ${location_window} key KP_Enter
|
|
|
|
xdotool windowactivate --sync ${location_window} key KP_Enter
|
2020-03-29 14:32:34 +02:00
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
function wait_through_installation {
|
2020-03-22 19:38:03 +01:00
|
|
|
# Wait through installation
|
|
|
|
wine_window_stage5=($(list_wine_windows))
|
|
|
|
installation_window=$(last_wine_window ${wine_window_stage5[@]})
|
|
|
|
while [ $(list_wine_windows | grep -c ^${installation_window}$) -eq 1 ]; do
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
sleep 5
|
2020-03-29 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function pass_shortcut_phase {
|
2020-03-22 19:38:03 +01:00
|
|
|
# No shortcut please
|
|
|
|
wine_window_stage6=($(list_wine_windows))
|
|
|
|
shortcut_window=$(last_wine_window ${wine_window_stage6[@]})
|
|
|
|
xdotool windowactivate --sync ${shortcut_window} key Tab
|
|
|
|
xdotool windowactivate --sync ${shortcut_window} key KP_Enter
|
2020-03-29 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function pass_registration_phase {
|
2020-03-22 19:38:03 +01:00
|
|
|
# No registration please
|
|
|
|
wine_window_stage7=($(list_wine_windows))
|
|
|
|
registration_window=$(last_wine_window ${wine_window_stage7[@]})
|
|
|
|
xdotool windowactivate --sync ${registration_window} key Tab
|
|
|
|
xdotool windowactivate --sync ${registration_window} key KP_Enter
|
2020-03-29 14:32:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function exit_from_installer {
|
2020-03-22 19:38:03 +01:00
|
|
|
# Exit from installer
|
2020-03-29 14:32:34 +02:00
|
|
|
xdotool windowclose ${installer_window}
|
|
|
|
set +e
|
|
|
|
while [ $(ps aux | awk '{if($1 == "'$(whoami)'") print $0}' | grep \\.exe | grep -vc grep) -gt 0 ]; do
|
|
|
|
ps aux | awk '{if($1 == "'$(whoami)'") print $0}' | grep \\.exe | grep -v grep | awk '{print $2}' | xargs kill -15
|
|
|
|
sleep 15
|
|
|
|
done
|
|
|
|
set -e
|
|
|
|
# rm -f ${XAUTHORITY}
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_patcher {
|
|
|
|
set -x
|
|
|
|
if [ ${TFT} -eq 1 ]; then
|
|
|
|
wine ${DISTDIR}/War3TFT_126a_English.exe &
|
|
|
|
else
|
|
|
|
wine ${DISTDIR}/War3ROC_126a_English.exe &
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function wait_for_patch_dialog {
|
|
|
|
local array=($(list_wine_windows))
|
|
|
|
local limit=3
|
|
|
|
if [ ${TFT} -eq 1 ]; then
|
|
|
|
limit=4
|
|
|
|
fi
|
|
|
|
while [ ${#array[@]} -ne ${limit} ]; do
|
|
|
|
sleep 1
|
|
|
|
array=($(list_wine_windows))
|
|
|
|
done
|
|
|
|
while [ $(ls ${WINEPREFIX}/drive_c/Program\ Files/Warcraft\ III | grep ^PTC.*\\.tmp$ -c) -ne 0 ]; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function close_patcher {
|
|
|
|
local wine_windows=($(list_wine_windows))
|
|
|
|
local patcher_window=$(last_wine_window ${wine_windows[@]})
|
|
|
|
xdotool windowclose ${patcher_window}
|
|
|
|
}
|
|
|
|
|
|
|
|
function close_xvfb {
|
|
|
|
set +e
|
|
|
|
while [ $(ps aux | awk '{if($1 == "'$(whoami)'") print $0}' | grep openbox | grep -vc grep) -gt 0 ]; do
|
|
|
|
ps aux | awk '{if($1 == "'$(whoami)'") print $0}' | grep openbox | grep -v grep | awk '{print $2}' | xargs kill -15
|
|
|
|
sleep 15
|
|
|
|
done
|
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
function main {
|
|
|
|
start_roc_installer
|
|
|
|
begin_install
|
|
|
|
accept_eula
|
|
|
|
pass_roc_cdkey_prompt
|
|
|
|
input_location
|
|
|
|
wait_through_installation
|
|
|
|
pass_shortcut_phase
|
|
|
|
exit_from_installer
|
|
|
|
if [ ${TFT} -eq 1 ]; then
|
|
|
|
start_tft_installer
|
|
|
|
begin_install
|
|
|
|
accept_eula
|
|
|
|
pass_tft_cdkey_prompt
|
|
|
|
wait_through_installation
|
|
|
|
pass_shortcut_phase
|
|
|
|
exit_from_installer
|
|
|
|
fi
|
|
|
|
if [ ${PATCH} -eq 1 ]; then
|
|
|
|
start_patcher
|
|
|
|
wait_for_patch_dialog
|
|
|
|
close_patcher
|
|
|
|
fi
|
|
|
|
close_xvfb
|
2020-03-22 19:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main $@
|