cloney revision 5680
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#!/bin/ksh
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami# CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami#
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami# clone a directory to another using symlinks, in a very clunky way
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahramiif [ $# != 2 ]; then
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami echo "usage $0 srcdir destdir"
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami exit 1
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahramifi
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesrcdir=$1
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahramidestdir=$2
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali BahramiPATH=/usr/bin
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahramiecho symlink cloning $srcdir to $destdir
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahramicd ${srcdir}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfind . -type d | \
bfed486ad8de8b8ebc6345a8e10accae08bf2f45Ali Bahrami grep -v '^.$' | \
cd3e933325e68e23516a196a8fea7f49b1e497c3Ali Bahrami gsed -e 's,^\./,,' | \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while read i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mkdir -p "${destdir}/$i"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# Copy files and symlinks, making sure we ignore the gnu-patch backup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte# files, too.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegfind . -type f -o -type l | \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte egrep -v '~[0-9]+~' | \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gsed -e 's,^\./,,' | \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while read i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedo
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rm -f "${destdir}/$i"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ln -s "${srcdir}/$i" "${destdir}/$i"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte