File: postinst

package info (click to toggle)
xvmount 3.7-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 152 kB
  • ctags: 68
  • sloc: ansic: 448; sh: 255; makefile: 90
file content (125 lines) | stat: -rw-r--r-- 2,744 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
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
# Debian standard handling
set -e
case $1 in
abort-*) exit 0;;
esac

# Subroutine to convert an old format configuration file into a new one
convert_xvmounttab()
{
  OLDFILE=/etc/xvmounttab.bak
  NEWFILE=/etc/xvmounttab

  mv ${NEWFILE} ${OLDFILE}

  LIST=`sed -e '/^[[:space:]]*#/d' \
          -e 's/[[:space:]][[:space:]]*/ /g' \
          -e 's/^\([^ ]*\) \([^ ]*\) \([^ ]*\).*/\3*\1/' "${OLDFILE}"`

  # Loop over all devices
  j=0
  for i in ${LIST}
  do

    MNTNAME=`echo $i |sed -e 's/^.*\*//'`
    MOUNTDIR=`echo $i |sed -e 's/\*.*$//' -e 's/\/$//'`

    if egrep -q "${MOUNTDIR}"'(.*[[:space:]]+){2}.*,?user,?' /etc/fstab
    then
      ANAME[$j]=${MNTNAME}
      APOINT[$j]=${MOUNTDIR}
      j=`expr $j + 1`
    fi
    NENTRY=`expr $j - 1 || true`
  done

  # Check for valid lines
  if [ $j -eq 0 ]
  then
    FAILED=1
    mv ${OLDFILE} ${NEWFILE}
  else
    FAILED=0
    # Output to the configuration file
    cat >${NEWFILE} <<EOF
# Configuration file for xvmount (3.7)
# automatically generated from old format (3.6) configuration file
#
# Name  directory
EOF

    j=0
    while [ $j -le $NENTRY ]; do
      echo "${ANAME[$j]}"  "${APOINT[$j]}" >>${NEWFILE}
      j=`expr $j + 1`
    done
  fi
}

# Main program

# Source debconf library.
. /usr/share/debconf/confmodule

SYSTEMCONF='/etc/xvmounttab'
DONE=0

# Existence of old configuration file
if [ -r "$SYSTEMCONF" ]
then
  FORCE='--force'
  # Detect old format
  if egrep -q -e '^[[:space:]]*([^[:space:]#]+[[:space:]]+){4}[^[:space:]#]+' ${SYSTEMCONF}
  then
     db_get xvmount/convert_old_config
     if [ "$RET" = "true" ]
     then
       # Convert old file
       convert_xvmounttab
       if [ $FAILED -ne 0 ] 
       then
         db_input medium xvmount/convert_failed || true
       else
         db_input low xvmount/convert_succeeded || true
         DONE=1
       fi
       db_go
     fi
  else
  # Check for new format
    if egrep -q -e '^[[:space:]]*[^[:space:]#]+[[:space:]]+[^[:space:]#]+' ${SYSTEMCONF}
    then
      # new format config already present
      DONE=1
    fi
  fi
else
  # Create new configuration file
  FORCE=''
fi

# Now actually create new configuration file if necessary
if [ ${DONE} -eq 0 ]
then
  RET=0
  xvmountconfig ${FORCE} --automatic || RET=$?
  
  case $RET in 
  0) # check new format file
     if egrep -q -e '[^[:space:]#]+[[:space:]]+[^[:space:]#]+' ${SYSTEMCONF}
     then
       db_input low xvmount/generate_succeeded || true
     else
       db_input medium xvmount/generate_failed || true 
     fi
     ;;
  8) db_input medium xvmount/empty_fstab || true ;;
  *) db_input medium xvmount/generate_failed || true ;;
  esac
  db_go
fi

# Update menus
if [ -x /usr/bin/update-menus ]; then update-menus; fi