-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackager
More file actions
executable file
·71 lines (56 loc) · 1.51 KB
/
Copy pathpackager
File metadata and controls
executable file
·71 lines (56 loc) · 1.51 KB
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
#!/usr/bin/env bash
draw_bar() {
local percent=$1
local cols=$(tput cols)
local bar_size=$((cols - 8))
local filled=$((percent * bar_size / 100))
local empty=$((bar_size - filled))
printf "\r["
for ((i=0; i<filled; i++)); do printf "#"; done
for ((i=0; i<empty; i++)); do printf "."; done
printf "] %3d%%" "$percent"
}
create_tar() {
local dir=$1
local name
name=$(basename "$dir").tar
echo "[LOG] Creating tarball: $name"
local total current percent
total=$(find "$dir" -type f | wc -l)
current=0
tar -cf "$name" "$dir" --verbose 2>&1 \
| while read -r file; do
current=$((current + 1))
percent=$((current * 100 / total))
draw_bar "$percent"
done
draw_bar 100
echo -e "\n[LOG] Tarball created: $name"
}
create_zip() {
local dir=$1
local name
name=$(basename "$dir").zip
echo "[LOG] Creating zip: $name"
local total current percent
total=$(find "$dir" -type f | wc -l)
current=0
zip -rv "$name" "$dir" 2>/dev/null | while read -r line; do
if [[ "$line" == *"adding:"* ]]; then
current=$((current + 1))
percent=$((current * 100 / total))
draw_bar "$percent"
fi
done
draw_bar 100
echo -e "\n[LOG] Zip created: $name"
}
if [ $# -lt 2 ]; then
echo "Usage: $0 [tar|zip] <directory>"
exit 1
fi
case $1 in
tar) create_tar "$2" ;;
zip) create_zip "$2" ;;
*) echo "[ERROR] Unknown option: $1 (use tar|zip)" ;;
esac