|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Let,s chect environment. For instance what we are on |
| 4 | + |
| 5 | +OS=`uname -s` |
| 6 | +MAC=`uname -m` |
| 7 | +RELEASE=`uname -r` |
| 8 | + |
| 9 | + |
| 10 | +# Whoarewe ? :) |
| 11 | + |
| 12 | +ME=`whoami` |
| 13 | + |
| 14 | + |
| 15 | +echo -n "Operating System Type: " |
| 16 | + |
| 17 | +if test "$OS" = Linux; then |
| 18 | + echo "Linux" |
| 19 | +elif test "$OS" = FreeBSD; then |
| 20 | + echo "FreeBSD" |
| 21 | +elif test "$OS" = OpenBSD; then |
| 22 | + echo "OpenBSD" |
| 23 | +elif test "$OS" = NetBSD; then |
| 24 | + echo "NetBSD" |
| 25 | +fi |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +echo -n "testing /usr/include/stdio.h..." |
| 30 | +if(test -f /usr/include/stdio.h); then |
| 31 | + echo "ok" |
| 32 | +else |
| 33 | + exit |
| 34 | +fi |
| 35 | + |
| 36 | +echo -n "testing /usr/include/stdlib.h..." |
| 37 | +if(test -f /usr/include/stdlib.h); then |
| 38 | + echo "ok" |
| 39 | +else |
| 40 | + exit |
| 41 | +fi |
| 42 | + |
| 43 | +echo -n "testing /usr/include/errno.h..." |
| 44 | +if(test -f /usr/include/errno.h); then |
| 45 | + echo "ok" |
| 46 | +else |
| 47 | + echo "no" |
| 48 | +fi |
| 49 | + |
| 50 | +if test "$OS" = Linux; then |
| 51 | + echo -n "testing /usr/include/pcap.h..." |
| 52 | + if(test -f /usr/include/pcap.h); then |
| 53 | + echo "ok" |
| 54 | + else |
| 55 | + exit |
| 56 | + fi |
| 57 | +fi |
| 58 | + |
| 59 | + |
| 60 | +echo -n "testing /usr/include/sys/socket.h..." |
| 61 | +if(test -f /usr/include/sys/socket.h); then |
| 62 | + echo "ok" |
| 63 | +else |
| 64 | + exit; |
| 65 | +fi |
| 66 | + |
| 67 | + |
| 68 | +echo -n "testing /usr/include/netinet/in.h..." |
| 69 | +if(test -f /usr/include/netinet/in.h); then |
| 70 | + echo "ok" |
| 71 | +else |
| 72 | + exit; |
| 73 | +fi |
| 74 | + |
| 75 | + |
| 76 | +echo -n "testing /usr/include/arpa/inet.h..." |
| 77 | +if(test -f /usr/include/arpa/inet.h); then |
| 78 | + echo "ok" |
| 79 | +else |
| 80 | + exit |
| 81 | +fi |
| 82 | + |
| 83 | +echo -n "testing /usr/include/netinet/if_ether.h..." |
| 84 | +if(test -f /usr/include/netinet/if_ether.h); then |
| 85 | + echo "ok" |
| 86 | +else |
| 87 | + exit |
| 88 | +fi |
| 89 | + |
| 90 | +if test "$OS" = Linux; then |
| 91 | + echo -n "testing /usr/include/libnet.h..." |
| 92 | + if(test -f /usr/include/libnet.h); then |
| 93 | + echo "ok" |
| 94 | + else |
| 95 | + exit |
| 96 | + fi |
| 97 | +elif test "$OS" = FreeBSD || test "$OS" = OpenBSD || test "$OS" = NetBSD; then |
| 98 | + echo -n "testing /usr/local/include/libnet.h..." |
| 99 | + if(test -f /usr/local/include/libnet.h); then |
| 100 | + echo "ok" |
| 101 | + else |
| 102 | + exit |
| 103 | + fi |
| 104 | +fi |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | +if test "$OS" = FreeBSD || test "$OS" = OpenBSD || test "$OS" = NetBSD; then |
| 112 | + echo -n "testing /usr/local/lib/libnet.a..." |
| 113 | + if(test -f /usr/local/lib/libnet.a); then |
| 114 | + echo "ok" |
| 115 | + else |
| 116 | + echo "can't find required libnet.a static library" |
| 117 | + exit |
| 118 | + fi |
| 119 | +fi |
| 120 | + |
| 121 | +if test "$OS" = Linux; then |
| 122 | + echo -n "testing /usr/lib/libnet.a..." |
| 123 | + if(test -f /usr/lib/libnet.a); then |
| 124 | + echo "ok" |
| 125 | + else |
| 126 | + echo "can't find required libnet.a static library" |
| 127 | + exit |
| 128 | + fi |
| 129 | + |
| 130 | +fi |
| 131 | + |
| 132 | + |
| 133 | +if test "$OS" = Linux; then |
| 134 | + echo -n "testing /usr/lib/libpcap.a..." |
| 135 | + if(test -f /usr/lib/libpcap.a); then |
| 136 | + echo "ok" |
| 137 | + else |
| 138 | + echo "can't find required libpcap.a static library" |
| 139 | + exit |
| 140 | + fi |
| 141 | +fi |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +echo -n "Writing MakeFile..." |
| 148 | + |
| 149 | +echo "#!/usr/bin/make -f" > Makefile |
| 150 | +echo "LIBNETDEFS = `libnet-config --defines`" >> Makefile |
| 151 | +echo "LIBNETLIB = `libnet-config --libs`" >> Makefile |
| 152 | +echo " " >> Makefile |
| 153 | +echo " " >> Makefile |
| 154 | +echo "all: kn_arp.c kn_main.c kn_defs.h" >> Makefile |
| 155 | +echo " gcc -Wall -c kn_main.c" >> Makefile |
| 156 | + |
| 157 | +if test "$OS" = Linux; then |
| 158 | + echo " gcc -Wall \$(LIBNETDEFS) -c kn_arp.c" >> Makefile |
| 159 | + echo " gcc -o knowlan kn_main.o kn_arp.o -lnet -lpcap" >> Makefile |
| 160 | + echo " " >> Makefile |
| 161 | + echo " " >> Makefile |
| 162 | + echo "install: knowlan" >> Makefile |
| 163 | + echo " /bin/cp knowlan /usr/sbin/knowlan" >> Makefile |
| 164 | + echo " /bin/chown root.root /usr/sbin/knowlan" >> Makefile |
| 165 | + echo " /bin/chmod 755 /usr/sbin/knowlan" >> Makefile |
| 166 | +elif test "$OS" = FreeBSD || test "$OS" = OpenBSD || test "$OS" = NetBSD; then |
| 167 | + echo " gcc -Wall -D__BSD__=1 -D__GLIBC__=1 -I/usr/local/include/ \$(LIBNETDEFS) -c kn_arp.c" >> Makefile |
| 168 | + echo " gcc -o knowlan kn_main.o kn_arp.o /usr/local/lib/libnet.a -lpcap" >> Makefile |
| 169 | + echo " " >> Makefile |
| 170 | + echo " " >> Makefile |
| 171 | + echo "install: knowlan" >> Makefile |
| 172 | + echo " /bin/cp knowlan /usr/sbin/knowlan" >> Makefile |
| 173 | + echo " /bin/chown root.root /usr/sbin/knowlan" >> Makefile |
| 174 | + echo " /bin/chmod 755 /usr/sbin/knowlan" >> Makefile |
| 175 | +fi |
| 176 | + |
| 177 | +echo "clean:" >> Makefile |
| 178 | +echo " find ./ -name \"*.o\" -exec rm -rf {} \;" >> Makefile |
| 179 | +echo " find ./ -name \"knowlan\" -exec rm -rf {} \;" >> Makefile |
| 180 | +echo " find ./ -name \"*core\" -exec rm -rf {} \;" >> Makefile |
| 181 | + |
| 182 | +echo "Done." |
| 183 | + |
0 commit comments