tkpkg revision 4996
1#!/usr/local/bin/wish -f
2#$Id: tkpkg,v 1.1 1994/01/06 08:16:20 jkh Exp $
3#
4#$Log: tkpkg,v $
5# Revision 1.1  1994/01/06  08:16:20  jkh
6# Cleaning house.
7#
8# Revision 1.1  1993/09/04  17:06:09  jkh
9# Added Rich's wish front-end.
10#
11# Revision 1.6  1993/09/03  23:37:22  rich
12# warn user if no tar archives are found in the current directory.
13# removed the revision string from the lower text frame.
14#
15# Revision 1.5  1993/09/03  15:48:04  rich
16# glob for .tar.gz, .tar.z and .tar.Z looking for archives
17#
18# Revision 1.4  1993/08/28  15:53:59  rich
19# added version and date info to lower text window.
20#
21# Revision 1.3  1993/08/28  15:47:12  rich
22# filtered out ^Ls in pkg_* output.
23#
24#
25set pkgname ""
26wm title . "Package Installation"
27#--------------------------------------------------------------
28# The top level main window, consisting of a bar of buttons and a list
29# of packages and a description of the current package.
30#--------------------------------------------------------------
31frame .menu -relief raised -borderwidth 1
32frame .frame -borderwidth 4
33
34scrollbar .frame.scroll -relief sunken -command ".frame.list yview"
35listbox .frame.list -yscroll ".frame.scroll set" -relief sunken -setgrid 1
36pack append .frame .frame.scroll {right filly} \
37        .frame.list {left expand fill}
38
39# build the lower window shoing the complete description of a pacage
40frame .f -borderwidth 4
41text .f.t -width 80 -height 20 -yscrollcommand ".f.s set" -relief sunken
42
43# Initially display instructions in this window.  Erase the
44# instructions and show the package description when the user clicks
45# on a package.
46# 
47.f.t insert end "Double click on a package above to see its
48complete description here."
49scrollbar .f.s -relief sunken -command ".f.t yview"
50pack append .f .f.s {right filly} .f.t {left expand fill}
51
52bind .frame.list <Double-Button-1> \
53    {foreach i [selection get] {do_description $i}}
54pack append .  .menu {top fill} \
55   .f {bottom expand fill} \
56   .frame {bottom expand fill}
57
58#----------------------------------------------------------------
59# Make menu bar:
60#----------------------------------------------------------------
61button .menu.inst -text "Install" \
62   -command "apply_to_pkg \"pkg_add -v\""
63button .menu.dein -text "Deinstall" \
64   -command "apply_to_pkg \"pkg_delete -v\""
65button .menu.installed -text "What is Installed?" \
66   -command "list_pkgs \"pkg_info -I -a |tr '	' ' '\""
67button .menu.available -text "What can I install?" \
68   -command "list_pkgs \"pkg_info -I -c [glob -nocomplain *.{tgz,tar.z,tar.gz,tar.Z}] |tr '	' ' '\""
69button .menu.cont -text "Contents?" \
70   -command "apply_to_pkg \"pkg_info -d -v\""
71button .menu.quit -text "Quit" -command "destroy ."
72button .menu.help -text "Help" -command "do_help"
73
74pack append .menu \
75  .menu.inst left \
76  .menu.dein left \
77  .menu.installed left \
78  .menu.available left \
79  .menu.cont left \
80  .menu.quit left \
81  .menu.help right
82#-------------------------------------------------------
83# Display the package description.
84#-------------------------------------------------------
85proc list_pkgs {s} {
86  set line ""
87  set f [eval "open {| sh -c \"$s\" } r"]
88  .frame.list delete 0 end
89  while {[gets $f line] > 0} {
90    .frame.list insert end $line
91  }
92  close $f
93}
94
95# display the list of available packages
96set archives [glob -nocomplain *.{tgz,tar.z,tar.gz,tar.Z}]
97if {$archives == ""} {
98  .frame.list delete 0 end
99 .frame.list insert end "Warning: no compressed tar archives files found."
100} else {
101  list_pkgs "pkg_info -I -c $archives |tr '	' ' '"
102}
103
104#-------------------------------------------------------
105# Display the package description.
106#-------------------------------------------------------
107proc do_description {s} {
108  global pkgname
109  regexp {[^ 	]*} $s filename
110  set pkgname $filename
111  .f.t delete 0.0 end
112  set cmd "pkg_info -d $filename |tr -d ''"
113  set f [eval "open {| csh -c \"$cmd\" } r"]
114  while {![eof $f]} {
115    .f.t insert end [read $f]
116  }
117}
118#-------------------------------------------------------
119# package install window.
120#-------------------------------------------------------
121proc do_help {{w .help}} {
122  catch {destroy $w}
123  toplevel $w
124  wm title $w "Help"
125  wm iconname $w "Help"
126  button $w.ok -text OK -command "destroy $w"
127  message $w.t -relief raised -bd 2 \
128    -text "You can install, deinstall and list info on the available packages.  To select a package and see its complete description, press mouse button 1 over the package name.  To install a selected package, press the Install button.  To exit, press the \"Quit\" button."
129  pack append $w $w.ok {bottom fillx} $w.t {expand fill}
130}
131#-------------------------------------------------------
132# Apply a command to a package.
133#-------------------------------------------------------
134proc apply_to_pkg {s} {
135    apply_to_pkg_err $s ""
136}
137#-------------------------------------------------------
138# Apply a command to a package, with error stream redirection instructions.
139#-------------------------------------------------------
140proc apply_to_pkg_err {s errredir} {
141  global pkgname
142  .f.t delete 0.0 end
143  if {$pkgname == ""} {
144    .f.t insert end "You must double click on a package name first!"
145  } else {
146    apply_to_pkg_int "$s $pkgname" "2>&1"
147  }
148}
149proc apply_to_pkg_int {s errredir} {
150    .f.t delete 0.0 end
151    .f.t insert end "Running: $s\n"
152    set f [eval "open {| sh -c \"$s $errredir\" } r"]
153    while {![eof $f]} {
154      .f.t insert end [read $f 64]
155    }
156}
157#-------------------------------------------------------
158# Invoke an arbitrary command.
159#-------------------------------------------------------
160proc do_command {s} {
161  .f.t delete 0.0 end
162  .f.t insert end "Running: $s\n"
163  set f [eval "open {| $s} r"]
164  while {![eof $f]} {
165    .f.t insert end [read $f 64]
166  }
167}
168# local variables:
169# mode: csh
170# compile-command: ""
171# comment-start: "# "
172# comment-start-skip: "# "
173# end:
174