-
Notifications
You must be signed in to change notification settings - Fork 1
/
main
69 lines (65 loc) · 2.32 KB
/
main
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
#!/usr/bin/env bash
# Canonical : https://github.com/lduran2/git-unzip-all/main
# Decompresses all Simulink models in this repo after pushing to
# remote.
# By : Leomar Duran <https://github.com/lduran2>
# When : 2022-01-01t10:21R
# Version : 1.3.1
#
# CHANGELOG :
# v1.3.1 - 2022-02-01t10:21R
# patch `ROOTDIR` -> `ROOT_DIR`
# standardized logs, blanks, `then`
#
# v1.3.0 - 2022-02-01t05:18R
# use `dirname` to hangle resource locality
#
# v1.2.2 - 2022-01-25t22:07R
# now assumed to be in `hooks/unzip-all`
# reconfigured for submodule
#
# v1.2.1 - 2022-01-25t20:02R
# nonverbose unzip bcs the files were not being unzipped
#
# v1.2.0 - 2022-01-25t06:40R
# trim spaces from patterns; root constant, progress message,
# verbose unzip
#
# v1.1.0 - 2022-01-24t04:51R
# decompresses any file matching patterns from "../.unzip"
#
# v1.0.0 - 2022-01-24t04:51R
# decompresses all Simulink models
#
# working directories
declare -r SOURCE_DIR=$(dirname $0)
declare -r ROOT_DIR="$SOURCE_DIR/../.."
# configuration file contains the file patterns to unzip
declare -r PATTERN_FILE="$ROOT_DIR/.unzip"
>&2 echo "Reading patterns from \`$PATTERN_FILE\` . . ."
# read all lines from the configuration file
while read SPACE_PATTERN ; do
# remove surrounding spaces
pattern=$(echo "$SPACE_PATTERN" | xargs)
# if the link is not a comment, accept it as a file pattern
if [[ "$pattern" != \#* ]] ; then
>&2 echo "Unzipping files matching \"${pattern%/\r}\" . . ."
# find each file matching the pattern
find "$ROOT_DIR/" -type f -name "$pattern" -printf '%p\n' |
# read the filename into FILE
while read FILE ; do
>&2 echo "Unzipping file \"$FILE\" . . ."
# unzip to a directory with the same name
# sans extension, overwriting any files therein
unzip_dir="${FILE%.*}"
unzip -o "$FILE" -d "$unzip_dir"
# unadd the file from commit
git reset HEAD "$FILE"
# add the zipped directory
git add "$unzip_dir"
done # while read FILE
# done find FILE
fi # [[ "$pattern" != \#* ]]; then
done < "$PATTERN_FILE" # while read SPACE_PATTERN
# confirm finished
>&2 echo "Done."