File: spruch.sh

package info (click to toggle)
fortunes-de 0.20-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,240 kB
  • ctags: 17
  • sloc: sh: 204; makefile: 87
file content (48 lines) | stat: -rwxr-xr-x 1,138 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
#!/bin/sh
FORTUNEPATH=/usr/local/games/
DATAPATH=/usr/local/share/games/fortunes
FORTUNE=${FORTUNEPATH}fortune
SCRIPT=`echo $0 | sed "s/^.*\/\([^\\]*\)/\1/"`
if [ _${SCRIPT}_ != _spruch_  -a _${SCRIPT}_ != _fortune_  ] ; then
  DB=/${SCRIPT}
fi

lang=$(locale | sed -ne 's/"$//;s/^LC_MESSAGES="\?//p')
l=$(sed -ne "s/^$(echo $lang | sed 's/\(\.\|\^\|\$\|\*\|\[\)/\\\1/g')[ 	]\+//ip" /etc/locale.alias)
[ -n "$l" ] && lang="$l"

# check for the currently used charmap
charmap=$(locale -k LC_CTYPE | sed -ne 's/^charmap="\([^"]*\)"$/\1/p')

# if there are any parameters check for given file name
found=0
if [ $# -gt 0 ] ; then
  for par in "$@" ; do
    if [ $found -eq 0 ] ; then
      if [ -e "$par" ] ; then
        DBPATH="$par"
	found=1
      fi
      if [ -e "${DATAPATH}/$par" ] ; then
        DBPATH="${DATAPATH}/$par"
	found=1
      fi
    fi
  done
fi
if [ $found -eq 0 ] ; then
  DBPATH="${DATAPATH}/de${DB}"
fi

if [ X"$1" = X"-x" ] ; then
   FORTUNE="${FORTUNE} ${DBPATH}"
   shift
else
   case "$lang" in
      de*)
      FORTUNE="${FORTUNE} ${DBPATH}"
     ;;
   esac
fi

$FORTUNE "$@" | iconv -f "iso-8859-1" -t "$charmap"