File: pipecp

package info (click to toggle)
pipemeter 1.1.3-1
  • links: PTS
  • area: main
  • in suites: bullseye, jessie-kfreebsd, sid, stretch, wheezy
  • size: 352 kB
  • ctags: 67
  • sloc: ansic: 651; sh: 230; makefile: 46
file content (63 lines) | stat: -rwxr-xr-x 1,899 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
#
#  Copy a file with pipemeter
# 
#  Copyright Clint Byrum 2003, All Rights Reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
#  ---
#  $Id: pipecp 54 2004-01-07 06:39:30Z clint $
#
echo "Note: pipecp is *alpha* quality software. You have been warned."

SRC=$1
DST=$2
SRCBASE=`basename $SRC`

if [ -d $SRC ] ; then
  # TODO: don't use tar for this
  echo -n "Finding size of source dir.."
  # TODO: maybe pipedu ?
  # XXX: requires gnu du
  SRCSIZE=`du -sk ${SRC} | awk {'print $1'}`
  echo "${SRCSIZE}k"
  if [ -d $DST ] ; then
    if [ ! -e $DST/$SRCBASE ] ; then
      mkdir $DST/$SRCBASE
      DST=$DST/$SRCBASE
    fi 
    tar cf - -C $SRC . | pipemeter -s ${SRCSIZE}k | tar xf - -C $DST
  elif [ -f $DST ] ; then
    # NO! ;)
    echo "$0: cannot overwrite non-directory with directory"
    exit 1
  elif [ ! -e $DST ] ; then
    # doesn't exist, lets create it
    mkdir $DST 
    cd $DST && tar cf - -C $SRC . | pipemeter -s ${SRCSIZE}k | tar xf - -C $DST
  fi
elif [ -f $SRC ] ; then
  if [ -d $DST ] ; then
    OUTFILE=$DST/$SRCBASE
  else
    OUTFILE=$DST
  fi
  echo pipemeter -f $SRC \> $OUTFILE
  pipemeter -f $SRC > $OUTFILE
fi
[ $? ] && exit 1
echo "SHOULD be removing $SRC ... but I'm chicken"