File 0002-Run-LDraw-application-after-checking-creating-of-LDR.patch of Package ldraw-library

From e74a0f8fdbd6444316492a315d24e8bd0dfec6f9 Mon Sep 17 00:00:00 2001
From: Jiri Bohac <jbohac@suse.cz>
Date: Wed, 9 Dec 2015 19:15:03 +0100
Subject: [PATCH 2/2] Run LDraw application after checking/creating of
 $LDRAWHOME directory

This is a wrapper for all the programs that are part of the
linux-ldraw project.  The system LDraw library is installed in
/usr/share/ldraw To allow users to have their own unofficial
parts, a custom ldconfig.ldr or other custom files, all the
programs are configured to use ~/.ldraw as the LDraw library
path by setting the LDRAWDIR environment variable.

If this directory does not exist, it is created and the
contents of the system-wide ldraw library is symlinked there.

All the linux-ldraw packages are supposed to suffix their
binary name with .bin and create a symlink named with the
original binary name pointing to this script
---
 ldraw-wrapper | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100755 ldraw-wrapper

diff --git a/ldraw-wrapper b/ldraw-wrapper
new file mode 100755
index 0000000..46f4649
--- /dev/null
+++ b/ldraw-wrapper
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# Run LDraw application after checking/creating of $LDRAWHOME directory
+
+# This is a wrapper for all the programs that are part of the
+# linux-ldraw project.  The system LDraw library is installed in
+# /usr/share/ldraw To allow users to have their own unofficial
+# parts, a custom ldconfig.ldr or other custom files, all the
+# programs are configured to use ~/.ldraw as the LDraw library
+# path by setting the LDRAWDIR environment variable.
+#
+# If this directory does not exist, it is created and the
+# contents of the system-wide ldraw library is symlinked there.
+#
+# All the linux-ldraw packages are supposed to suffix their
+# binary name with .bin and create a symlink named with the
+# original binary name pointing to this script
+
+
+function die() {
+	ERROR="ERROR: $1"
+	if [ -t 0 ] ; then
+		echo "$ERROR" >&2
+	else
+		xmessage "$ERROR"
+	fi
+	exit 1
+}
+
+
+APPLICATION="$(which -- "${0##*/}.bin")" || die "unknown application"
+LDRAWHOME="${HOME}/.ldraw"
+LDRAWSYS="/usr/share/ldraw"
+
+function create_ldraw_dir() {
+	local LDRAWHOME="$1"
+	echo "Creating LDraw directory $LDRAWHOME ."
+	mkdir "$LDRAWHOME" || die "Cannot create ${LDRAWHOME}. You may want to set the LDRAWDIR environment variable to point to a copy of the LDraw library."
+}
+
+function fill_ldraw_dir() {
+	local LDRAWHOME="$1"
+	for d_full in "${LDRAWSYS}"/*; do
+		d="${d_full##*/}"
+		if [[ ! -e "${LDRAWHOME}/${d}" ]]; then
+			echo "Creating symlink ${LDRAWHOME}/${d} -> ${LDRAWSYS}/${d}:"
+			ln -s "${LDRAWSYS}/${d}" "${LDRAWHOME}/${d}" || die "Cannot create symlink ${LDRAWHOME}/${d} ."
+		elif  [[ ! -L "${LDRAWHOME}/${d}" ]] || [[ $(readlink "${LDRAWHOME}/${d}") != "${LDRAWSYS}/${d}" ]]; then
+			echo "Warning: $LDRAWHOME/$d is not a symlink to the system LDraw library."
+		fi
+	done
+	mkdir -p "${LDRAWHOME}/unofficial/{p,parts}"
+}
+
+
+# main()
+
+if [ -z "${LDRAWDIR}" ] ; then
+	if [ ! -d "$LDRAWHOME" ] ; then
+		if [ -e "$LDRAWHOME" ] ; then
+			die "Cannot create $LDRAWHOME directory."
+		else
+			create_ldraw_dir "$LDRAWHOME"
+		fi
+	fi
+	fill_ldraw_dir "$LDRAWHOME"
+	export LDRAWDIR="${LDRAWHOME}"
+fi
+
+exec $APPLICATION "$@"
-- 
2.8.1
openSUSE Build Service is sponsored by