File: postrm.functions

package info (click to toggle)
tetex-base 3.0.dfsg.3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 239,592 kB
  • ctags: 10,610
  • sloc: xml: 103,461; perl: 9,398; ruby: 2,850; python: 1,551; php: 1,067; sh: 981; lisp: 494; makefile: 371; awk: 88
file content (129 lines) | stat: -rw-r--r-- 3,095 bytes parent folder | download | duplicates (2)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#################################################################
#    Function definitions included from file postrm.functions
#################################################################
# $Id: postrm.functions 2087 2006-12-19 12:42:02Z frank $
# Copyright 2004 Frank Kster <frank@debian.org>

remove_with_backups(){
  file=$1
  for extension in $DPKG_EXT; do
    rm -f $file$extension
  done
  rm -f $file
}

ucf_purge(){
  directory=/etc/texmf
  case "$1" in
    -d|--directory)
      directory=$2
      shift 2
      ;;
  esac
  filelist="$@"
  if [ -x /usr/bin/ucf ]; then # we can't rely on ucf being still installed in postrm
    purgefile(){ ucf --purge $1; remove_with_backups $1; }
  else
    purgefile(){ remove_with_backups $1; }
  fi
  for file in $filelist; do
    # does this filename start with a leading slash?
    relativename=${file#/}
    if [ ! "$file" = "$relativename" ]; then 
      # leading slash, change directory
      directory=`dirname $file`
      file=`basename $file`
    fi
    purgefile $directory/$file
  done
}

run_if_exist(){
  checkonly=false
  if [ "$1" = "-c" ] || [ "$1" = "--check-only" ]; then
    checkonly=true
    shift
  fi
  command=$1
  shift
  args="$@"
  binary=""
  test -x `which $command` && binary=`which $command` || true
  if [ $checkonly = false ]; then
    if [ -n "$binary" ]; then # else return 0 - no need to code that
      $command $args
    fi
  else
    if [ -n "$binary" ]; then return 0; else return 1; fi
  fi
}

debug(){
  true "$*"
}
# debug(){
#   echo -en "$*"
# }

postrm_abort_restore_file(){
  file=/etc/texmf/$1
  newname=`get_newfilename $1`
  debug $file
  test -f "$file" || return 0
  debug "handled\n"
  if [ -e $file.$PREINST_MOVE_EXT ]; then
    mv $file.$PREINST_MOVE_EXT $file
  else
    if [ -e /etc/texmf/$newname ]; then
      mv /etc/texmf/$newname $file 
    fi
  fi
}
postrm_abort_restore_file_ucf(){
  file=/etc/texmf/$1
  newname=`get_newfilename $1`
  debug $file
  test -f "$file" || return 0
  debug "handled\n"
  if [ -e $file.$PREINST_MOVE_EXT ]; then
    mv $file.$PREINST_MOVE_EXT $file
  else
    if [ -e /etc/texmf/$newname ]; then
      mkdir /etc/texmf/`dirname $newname`
      ucf /etc/texmf/$newname $file 
      rm /etc/texmf/$newname
    fi
  fi
}

# taken from tex-common's postrm-texlsr
dhit_check_run_without_errors ()
{
    silent=0
    if [ "$1" = "-silent" ] ; then
        silent=1
	shift
    fi
    if which "$1" >/dev/null; then
        tempfile=$(mktemp -p /tmp checkrun.XXXXXXXX)
        if [ $silent = 0 ] ; then
	    printf "Running '$*'.\nThis may take some time..."
	fi
        set +e
        if "$@" > $tempfile 2>&1 ; then
            rm -f $tempfile
            [ $silent = 0 ] && echo " done."
        else
            echo
            echo "$* failed. Output has been stored in"
            echo "$tempfile"
            echo "If tex-common is not configured you can ignore this error" \
                 "message!"
            echo "Otherwise, please include this file if you report a bug."
            echo
        fi
        set -e
    fi

    return 0
}