All pastes #30443 Raw Edit

Someone

public text v1 · immutable
#30443 ·published 2005-11-23 01:13 UTC
rendered paste body
#! /bin/bash

bzip_binary='/usr/bin/bzip2_bin'


Reallink_Decompress() {
  echo "operation mode: bzip decompress"
  realfile=`readlink $1`

  if [ "X$realfile" = "X" ] ; then
    echo "No symlink"
    realdir=`pwd`
    realfile=$1
    targetdir=`pwd`
  else

    realdir=`dirname $realfile`
    realfile=`basename $realfile`
    targetdir=`pwd`
  fi




  targetfile="copy-${realfile}"

  full_realfile="$realdir/$realfile"
  full_targetfile="${targetdir}/${targetfile}"


  if [ $realdir != $targetdir ] ; then
    echo "Symlink is dereferenced as: " $full_realfile
    #echo "real file: "$full_realfile
    #echo "target file: "$full_targetfile
  fi

  echo "copying... $realfile to $targetfile"
  cp -f $full_realfile $full_targetfile


  targetfile_unbzipped=`basename $full_targetfile .bz2`
  if [ -e $targetfile_unbzipped ] ; then
    echo "bunzip outputfile already excists: "$targetfile_unbzipped
    exit 0
  else
    echo "decompressing... $targetfile"
    $bzip_binary $full_targetfile -d

  fi
}

Compress() {
  echo "operation mode: bzip compress"
  echo "Now compressing... -f $* "
  $bzip_binary -f $*
}

if  [ $1 == "-d" ] ; then

  if [ $2 = "-d" ] ; then
    Reallink_Decompress $1
  fi

  if [ $1 = "-d" ] ; then
    Reallink_Decompress $2
  fi

 else
    Compress $*
 fi