]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/dialog/samples/copifuncs/admin.funcs
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / dialog / samples / copifuncs / admin.funcs
1 #!/bin/bash
2 # $Id: admin.funcs,v 1.2 2001/01/15 22:20:11 tom Exp $
3 #
4 #  ComeOn Point Functions! v0.9.2
5 #  - usate da vari altri moduli ComeOn Point...
6 #
7 #  AUTHOR: Beppe (beppe.dem@nsm.it)
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19 #  You should have received a copy of the GNU General Public License
20 #  along with this program; if not, write to the Free Software
21 #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #
23
24 # Args: source_file, domain, nldir
25 install_nodelist() {
26
27   NODELIST="$1"
28   FOR_DOMAIN="$2"
29   NODEDIR="$3"
30
31   dialog --backtitle "$TITLE" --infobox "Installo la nodelist '$NODELIST' per il domain $FOR_DOMAIN, attendere prego..." 0 0
32
33   cp "$NODELIST" $NODEDIR/$FOR_DOMAIN.ndl
34   chown fnet.uucp $NODEDIR/$FOR_DOMAIN.ndl
35
36   echo "y" | su -l fnet -c "ifindex" >/dev/null
37 }
38
39 # Args: source, dest
40 add_alias() {
41
42   SOURCE=$1
43   DEST=$2
44   ALIASES=/etc/aliases
45   ENTRY="`grep $SOURCE: $ALIASES`"
46
47   dialog --backtitle "$TITLE" --infobox "Creo un alias per redirigere le mail per $SOURCE a $DEST ..." 0 0
48
49   if [ ! "$ENTRY" ]
50   then
51     echo "$SOURCE: $DEST" >>$ALIASES
52   else
53     OLDDEST="`echo $ENTRY | cut -f2 -d:`"
54     mkstemp alias
55     sed /"$SOURCE:"/s/"$OLDDEST"/" $DEST"/ $ALIASES >$tmp_alias
56     cat $tmp_alias >$ALIASES
57     rm $tmp_alias
58   fi
59   mkaliases >/dev/null
60
61
62 # Args: Areas_pathname, newsgroup, area_ftn, description [, expire_days]
63 # Returns: 1 - innd not running
64 #          2 - already existing newsgroup
65 #          3 - already existing ftn_area
66 create_newsgroup() {
67
68   AREAS="$1"
69   NEWSGROUP="$2"
70   AREA="$3"
71   DESCRIPTION="$4"
72   EXPIRE_DAYS="$5"
73
74   NEWSGROUPS=~news/newsgroups
75   EXPIRECTL=~news/expire.ctl
76
77   dialog --backtitle "$TITLE" --infobox "Creo il newsgroup $NEWSGROUP per contenere i messaggi dell'area $AREA..." 0 0
78
79   if [ ! "`ps ax | grep ~news/etc/innd`" ]
80   then
81     return 1
82   fi
83
84   if [ "`cut $NEWSGROUPS -f1 | cut -f1 -d\  | grep -x $NEWSGROUP`" ]
85   then
86     return 2
87   fi
88
89   if [ "`cut $AREAS -f1 | cut -f1 -d\  | grep -x $AREA`" ]
90   then
91     return 3
92   fi
93
94   su -l news -c "bin/ctlinnd newgroup $NEWSGROUP" >/dev/null
95   echo -e "$NEWSGROUP\t$DESCRIPTION" >> $NEWSGROUPS
96   echo -e "$AREA\t$NEWSGROUP\t`echo $NEWSGROUP | cut -f1 -d.`" >> $AREAS
97
98   if [ "$EXPIRE_DAYS" ]; then
99     echo "$NEWSGROUP:A:2:$EXPIRE_DAYS:$EXPIRE_DAYS" >> $EXPIRECTL
100   fi
101
102   chown news.news $NEWSGROUPS $EXPIRECTL
103   chmod 440 $EXPIRECTL
104   chown fnet.uucp $AREAS
105 }
106
107 # Returns: 0 if ok, 1 if (innd not running), 2 if (no that newsgroup)
108 # Args: Areas_pathname, newsgroup
109 rmgroup() {
110
111   AREAS=$1
112   NEWSGR=$2
113   NEWSGROUPS=~news/newsgroups
114   EXPIRE=~news/expire.ctl
115
116   dialog --backtitle "$TITLE" --infobox "Elimino il newsgroup $NEWSGR ed i messaggi in esso contenuti, attendere prego. Questa operazione potrebbe durare alcuni minuti." 0 0
117
118   if [ ! "`ps x | grep ~news/etc/innd`" ]
119   then
120     return 1
121   fi
122
123   if [ ! "`cut -f1 $NEWSGROUPS | cut -f1 -d\  | grep -x $NEWSGR`" ]
124   then
125     return 2
126   else
127
128 # Updating newsgroups file
129     if [ -f $NEWSGROUPS ]
130     then
131       mkstemp groups
132       mv $NEWSGROUPS $NEWSGROUPS~
133       grep -v $NEWSGR $NEWSGROUPS~ >$tmp_groups
134       mv $tmp_groups $NEWSGROUPS
135     else
136       :> $NEWSGROUPS
137     fi
138     chown news.news $NEWSGROUPS
139
140 # Updating Areas file
141     if [ -f $AREAS ]
142     then
143       mkstemp areas
144       mv $AREAS $AREAS~
145       grep -v $NEWSGR $AREAS~ >$tmp_areas
146       mv $tmp_areas $AREAS
147     else
148       :> $AREAS
149     fi
150     chown fnet.uucp $AREAS
151
152 # Updating expire.ctl file
153     if [ -f $EXPIRE ]
154     then
155       mkstemp expire
156       mv $EXPIRE $EXPIRE~
157       grep -v "$NEWSGR:" $EXPIRE~ >$tmp_expire
158       mv $tmp_expire $EXPIRE
159     else
160       :> $EXPIRE
161     fi
162     chown news.news $EXPIRE
163     chmod 444 $EXPIRE
164 # Remove pending articles
165     echo -e "\n$NEWSGR:A:0:0:0" >>$EXPIRE
166     su -l news -c "bin/news.daily" >/dev/null
167     mkstemp expire
168     grep -v $NEWSGR $EXPIRE >$tmp_expire
169     mv $tmp_expire $EXPIRE
170     chown news.news $EXPIRE
171     chmod 444 $EXPIRE
172
173 # Updating active file
174     su -l news -c "bin/ctlinnd rmgroup $NEWSGR" >/dev/null
175   fi
176 }
177
178 # Args: newsgroups_wildmat, days_to_keep
179 set_expire_time() {
180
181         NEWSGROUP="$1"
182         KEEPDAYS="$2"
183         EXPIRE=~news/expire.ctl
184
185         dialog --backtitle "$TITLE" --infobox "Imposto a $KEEPDAYS il numero di giorni di mantenimento dei messaggi del newsgroup $NEWSGROUP..." 0 0
186
187         if [ ! -f $EXPIRE ]
188         then
189                 :> $EXPIRE
190
191         elif [ "`cut $EXPIRE -s -f1 -d: | grep -x $NEWSGROUP`" ]
192         then
193                 mkstemp expire
194                 grep -v "$NEWSGROUP:" $EXPIRE >$tmp_expire
195                 mv $tmp_expire $EXPIRE
196         fi
197         echo -e "\n$NEWSGROUP:A:2:$KEEPDAYS:$KEEPDAYS" >>$EXPIRE
198         chown news.news $EXPIRE
199         chmod 444 $EXPIRE
200 }