-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZipForJudge.sh
82 lines (60 loc) · 2.01 KB
/
ZipForJudge.sh
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
#!/bin/bash
# This script navigates to the specified directory and archives all files/folders
# Exceptions are "bin" and "obj" folders, as well as "Migrations" folder, hidden files, and/or folders
# Archive is created at the source location
# Ask User if they wish to keep Migrations or not?
read -p "Do you want to keep the 'Migrations' folder? ([Y/Yes]/[N/No]): " choice
keepMigration=false
if [[ "$choice" =~ ^[Yy](es)?$ ]]; then
keepMigration=true
fi
# Prompt User for Source Directory
read -p "Enter the full path of the source directory to copy: " sourcedir
# Find the Name of the Last Folder in Source Directory
foldername=$(basename "$sourcedir")
# Set Archive Name to Last Folder Name Without .zip Extension
archivename="${foldername%.*}"
# Set Destination Path to Source Directory
destpath="$sourcedir"
# Set Destination Path to Desktop
# destpath="$HOME/Desktop"
# Create a Temporary Directory for Exclusion file
tempdir=$(mktemp -d)
# Create a Temporary Directory for Copy
tempdir_copy="$tempdir/tmp"
# Create exclude.txt File in Temp Directory
cat << EOF > "$tempdir/exclude.txt"
/hid
bin/
obj/
.vs/
.zip
Datasets/
ExportResults/
ImportResults/
TestResults/
EOF
# If Choice is No Remove Migrations from .zip
if [ "$keepMigration" = false ]; then
echo "Removing Migrations..."
echo "Migrations/" >> "$tempdir/exclude.txt"
fi
# Copy Files From Source Directory to Temp Directory
rsync -a --exclude-from="$tempdir/exclude.txt" "$sourcedir"/* "$tempdir_copy"
# If Older Archive Exists -> Delete
if [ -f "$destpath/$archivename.zip" ]; then
rm -f "$destpath/$archivename.zip"
fi
# Change directory to temporary directory
cd "$tempdir_copy" || exit
# Create zip Archive at Specified Path (using zip command)
zip -r -q "$destpath/$archivename.zip" .
# Return to previous directory
cd - >/dev/null || exit
# Delete Temporary Directory for Exclusion file
rm -f "$tempdir/exclude.txt"
# Delete Temporary Directory
rm -rf "$tempdir"
# Output
echo
echo "Archive is created and is located at $destpath/$archivename.zip"