File: install.wish

package info (click to toggle)
addressbook 0.7-13
  • links: PTS
  • area: main
  • in suites: potato
  • size: 960 kB
  • ctags: 160
  • sloc: tcl: 6,002; perl: 528; ansic: 362; awk: 205; sh: 123; makefile: 95
file content (611 lines) | stat: -rw-r--r-- 16,622 bytes parent folder | download | duplicates (4)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
#!/usr/bin/tcl
#
set home $env(HOME)
set possible_languages "english german french spanish dutch swedish italian finnish"

set installas root
set language english

set def(mycountry,english) "USA"
set def(mycountry,german) "D"
set def(mycountry,french) "F"
set def(mycountry,spanish) "E"
set def(mycountry,dutch) "NL"
set def(mycountry,swedish) "S"
set def(mycountry,italian) "I"
set def(mycountry,finnish) "SF"
set def(myareacode,english) "1212"
set def(myareacode,german) "089"
set def(myareacode,french) "1"
set def(myareacode,spanish) "91"
set def(myareacode,dutch) "020"
set def(myareacode,swedish) "0"
set def(myareacode,italian) "02"
set def(myareacode,finnish) "0"

set def(installin,root) "/usr/local/bin"
set def(installin,user) "$home/bin"
set def(libdir,root) "/usr/local/lib/addressbook"
set def(libdir,user) "$home/addressbook"
set def(configfile,root) "$def(libdir,root)/addressbook.config"
set def(configfile,user) "$def(libdir,user)/addressbook.config"
set def(myconfigfile,root) "~/.addressbook.config"
set def(myconfigfile,user) "~/.addressbook.config"
set def(adrfile,root) "$def(libdir,root)/addresses.dat"
set def(adrfile,user) "$def(libdir,user)/addresses.dat"
set def(adrfile2,root) "~/.addresses.dat"
set def(adrfile2,user) ""

set all_languagedependant "mycountry myareacode"
set all_rootdependant "installin libdir configfile myconfigfile adrfile adrfile2"
set all_progs "wish mpage latex dvips perl gawk"
set all_nodependant "address tel fax letter email"
set all_things "$all_languagedependant $all_rootdependant $all_progs $all_nodependant"

set mes(mycountry) "Country you are in"
set mes(myareacode) "Telephone area code"
set mes(installin) "Where should addressbook be installed"
set mes(libdir) "Librarydirectory"
set mes(configfile) "Global Configurationfile"
set mes(myconfigfile) "Private Configurationfile"
set mes(adrfile) "Default Addressfile"
set mes(adrfile2) "Second Addressfile"
set mes(wish) "Where is wish"
set mes(mpage) "Where is mpage"
set mes(latex) "Where is latex"
set mes(dvips) "Where is dvips"
set mes(perl) "Where is perl"
set mes(gawk) "Where is gawk"
set mes(address) "for all information"
set mes(tel) "for telephone number"
set mes(fax) "for fax number"
set mes(letter) "for postal address"
set mes(email) "for email address"


set use_old 0

proc main {} {
    header
    lookforold
}


proc header {} {
    wm title . "Addressbook installation"
    wm iconname . "Addressbook installation"

    frame .h -relief raised -borderwidth 2
    pack .h -fill both
    label .h.l1 -text "Addressbook 0.7"
    label .h.l2 -text "Copyright (C) 1995, 1996, 1997 Clemens Durka"
    label .h.l3 -text "Installation procedure"
    pack .h.l1 .h.l2 .h.l3
}


proc lookforold {} {
    if [file exists tmp/last_config] {
	frame .k
	pack .k
	
	label .k.space -text " "
	label .k.l1 -text "I see that you have configured addressbook previously."
	label .k.l2 -text "Do you want to use these values?"
	pack .k.space .k.l1 .k.l2
 
	frame .k.b
	pack .k.b
	button .k.b.1 -text "Yes, use old values" -command { destroy .k ; set use_old 1 ; load_config ; rootoruser }
	button .k.b.2 -text "No, reset to default" -command { destroy .k ; set use_old 0 ; rootoruser }
	button .k.b.3 -text "Cancel installation" -command {destroy . ; exit}
	pack .k.b.1 .k.b.2 .k.b.3 -fill both
    } else {
	rootoruser
    }
}


proc rootoruser {} {
    global possible_languages

    frame .i
    pack .i

    label .i.space -text " "
    pack .i.space
    message .i.m1 -aspect 1500 -text "You have two possibilities to install addressbook: as root or as user"
    message .i.m2 -aspect 580 -text "root: will install it in a public directory like \
	    /usr/local/bin, so that all user of the system can use it. However \
	    everyone can have a personal configfile to override defaults. (recommended) \
	    You have to be root now, to install as root. If not, please \
	    exit now and restart the installation as root."
    
    message .i.m3 -aspect 900 -text "user: will install it in your private homedirectory. \
	    Only recommended, if you have no root privileges and your sysadmin has \
	    no time to install it."

    pack .i.m1 .i.m2 .i.m3
    
    frame .i.1 -relief ridge -borderwidth 2
    pack .i.1
    label .i.1.l -text "Install as"
    radiobutton .i.1.1 -text "root" -variable installas -value root
    radiobutton .i.1.2 -text "user" -variable installas -value user
    pack .i.1.l .i.1.1 .i.1.2 -side left

    frame .i.2 -relief ridge -borderwidth 2
    pack .i.2
    label .i.2.l -text "Default language the program will run"
    pack .i.2.l
    foreach c $possible_languages {
	radiobutton .i.2.$c -text $c -variable language -value $c
	pack .i.2.$c -side left
    }

    frame .i.b
    pack .i.b
    button .i.b.1 -text "Continue" -command { destroy .i ; setvalues }
    button .i.b.2 -text "Cancel installation" -command {destroy . ; exit}
    pack .i.b.1 .i.b.2 -side left
}


proc setvalues {} {
    global installasroot possible_languages all_things mes use_old

    if !$use_old {
	set_defaults
    }

    frame .j
    pack .j

    label .j.1 -text "Please use a countrycode like USA, CDN, D, F, GB, I, N, ZA, IL"
    label .j.2 -text "(for correct omission for local calls)"
    label .j.3 -text  "including 1 for USA, like 1212 for New York, 1 for Paris, 089 for Mnchen)"
    label .j.4 -relief raised -text "For the following questions, the default answers should work."
    label .j.5 -relief raised -text "The following programs are not absolutely needed"
    label .j.6 -relief raised -text "Names for the comandline programms for a fast lookup without GUI"

    foreach a $all_things {
	frame .j.$a
	pack .j.$a
	label .j.$a.l -text $mes($a) -width 35
	entry .j.$a.e -width 35 -relief sunken
	pack .j.$a.l .j.$a.e -side left
    }

    pack .j.1 -after .j.mycountry
    pack .j.2 -after .j.myareacode
    pack .j.3 -after .j.2
    pack .j.4 -after .j.3 -fill both
    pack .j.5 -after .j.wish -fill both
    pack .j.6 -after .j.gawk -fill both

    frame .j.b
    pack .j.b
    button .j.b.1 -text "Continue" -command { get_entries ; destroy .j ; do_configure }
    button .j.b.2 -text "Reload defaults" -command { set_defaults ; load_entries }
    button .j.b.3 -text "Save values" -command { get_entries ; save_config }
    button .j.b.4 -text "Cancel installation" -command {destroy . ; exit}
    pack .j.b.1 .j.b.2 .j.b.3 .j.b.4 -side left

    load_entries
}


proc set_defaults {} {
    global all_progs all_languagedependant all_rootdependant all_nodependant
    global language installas value def

    foreach p $all_progs {
	if [catch {set value($p) [exec which $p]} ] {
	    set value($p) {}
	}
    }

    foreach p $all_languagedependant {
	set value($p) $def($p,$language)
    }

    foreach p $all_rootdependant {
	set value($p) $def($p,$installas)
    }

    foreach p $all_nodependant {
	set value($p) addr-$p
    }
    set value(address) address
}

proc load_entries {} {
    global all_things value
    
    foreach a $all_things {
	.j.$a.e delete 0 end
	.j.$a.e insert 0 $value($a)
    }
}

proc get_entries {} {
    global all_things value
    foreach a $all_things {
	set value($a) [.j.$a.e get]
    }
}

proc save_config {} {
    global value all_things language installas

    catch {exec mkdir "tmp"}
    set f [open "tmp/last_config" w]
    puts $f "language $language"
    puts $f "installas $installas"
    foreach a $all_things {
	puts $f "value($a) $value($a)"
    }
    close $f
}


proc load_config {} {
    global value language installas
    
    set f [open "tmp/last_config" r]
    while {![eof $f]} {
	set line [gets $f]
	set [lindex $line 0] [lindex $line 1]
    }
}


proc do_configure {} {
    global value language
    
    save_config

    if [catch {set f [open "tmp/addressbook" w]} result] {
	puts "Error on writing [exec pwd]/tmp/addressbook: $result"
	exit
    } else {
	puts $f "#!$value(wish) -f"
	puts $f "#  ^^^^^^^^^^^^^^^^^^^^^^^ modify the path to find wish on your computer#"
	puts $f "set configfile \"$value(configfile)\""
	puts $f "set myconfigfile \"$value(myconfigfile)\""
	
	if [catch {set g [open "bin/addressbook" r]} result] {
	    puts "Error on reading [exec pwd]/bin/addressbook: $result"
	    exit
	} else {
	    # Ignore the first 6 lines
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    
	    while {![eof $g]} {
		puts $f [gets $g]
	    }
	    close $g
	}
	close $f
	catch {exec chmod 0755 tmp/addressbook}
    }
    
    
    if [catch {set f [open "tmp/address" w]} result] {
	puts "Error on writing [exec pwd]/tmp/address: $result"
	exit
    } else {
	puts $f "#!$value(perl)"
	puts $f "#  ^^^^^^^^^^^^^^^^^^^^^^^ modify the path to find perl on your computer#"
	puts $f "\$HOME=\$ENV{HOME};" 
	puts $f "\$CONFIGFILE=\"$value(configfile)\";"
	puts $f "\$MYCONFIGFILE=\"$value(myconfigfile)\";"
	puts $f "\$LIBDIR=\"$value(libdir)\";"
	
	if [catch {set g [open "bin/address" r]} result] {
	    puts "Error on reading [exec pwd]/bin/address: $result"
	    exit
	} else {
	    # Ignore the first 8 lines
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    set line [gets $g]
	    
	    while {![eof $g]} {
		puts $f [gets $g]
	    }
	    close $g
	}
	close $f
	catch {exec chmod 0755 tmp/address}
    }
    
    
    if [catch {set f [open "tmp/addressbook.config" w]} result] {
	puts "Error on writing [exec pwd]/tmp/addressbook.config: $result"
	exit 1
    } else {
	if [catch {set g [open "lib/addressbook.config" r]} result] {
	    puts "Error on reading [exec pwd]/lib/addressbook.config: $result"
	    exit 1
	} else {
	    while {![eof $g]} {
		set line [gets $g]
		switch -glob $line {
		    "language*" {
			set line "language $language"
		    }
		    "mycountry*" {
			set line "mycountry $value(mycountry)"
		    }
		    "myareacode*" {
			set line "myareacode $value(myareacode)"
		    }
		    "libdir*" {
			set line "libdir $value(libdir)"
		    }
		    "adrfile *" {
			set line "adrfile $value(adrfile)"
		    }
		    "adrfile1 *" {
			set line "adrfile1 $value(adrfile)"
		    }
		    "adrfile2 *" {
			if {$value(adrfile2) != ""} {
			    set line "adrfile2 $value(adrfile2)"
			}
		    }
		    "latex*" {
			set line "latex $value(latex)"
		    }
		    "mpage*" {
			set line "mpage $value(mpage)"
		    }
		    "dvips*" {
			set line "dvips $value(dvips)"
		    }
		    "gawk*" {
			set line "gawk $value(gawk)"
		    }
		}
		puts $f $line
	    }
	    close $g
	}
	close $f
    }
    
    # process addressbook.1
    if [catch {set f [open "tmp/addressbook.1" w]} result] {
	puts "Error on writing [exec pwd]/tmp/addressbook.1: $result"
	exit 1
    } else {
	if [catch {set g [open "addressbook.1.in" r]} result] {
	    puts "Error on reading [exec pwd]/addressbook.1.in: $result"
	    exit 1
	} else {
	    while {![eof $g]} {
		set line [gets $g]
		switch -glob $line {
		    ".BR address *" {
			set line ".BR $value(address) (1),"
		    }
		    ".BR tel *" {
			set line ".BR $value(tel) (1),"
		    }
		    ".BR email *" {
			set line ".BR $value(email) (1),"
		    }
		    ".BR fax *" {
			set line ".BR $value(fax) (1),"
		    }
		    ".BR letter *" {
			# note this is the last line, no comma
			set line ".BR $value(letter) (1)"
		    }
		}
		puts $f $line
	    }
	    close $g
	}
	close $f
    }

    # process address.1
    if [catch {set f [open "tmp/address.1" w]} result] {
	puts "Error on writing [exec pwd]/tmp/address.1: $result"
	exit 1
    } else {
	if [catch {set g [open "$value(address).1.in" r]} result] {
	    puts "Error on reading [exec pwd]/$value(address).1.in: $result"
	    exit 1
	} else {
	    while {![eof $g]} {
		set line [gets $g]
		switch -glob $line {
		    "*matchaddress*" {
			regsub "(.*)matchaddress(.*)" $line "\\1$value(address)\\2" $line
		    }
		    "*matchtel*" {
			regsub "(.*)matchtel(.*)" $line "\\1$value(tel)\\2" $line
		    }
		    "*matchfax*" {
			regsub "(.*)matchfax(.*)" $line "\\1$value(fax)\\2" $line
		    }
		    "*matchletter*" {
			regsub "(.*)matchletter(.*)" $line "\\1$value(letter)\\2" $line
		    }
		    "*matchemail*" {
			regsub "(.*)matchemail(.*)" $line "\\1$value(email)\\2" $line
		    }
		    # um, what happened to addr-birthday?
		}
		puts $f $line
	    }
	    close $g
	}
	close $f
    }


    frame .l
    pack .l

    label .l.space -text " "
    label .l.l1 -text "Addressbook is now configured."
    label .l.l2 -text "If you want, you can verify the files in the ./tmp directory."
    label .l.l3 -text " "
    label .l.l4 -text "Now addressbook will be installed."

    pack .l.space .l.l1 .l.l2 .l.l3 .l.l4
 
    frame .l.b
    pack .l.b
    button .l.b.1 -text "Continue installation" -command { destroy .l ; do_install }
    button .l.b.2 -text "Cancel installation" -command {destroy . ; exit}
    pack .l.b.1 .l.b.2 -side left
}

proc cpbak {from to} {
    # copy and backup
    if {[file exists $to]} {
	if [catch {exec mv $to $to.OLD} result] {
	    puts stderr "Error while making backup of old programm. $result"
	}
    }
    if [catch {exec cp $from $to} result] {
	puts "*** Please invoke 'cp $from $to'"
    }
}

proc mkd {dir} {
    if [catch {exec mkdir -p $dir} result] {
	if {![string match "*File exists*" $result]} {
	    puts "*** Please invoke 'mkdir $dir'"
	}
    }
}    

proc lnbak {from to} {
    # link and backup
    if {[file exists $to]} {
	if [catch {exec mv $to $to.OLD} result] {
	    puts stderr "Error while making backup of old programm. $result"
	}
    }
    if [catch {exec ln -s $from $to} result] {
	puts "*** Please invoke 'ln -s $from $to'"
    }
}

proc do_install {} {
    global value

    mkd $value(installin)

    cpbak tmp/addressbook $value(installin)/addressbook
    
    mkd $value(libdir)
    mkd $value(libdir)/bitmaps
    mkd $value(libdir)/sample

    cpbak tmp/addressbook.config $value(configfile)

    if [catch {
	foreach p "[glob lib/bitmaps/*]" {
	    exec cp $p $value(libdir)/bitmaps
	}
    } result ] {
	puts "*** Please invoke 'cp lib/bitmaps/* $value(libdir)/bitmaps'"
    }
    
    cpbak lib/countries $value(libdir)/countries

    if [catch {
	foreach p "[glob lib/*.translation] [glob lib/*.helptext]" {
	    exec cp $p $value(libdir)
	}
    } result ] {
	puts "*** Please invoke 'cp lib/*.translation lib/*.helptext $value(libdir)'"
    }
    
    if [catch {
	foreach p "sample/README [glob sample/*.dat] [glob sample/*.fmt]" {
	    exec cp $p $value(libdir)/sample
	}
    } result ] {
	puts "*** Please invoke 'cp tmp/* $value(libdir)/sample'"
    }
    
    cpbak tmp/address $value(installin)/$value(address)

    lnbak $value(address) $value(installin)/$value(tel)
    lnbak $value(address) $value(installin)/$value(fax)
    lnbak $value(address) $value(installin)/$value(email)
    lnbak $value(address) $value(installin)/$value(letter)

    cpbak MANUAL $value(libdir)/MANUAL
    cpbak REGISTRATION $value(libdir)/REGISTRATION

    frame .m
    pack .m
    label .m.space -text " "
    label .m.l1 -text "Addressbook is now installed."
    label .m.l2 -text "If something went wrong, try to invoke the corresponding command"
    label .m.l3 -text "manually and restart the installationprocedure after the problem has been fixed."
    label .m.l4 -text " "
    pack .m.space .m.l1 .m.l2 .m.l3 .m.l4

    if {![file exists $value(libdir)/addresses.dat] &&
        ![file exists $value(libdir)/addresses.dat.fmt]} {
	    cpbak lib/addresses.dat $value(libdir)/addresses.dat
	    cpbak lib/addresses.dat.fmt $value(libdir)/addresses.dat.fmt
    } else {
	cpbak lib/addresses.dat $value(libdir)/addresses_sample.dat
	cpbak lib/addresses.dat.fmt $value(libdir)/addresses_sample.dat.fmt
	label .m.l5 -text "Existing addresses.dat found."
	label .m.l6 -text "No addressfile installed. You can find some in the"
	label .m.l7 -text "sample directory: $value(libdir)/sample"
	label .m.l8 -text " "
	pack .m.l5 .m.l6 .m.l7 .m.l8
    }
    if {![file exists $value(libdir)/addresses_usa.dat] &&
        ![file exists $value(libdir)/addresses_usa.dat.fmt]} {
	    cpbak lib/addresses_usa.dat $value(libdir)/addresses_usa.dat
	    cpbak lib/addresses_usa.dat.fmt $value(libdir)/addresses_usa.dat.fmt
    }

    label .m.l9 -text "To invoke the programm, just type addressbook."
    label .m.l10 -text "If you have problems, please read the manual first."

    pack .m.l9 .m.l10
 
    frame .m.b
    pack .m.b
    button .m.b.1 -text "OK" -command { destroy . }
    pack .m.b.1
}


main