-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip_it
executable file
·49 lines (42 loc) · 878 Bytes
/
zip_it
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
#!/bin/bash
if ! command -v zip >/dev/null; then
echo "\033[33mZip tool is not installed.\033[0m"
read -p "Do you want to install it? (y/n) " choice
case "$choice" in
y | Y)
echo "Installing zip tool..."
yum install -y zip
;;
n | N)
echo "Exiting script."
exit 1
;;
*)
echo "Invalid choice. Exiting script."
exit 1
;;
esac
fi
if [ ! -d "packed" ]; then
mkdir "packed"
fi
if [ $# -eq 0 ]; then
echo "Usage: zip_it <file/dir> [name]"
exit 1
fi
if [ $# -eq 1 ]; then
name=$(basename "$1")
else
name="$2"
fi
if [ -d "$1" ]; then
zip -r "packed/$name.zip" "$1"
else
zip "packed/$name.zip" "$1"
fi
if [ $? -eq 0 ]; then
echo -e "\033[32mFile compressed to packed/$name.zip\033[0m"
else
echo -e "\033[31mCompression failed.\033[0m"
fi
exit 0