-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2_package
executable file
·49 lines (41 loc) · 1.17 KB
/
p2_package
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
#!/usr/bin/env bash
ZIP_FILE=project2.zip
REQUIRED_FILES="actor.php movie.php search.php review.php sql/create.sql sql/load.sql"
CUR_DIR=$(pwd -P)
SRC_DIR=${CUR_DIR}
#error function
function error_exit()
{
echo -e "ERROR: $1" 1>&2
rm -rf ${TMP_DIR}
exit 1
}
# make sure running in container
if [ `whoami` != "cs143" ]; then
error_exit "You need to run this script within the container"
fi
# if the source directory is passed as parameter, use it
if [ $# -eq 1 ]; then
SRC_DIR=$1
fi
# remove the zip file if it already exists
if [ -f ${CUR_DIR}/${ZIP_FILE} ]; then
rm -f ${CUR_DIR}/${ZIP_FILE}
fi
# change to the directory with the submission files
cd ${SRC_DIR}
# check the existence of the required files
for FILE in ${REQUIRED_FILES}
do
if [ ! -f ${FILE} ]; then
echo "ERROR: Cannot find ${FILE} in ${DIR}" 1>&2
exit 1
fi
done
# create the zip file
zip -rq ${CUR_DIR}/${ZIP_FILE} . -x p2_package p2_test .DS_Store Thumbs.db '.git/*' '*/.DS_Store' '*/Thumbs.db' '*/*.del' @
if [ $? -ne 0 ]; then
error_exit "Create ${CUR_DIR}/${ZIP_FILE} failed, check for error messages in console."
fi
echo "[SUCCESS] Created '${CUR_DIR}/${ZIP_FILE}'"
exit 0