-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbxcp
executable file
·62 lines (56 loc) · 1.61 KB
/
bxcp
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
#!/bin/bash
# bxcp
#
# Author: William T. Hollingsworth
# Last Revision: 28.10.2020
# Usage: bxcp <source> <destination>
#
# Description:
# Given a source directory that contains a set of zip archives, extract a copy
# of the contents to a destination directory. A folder will be created for each
# archive using the basename of the archive.
#
# Revision History:
# 28.10.2020
# - Inital version.
if [ $# -ne 2 ]
then
echo "usage: bxcp <source> <destination>"
exit 2
fi
# for consistentcy with ${dest} below
if [ ! -d "$1" ]
then
echo "\"$1\" is not a valid directory"
exit 2
fi
src=$(realpath $1)
# we're going to pushd into ${src}, so we need an absolute path for this
if [ ! -d "$2" ]
then
echo "\"$2\" is not a valid directory"
exit 2
fi
dest=$(realpath $2)
# get all of the submissions for that block
pushd "${src}" > /dev/null 2>&1
for zipfile in *.zip
do
# find the location of the first . character to get the basename
# `basename` tries to do this but doesn't play nice with things
# like ".zip.zip"
ext_index=$(expr index "${zipfile}" ".")
filename=${zipfile:0:${ext_index}-1}
# construct the path of the extraction directory
extract_dir="${dest}/${filename}"
if [ ! -d "${extract_dir}" ]
then
mkdir --parents "${extract_dir}"
fi
# extract the archive
# -o will overwrite existing files! This is not ideal, but MinGW's unzip
# is not compiled with support for any option that will allow renaming
echo "extracting the contents of \"${zipfile}\" to \"${extract_dir}\"..."
unzip -q -o "${zipfile}" -d "${extract_dir}"
done
popd > /dev/null 2>&1