File: sdate.in

package info (click to toggle)
sdate 0.7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 212 kB
  • sloc: sh: 3,027; ansic: 146; makefile: 39; perl: 18
file content (115 lines) | stat: -rwxr-xr-x 1,985 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh

usage () {
cat - >&2 <<EOF
sdate, never ending September date
   usage: sdate [-e|--epoch yyyy-mm] [-c|--covid vv] [-l|--lib sdatelib]
                [-h|--help] [-v|--version] [--] [command]
EOF
  exit 1
}

# strip /bin/sdate to find install prefix
PREFIX=@prefix@
BINDIR=@bindir@
    
LIB=lib@sdate_transformed@.so.0
PATHS=@libdir@:${PREFIX}/lib64/libsdate

libfound=no

GETOPTEST=`getopt --version`
case $GETOPTEST in
getopt*) # GNU getopt
    TEMP=`getopt -l lib: -l covid: -l epoch: -l version -l help -- +l:f:e:c:s:ub:vh "$@"`
    ;;
*) # POSIX getopt ?
    TEMP=`getopt l:f:e:c:s:ub:vh "$@"`
    ;;
esac

if test "$?" -ne 0; then
  usage
fi

eval set -- "$TEMP"

while test "X$1" != "X--"; do
  case "$1" in
    -l|--lib)
       shift
       LIB=`eval echo "$1"`
       PATHS=
       ;;
    -e|--epoch)
       shift
       SDATE_EPOCH="$1"
       export SDATE_EPOCH
       ;;
    -c|--covid)
       shift
       case "$1" in
	 19)
	    SDATE_EPOCH="2020-03"
	    export SDATE_EPOCH
	    ;;
	 *)
	    echo "Unknown COVID variant - supported variants are: 19"
	    exit 1
	    ;;
       esac
       ;;
    -v|--version)
       echo "sdate version @VERSION@"
       exit 0
       ;;
    -h|--help)
       usage
       ;;
  esac
  shift
done

shift #get rid of the '--'

# make sure the preload is available
if [ -n "$PATHS" ]
then
    for dir in `echo $PATHS | sed 's/:/ /g'`
    do
	if test -r "$dir/$LIB"
	then
	    libfound=yes
	fi
    done
else
    if test -r "$LIB"
    then
	libfound=yes
    fi
fi

if test $libfound = no
then
    echo >&2 "sdate: preload library not found in $PATHS, aborting."
    exit 1
fi

# Keep other library paths
if test -n "$LD_LIBRARY_PATH"; then
  PATHS="$PATHS:$LD_LIBRARY_PATH"
fi
# ...and preloaded libs
if test -n "$LD_PRELOAD"; then
  LIB="$LIB $LD_PRELOAD"
fi

if test -z "$*"; then
  LD_LIBRARY_PATH="$PATHS" LD_PRELOAD="$LIB" date
  RESULT=$?
else
  LD_LIBRARY_PATH="$PATHS" LD_PRELOAD="$LIB" "$@"
  RESULT=$?
fi

exit $RESULT