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