File: update-ispell-dictionary

package info (click to toggle)
ispell 3.1.20.0-4.3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,684 kB
  • ctags: 966
  • sloc: ansic: 8,374; makefile: 2,023; yacc: 1,711; lisp: 1,613; sh: 1,053; objc: 385; csh: 215; python: 112
file content (170 lines) | stat: -rw-r--r-- 4,461 bytes parent folder | download | duplicates (3)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/sh
# $Id: update-ispell-dictionary,v 1.9 2003/06/17 14:27:17 david Exp $
#
# Bash script to select a new ispell default dictionary.
# Included as part of the Debian/GNU Linux ispell package.
#
# Kenneth MacDonald <K.MacDonald@ed.ac.uk> September 1995
#
# This script makes extensive use of 'update-alternatives' from the
# dpkg suite of programs.  Priority information for each of the
# alternatives is stored, read and acted upon by 'update-alternatives'.
# IMPORTANT: All ispell dictionary packages should install themselves
# with priority 10.  This script will then assign priority 999 to the
# chosen default, and re-run update-alternatives.

# note we use "/bin/echo -e" because -e is not standard (e.g.
# ash builting echo doesn't support it).

set -e

if [ $(id -u) != 0 ]; then
  echo $0: You must run this as root.
  exit 1
fi

NEWERSCRIPT=/usr/sbin/select-default-ispell

# If $NEWERSCRIPT (provided by the dictionaries-common
# package) is there, use that instead; the previous methods (the
# rest of this file) are obsolete.

if [ -x $NEWERSCRIPT ] ; then
    echo $0 is now obsolete, and will eventually
    echo be removed.  I am running its replacement, 
    echo $NEWERSCRIPT, for you...
    sh -c $NEWERSCRIPT
    exit $?
fi

# Do nothing if running in noninteractive mode
DEBIAN_FRONTEND=`echo "$DEBIAN_FRONTEND" | tr A-Z a-z`
if [ "$DEBIAN_FRONTEND" = "noninteractive" ]; then
    echo "$0: Running in noninteractive mode.  Not doing anything."
    exit 0
fi

# Find the current dictionaries on the system, and format into a menu.

get_dictionaries() {
 dictionaries=`/usr/sbin/update-alternatives --display ispell-dictionary.hash \
	| grep priority \
	| sort -r -n -k 4 \
	| sed 's+/usr/lib/ispell/++' \
	| sed 's/\.hash//' \
	| awk '{printf ("\\\t[%d] %s\\\n", NR, $1)}'`

 if [ ! -z "$dictionaries" ]
 then 
  num_dictionaries=`/bin/echo -e $dictionaries | grep -c '\[.*\]'`
 else
  num_dictionaries='None'
 fi

}
# ----------------------------------------------------------------------

# Find the current default dictionary, set to None if none found.

get_default () {
 current_default=`/usr/sbin/update-alternatives \
	--display ispell-dictionary.hash \
	| grep 999 \
	| sed 's+/usr/lib/ispell/++' \
	| sed 's/\.hash//' \
	| awk '{print $1}'`

 if [ -z $current_default ]
 then
  current_default='None'
 fi
}

# ----------------------------------------------------------------------

# Keep prompting for default until valid choice made.

choose_default ()
{
 /bin/echo
 /bin/echo -e $dictionaries

 echo -n "Select the number of the default dictionary [1] "
 read num
 selected_num=${num:-1}

 selected=`/bin/echo -e $dictionaries | grep "\[$selected_num\]" | awk '{print $2}'`

 if [ -z $selected ]
 then
   /bin/echo -e "\nInvalid choice - try again!\n"
   choose_default
 fi
}

# ----------------------------------------------------------------------

# Promote the selected dictionary to be the default.

make_default ()
{
 echo -n "Making $selected the default ispell dictionary..."

 update-alternatives --quiet --install /usr/lib/ispell/default.hash \
	ispell-dictionary.hash /usr/lib/ispell/$selected.hash 999 \
	--slave /usr/lib/ispell/default.aff ispell-dictionary.aff \
	/usr/lib/ispell/$selected.aff > /dev/null

 echo "done."
}

# ----------------------------------------------------------------------

# Demote the old default dictionary.

demote_default ()
{
 echo -n "Demoting $current_default (old default)..."

 update-alternatives --quiet --install /usr/lib/ispell/default.hash \
	ispell-dictionary.hash /usr/lib/ispell/$current_default.hash 10 \
	--slave /usr/lib/ispell/default.aff ispell-dictionary.aff \
	/usr/lib/ispell/$current_default.aff > /dev/null

 echo "done."
}

# ----------------------------------------------------------------------

/bin/echo -e "Please wait while I search for ispell dictionaries..."
get_dictionaries

if [ $num_dictionaries != "None" ]
then

 get_default

 if [ $num_dictionaries != "1" ]
 then
  choose_default
 else
   selected=`/bin/echo -e $dictionaries | grep '\[.*\]' | awk '{print $2}'`
   echo There is only one installed dictionary - $selected.
 fi

 if ([ $current_default != 'None' ] && [ $current_default != $selected ])
 then
  demote_default
 fi

 if [ $selected != $current_default ]
 then
  make_default
 else
  echo No change - $selected is already the default.
 fi

else
 echo "WARNING: No ispell dictionaries found -- you should install one."
 exit
fi