#!/bin/bash
set -e

# 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

cp -f /usr/lib/eagle/bin/eagle ~/.eagle/bin

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