1 #!/usr/local/bin/wish -f
5 wm title . "Package Installation"
6 #--------------------------------------------------------------
7 # The top level main window, consisting of a bar of buttons and a list
8 # of packages and a description of the current package.
9 #--------------------------------------------------------------
10 frame .menu -relief raised -borderwidth 1
11 frame .frame -borderwidth 4
13 scrollbar .frame.scroll -relief sunken -command ".frame.list yview"
14 listbox .frame.list -yscroll ".frame.scroll set" -relief sunken -setgrid 1
15 pack append .frame .frame.scroll {right filly} \
16 .frame.list {left expand fill}
18 # build the lower window shoing the complete description of a pacage
19 frame .f -borderwidth 4
20 text .f.t -width 80 -height 20 -yscrollcommand ".f.s set" -relief sunken
22 # Initially display instructions in this window. Erase the
23 # instructions and show the package description when the user clicks
26 .f.t insert end "Double click on a package above to see its
27 complete description here."
28 scrollbar .f.s -relief sunken -command ".f.t yview"
29 pack append .f .f.s {right filly} .f.t {left expand fill}
31 bind .frame.list <Double-Button-1> \
32 {foreach i [selection get] {do_description $i}}
33 pack append . .menu {top fill} \
34 .f {bottom expand fill} \
35 .frame {bottom expand fill}
37 #----------------------------------------------------------------
39 #----------------------------------------------------------------
40 button .menu.inst -text "Install" \
41 -command "apply_to_pkg \"pkg_add -v\""
42 button .menu.dein -text "Deinstall" \
43 -command "apply_to_pkg \"pkg_delete -v\""
44 button .menu.installed -text "What is Installed?" \
45 -command "list_pkgs \"pkg_info -I -a |tr ' ' ' '\""
46 button .menu.available -text "What can I install?" \
47 -command "list_pkgs \"pkg_info -I -c [glob -nocomplain *.{tgz,tar.z,tar.gz,tar.Z}] |tr ' ' ' '\""
48 button .menu.cont -text "Contents?" \
49 -command "apply_to_pkg \"pkg_info -d -v\""
50 button .menu.quit -text "Quit" -command "destroy ."
51 button .menu.help -text "Help" -command "do_help"
56 .menu.installed left \
57 .menu.available left \
61 #-------------------------------------------------------
62 # Display the package description.
63 #-------------------------------------------------------
66 set f [eval "open {| sh -c \"$s\" } r"]
67 .frame.list delete 0 end
68 while {[gets $f line] > 0} {
69 .frame.list insert end $line
74 # display the list of available packages
75 set archives [glob -nocomplain *.{tgz,tar.z,tar.gz,tar.Z}]
76 if {$archives == ""} {
77 .frame.list delete 0 end
78 .frame.list insert end "Warning: no compressed tar archives files found."
80 list_pkgs "pkg_info -I -c $archives |tr ' ' ' '"
83 #-------------------------------------------------------
84 # Display the package description.
85 #-------------------------------------------------------
86 proc do_description {s} {
88 regexp {[^ ]*} $s filename
91 set cmd "pkg_info -d $filename |tr -d '
\f'"
92 set f [eval "open {| csh -c \"$cmd\" } r"]
94 .f.t insert end [read $f]
97 #-------------------------------------------------------
98 # package install window.
99 #-------------------------------------------------------
100 proc do_help {{w .help}} {
104 wm iconname $w "Help"
105 button $w.ok -text OK -command "destroy $w"
106 message $w.t -relief raised -bd 2 \
107 -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."
108 pack append $w $w.ok {bottom fillx} $w.t {expand fill}
110 #-------------------------------------------------------
111 # Apply a command to a package.
112 #-------------------------------------------------------
113 proc apply_to_pkg {s} {
114 apply_to_pkg_err $s ""
116 #-------------------------------------------------------
117 # Apply a command to a package, with error stream redirection instructions.
118 #-------------------------------------------------------
119 proc apply_to_pkg_err {s errredir} {
122 if {$pkgname == ""} {
123 .f.t insert end "You must double click on a package name first!"
125 apply_to_pkg_int "$s $pkgname" "2>&1"
128 proc apply_to_pkg_int {s errredir} {
130 .f.t insert end "Running: $s\n"
131 set f [eval "open {| sh -c \"$s $errredir\" } r"]
133 .f.t insert end [read $f 64]
136 #-------------------------------------------------------
137 # Invoke an arbitrary command.
138 #-------------------------------------------------------
139 proc do_command {s} {
141 .f.t insert end "Running: $s\n"
142 set f [eval "open {| $s} r"]
144 .f.t insert end [read $f 64]
149 # compile-command: ""
150 # comment-start: "# "
151 # comment-start-skip: "# "