File: update.sh

package info (click to toggle)
tex-guy 1.2.4-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,676 kB
  • ctags: 2,778
  • sloc: ansic: 26,147; sh: 8,358; makefile: 663; awk: 78; perl: 63
file content (39 lines) | stat: -rwxr-xr-x 691 bytes parent folder | download | duplicates (3)
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
#! /bin/sh
# Usage:  update TARGET NEW 
#    Update TARGET file if its contents is different from NEW file.
#    If the their contents are the same, timestamp of TARGET file
#    never changed. 
#
#    NOTE 1: NEW file is deleted if two files are the same.
#    NOTE 2: TARGET file is deleted if two files are not the same.

EXEC=0

case X-$1 in
  X--x)
    shift
    EXEC=1
    ;;
esac

TARGET=$1
NEW=$2

if [ ! -f $NEW ] ; then
  echo "Not found: $NEW"
  exit 1;
fi

if cmp -s $TARGET $NEW 2>/dev/null; then 
  rm -f $NEW;
  echo "$TARGET is unchanged";
else
  rm -f $TARGET; 
  mv -f $NEW $TARGET;
  case $EXEC in
  1)
    chmod a+x $TARGET
    ;;
  esac
  echo "$TARGET is created"; 
fi