12345678910111213141516171819202122232425262728293031323334353637383940 |
- #!/bin/sh
- set -e -x
- if [ -n "$PLUGIN_SOURCE" -a -n "$PLUGIN_TARGET" ]; then
- set "$PLUGIN_SOURCE" "$PLUGIN_TARGET"
- fi
- if [ ! -d "$1" ]; then
- echo "$1" must be a directory >&2
- exit 1
- fi
- SOURCE_TMP=`realpath "$1"`
- SOURCE_DIR=`dirname "$SOURCE_TMP"`
- SOURCE_BASE=`basename "$SOURCE_TMP"`
- if [ -f "$2" -a ! -L "$2" ]; then
- echo "$2" must not exist or be a symlink >&2
- exit 2
- fi
- TARGET_DIR_TMP=`dirname "$2"`
- if [ ! -d "$TARGET_DIR_TMP" ]; then
- echo "$TARGET_DIR_TMP" must be a directory >&2
- exit 3
- fi
- TARGET_DIR=`realpath "$TARGET_DIR_TMP"`
- TARGET_BASE=`basename "$2"`
- cd "$TARGET_DIR"
- DIR=`mktemp -d -p . "$TARGET_BASE".XXXXXX`
- mv "$SOURCE_DIR/$SOURCE_BASE" "$DIR"
- chmod a+rx "$DIR"
- ln -s "$DIR/$SOURCE_BASE" "$DIR.link"
- mv -T "$DIR.link" "$TARGET_BASE"
- for OTHER in "$TARGET_BASE".*; do
- test "$OTHER" -ef "$DIR" || rm -rf "$OTHER"
- done
|