summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/installer/linux/autoconfighelper.sh
blob: 3dfca77c2e3af13851a0388b267a1717a84e58cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/sh
#
# %coypright%
#
# Please report bugs to: %maintainer%
#
# %license%
#
# Configuration guessing script for KMyFirewall %version%
# This is an automatic generated file DO NOT EDIT
#
# Exaple output
# <targetconfig name="Untitled" description="No Description Available" >
#   <interface name="eth0" />
#   <interface name="lo" />
#   <os name="linux" />
#   <backend name="iptables" />
#   <distribution name="sysv" />
#   <initPath name="/etc/init.d" />
#   <IPTPath name="/sbin/iptables" />
#   <modprobePath name="/sbin/modprobe" />
#   <rcDefaultPath name="/etc/rc2.d" />
# </targetconfig>
#

REQUIREDOS="Linux"
REQUIREDTOOLS="bash stat ifconfig grep sort cut"
INERACTIVE="0"
XMLCONFIG=""
DIST="sysv"


checkRequirements() {
	if [ "$INERACTIVE" = "1" ]; then
		echo "Checking system requirements"
	fi
	
	OS=`uname`
	if  [ "$OS" != "$REQUIREDOS" ]; then
		
		echo
		echo "ERROR: Wrong OS: $OS"
		echo "ERROR: This scripts is written for $REQUIREDOS"
		echo
		exit 1
	fi
	
	for PROG in $REQUIREDTOOLS; do
		if [ "$INERACTIVE" = "1" ]; then
			echo -n  "Checking for $PROG...\t\t "
		fi
		PROGPATH=""
		PROGNAME="which"
		SEARCH="/bin /sbin /usr/bin /usr/sbin"
		for s in $SEARCH; do
			if [ -e "$s/$PROGNAME" ]; then
				PROGPATH="$s/$PROGNAME";
			fi
		done
		
		if [ "$PROGPATH" != "" ]; then
			PROGPATH=`which $PROG`
			if [ "$?" != "0" ]; then
				echo
				echo "ERROR: $PROG not found. Installation aborted!"
				echo 
				exit 1
			fi
			if [ "$INERACTIVE" = "1" ]; then
				echo " found $PROG at $PROGPATH"
			fi
		else
			if [ "$INERACTIVE" = "1" ]; then
				echo "Requirement Checks Faild"
			fi
		fi
	done
	if [ "$INERACTIVE" = "1" ]; then
		echo 
	fi
}



writeXmlHeader() {
	XMLCONFIG=$XMLCONFIG"<targetconfig name=\"Untitled\" description=\"No Description Available\"><os name=\"linux\" /><backend name=\"iptables\" />";
}

writeXmlFooter() {
	XMLCONFIG=$XMLCONFIG"</targetconfig>";
}


checkDist() {
	if [ -e /etc/slackware-version ]; then
		setslakware;
		return;
	fi
	
	if [ -e /usr/bin/emerge ]; then
		setgentoo;
		return;
	fi
	setSysv
}

setSlakware() {
	#echo "Set To Slackware"
	DIST="slackware"
	XMLCONFIG=$XMLCONFIG"<distribution name=\"slackware\" />";
}

setGentoo() {
	#echo "Set To Gentoo"
	DIST="gentoo"
	XMLCONFIG=$XMLCONFIG"<distribution name=\"gentoo\" />";
}

setSysv() {
	#echo "Set To SysV"
	DIST="sysv"
	XMLCONFIG=$XMLCONFIG"<distribution name=\"sysv\" />";
}

setIPTables() {
	PROGNAME="iptables"
	SEARCH="/bin /sbin /usr/bin /usr/sbin"
	for s in $SEARCH; do
		if [ -e "$s/$PROGNAME" ]; then
			XMLCONFIG=$XMLCONFIG"<IPTPath name=\"$s/$PROGNAME\" />";
		fi
		
	done
}

setModprobe() {
	PROGNAME="modprobe"
	SEARCH="/ /bin /sbin /usr/bin /usr/sbin"
	for s in $SEARCH; do
		if [ -e "$s/$PROGNAME" ]; then
			XMLCONFIG=$XMLCONFIG"<modprobePath name=\"$s/$PROGNAME\" />";
		fi
		
	done
}

setInitDir() {
	SEARCH="/init.d /etc/init.d /etc/sbin.d"
	for s in $SEARCH; do
		if [ -e "$s" ]; then
			XMLCONFIG=$XMLCONFIG"<initPath name=\"$s\" />";
		fi
		
	done
}

setDefaultRunlevelDir() {
	if [ -e /etc/debian_version ]; then
		XMLCONFIG=$XMLCONFIG"<rcDefaultPath name=\"/etc/rc2.d\" />";
		return
	fi
	
	SEARCH="/etc/runlevels/default/ /etc/init.d/rc5.d /etc/rc5.d /sbin/rc5.d"
	
	for s in $SEARCH; do
		if [ -d "$s" ]; then
			XMLCONFIG=$XMLCONFIG"<rcDefaultPath name=\"$s\" />";
			return
		fi
	done
}

setInterfaces() {
	RET=`/sbin/ifconfig | grep ' Link' | cut -f1 -d' ' | sort`
	for i in $RET; do
		# echo "Found Interface: $i"
		XMLCONFIG=$XMLCONFIG"<interface name=\"$i\" />";
	done
}

returnXml() {
	echo $XMLCONFIG
}

printHello() {
    if [ "$INERACTIVE" = "1" ]; then
    	echo "KMyFirewall Auto Configuration Helper"
    	echo "Please report bugs to: %maintainer%"
    	echo
    fi
}

printHelp() {
	echo "Usage: $0 [-q] { --install | --uninstall | --reinstall | --extract | --start | --stop | --help }"
	echo
	echo "Switches"
	echo "	-q"
	echo "		Do not require any user interaction."
	echo
# 	echo "Options:"
# 	echo "	install|--install|-i"
# 	echo "		Install the configuration."
# 	echo "		The installed firewall scrip will be automaticaly run at system boot."
# 	echo 
# 	echo "	uninstall|--uninstall|-u"
# 	echo "		Uninstall the configuration form the system."
# 	echo 
# 	echo "	reinstall|--reinstall|-r"
# 	echo "		Re-Installs the configuration e.g. the same as install.sh uninstall"
# 	echo "		followed by install.sh install"
# 	echo
# 	echo "	extract|--extract|-e"
# 	echo "		Only extract the installation files."
# 	echo "		The firewall will not be installed."
# 	echo 
# 	echo "	start|--start|-s"
# 	echo "		Only extract the installation files and."
# 	echo "		runs the firewall script."
# 	echo "		The firewall will not be installed."
# 	echo 
# 	echo "	stop|--stop|-c"
# 	echo "		Only extract the installation files and."
# 	echo "		stops the firewall script."
# 	echo "		The firewall will not be installed."
# 	echo 
# 	echo "	help|--help|-h"
# 	echo "		Print this help message"
# 	echo
}

#
# Execution starts here
#

printHello

COMMAND=$1

if [ "$COMMAND" = "-q" ]; then
	COMMAND="$2"
	INERACTIVE="0";
fi

case $COMMAND in
	
	help|--help|-h)
	printHelp
	;;

	*)
	checkRequirements
	writeXmlHeader
	checkDist
	setIPTables
	setModprobe
	setInitDir
	setDefaultRunlevelDir
	setInterfaces
	writeXmlFooter
	returnXml
    ;;
esac

exit 0