4e3819cf |
1 | #! /bin/sh |
2 | # |
3 | # $Id: makedev.unet.in,v 1.1 2001/01/25 22:03:39 mdw Exp $ |
4 | # |
5 | # Make usernet devices |
6 | # |
7 | # (c) 1998 Mark Wooding |
8 | # |
9 | |
10 | #----- Licensing notice ----------------------------------------------------- |
11 | # |
12 | # This program is free software; you can redistribute it and/or modify |
13 | # it under the terms of the GNU General Public License as published by |
14 | # the Free Software Foundation; either version 2 of the License, or |
15 | # (at your option) any later version. |
16 | # |
17 | # This program is distributed in the hope that it will be useful, |
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | # GNU General Public License for more details. |
21 | # |
22 | # You should have received a copy of the GNU General Public License |
23 | # along with this program; if not, write to the Free Software Foundation, |
24 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | |
26 | #----- Revision history ----------------------------------------------------- |
27 | # |
28 | # $Id: makedev.unet.in,v 1.1 2001/01/25 22:03:39 mdw Exp $ |
29 | |
30 | # --- Configuration stuff --- |
31 | |
32 | unet_major=@MAJORDEV@ |
33 | unet_transMinor=@TRANSMINOR@ |
34 | unet_persistent=@NPERSIST@ |
35 | unet_mode=600 |
36 | |
37 | # --- Sanity check --- |
38 | |
39 | case `uname -s` in |
40 | [Ll]inux) ;; |
41 | *) |
42 | echo >&2 "$0: this program is Linux-specific" ;; |
43 | esac |
44 | |
45 | # --- Sort out command line arguments --- |
46 | |
47 | while [ $# -gt 0 ]; do |
48 | opt="$1"; shift; |
49 | case "$opt" in |
50 | |
51 | # --- Help requests --- |
52 | |
53 | -h|-he|-hel|-help | --h|--he|--hel|--help) |
54 | cat <<EOF |
55 | makedev.unet [OPTIONS...] |
56 | |
57 | Constructs usernet device nodes. |
58 | |
59 | The usernet device allows userspace processes to process and distribute |
60 | network packets. See the Usernet manual for more details. |
61 | |
62 | Options provided: |
63 | |
64 | --help Display this help text. |
65 | -p, --persistent=NUM Configure NUM persistent unet devices. |
66 | -t, --transient=NUM Use minor device NUM for transient unets. |
67 | -M, --major=NUM Use major device NUM instead of $unet_major. |
68 | EOF |
69 | exit |
70 | ;; |
71 | |
72 | # --- Set number of persistent devices --- |
73 | |
74 | -p | --p|--pe|--per|--pers|--persi|--persis|--persist|\ |
75 | --persiste|--persisten|--persistent) |
76 | unet_persistent="$1"; shift ;; |
77 | |
78 | -p*) |
79 | unet_persistent="`echo "$opt" | cut -b 3-`" ;; |
80 | |
81 | --p=*|--pe=*|--per=*|--pers=*|--persi=*|--persis=*|--persist=*|\ |
82 | --persiste=*|--persisten=*|--persistent=*) |
83 | unet_persistent="`echo "$opt" | sed -e "s/^[-a-z]*=//"`" ;; |
84 | |
85 | # --- Set transient minor device --- |
86 | |
87 | -t | --t|--tr|--tra|--tran|--trans|--transi|--transie|\ |
88 | --transien|--transient) |
89 | unet_transMinor="$1"; shift ;; |
90 | |
91 | -t*) |
92 | unet_transMinor="`echo "$opt" | cut -b 3-`" ;; |
93 | |
94 | --t=*|--tr=*|--tra=*|--tran=*|--trans=*|--transi=*|--transie=*|\ |
95 | --transien=*|--transient=*) |
96 | unet_transMinor="`echo "$opt" | sed -e "s/^[-a-z]*=//"`" ;; |
97 | |
98 | # --- Set major number (caution!) --- |
99 | |
100 | -M | --ma|--maj|--majo|--major) |
101 | unet_major="$1"; shift ;; |
102 | |
103 | -M*) |
104 | unet_major="`echo "$opt" | cut -b 3-`" ;; |
105 | |
106 | --ma=*|--maj=*|--majo=*|--major=*) |
107 | unet_major="`echo "$opt" | sed -e "s/^[-a-z]*=//"`" ;; |
108 | |
109 | # --- Set default mode --- |
110 | |
111 | -m | --m|--mo|--mod|--mode) |
112 | unet_mode="$1"; shift ;; |
113 | |
114 | -m*) |
115 | unet_mode="`echo "$opt" | cut -b 3-`" ;; |
116 | |
117 | --m=*|--mo=*|--mod=*|--mode=*) |
118 | unet_mode="`echo "$opt" | sed -e "s/^[-a-z]*=//"`" ;; |
119 | |
120 | # --- Unknown option --- |
121 | |
122 | *) |
123 | echo >&2 "$0: unknown option $opt"; exit 1 ;; |
124 | |
125 | esac |
126 | done |
127 | |
128 | # --- Do the stuff --- |
129 | |
130 | rm -f /dev/unet* |
131 | if [ "$unet_persistent" -gt 0 ]; then |
132 | i=0 |
133 | while [ "$i" -lt "$unet_persistent" ]; do |
134 | mknod -m "$unet_mode" /dev/unet$i c "$unet_major" $i |
135 | i=`expr $i + 1` |
136 | done |
137 | fi |
138 | mknod -m "$unet_mode" /dev/unet c "$unet_major" "$unet_transMinor" |
139 | |
140 | exit 0 |