You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
836 B
Bash
41 lines
836 B
Bash
#!/usr/bin/env bash
|
|
|
|
# Enable strict mode
|
|
set -euo pipefail
|
|
|
|
# Attempt to create a specific directory as a crude lock
|
|
machine_dir=$HOME/486
|
|
lock_dir=$machine_dir/.locked
|
|
if ! mkdir "$lock_dir" 2> /dev/null
|
|
then
|
|
echo "Lockout failed. The machine may already be running." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Initialize globals used by handle-trap
|
|
signals='INT TERM'
|
|
|
|
# Usage: handle-trap [exit_code]
|
|
#
|
|
# Removes the lock upon script exit or signal
|
|
#
|
|
# Positional arguments:
|
|
# exit_code Optional exit code for which to trigger a script exit
|
|
function handle-trap
|
|
{
|
|
trap - EXIT $signals
|
|
rm -r "$lock_dir"
|
|
if [[ $# -gt 0 ]]
|
|
then
|
|
exit "$1"
|
|
fi
|
|
}
|
|
|
|
# Set the trap
|
|
trap handle-trap EXIT
|
|
trap 'handle-trap 1' $signals
|
|
|
|
# Change into the machine directory and start the machine
|
|
cd "$machine_dir"
|
|
86Box.app/Contents/MacOS/86Box
|