summarylogtreecommitdiffstats
path: root/jkazip
blob: dbc700e04a537c6e331d9397e8fc92504311d92d (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
#!/bin/bash
#JKA - ZIP
#A script for de/compress files and folders in many formats
#Author: JKA Network - contacto@jkanetwork.com
#Function decompress(); decompress the file whith the format especified

# gettext initialization
export TEXTDOMAIN='jkazip'
export TEXTDOMAINDIR='/usr/share/locale'

function decompress() {
	msg_de=""$(gettext "%s has been decompressed")" "$2""
	if [ $files -eq 0 ];then
		format=$(ls $2 | cut -f2 -d".")
		format2=$(ls $2 | cut -f3 -d".")
	else
		format=$(echo $1 | cut -f1 -d".")
		format2=$(echo $1 | cut -f2 -d".")
	fi
	if [ $format = "tar" ];then
		if [ -z $format2 ];then
			tar xvf $2
			if [ $? -eq 0 ];then
				printf -- $msg_de
				echo
			fi
		elif [ $format2 = "gz" ];then
			tar xvzf $2
			if [ $? -eq 0 ];then
				printf -- $msg_de
				echo
			fi
		elif [ $format2 = "bz2" ];then
			tar xvjf $2
			if [ $? -eq 0 ];then
				printf -- $msg_de
				echo
			fi
		elif [ $format2 = "xz" ];then
			tar xvJf $2
			if [ $? -eq 0 ];then
				printf -- $msg_de
				echo
			fi
		fi
	elif [ $format = "tbz2" ];then
		tar xvjf $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "tgz" ];then
		tar xvjf $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "txz" ];then
		tar xvJf $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "7z" -o $format = "7zip" ];then
		7z e $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "zip" ];then
		unzip $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "gz" -o $format = "gzip" ];then
		gzip -dk $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "bz2" -o $format = "bzip" ];then
		bzip2 -dk $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	elif [ $format = "rar" ];then
		rar -x $2
		if [ $? -eq 0 ];then
			printf -- $msg_de
			echo
		fi
	else
		printf -- "$(gettext "Format %s unknown")" "$format"
		echo
	fi
}
version="1.0.0"
if [ -z $1 ];then
	echo "$(gettext "No option specified, use jkazip -h")"
elif [ $1 = "-h" ];then
	echo "$(gettext "	synopsis:	jkazip <options> <file or directory>")"
	echo ""
	echo "$(gettext "	-d,		decompress file")"
	echo "$(gettext "	-f <format>,	specified format whe decompress, necessary only when the name have more than one point before the file extension")"
	echo "$(gettext "	-c <format>,	compress file")"
	echo "$(gettext "	-h,		show help box and exit")"
	echo "$(gettext "	-v,		show version")"
	echo ""
	echo "$(gettext "	The order must be \"jkazip -d [-f format] <file or directory>\" or \"jkazip -c <format> <file or directory\"")"
	echo ""
	echo "$(gettext "	Examples")"
	echo "$(gettext "	jkazip -d -f \"tar.gz\" file.txt.tar.gz")"
	echo "$(gettext "	jkazip -d file.7z")"
	echo "$(gettext "	jkazip -c \"tar.xz\" directory")"
	echo ""
	echo "$(gettext "	Supported formats: tar,gzip,bzip2,xzip,7z,zip and rar")"
	echo "$(gettext "	Only one file or directory (some formats don't support directories), for more options use the each program individualy")"
	echo ""
elif [ $1 = "-v" ];then
	printf -- "$(gettext "jkazip by JKA Network; version %s")" "$version"
	echo
elif [ $1 = "-d" ];then
	if [ -z $2 ];then
		echo "$(gettext "No file or directory specified")"
		exit
	elif [ $2 = "-f" ];then
		files=1
	elif [ -d $2 ];then
		files=0
		printf -- "$(gettext "Directory %s will be decompressed")" "$2"
		echo
	elif [ -f $2 ];then
		files=0
		echo "$(gettext "File $ will be decompressed")"
	else
		printf -- "$(gettext "%s no such file or directory")" "$2"
		echo
		exit
	fi
	if [ $files -eq 0 ];then
		decompress 0 $2
	elif [ $files -eq 1 ];then
		if [ -d $4 ];then
			printf -- "$(gettext "Directory %s will be decompressed")" "$4"
			echo
		elif [ -f $4 ];then
			printf -- "$(gettext "File %s will be decompressed")" "$4"
			echo
		else
			printf -- "$(gettext "%s no sush a file or directory")" "$4"
			echo
			exit
		fi
		decompress $3 $4
	fi
elif [ $1 = "-c" ];then
	if [ -z $3 ];then
		echo "$(gettext "No file or directory specified")"
		exit
	elif [ -d $3 ];then
		printf -- "$(gettext "The directory %s will be compressed")" "$3"
		echo
	elif [ -f $3 ];then
		printf -- "$(gettext "The file %s will be compressed")" "$3"
		echo
	else
		printf -- "$(gettext "%s no such file or directory")" "$3"
		echo
		exit
	fi
	msg_co=""$(gettext "%s has been compressed")" "$3""
	if [ -z $2 ];then
		echo "$(gettext "No format specified")"
	elif [ $2 = "tar" ] 2> /dev/null ;then
		tar cvf $3.tar $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "tar.gz" ] 2> /dev/null ;then
		tar cvzf $3.tar.gz $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "tar.bz2" ] 2> /dev/null ;then
		tar cvjf $3.tar.bz2 $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "tar.xz" ] 2> /dev/null ;then
		tar cvJf $3.tar.xz $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "tbz2" ] 2> /dev/null ;then
		tar cvjf $3.tbz2 $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "tgz" ] 2> /dev/null ;then
		tar cvjf $3.tgz $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "txz" ] 2> /dev/null ;then
		tar cvJf $3.txz $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "7z" -o $2 = "7zip" ] 2> /dev/null ;then
		7z a $3.7z $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "zip" ] 2> /dev/null ;then
		zip $3.zip $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "gz" -o $2 = "gzip" ] 2> /dev/null ;then
		gzip -9k $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "bz2" -o $2 = "bzip2" ] 2> /dev/null ;then
		bzip2 -k $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	elif [ $2 = "rar" ] 2> /dev/null ;then
		rar -a $3.rar $3
		if [ $? -eq 0 ];then
			printf -- $msg_co
			echo
		fi
	else
		printf -- "$(gettext "Format %s unknown")" "$2"
		echo
	fi
else
	echo "$(gettext "Unknown option")"
fi