Initial revision
[citadel.git] / citadel / dnetsetup
1 #!/bin/sh
2
3 # dnetsetup version 1.0
4 # Copyright (c)1998 by Art Cancro / All rights reserved.
5 # This program is distributed under the terms of the GNU General Public
6 # License.  See copyright.txt for more information.
7 #
8 # dnetsetup requires Savio Lam's "dialog" program to perform its interactive
9 # dialogs.  This program is standard on most Linux systems, and should be
10 # easy enough to get on other systems.
11
12 cleanup() {
13         rm -f $tempfile $tempfile2 $menucmd 2>/dev/null
14         exit
15         }
16
17
18 roomlist() {
19         node=$1
20         
21         ./netsetup roomlist $1 >$tempfile 2>&1
22         $DIALOG --textbox $tempfile $menuheight $menuwidth
23         }
24
25
26 unshare() {
27         node=$1
28
29         ./netsetup roomlist $node >$tempfile
30         numrooms=`cat $tempfile |wc -l`
31         sed s/\ /\\\\\ /g <$tempfile | sed s/$/\ \"\"/g >$tempfile2
32         echo $DIALOG --menu \"Select the room you wish to stop sharing\" \
33                 $menuheight $menuwidth $numrooms \
34                 `cat $tempfile2` >$menucmd
35         if sh $menucmd 2>$tempfile; then
36                 room_to_delete=`cat $tempfile`
37
38                 if $DIALOG --yesno "Are you sure you wish to stop sharing $room_to_delete ?" 5 $menuwidth ; then
39                         if ./netsetup unshare $node "$room_to_delete" 2>$tempfile; then
40                                 $DIALOG --msgbox "$room_to_delete has been unshared." 5 $menuwidth
41                         else
42                                 $DIALOG --textbox $tempfile $menuheight $menuwidth
43                                 fi
44                         fi
45                 fi
46
47         }
48
49 do_share() {
50         node=$1
51
52         if $DIALOG --inputbox "Enter name of room to share:" \
53                 $menuheight $menuwidth 2>$tempfile ; then
54         
55                 room_to_share=`cat $tempfile`   
56                 if ./netsetup share $node "$room_to_share" 2>$tempfile; then
57                         $DIALOG --msgbox "$room_to_share has been added." 5 $menuwidth
58                 else
59                         $DIALOG --textbox $tempfile $menuheight $menuwidth
60                         fi
61
62                 fi
63         }
64
65
66 edit_this_node() {
67         node=$1
68         choice=nothing_yet
69
70         while [ $choice != EXIT ]
71         do
72                 if $DIALOG --menu "Editing $node" $menuheight $menuwidth 4 \
73                         LIST    "List currently shared rooms" \
74                         SHARE   "Add a shared room" \
75                         UNSHARE "Stop sharing a room" \
76                         EXIT    "Return to main menu" 2>$tempfile; then
77                                 choice=`cat $tempfile`
78                         else
79                                 choice="EXIT"
80                                 fi
81
82                 [ $choice = "LIST" ] && roomlist $node
83                 [ $choice = "SHARE" ] && do_share $node
84                 [ $choice = "UNSHARE" ] && unshare $node
85
86                 done
87         }
88
89
90 edit_a_node() {
91
92         ./netsetup nodelist >$tempfile
93         numnodes=`cat $tempfile |wc -l`
94         sed s/$/\ \"\"/g <$tempfile >$tempfile2
95         echo $DIALOG --menu \"Select the node you wish to edit\" \
96                 $menuheight $menuwidth $numnodes \
97                 `cat $tempfile2` >$menucmd
98         if sh $menucmd 2>$tempfile; then
99                 system_to_edit=`cat $tempfile`
100                 edit_this_node $system_to_edit
101         else
102                 true
103                 fi
104         }
105
106
107
108
109
110
111 delete_network_nodes() {
112
113         ./netsetup nodelist >$tempfile
114         numnodes=`cat $tempfile |wc -l`
115         sed s/$/\ \"\"/g <$tempfile >$tempfile2
116         echo $DIALOG --menu \"Select the node you wish to delete\" \
117                 $menuheight $menuwidth $numnodes \
118                 `cat $tempfile2` >$menucmd
119         if sh $menucmd 2>$tempfile; then
120                 system_to_delete=`cat $tempfile`
121
122                 if $DIALOG --yesno "Are you sure you wish to delete $system_to_delete ?" 5 $menuwidth ; then
123                         if ./netsetup deletenode $system_to_delete 2>$tempfile; then
124                                 $DIALOG --msgbox "$system_to_delete has been deleted." 5 $menuwidth
125                         else
126                                 $DIALOG --textbox $tempfile $menuheight $menuwidth
127                                 fi
128                         fi
129                 fi
130
131         }
132
133
134 add_a_node() {
135         node=$1
136
137         if $DIALOG --inputbox "Enter name of new node:" \
138                 $menuheight $menuwidth 2>$tempfile ; then
139         
140                 new_node=`cat $tempfile`        
141                 if ./netsetup addnode $new_node 2>$tempfile; then
142                         $DIALOG --msgbox "$new_node has been created." 5 $menuwidth
143                 else
144                         $DIALOG --textbox $tempfile $menuheight $menuwidth
145                         fi
146
147                 fi
148         }
149
150
151 # Main loop...
152 clear
153 tempfile=/tmp/dnetsetup.$$.1
154 tempfile2=/tmp/dnetsetup.$$.2
155 menucmd=/tmp/dnetsetup.$$.3
156 menuheight=20
157 menuwidth=72
158 DIALOG=dialog
159 while true
160 do
161         if $DIALOG --menu "Citadel/UX Network Setup" $menuheight $menuwidth 4 \
162                 EDIT    "View or change a network node" \
163                 ADD     "Add a new network node" \
164                 DELETE  "Delete a network node" \
165                 EXIT    "Exit from Network Setup" \
166                 2>$tempfile; then
167                         choice=`cat $tempfile`
168                 else
169                         choice=EXIT
170                 fi
171         rm -f $tempfile
172
173         [ $choice = "EXIT" ] && cleanup
174         [ $choice = "DELETE" ] && delete_network_nodes
175         [ $choice = "EDIT" ] && edit_a_node
176         [ $choice = "ADD" ] && add_a_node
177
178         done