#!/bin/bash
set -e

if [ -z $DISPLAY ]; then
	echo "eagle: cannot open display" >&2
	exit 1
fi

# Prevent eagle from crashing if the composite extension is enabled.
export XLIB_SKIP_ARGB_VISUALS=1

if [ -r /usr/share/eagle/bin/eagle.key ]; then
	exec -a /usr/share/eagle/bin/eagle /usr/lib/eagle/bin/eagle "$@"
fi

if [ ! -d ~/.eagle ]; then
	mkdir ~/.eagle
	ln -s /usr/share/eagle/* ~/.eagle
	rm -f ~/.eagle/bin
	mkdir ~/.eagle/bin
	ln -s /usr/share/eagle/bin/* ~/.eagle/bin
fi

exec -a ~/.eagle/bin/eagle /usr/lib/eagle/bin/eagle "$@"
