summaryrefslogtreecommitdiffstats
path: root/kmyfirewall/installer/linux/installpackage.sh
blob: d2d00ee57b4ca1251af6fe3c3d2657d2b1a1ffbd (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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/sh
#
# %coypright%
#
# Please report bugs to: %maintainer%
#
# %license%
#
# Installer Package script for KMyFirewall %version%
# This is an automatic generated file DO NOT EDIT

DATA="%data%"

REQUIREDTOOLS="bash stat openssl tar gzip"
EXTRACTDIR="/tmp/kmyfirewall.d"
CURRDIR=`pwd`
EXTRACTPATH=$EXTRACTDIR

INERACTIVE="1"

checkRequirements() {
	USR=`whoami`
	if [ "$USR" != "root" ]; then
		echo
		echo "This script need to be run as root."
		echo
		exit 1;
	fi
	
	echo -n "Checking system requirements...\t\t"
	for PROG in $REQUIREDTOOLS; do
		if [ "$INERACTIVE" = "1" ]; then
			echo -n  "Checking for $PROG...\t\t "
		fi
		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
	done
	echo "Done"
}

extract() {
	if [ "$INERACTIVE" = "1" ]; then
		echo "Enter the path to the directory used to"
		echo "extract the installation files"
		echo
		echo -n "Extract to [$EXTRACTPATH]: "
		
		read newpath
		if [ "$newpath" != "" ]; then
			EXTRACTDIR=$newpath
		fi
	fi
	EXTRACTPATH=$EXTRACTDIR
	# EXTRACTPATH=$EXTRACTDIR
	
	if [ -e  $EXTRACTPATH ]; then
		realydel="n"
		if [ "$INERACTIVE" = "1" ]; then
			echo "$EXTRACTPATH allready exists. Do you want to delete it? [y/N]"
			read realydel
		else 
			realydel="y"
		fi
		
		if [ "$realydel" != "y" ]; then
			extract
		else 
			if [ "$INERACTIVE" = "1" ]; then
				echo "Deleting $EXTRACTPATH..."
			fi
			rm -rf "$EXTRACTPATH"
		fi
	fi
	
	echo "Exctracting data to $EXTRACTPATH..."
	mkdir "$EXTRACTPATH"
	cd "$EXTRACTPATH"
	
	touch data.b64
	for LINE in $DATA; do
		echo $LINE >> data.b64
	done
 	
 	openssl base64 -d -in data.b64 -out data.tar.gz
	rm data.b64
	tar xfz data.tar.gz
	# cd "$CURRDIR"
	echo
}

install() {
	cd "$EXTRACTPATH"
	
	if [ "$INERACTIVE" = "1" ]; then
		bash install.sh --install
	else 
		bash install.sh -q --install
	fi
	
	# cd "$CURRDIR"
}

uninstall() {
	cd "$EXTRACTPATH"

	if [ "$INERACTIVE" = "1" ]; then
		bash install.sh --uninstall
	else 
		bash install.sh -q --uninstall
	fi
	# cd "$CURRDIR"
}

start() {
	cd "$EXTRACTPATH"
	
	if [ "$INERACTIVE" = "1" ]; then
		bash data/kmyfirewall.sh -v start
	else 
		bash data/kmyfirewall.sh -v start
	fi
	
	# cd "$CURRDIR"
}
stop() {
	cd "$EXTRACTPATH"
	
	if [ "$INERACTIVE" = "1" ]; then
		bash data/kmyfirewall.sh -v stop
	else 
		bash data/kmyfirewall.sh -v stop
	fi
	
	# cd "$CURRDIR"
}


reinstall() {
	cd "$EXTRACTPATH"
	bash install.sh --reinstall
	if [ "$INERACTIVE" = "1" ]; then
		bash install.sh --reinstall
	else 
		bash install.sh -q --reinstall
	fi
	# cd "$CURRDIR"
}

delpackage() {
	realydel="y"
	
	if [ "$INERACTIVE" = "1" ]; then
		echo -n "Do you want to delete the extracted installation files? [Y/n]: "
		read realydel
	fi
	
	if [ "$realydel" != "n" ]; then
		# if [ "$INERACTIVE" = "1" ]; then
			echo -n "Deleting $EXTRACTPATH...\t\t"
		# fi
		rm -rf "$EXTRACTPATH"
		echo "Done"
	fi 
	echo
}

copyToInstallDir() {
	cd "$CURRDIR"
	echo "Copy installer package to /etc/kmyfirewall/kmfpackage.kmfpkg...\t\t"
	cp $0 /etc/kmyfirewall/
	echo "Done"
}

printHello() {
    echo "KMyFirewall Installer Package v%version%"
    echo "Please report bugs to: %maintainer%"
    echo
}
printHelp() {
	echo "Usage: $0 [-q] { --install | --uninstall | --reinstall | --extract | --start | --stop | --help }"
	echo
	echo "Switches"
	echo "	-q"
	echo "		No 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
#

COMMAND=$1

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

printHello

case $COMMAND in
	install|--install|-i)
	checkRequirements
	extract
    install
    delpackage
    copyToInstallDir
	;;

    uninstall|--uninstall|-u)
    checkRequirements
    extract
    # install
    uninstall
    delpackage
    ;;
    
	reinstall|--reinstall|-r)
	checkRequirements
	extract
    reinstall
    delpackage
    copyToInstallDir
	;;
	
	extract|--extract|-e)
	checkRequirements
	extract
	;;
	
	start|--start|-s)
	checkRequirements
	extract
	start
	delpackage
	copyToInstallDir
	;;
	
	stop|--stop|-c)
	checkRequirements
	extract
	stop
	delpackage
	copyToInstallDir
	;;
	
	help|--help|-h)
	printHelp
	;;

	*)
	checkRequirements
	extract
    install
    delpackage
    copyToInstallDir
    ;;
esac