aboutsummaryrefslogtreecommitdiffstats
path: root/tools/textify.sh
blob: b9a7e7ecd05e7f3a47a445df83893b9778cfd9f8 (plain)
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
#!/bin/bash
#
# $Id$
#
# Text file conversion script for packaging on Windows
#
# This script copies a text file from a source to a destination,
# converting line endings and adding a ".txt" filename extension
# if needed. If the destination is a directory the source file
# name is used. Newer files will not be overwritten.
#
# The destination file should be double-clickable and usable
# when Notepad is the default editor.

SRC="$1"
DST="$2"

err_exit () {
    for str in "$@" ; do
        echo "ERROR: $str"
    done
    echo "Usage:"
    echo "  $0 <source file> <destination file>"
    echo ""
    exit 1
}

if [ -z "$SRC" -o -z "$DST" ] ; then
    err_exit
fi

if [ ! -r "$SRC" ] ; then
    err_exit "Can't read $SRC"
fi    

if [ -f "$DST" -a "$DST" -nt "SRC" ]; then
    exit 0
fi

if [ -d "$DST" ] ; then
    DSTBASE=`basename "$SRC" txt`
    DST="$DST/$DSTBASE.txt"
else
    DSTDIR=`dirname "$DST"`
    DSTBASE=`basename "$DST" txt`
    DST="$DSTDIR/$DSTBASE.txt"
fi

cp "$SRC" "$DST"
u2d "$DST"