493446b
#!/bin/bash
493446b
493446b
shopt -s nullglob
493446b
493446b
GIMPTOOL="@GIMPTOOL@"
493446b
GIMPPLUGINDIR="`"$GIMPTOOL" --gimpplugindir`"
493446b
EXITVAL=0
493446b
493446b
showhelp () {
493446b
	cat << EOF
493446b
Usage: gimp-plugin-mgr <mode> [<pluginname> [<pluginname> [...]]
493446b
Mode can be:
493446b
--install|-i:	install plugin(s)
493446b
--uninstall|-u:	uninstall plugin(s)
493446b
--help|-h:	show this message
493446b
EOF
493446b
}
493446b
493446b
install_uninstall () {
493446b
    local action="$1"
493446b
    shift
493446b
    local plugins="$@"
493446b
    pushd "$GIMPPLUGINDIR/plug-ins" >&/dev/null
493446b
    if [ "$plugins" == "*" ]; then
493446b
        pushd "/etc/gimp/plugins.d" >&/dev/null
493446b
        plugins=""
493446b
        for file in *; do
493446b
            plugins="$plugins ${file%.conf}"
493446b
        done
493446b
        popd >&/dev/null
493446b
    fi
493446b
493446b
	for plugin in $plugins; do
493446b
        PLUGINFILE=
493446b
        if [ ! -r "/etc/gimp/plugins.d/${plugin}.conf" ]; then
493446b
            echo "gimp-plugin-mgr: can't read /etc/gimp/plugins.d/${plugin}.conf" >&2
493446b
            EXITVAL=$(( $EXITVAL + 1 ))
493446b
            continue
493446b
        fi
493446b
        . "/etc/gimp/plugins.d/${plugin}.conf"
493446b
        case "$action" in
493446b
        install)
493446b
            if [ ! "$PLUGINFILE" ]; then
493446b
                echo "gimp-plugin-mgr: PLUGINFILE not defined for $plugin" >&2
493446b
                EXITVAL=$(( $EXITVAL + 1 ))
493446b
                continue
493446b
            fi
493446b
            ln -snf "$PLUGINFILE" "$GIMPPLUGINDIR/plug-ins/$plugin"
493446b
            ;;
493446b
        uninstall)
493446b
            if [ ! -L "$GIMPPLUGINDIR/plug-ins/$plugin" ]; then
493446b
                echo "gimp-plugin-mgr: $GIMPPLUGINDIR/plug-ins/$plugin not a symbolic link" >&2
493446b
                EXITVAL=$(( $EXITVAL + 1 ))
493446b
                continue
493446b
            fi
493446b
            rm -f "$plugin"
493446b
            ;;
493446b
        esac
493446b
	done
493446b
    popd >&/dev/null
493446b
}
493446b
493446b
case "$1" in
493446b
--install|-i)
493446b
    shift
493446b
	install_uninstall install "$@"
493446b
	;;
493446b
--uninstall|-u)
493446b
    shift
493446b
	install_uninstall uninstall "$@"
493446b
	;;
493446b
*)
493446b
	if [ "$1" != "--help" -a "$1" != "-h" ]; then
493446b
		EXITVAL=1
493446b
	fi
493446b
	showhelp
493446b
	;;
493446b
esac
493446b
493446b
exit $EXITVAL