Skip to content

Instantly share code, notes, and snippets.

@ukos-git
Created February 5, 2018 20:44
Show Gist options
  • Save ukos-git/5f3370dd40a0ac68cd6ee2e13a675b44 to your computer and use it in GitHub Desktop.
Save ukos-git/5f3370dd40a0ac68cd6ee2e13a675b44 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# source: https://askubuntu.com/questions/1002349/install-a-program-automatically-with-terminal-which-has-menus
# dependencies: sudo imagemagick xvfb
# constants
SERVERNUM=99
SCREENSHOT=status.png
CROSSWORKS_PID=
XVFB_PID=
PROGRESS_PID=
KEYS_PID=
# function find_free_servernum() taken from xvfb-run
# Xvfb is part of x.org and licensed under MIT
# http://opensource.org/licenses/mit-license.php
#
# Find a free server number by looking at .X*-lock files in /tmp.
find_free_servernum() {
# Sadly, the "local" keyword is not POSIX. Leave the next line commented in
# the hope Debian Policy eventually changes to allow it in /bin/sh scripts
# anyway.
#local i
i=$SERVERNUM
while [ -f /tmp/.X$i-lock ]; do
i=$(($i + 1))
done
echo $i
}
start_xvfb() {
SERVERNUM=$(find_free_servernum)
echo starting virtual DISPLAY at :$SERVERNUM
export DISPLAY=:$SERVERNUM
Xvfb $DISPLAY -screen 0 1280x800x16 &> /dev/null &
XVFB_PID=$!
}
install_crossworks() {
check_root
if [ ! -e ./install_crossworks ]; then
echo crossworks installation file not found
exit 1
fi
timeout --kill-after=90s 90s sudo -n ./install_crossworks &
CROSSWORKS_PID=$!
crossworks_enter_keys &
KEYS_PID=$!
show_progress &
PROGRESS_PID=$!
if wait $CROSSWORKS_PID; then
echo ok
fi
kill "$PROGRESS_PID" &> /dev/null
kill "$KEYS_PID" &> /dev/null
}
crossworks_enter_keys() {
# wait for archive to get checked for crc errors
sleep 5
# press next
xdotool key KP_Enter
sleep 1
# accept license
xdotool key Tab Tab Tab space Tab Tab KP_Enter
sleep 1
# select install directory
xdotool key KP_Enter
sleep 1
# start installation
xdotool key KP_Enter
sleep 60
# exit installation
xdotool key KP_Enter
sleep 1
}
show_progress() {
while /bin/true; do
take_screenshot
echo -n .
sleep 1
done
}
take_screenshot() {
import -window root $SCREENSHOT
sudo chown $USER $SCREENSHOT
}
check_root() {
if ! sudo -n /bin/true 2>/dev/null; then
echo super user is required for installation.
sudo /bin/true
fi
}
check_installation() {
if [ -e /usr/share/crossworks_for_arm_4.1/bin/crossstudio ]; then
echo Crossworks installed.
exit 0
fi
}
cleanup() {
kill "$PROGRESS_PID" &> /dev/null
kill "$CROSSWORKS_PID" &> /dev/null
kill "$XVFB_PID" &> /dev/null
kill "$KEYS_PID" &> /dev/null
}
trap cleanup EXIT
check_installation
start_xvfb
install_crossworks
check_installation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment