# $Id: ghc-pkg-register.sh 273 2009-12-14 20:34:36Z elkner $ #i postinstall=${SCRIPTDIR}/ghc-pkg-register.sh #i postremove=${SCRIPTDIR}/ghc-pkg-register.sh #i package.conf=${TMPBUILD}/package.conf FGREP=/usr/bin/fgrep GREP=/usr/bin/grep SED=/usr/bin/sed # ghc installed ? if [ -z "$PKG_INSTALL_ROOT" -o "$PKG_INSTALL_ROOT" = "/" ]; then PARAM="" else PARAM="-R $PKG_INSTALL_ROOT" fi pkginfo -q $PARAM LNFghc if [ $? -ne 0 ]; then echo "Unable to locate the GHC package.conf file" echo "Unable to register ${PKGINST}." exit 1 fi DIR=`pkgparam $PARAM LNFghc BASEDIR` VER=`pkgparam $PARAM LNFghc VERSION` PKGCONF="${PKG_INSTALL_ROOT}/${DIR}/lib/ghc-${VER}/package.conf" if [ ! -f "$PKGCONF" ]; then echo "${PKG_INSTALL_ROOT}/${DIR}/lib/ghc-${VER}/package.conf seems not to be file - exiting." exit 2 fi FNAME=`basename $0` IDIR=`dirname $0` if [ ! -f "${IDIR}/package.conf" ]; then echo "Missing ${IDIR}/package.conf - exiting" exit 2 fi T_PKGCONF=`mktemp -t XXXX` if [ "$FNAME" = "postremove" ]; then echo "Trying to unregister modules ..." UNREGISTER="true" else echo "Trying to register modules ..." fi $SED -e "s,@CLIENT_BASEDIR@,${CLIENT_BASEDIR},g" \ "${IDIR}/package.conf" >$T_PKGCONF if [ $? -ne 0 ]; then echo "Unable to prepare package.conf - exiting." rm -f $T_PKGCONF exit 2 fi # Now we have all we need and may proceed as in ghc-pkg-register.sh TMP=`mktemp -t XXXXX` TMP2=`mktemp -t XXXX` if [ "$UNREGISTER" = "true" ]; then cp "$PKGCONF" $TMP fi $FGREP -s InstalledPackageInfo "$T_PKGCONF" if [ $? -ne 0 ]; then echo "\"${IDIR}/package.conf\" seems not to be a ghc package.conf snippet - exiting" rm -f $T_PKGCONF $TMP $TMP2 exit 2 fi $FGREP InstalledPackageInfo ${T_PKGCONF} | while read LINE ; do LOOKUP=`echo $LINE | $SED -e 's,^\[, ,' -e 's/, versionTags.*//'` NAME=`echo $LOOKUP | $SED -e 's,.*PackageName ",,' -e 's,".*= ,,'` if [ "$UNREGISTER" = "true" ]; then $FGREP -v "$LOOKUP" $TMP >$TMP2 cmp -s $TMP $TMP2 if [ $? -eq 0 ]; then echo "\"$NAME\" is not registered - skipped" else echo "\"$NAME\" unregistered" cp $TMP2 $TMP fi else $FGREP -s "$LOOKUP" "$PKGCONF" if [ $? -ne 0 ]; then echo "Registering \"$NAME\" in package.conf" echo " ${LINE}," >>$TMP else echo "\"$NAME\" is already registered - skipped" fi fi done if [ "$UNREGISTER" = "true" ]; then cmp -s $TMP "$PKGCONF" if [ $? -ne 0 ]; then # file has been changed # remove trailing , in the last line and append to the original one $SED -e '$d' $TMP | $SED -e '$ s/,$//' >$TMP2 echo ']' >>$TMP2 cp $TMP2 "$PKGCONF" else echo "$PKGCONF unchanged" fi elif [ -s "$TMP" ]; then # remove last line with a ] and add a trailing , to the new last line $SED -e '$d' "$PKGCONF" | $SED -e '$ s/$/,/' >$TMP2 # remove trailing , in the last line and append to the original one $SED -e '$ s/,$//' $TMP >>$TMP2 echo ']' >>$TMP2 cp $TMP2 "$PKGCONF" else echo "$PKGCONF unchanged" fi rm -f $TMP $TMP2 $T_PKGCONF