Merge remote-tracking branch 'pootle/master'
[gammu.git] / utils / gammu-config
blob4a8e07cc7d750ad788ef444667dca604e9e539b5
1 #!/bin/bash
2 # Gammu configuration generator
3 # Copyright (C) 2003 - 2009 Michal Cihar <michal@cihar.com>
4 # vim: expandtab sw=4 ts=4 sts=4:
6 DIALOG_SIZE="8 70"
7 MENU_SIZE="0 0 0"
8 INPUT_SIZE="0 0"
9 FILE_SIZE="20 60"
10 CONFIG=~/.gammurc
11 NAME="Gammu configurator"
12 VERSION="0.4"
13 COPYRIGHT="Copyright (C) 2003 - 2009 Michal Cihar <michal@cihar.com>"
14 FORCE=0
16 # Some defaults:
18 D_PORT=/dev/mobile
19 D_MODEL=
20 D_CONNECTION=at19200
21 D_SYNCHRONIZETIME=yes
22 D_LOGFILE=
23 D_LOGFORMAT=nothing
24 D_LOCKING=
25 D_GAMMULOC=
27 TEMPFILE=`mktemp /tmp/gammu-config.XXXXXXXXXX`
29 showhelp() {
30 echo "$NAME $VERSION"
31 echo "$COPYRIGHT"
32 echo
33 echo "Usage: `basename $0` [-f|--force] [-c|--config config]"
34 echo
35 exit 100
38 cfgread() {
39 grep '^[[:space:]]*'$1'[[:space:]]*=' "$CONFIG"| sed 's/^[^=]*=[[:space:]]*\([^#;]*\)[#;]\?.*$/\1/'
42 while [ "$#" -ge 1 ] ; do
43 case "$1" in
44 -f|--force)
45 FORCE=1
47 -c|--config)
48 if [ "x$2" != "x" ] ; then
49 CONFIG="$2"
50 shift
51 else
52 showhelp
56 showhelp
58 esac
59 shift
60 done
62 if type dialog > /dev/null 2>&1 ; then
63 DIALOG=dialog
64 elif type cdialog > /dev/null 2>&1 ; then
65 DIALOG=cdialog
66 elif type whiptail > /dev/null 2>&1 ; then
67 DIALOG=whiptail
68 else
69 echo "You need dialog, cdialog or whiptail installed to make this work"
70 exit 1
73 if [ -f "$CONFIG" ] ; then
74 if [ ! -w "$CONFIG" ] ; then
75 $DIALOG --msgbox "Configuration file \"$CONFIG\" is not writable!" $DIALOG_SIZE
76 exit 2
79 if [ $FORCE -ne 1 ] ; then
80 $DIALOG --yesno "Configuration file \"$CONFIG\" exists.\nDo you still wish to configure Gammu?" $DIALOG_SIZE
81 if [ $? -eq 1 ] ; then
82 exit 0
86 $DIALOG --yesno "Configuration file \"$CONFIG\" exists.\nDo you wish to read defaults from it?" $DIALOG_SIZE
87 if [ $? -eq 0 ] ; then
88 echo "Parsing current Gammu configuration form \"$CONFIG\""
89 PORT=`cfgread port`
90 MODEL=`cfgread model`
91 CONNECTION=`cfgread connection`
92 SYNCHRONIZETIME=`cfgread synchronizetime`
93 LOGFILE=`cfgread logfile`
94 LOGFORMAT=`cfgread logformat`
95 LOCKING=`cfgread use_locking`
96 GAMMULOC=`cfgread gammuloc`
100 mainmenu() {
101 if [ $DIALOG = dialog ] ; then
102 EXTRA="--help-button --ok-label Edit --cancel-label Exit --extra-button --extra-label Save"
103 EXTRA_MENU=""
104 else
105 EXTRA=""
106 EXTRA_MENU="H Help S Save"
108 $DIALOG $EXTRA --menu "Current Gammu configuration" $MENU_SIZE \
109 P "Port (${PORT:-$D_PORT})" \
110 C "Connection (${CONNECTION:-$D_CONNECTION})" \
111 M "Model (${MODEL:-$D_MODEL})" \
112 D "Synchronize time (${SYNCHRONIZETIME:-$D_SYNCHRONIZETIME})" \
113 F "Log file (${LOGFILE:-$D_LOGFILE})" \
114 O "Log format (${LOGFORMAT:-$D_LOGFORMAT})" \
115 L "Use locking (${LOCKING:-$D_LOCKING})" \
116 G "Gammu localisation (${GAMMULOC:-$D_GAMMULOC})" \
117 $EXTRA_MENU \
118 2>"$TEMPFILE"
119 BUTTON=$?
120 ITEM=`cat "$TEMPFILE"`
121 if [ "$DIALOG" = whiptail -a "$BUTTON" = 0 ] ; then
122 if [ "$ITEM" = H ] ; then
123 BUTTON=2
124 elif [ "$ITEM" = S ] ; then
125 BUTTON=3
130 editP() {
131 if [ $DIALOG = dialog ] ; then
132 $DIALOG --fselect "${PORT:-$D_PORT}" $FILE_SIZE 2>"$TEMPFILE"
133 err=$?
134 else
135 err=255
137 if [ $err -eq 255 ] ; then
138 if $DIALOG --inputbox "Enter phone port" $INPUT_SIZE "${PORT:-$D_PORT}" 2>"$TEMPFILE" ; then
139 PORT=`cat "$TEMPFILE"`
141 elif [ $err -eq 0 ] ; then
142 PORT=`cat "$TEMPFILE"`
146 helpwin() {
147 $DIALOG --textbox /proc/self/fd/5 0 0 5<< EOT
148 # Port : in Windows/DOS: "com*:",
149 # (instead of "*" please put "1", "2", etc.)
150 # in other (Linux/Unix) "/dev/ttyS%"
151 # or "/dev/ircomm%" ("irda" connection)
152 # (instead of "%" please put "0", "1", "2", etc.)
153 # Model : use only, when Gammu doesn't recognize your phone model.
154 # Put it here. Example values: "6110", "6150", "6210", "8210"
155 # Connection : type of connection. Use "fbus" or "mbus" or "dlr3" or
156 # "irda" (Infrared over sockets) or "infrared" (DirectIR)
157 # or "at19200" (AT commands on 19200, 8 bits, None parity,
158 # 1 stop bit, no flow control) or "at115200" (AT commands on
159 # 115200, 8 bits, None parity, 1 stop bit, no flow control)
160 # or "atblue" (AT over BlueTooth) or "dlr3blue" (FBUS
161 # over BlueTooth)
162 # SynchronizeTime: if you want to set time from computer to phone during
163 # starting connection. Do not rather use this option when want
164 # to reset phone during connection (in some phones need to
165 # set time again after restart)
166 # Logfile : Use, when want to have logfile from communication.
167 # Logformat : What debug info and format should be used:
168 # "nothing" - no debug level, "text" - transmission dump in
169 # text format, "textall" - all possible info in text format,
170 # "errors" - errors in text format, "binary" - transmission
171 # dump in binary format
172 # Use_Locking : under Unix/Linux use "yes", if want to lock used device
173 # to prevent using it by other applications
174 # GammuLoc : name of localisation file
178 editgeneral() {
179 TITLE="$1"
180 VAR="$2"
181 shift
182 shift
184 if ( $DIALOG --menu "$TITLE" $MENU_SIZE "$@" 2>"$TEMPFILE" ) ; then
185 VALUE=`cat "$TEMPFILE"`
186 eval "$VAR='$VALUE'"
190 editC() {
191 editgeneral "Select your phone connection" CONNECTION \
192 at "" \
193 at19200 "" \
194 at115200 "" \
195 fbus "" \
196 fbus-nodtr "" \
197 fbusirda "" \
198 fbusdlr3 "" \
199 fbusdku5 "" \
200 mbus "" \
201 irdaphonet "" \
202 irdaat "" \
203 irdaobex "" \
204 dku2phonet "" \
205 dku5fbus2 "" \
206 dku5fbus2-nodtr "" \
207 bluerffbus "" \
208 bluerfphonet "" \
209 bluephonet "" \
210 bluerfat "" \
211 blueat "" \
212 phonetblue "" \
213 fbusblue "" \
214 fbuspl2303 "" \
218 editM() {
219 editgeneral "Select your phone model" MODEL \
220 "" "Automatic detection (use this if unsure)" \
221 at "AT Generic phones" \
222 alcatel "Alcatel BE5 (501,701)" \
223 7110 "Nokia 6210|6250|7110|7190" \
224 9210 "Nokia 9210" \
225 6110 "Nokia 3210|33x0|3410|51x0|5210|5510|61x0|82x0|88x0" \
226 6510 "Nokia 3510|6310|6310i|6510|8310|8910" \
227 NAUTO "Nokia with autodetection"
230 editD() {
231 editgeneral "Synchronize time with PC on each connect?" SYNCHRONIZETIME \
232 yes "" \
233 no ""
236 editF() {
237 if [ $DIALOG = dialog ] ; then
238 $DIALOG --fselect "${LOGFILE:-$D_LOGFILE}" $FILE_SIZE 2>"$TEMPFILE"
239 err=$?
240 else
241 err=255
243 if [ $err = 255 ] ; then
244 if ( $DIALOG --inputbox "Enter log file" $INPUT_SIZE "${LOGFILE:-$D_LOG_FILE}" 2>"$TEMPFILE" ) ; then
245 LOGFILE=`cat "$TEMPFILE"`
247 elif [ $err = 0] ; then
248 LOGFILE=`cat "$TEMPFILE"`
252 editO() {
253 editgeneral "Select log format" LOGFORMAT \
254 nothing "no debug level" \
255 text "transmission dump in text format" \
256 textdate "transmission dump in text format with date" \
257 textall "all possible info in text format" \
258 textalldate "all possible info in text format with date" \
259 errors "errors in text format" \
260 errorsdate "errors in text format with date" \
261 binary "transmission dump in binary format"
264 editL() {
265 editgeneral "Use device locking?" LOCKING \
266 yes "" \
267 no ""
270 editG() {
271 if [ $DIALOG = dialog ] ; then
272 $DIALOG --fselect "${GAMMULOC:-${D_GAMMULOC:-/}}" $FILE_SIZE 2>"$TEMPFILE"
273 err=$?
274 else
275 err=255
277 if [ $err = 255 ] ; then
278 if ( $DIALOG --inputbox "Enter localisation file" $INPUT_SIZE "${GAMMULOC:-${D_GAMMULOC:-/}}" 2>"$TEMPFILE" ) ; then
279 LOGFILE=`cat "$TEMPFILE"`
281 elif [ $err = 0] ; then
282 LOGFILE=`cat "$TEMPFILE"`
287 mainmenu
289 while [ $BUTTON -eq 0 -o $BUTTON -eq 2 ] ; do
290 if [ $BUTTON -eq 2 ] ; then
291 helpwin
292 else
293 edit$ITEM
296 mainmenu
297 done
299 if [ $BUTTON -eq 3 ] ; then
300 if [ -f "$CONFIG" -a $FORCE -ne 1 ] ; then
301 $DIALOG --yesno "Do you really wish to overwrite file \"$CONFIG\", with selected Gammu configuration?" $DIALOG_SIZE
302 if [ $? -eq 1 ] ; then
303 exit 0
306 echo save
307 cat > "$CONFIG" << EOT
308 # This is a generated gammurc file.
309 # It was generated by $NAME $VERSION
311 # In Unix/Linux : copy it into your home directory and name it .gammurc
312 # or into /etc and name it gammurc
313 # In Win32 : copy it into directory with Gammu.exe and name gammurc
315 # Port : in Windows/DOS: "com*:",
316 # (instead of "*" please put "1", "2", etc.)
317 # in other (Linux/Unix) "/dev/ttyS%"
318 # or "/dev/ircomm%" ("irda" connection)
319 # (instead of "%" please put "0", "1", "2", etc.)
320 # Model : use only, when Gammu doesn't recognize your phone model.
321 # Put it here. Example values: "6110", "6150", "6210", "8210"
322 # Connection : type of connection. Use "fbus" or "mbus" or "dlr3" or
323 # "irda" (Infrared over sockets) or "infrared" (DirectIR)
324 # or "at19200" (AT commands on 19200, 8 bits, None parity,
325 # 1 stop bit, no flow control) or "at115200" (AT commands on
326 # 115200, 8 bits, None parity, 1 stop bit, no flow control)
327 # or "atblue" (AT over BlueTooth) or "dlr3blue" (FBUS
328 # over BlueTooth)
329 # SynchronizeTime: if you want to set time from computer to phone during
330 # starting connection. Do not rather use this option when want
331 # to reset phone during connection (in some phones need to
332 # set time again after restart)
333 # Logfile : Use, when want to have logfile from communication.
334 # Logformat : What debug info and format should be used:
335 # "nothing" - no debug level, "text" - transmission dump in
336 # text format, "textall" - all possible info in text format,
337 # "errors" - errors in text format, "binary" - transmission
338 # dump in binary format
339 # Use_Locking : under Unix/Linux use "yes", if want to lock used device
340 # to prevent using it by other applications
341 # GammuLoc : name of localisation file
343 [gammu]
345 port = ${PORT:-$D_PORT}
346 model = ${MODEL:-$D_MODEL}
347 connection = ${CONNECTION:-$D_CONNECTION}
348 synchronizetime = ${SYNCHRONIZETIME:-$D_SYNCHRONIZETIME}
349 logfile = ${LOGFILE:-$D_LOGFILE}
350 logformat = ${LOGFORMAT:-$D_LOGFORMAT}
351 use_locking = ${LOCKING:-$D_LOCKING}
352 gammuloc = ${GAMMULOC:-$D_GAMMULOC}
354 $DIALOG --msgbox "Configuration saved to \"$CONFIG\"" $DIALOG_SIZE
357 rm -f "$TEMPFILE"