rewrite bin/tar-entry.sh

We rewrote the `bin/tar-entry.sh` algorithm so that we do NOT have
to require Linux to produce a compressed tarball that is byte-for-byte
identical to a macOS compressed tarball for the same entry.

Changed `bin/tar-entry.sh` VERSION from "1.2 2024-03-22"
to "1.3 2024-03-25".

Added `bin/untar-entry.sh` to untar an entry from the
compressed tarball.

Added `make untar_entry_tarball` to untar all entry files.

Added `make untar_year_tarball` and `make untar_all_tarball`
stub Makefile rules.  The core it referred to does not yet exist.

Updated IOCCC manifest.  Updated `.entry.json` for `2004/sds`.

Performed `make www` to update web pages.  In most cases the
entry `index.html` added an inventory link for the new `.tar.tstamp` file.

Performed `form_entry_tarball` to complete the test of the above.

TODO: Test the results under Linux.

TODO: Update `bin/tar-year.sh`.  Update year level compressed tarballs.

TODO: Update `bin/tar-all.sh`.  Update top level compressed tarball.

TODO: Write `bin/untar-year.sh` and `bin/untar-all.sh`.
This commit is contained in:
Landon Curt Noll committed 2024-03-25 22:44:34 -07:00
1 parent f3b5ff762f
commit 9f57052020
1003 files changed
+1376 -550

No files matched your search

+17
View File
@@ -367,6 +367,23 @@ bin/all-years.sh -v 3 bin/tar-year.sh -v 1 -W
```
## [untar-entry.sh](untar-entry.sh)
Untar an entry's a compressed tarball.
Usage:
```sh
bin/untar-entry.sh -v 1 YYYY/dir
```
Suggested usage:
```sh
bin/all-run.sh -v 3 bin/untar-entry.sh -v 1
```
# <a name="how"></a>How IOCCC HTML content is built
The [md2html.sh](md2html.sh) tool is the primary tool that
+9 -3
View File
@@ -276,6 +276,12 @@ We sort with lines starting with <code>!</code> fourth.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="ex">bin/tar-year.sh</span> <span class="at">-v</span> 1 YYYY</span></code></pre></div>
<p>Suggested usage:</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="ex">bin/all-years.sh</span> <span class="at">-v</span> 3 bin/tar-year.sh <span class="at">-v</span> 1 <span class="at">-W</span></span></code></pre></div>
<h2 id="untar-entry.sh"><a href="untar-entry.sh">untar-entry.sh</a></h2>
<p>Untar an entry’s a compressed tarball.</p>
<p>Usage:</p>
<div class="sourceCode" id="cb27"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="ex">bin/untar-entry.sh</span> <span class="at">-v</span> 1 YYYY/dir</span></code></pre></div>
<p>Suggested usage:</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="ex">bin/all-run.sh</span> <span class="at">-v</span> 3 bin/untar-entry.sh <span class="at">-v</span> 1</span></code></pre></div>
<h1 id="how-ioccc-html-content-is-built"><a name="how"></a>How IOCCC HTML content is built</h1>
<p>The <a href="md2html.sh">md2html.sh</a> tool is the primary tool that
is used to form all IOCCC related HTML pages for the <a href="https://www.ioccc.org">official IOCCC web
@@ -292,16 +298,16 @@ built uses, by default, files from the <a href="../inc/index.html">inc directory
the file name form:</p>
<pre><code>*.default.html</code></pre>
<p>By using command line options of the form:</p>
<div class="sourceCode" id="cb28"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="ex">-H</span> phase=name</span></code></pre></div>
<div class="sourceCode" id="cb30"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="ex">-H</span> phase=name</span></code></pre></div>
<p>where <code>phase</code> is the name of an HTML phase,
a non-default file may be used. For example:</p>
<div class="sourceCode" id="cb29"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="ex">-H</span> topnav=up2index</span></code></pre></div>
<div class="sourceCode" id="cb31"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="ex">-H</span> topnav=up2index</span></code></pre></div>
<p>will cause <a href="../inc/topnav.up2index.html">inc/topnav.up2index.html</a>
instead of <a href="../inc/topnav.default.html">inc/topnav.default.html</a> to be
used during the <em>topnav</em> HTML phase.</p>
<p>If <code>name</code> is dot (i.e., <code>.</code>), then the given HTML phase is skipped.
For example:</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="ex">-H</span> footer=.</span></code></pre></div>
<div class="sourceCode" id="cb32"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="ex">-H</span> footer=.</span></code></pre></div>
<p>will cause no HTML content to be produced during the <code>footer</code> HTML phase.</p>
<h2 id="html-phases"><a name="html"></a>HTML phases</h2>
<p>The following HTML phase files are used to build HTML content:</p>
+225 -198
View File
@@ -83,7 +83,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an
# set variables referenced in the usage message
#
export VERSION="1.2 2024-03-22"
export VERSION="1.3 2024-03-25"
NAME=$(basename "$0")
export NAME
export V_FLAG=0
@@ -338,10 +338,6 @@ if [[ ! -r $ENTRY_JSON ]]; then
exit 5
fi
# determine the name of our tarball
#
export TARBALL="$YYYY_DIR/$ENTRY_ID.tar.bz2"
# verify we have our awk tool
#
export FILELIST_ENTRY_JSON_AWK="$BIN_DIR/filelist.entry.json.awk"
@@ -462,33 +458,13 @@ if [[ ! -s $DOT_TAR_TSTAMP ]]; then
exit 6
fi
# verify that the last tar timestamp in the .tar.tstamp file is an integer > 0
# determine the name of our tarball
#
export LAST_TAR_TSTAMP
LAST_TAR_TSTAMP=$(< "$DOT_TAR_TSTAMP")
if [[ $LAST_TAR_TSTAMP =~ ^-?[0-9]+$ ]]; then
if [[ $LAST_TAR_TSTAMP -le 0 ]]; then
echo "$0: ERROR: entry .tar.tstamp: $DOT_TAR_TSTAMP contents must be an integer > 0: $LAST_TAR_TSTAMP" 1>&2
exit 6
fi
else
echo "$0: ERROR: entry .tar.tstamp: $DOT_TAR_TSTAMP contents is not an integer: $LAST_TAR_TSTAMP" 1>&2
exit 6
fi
# convert the last tar timestamp into a date string
# TARBALL - the same of the compressed tarball to verify and if needed re-build
# REBUILD_TARBALL - if non-empty, we need to re-build TARBALL and update tar timestamps
#
export LAST_TAR_DATE
LAST_TAR_DATE=$(TZ=UTC date -r "$LAST_TAR_TSTAMP")
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: TZ=UTC date -r $LAST_TAR_TSTAMP failed, error: $status" 1>&2
exit 6
fi
if [[ -z $LAST_TAR_DATE ]]; then
echo "$0: ERROR: TZ=UTC date -r $LAST_TAR_TSTAMP produced an empty string" 1>&2
exit 6
fi
export TARBALL="$YYYY_DIR/$ENTRY_ID.tar.bz2"
export REBUILD_TARBALL=
# parameter debugging
#
@@ -513,15 +489,14 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: ENTRY_ID=$ENTRY_ID" 1>&2
echo "$0: debug[3]: DOT_PATH=$DOT_PATH" 1>&2
echo "$0: debug[3]: ENTRY_JSON=$ENTRY_JSON" 1>&2
echo "$0: debug[3]: TARBALL=$TARBALL" 1>&2
echo "$0: debug[3]: FILELIST_ENTRY_JSON_AWK=$FILELIST_ENTRY_JSON_AWK" 1>&2
echo "$0: debug[3]: IOCCC_CSS=$IOCCC_CSS" 1>&2
echo "$0: debug[3]: VAR_MK=$VAR_MK" 1>&2
echo "$0: debug[3]: TOP_TAR_TSTAMP=$TOP_TAR_TSTAMP" 1>&2
echo "$0: debug[3]: YEAR_TAR_TSTAMP=$YEAR_TAR_TSTAMP" 1>&2
echo "$0: debug[3]: DOT_TAR_TSTAMP=$DOT_TAR_TSTAMP" 1>&2
echo "$0: debug[3]: LAST_TAR_TSTAMP=$LAST_TAR_TSTAMP" 1>&2
echo "$0: debug[3]: LAST_TAR_DATE=$LAST_TAR_DATE" 1>&2
echo "$0: debug[3]: TARBALL=$TARBALL" 1>&2
echo "$0: debug[3]: REBUILD_TARBALL=$REBUILD_TARBALL" 1>&2
fi
# If -N, time to exit
@@ -533,9 +508,40 @@ if [[ -n $DO_NOT_PROCESS ]]; then
exit 0
fi
# test - if needed - if the tarball is a non-empty writable file
#
if [[ -z $REBUILD_TARBALL && ! -e $TARBALL ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"tarball does not exist: $TARBALL" 1>&2
fi
fi
if [[ -z $REBUILD_TARBALL && ! -f $TARBALL ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"tarball is not a file: $TARBALL" 1>&2
fi
fi
if [[ -z $REBUILD_TARBALL && ! -w $TARBALL ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"tarball is not a writable file: $TARBALL" 1>&2
fi
fi
if [[ -z $REBUILD_TARBALL && ! -s $TARBALL ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"tarball is not a non-empty writable file: $TARBALL" 1>&2
fi
fi
# create a temporary file manifest list
#
TMP_MANIFEST_LIST=".$NAME.$$.manifest.list"
export TMP_MANIFEST_LIST=".$NAME.$$.manifest.list"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: temporary file manifest list: $TMP_MANIFEST_LIST" 1>&2
fi
@@ -557,24 +563,24 @@ fi
# create a temporary sort list of files to tar
#
TMP_TAR_LIST=".$NAME.$$.tar.list"
export TMP_FILES_TO_TAR=".$NAME.$$.tar.list"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: temporary file tar list: $TMP_TAR_LIST" 1>&2
echo "$0: debug[3]: temporary of files to tar: $TMP_FILES_TO_TAR" 1>&2
fi
if [[ -z $NOOP ]]; then
trap 'rm -f $TMP_MANIFEST_LIST $TMP_TAR_LIST; exit' 0 1 2 3 15
rm -f "$TMP_TAR_LIST"
if [[ -e $TMP_TAR_LIST ]]; then
echo "$0: ERROR: cannot remove temporary file tar list: $TMP_TAR_LIST" 1>&2
trap 'rm -f $TMP_MANIFEST_LIST $TMP_FILES_TO_TAR; exit' 0 1 2 3 15
rm -f "$TMP_FILES_TO_TAR"
if [[ -e $TMP_FILES_TO_TAR ]]; then
echo "$0: ERROR: cannot remove temporary of files to tar: $TMP_FILES_TO_TAR" 1>&2
exit 12
fi
:> "$TMP_TAR_LIST"
if [[ ! -e $TMP_TAR_LIST ]]; then
echo "$0: ERROR: cannot create temporary file tar list: $TMP_TAR_LIST" 1>&2
:> "$TMP_FILES_TO_TAR"
if [[ ! -e $TMP_FILES_TO_TAR ]]; then
echo "$0: ERROR: cannot create temporary of files to tar: $TMP_FILES_TO_TAR" 1>&2
exit 13
fi
elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary file tar list is not used: $TMP_TAR_LIST" 1>&2
echo "$0: debug[3]: because of -n, temporary of files to tar is not used: $TMP_FILES_TO_TAR" 1>&2
fi
# create a temporary exit code
@@ -582,12 +588,12 @@ fi
# It is a pain to set the EXIT_CODE deep inside a loop, so we write the EXIT_CODE into a file
# and read the file (setting EXIT_CODE again) after the loop. A hack, but good enough for our needs.
#
TMP_EXIT_CODE=".$NAME.$$.exit.code"
export TMP_EXIT_CODE=".$NAME.$$.exit.code"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: temporary exit code: $TMP_EXIT_CODE" 1>&2
fi
if [[ -z $NOOP ]]; then
trap 'rm -f $TMP_MANIFEST_LIST $TMP_TAR_LIST $TMP_EXIT_CODE; exit' 0 1 2 3 15
trap 'rm -f $TMP_MANIFEST_LIST $TMP_FILES_TO_TAR $TMP_EXIT_CODE; exit' 0 1 2 3 15
rm -f "$TMP_EXIT_CODE"
if [[ -e $TMP_EXIT_CODE ]]; then
echo "$0: ERROR: cannot remove temporary exit code: $TMP_EXIT_CODE" 1>&2
@@ -602,28 +608,6 @@ elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary exit code is not used: $TMP_EXIT_CODE" 1>&2
fi
# create a temporary tarball
#
TMP_TARBALL=".$NAME.$$.tar.bz2"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: temporary tarball: $TMP_TARBALL" 1>&2
fi
if [[ -z $NOOP ]]; then
trap 'rm -f $TMP_MANIFEST_LIST $TMP_TAR_LIST $TMP_EXIT_CODE $TMP_TARBALL; exit' 0 1 2 3 15
rm -f "$TMP_TARBALL"
if [[ -e $TMP_TARBALL ]]; then
echo "$0: ERROR: cannot remove temporary tarball: $TMP_TARBALL" 1>&2
exit 16
fi
:> "$TMP_TARBALL"
if [[ ! -e $TMP_TARBALL ]]; then
echo "$0: ERROR: cannot create temporary tarball: $TMP_TARBALL" 1>&2
exit 17
fi
elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary tarball is not used: $TMP_TARBALL" 1>&2
fi
# generate sorted list of entry files from the entry's manifest
#
# We also add ioccc.css and var.mk from the top level.
@@ -668,16 +652,16 @@ if [[ -z $NOOP ]]; then
else
echo "$file"
fi
done > "$TMP_TAR_LIST"
done > "$TMP_FILES_TO_TAR"
if [[ $V_FLAG -ge 7 ]]; then
echo "$0: debug[7]: list of files to tar start below" 1>&2
cat "$TMP_TAR_LIST" 1>&2
echo "$0: debug[7]: list of files to tar starts below" 1>&2
cat "$TMP_FILES_TO_TAR" 1>&2
echo "$0: debug[7]: list of files to tar ends above" 1>&2
fi
elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary file tar list was not formed: $TMP_MANIFEST_LIST" 1>&2
echo "$0: debug[3]: because of -n, temporary of files to tar was not formed: $TMP_MANIFEST_LIST" 1>&2
fi
if [[ ! -s "$TMP_TAR_LIST" ]]; then
if [[ ! -s "$TMP_FILES_TO_TAR" ]]; then
echo "$0: ERROR: no files found to tar for: $ENTRY_JSON" 1>&2
exit 1
fi
@@ -687,167 +671,179 @@ if [[ -z $EXIT_CODE ]]; then
exit 18
fi
# form the tarball
#
# We use gnu tar to form the bzip2 compressed tarball with careful arguments
# so that the resulting tarball is the same, byte for byte.
# create a temporary list of files found in the tarball
#
export TMP_TARBALL_LIST=".$NAME.$$.tarball.list"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: temporary of files in the tarball: $TARBALL: $TMP_TARBALL_LIST" 1>&2
fi
if [[ -z $NOOP ]]; then
# case: form the tarball verbosely if -v 5 or more
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: about to execute:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --totals" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcvf $TMP_TARBALL < $TMP_TAR_LIST" 1>&2
"$GTAR_TOOL" --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name \
--owner=501 --group=20 --numeric-owner --totals \
--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime' \
--mtime="$LAST_TAR_DATE" -jcvf "$TMP_TARBALL" < "$TMP_TAR_LIST"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --totals" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcvf $TMP_TARBALL < $TMP_TAR_LIST failed, error: $status" 1>&2
exit 8
fi
# case: form the tarball silently
#
else
"$GTAR_TOOL" --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name \
--owner=501 --group=20 --numeric-owner \
--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime' \
--mtime="$LAST_TAR_DATE" -jcf "$TMP_TARBALL" < "$TMP_TAR_LIST"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcf $TMP_TARBALL < $TMP_TAR_LIST failed, error: $status" 1>&2
exit 8
fi
trap 'rm -f $TMP_MANIFEST_LIST $TMP_FILES_TO_TAR $TMP_EXIT_CODE $TMP_TARBALL_LIST; exit' 0 1 2 3 15
rm -f "$TMP_TARBALL_LIST"
if [[ -e $TMP_TARBALL_LIST ]]; then
echo "$0: ERROR: cannot remove temporary of files in the tarball: $TARBALL: $TMP_TARBALL_LIST" 1>&2
exit 16
fi
# verify the tarball is not empty
#
if [[ ! -s $TMP_TARBALL ]]; then
echo "$0: ERROR: tarball is missing is empty: $TMP_TARBALL" 1>&2
exit 8
:> "$TMP_TARBALL_LIST"
if [[ ! -e $TMP_TARBALL_LIST ]]; then
echo "$0: ERROR: cannot create temporary of files in the tarball: $TARBALL: $TMP_TARBALL_LIST" 1>&2
exit 17
fi
# case: -n
#
elif [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[6]: because of -n, did not execute:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --totals" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcvf $TMP_TARBALL < $TMP_TAR_LIST" 1>&2
elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary of files in the tarball: $TARBALL is not used: $TMP_TARBALL_LIST" 1>&2
fi
# update the tarball only if the tarball contents is different
# create a temporary tarball
#
TMP_TARBALL=".$NAME.$$.tar.bz2"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: temporary tarball: $TMP_TARBALL" 1>&2
fi
if [[ -z $NOOP ]]; then
if cmp -s "$TMP_TARBALL" "$TARBALL"; then
trap 'rm -f $TMP_MANIFEST_LIST $TMP_FILES_TO_TAR $TMP_EXIT_CODE $TMP_TARBALL_LIST $TMP_TARBALL; exit' 0 1 2 3 15
rm -f "$TMP_TARBALL"
if [[ -e $TMP_TARBALL ]]; then
echo "$0: ERROR: cannot remove temporary tarball: $TMP_TARBALL" 1>&2
exit 16
fi
:> "$TMP_TARBALL"
if [[ ! -e $TMP_TARBALL ]]; then
echo "$0: ERROR: cannot create temporary tarball: $TMP_TARBALL" 1>&2
exit 17
fi
elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, temporary tarball is not used: $TMP_TARBALL" 1>&2
fi
# case: tarball did not change
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: file did not change: $TARBALL" 1>&2
# test - if needed - if the sorted list of files from the tarball matches the sorted list of found entry files
#
if [[ -z $REBUILD_TARBALL ]]; then
# form he sorted list of files in the tarball
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: $GTAR_TOOL -jtf $TARBALL > $TMP_TARBALL_LIST" 1>&2
fi
"$GTAR_TOOL" -jtf "$TARBALL" > "$TMP_TARBALL_LIST"
status="$?"
if [[ $status -ne 0 ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"failed to list files in tarball: $TARBALL, error: $status" 1>&2
fi
fi
if [[ -z $REBUILD_TARBALL ]]; then
LC_ALL=C sort -d -u "$TMP_TARBALL_LIST" -o "$TMP_TARBALL_LIST"
status="$?"
if [[ $status -ne 0 ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"failed to sort list of files in tarball: $TARBALL, error: $status" 1>&2
fi
else
if ! cmp -s "$TMP_TARBALL_LIST" "$TMP_FILES_TO_TAR"; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"sorted list of files in tarball: $TMP_TARBALL_LIST" \
"does not match sorted list of found entry files: $TMP_FILES_TO_TAR" 1>&2
fi
fi
fi
fi
fi
else
# test - if needed - if the files in the tarball match the contents of the entry's files
#
if [[ -z $REBUILD_TARBALL ]]; then
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: TZ=UTC LC_ALL=C $GTAR_TOOL --compare --file=$TARBALL -C . 2>&1 |" \
"grep -E -v ': (Uid|Gid|Mod time) differs$'" 1>&2
fi
TAR_CONTENTS_DIFFERS=$(TZ=UTC LC_ALL=C "$GTAR_TOOL" --compare --file="$TARBALL" -C . 2>&1 | \
grep -E -v ': (Uid|Gid|Mod time) differs$')
if [[ -n $TAR_CONTENTS_DIFFERS ]]; then
REBUILD_TARBALL="true"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: REBUILD_TARBALL set to: $REBUILD_TARBALL," \
"contents of tarball: $TARBALL differs from contents of entry: $YYYY_DIR" 1>&2
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: tar differences starts below" 1>&2
echo "$TAR_CONTENTS_DIFFERS" 1>&2
echo "$0: debug[3]: tar differences ends above" 1>&2
fi
fi
fi
# test - if needed - update the tarball
#
# We use gnu tar to form the bzip2 compressed tarball with careful arguments
# so that the resulting tarball is consistent. There are systems for which the
# tarball won't be the same. However we do not need that. All of the tests
# above are such that if $REBUILD_TARBALL is not empty, then the tarball needs
# to updated regardless.
#
if [[ -n $REBUILD_TARBALL ]]; then
if [[ -z $NOOP ]]; then
# update .tar.tstamp with the timestamp of now
#
LAST_TAR_TSTAMP=$(TZ=UTZ date '+%s')
TAR_TIMESTAMP=$(TZ=UTZ date '+%s')
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: new TZ=UTC date +%s failed, error: $status" 1>&2
exit 8
fi
if [[ $LAST_TAR_TSTAMP =~ ^-?[0-9]+$ ]]; then
if [[ $LAST_TAR_TSTAMP -le 0 ]]; then
echo "$0: ERROR: new LAST_TAR_TSTAMP is not an integer > 0: $LAST_TAR_TSTAMP" 1>&2
if [[ $TAR_TIMESTAMP =~ ^-?[0-9]+$ ]]; then
if [[ $TAR_TIMESTAMP -le 0 ]]; then
echo "$0: ERROR: new TAR_TIMESTAMP is not an integer > 0: $TAR_TIMESTAMP" 1>&2
exit 8
fi
else
echo "$0: ERROR: new LAST_TAR_TSTAMP is not an integer: $LAST_TAR_TSTAMP" 1>&2
echo "$0: ERROR: new TAR_TIMESTAMP is not an integer: $TAR_TIMESTAMP" 1>&2
exit 8
fi
# report new timestamp
# case: form the tarball verbosely if -v 5 or more
#
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: new LAST_TAR_TSTAMP=$LAST_TAR_TSTAMP" 1>&2
echo "$0: debug[1]: new LAST_TAR_DATE=$LAST_TAR_DATE" 1>&2
echo "$0: debug[1]: updating: $DOT_TAR_TSTAMP" 1>&2
fi
echo "$LAST_TAR_TSTAMP" > "$DOT_TAR_TSTAMP"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: updating: $YEAR_TAR_TSTAMP" 1>&2
fi
echo "$LAST_TAR_TSTAMP" > "$YEAR_TAR_TSTAMP"
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: updating: $TOP_TAR_TSTAMP" 1>&2
fi
echo "$LAST_TAR_TSTAMP" > "$TOP_TAR_TSTAMP"
# convert the new LAST_TAR_TSTAMP into a date string
#
LAST_TAR_DATE=$(TZ=UTC date -r "$LAST_TAR_TSTAMP")
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: new date -r $LAST_TAR_TSTAMP failed, error: $status" 1>&2
exit 8
fi
if [[ -z $LAST_TAR_DATE ]]; then
echo "$0: ERROR: new date -r $LAST_TAR_TSTAMP produced an empty string" 1>&2
exit 8
fi
# case: re-form the tarball verbosely if -v 3 or more
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: about to re-execute:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --totals" \
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: about to execute:" \
"TZ=UTC LC_ALL=C $GTAR_TOOL --files-from=- --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --mtime=@${TAR_TIMESTAMP}" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcvf $TMP_TARBALL < $TMP_TAR_LIST" 1>&2
"$GTAR_TOOL" --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name \
--owner=501 --group=20 --numeric-owner --totals \
"--totals -jcvf $TMP_TARBALL < $TMP_FILES_TO_TAR" 1>&2
TZ=UTC LC_ALL=C "$GTAR_TOOL" --files-from=- --no-acls --no-xattrs --no-selinux --sort=name \
--owner=501 --group=20 --numeric-owner --mtime="@${TAR_TIMESTAMP}" \
--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime' \
--mtime="$LAST_TAR_DATE" -jcvf "$TMP_TARBALL" < "$TMP_TAR_LIST"
--totals -jcvf "$TMP_TARBALL" < "$TMP_FILES_TO_TAR"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: 2nd:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --totals" \
echo "$0: ERROR:" \
"TZ=UTC LC_ALL=C $GTAR_TOOL --files-from=- --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --mtime=@${TAR_TIMESTAMP}" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcvf $TMP_TARBALL < $TMP_TAR_LIST failed, error: $status" 1>&2
"--totals -jcvf $TMP_TARBALL < $TMP_FILES_TO_TAR failed, error: $status" 1>&2
exit 8
fi
# case: re-form the tarball silently
# case: form the tarball silently
#
else
"$GTAR_TOOL" --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name \
TZ=UTC LC_ALL=C "$GTAR_TOOL" --files-from=- --no-acls --no-xattrs --no-selinux --sort=name \
--owner=501 --group=20 --numeric-owner \
--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime' \
--mtime="$LAST_TAR_DATE" -jcf "$TMP_TARBALL" < "$TMP_TAR_LIST"
--totals -jcf "$TMP_TARBALL" < "$TMP_FILES_TO_TAR"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR: 2nd:" \
"$GTAR_TOOL --files-from=- --sparse --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner" \
echo "$0: ERROR:" \
"TZ=UTC LC_ALL=C $GTAR_TOOL --files-from=- --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner --mtime=@${TAR_TIMESTAMP}" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=$LAST_TAR_DATE -jcf $TMP_TARBALL < $TMP_TAR_LIST failed, error: $status" 1>&2
"--totals -jcf $TMP_TARBALL < $TMP_FILES_TO_TAR failed, error: $status" 1>&2
exit 8
fi
fi
@@ -855,11 +851,11 @@ if [[ -z $NOOP ]]; then
# verify the tarball is not empty
#
if [[ ! -s $TMP_TARBALL ]]; then
echo "$0: ERROR: updated tarball is missing is empty: $TMP_TARBALL" 1>&2
echo "$0: ERROR: tarball is missing is empty: $TMP_TARBALL" 1>&2
exit 8
fi
# case: tarball changed, update the file
# move temporary tarball into the permanent tarball
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: mv -f -- $TMP_TARBALL $TARBALL" 1>&2
@@ -881,16 +877,47 @@ if [[ -z $NOOP ]]; then
echo "$0: ERROR: not a non-empty index HTML file: $TARBALL" 1>&2
exit 8
fi
# update tar timestamp
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: new TAR_TIMESTAMP=$TAR_TIMESTAMP" 1>&2
fi
echo "$TAR_TIMESTAMP" > "$DOT_TAR_TSTAMP"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: updating: $YEAR_TAR_TSTAMP" 1>&2
fi
echo "$TAR_TIMESTAMP" > "$YEAR_TAR_TSTAMP"
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: updating: $TOP_TAR_TSTAMP" 1>&2
fi
echo "$TAR_TIMESTAMP" > "$TOP_TAR_TSTAMP"
# case: -n
#
elif [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: because of -n, did not execute:" \
"TZ=UTC LC_ALL=C $GTAR_TOOL --files-from=- --no-acls --no-xattrs --no-selinux --sort=name" \
"--owner=501 --group=20 --numeric-owner" \
"--pax-option='exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime'" \
"--mtime=@${TAR_TIMESTAMP} --totals -jcvf $TMP_TARBALL < $TMP_FILES_TO_TAR" 1>&2
echo "$0: debug[5]: because of -n, did not move temporary tarball: $TMP_TARBALL" \
"into the permanent tarball: $TARBALL" 1>&2
echo "$0: debug[5]: because of -n, did not update $DOT_TAR_TSTAMP nor $YEAR_TAR_TSTAMP nor $TOP_TAR_TSTAMP" 1>&2
fi
# case: tarball update not needed
#
elif [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: because of -n, tarball was not touched: $TARBALL" 1>&2
echo "$0: debug[1]: no need to update $TARBALL" 1>&2
fi
# All Done!!! -- Jessica Noll, Age 2
#
if [[ -z $NOOP ]]; then
rm -f "$TMP_MANIFEST_LIST" "$TMP_TAR_LIST" "$TMP_EXIT_CODE" "$TMP_TARBALL"
rm -f "$TMP_MANIFEST_LIST" "$TMP_FILES_TO_TAR" "$TMP_EXIT_CODE" "$TMP_TARBALL_LIST" "$TMP_TARBALL"
elif [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: -n disabled execution of: rm -f $TMP_MANIFEST_LIST $TMP_TAR_LIST $TMP_EXIT_CODE $TMP_TARBALL" 1>&2
echo "$0: debug[1]: -n disabled execution of: rm -f $TMP_MANIFEST_LIST $TMP_FILES_TO_TAR" \
"$TMP_EXIT_CODE $TMP_TARBALL_LIST $TMP_TARBALL" 1>&2
fi
exit "$EXIT_CODE"
+402
View File
@@ -0,0 +1,402 @@
#!/usr/bin/env bash
#
# untar-entry.sh - untar files belonging to an entry
#
# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby granted,
# provided that the above copyright, this permission notice and text
# this comment, and the disclaimer below appear in all of the following:
#
# supporting documentation
# source copies
# source works derived from this source
# binaries derived from this source or from derived source
#
# LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
# EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
# USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
# chongo (Landon Curt Noll, http://www.isthe.com/chongo/index.html) /\oo/\
#
# Share and enjoy! :-)
# firewall - run only with a bash that is version 5.1.8 or later
#
# The "/usr/bin/env bash" command must result in using a bash that
# is version 5.1.8 or later.
#
# We could relax this version and insist on version 4.2 or later. Versions
# of bash between 4.2 and 5.1.7 might work. However, to be safe, we will require
# bash version 5.1.8 or later.
#
# WHY 5.1.8 and not 4.2? This safely is done because macOS Homebrew bash we
# often use is "version 5.2.26(1)-release" or later, and the RHEL Linux bash we
# use often use is "version 5.1.8(1)-release" or later. These versions are what
# we initially tested. We recommend you either upgrade bash or install a newer
# version of bash and adjust your $PATH so that "/usr/bin/env bash" finds a bash
# that is version 5.1.8 or later.
#
# NOTE: The macOS shipped, as of 2024 March 15, a version of bash is something like
# bash "version 3.2.57(1)-release". That macOS shipped version of bash
# will NOT work. For users of macOS we recommend you install Homebrew,
# (see https://brew.sh), and then run "brew install bash" which will
# typically install it into /opt/homebrew/bin/bash, and then arrange your $PATH
# so that "/usr/bin/env bash" finds "/opt/homebrew/bin" (or whatever the
# Homebrew bash is).
#
# NOTE: And while MacPorts might work, we noticed a number of subtle differences
# with some of their ported tools to suggest you might be better off
# with installing Homebrew (see https://brew.sh). No disrespect is intended
# to the MacPorts team as they do a commendable job. Nevertheless we ran
# into enough differences with MacPorts environments to suggest you
# might find a better experience with this tool under Homebrew instead.
#
if [[ -z ${BASH_VERSINFO[0]} ||
${BASH_VERSINFO[0]} -lt 5 ||
${BASH_VERSINFO[0]} -eq 5 && ${BASH_VERSINFO[1]} -lt 1 ||
${BASH_VERSINFO[0]} -eq 5 && ${BASH_VERSINFO[1]} -eq 1 && ${BASH_VERSINFO[2]} -lt 8 ]]; then
echo "$0: ERROR: bash version needs to be >= 5.1.8: $BASH_VERSION" 1>&2
echo "$0: Warning: bash version >= 4.2 might work but 5.1.8 was the minimum we tested" 1>&2
echo "$0: Notice: For macOS users: install Homebrew (see https://brew.sh), then run" \
""brew install bash" and then modify your \$PATH so that \"#!/usr/bin/env bash\"" \
"finds the Homebrew installed (usually /opt/homebrew/bin/bash) version of bash" 1>&2
exit 4
fi
# setup bash file matching
#
# We must declare arrays with -ag or -Ag, and we need loops to "export" modified variables.
# This requires a bash with a version 4.2 or later. See the larger comment above about bash versions.
#
shopt -s nullglob # enable expanded to nothing rather than remaining unexpanded
shopt -u failglob # disable error message if no matches are found
shopt -u dotglob # disable matching files starting with .
shopt -u nocaseglob # disable strict case matching
shopt -u extglob # enable extended globbing patterns
shopt -s globstar # enable ** to match all files and zero or more directories and subdirectories
# set variables referenced in the usage message
#
export VERSION="1.0 2024-03-25"
NAME=$(basename "$0")
export NAME
export V_FLAG=0
GIT_TOOL=$(type -P git)
export GIT_TOOL
if [[ -z "$GIT_TOOL" ]]; then
echo "$0: FATAL: git tool is not installed or not in \$PATH" 1>&2
exit 5
fi
"$GIT_TOOL" rev-parse --is-inside-work-tree >/dev/null 2>&1
status="$?"
if [[ $status -eq 0 ]]; then
TOPDIR=$("$GIT_TOOL" rev-parse --show-toplevel)
fi
export TOPDIR
export REPO_URL="https://github.com/ioccc-src/temp-test-ioccc"
export CAP_W_FLAG_FOUND=
GTAR_TOOL=$(type -P gtar)
export GTAR_TOOL
if [[ -z "$GIT_TOOL" ]]; then
echo "$0: FATAL: gtar (gnu tar) tool is not installed or not in \$PATH" 1>&2
exit 8
fi
# set usage message
#
export USAGE="usage: $0 [-h] [-v level] [-V] [-d topdir] [-D docroot/] [-n] [-N]
[-p tool] [-u repo_url] [-w site_url] [-W]
YYYY/dir
-h print help message and exit
-v level set verbosity level (def level: 0)
-V print version string and exit
-d topdir set topdir (def: $TOPDIR)
-D docroot/ This option is ignored
-n go thru the actions, but do not update any files (def: do the action)
-N do not process file, just parse arguments and ignore the file (def: process the file)
-p tool This option is ignored
-u repo_url This option is ignored
-w site_url This option is ignored
-W Warn if a file in the manifest is missing: (def: error if a file is missing)
YYYY/dir path from topdir to entry directory: must contain the files: README.md, .path and .entry.json
Exit codes:
0 all OK
1 some internal tool exited non-zero
2 -h and help string printed or -V and version string printed
3 command line error
4 bash version is too old
5 some internal tool is not found or not an executable file
6 problems found with or in the topdir or topdir/YYYY directory
7 problems found with or in the entry topdir/YYYY/dir directory
8 gnu tar is missing or execution failed or error in forming compressed tarball
>= 10 internal error
$NAME version: $VERSION"
# setup
#
export NOOP=
export DO_NOT_PROCESS=
# parse command line
#
while getopts :hv:Vd:D:nNp:u:U:w:W flag; do
case "$flag" in
h) echo "$USAGE" 1>&2
exit 2
;;
v) V_FLAG="$OPTARG"
;;
V) echo "$VERSION"
exit 2
;;
d) TOPDIR="$OPTARG"
;;
D) ;;
n) NOOP="-n"
;;
N) DO_NOT_PROCESS="-N"
;;
p) ;;
u) ;;
U) ;;
w) ;;
W) CAP_W_FLAG_FOUND="true"
;;
\?) echo "$0: ERROR: invalid option: -$OPTARG" 1>&2
echo 1>&2
print_usage 1>&2
exit 3
;;
:) echo "$0: ERROR: option -$OPTARG requires an argument" 1>&2
echo 1>&2
echo "$USAGE" 1>&2
exit 3
;;
*) echo "$0: ERROR: unexpected value from getopts: $flag" 1>&2
echo 1>&2
echo "$USAGE" 1>&2
exit 3
;;
esac
done
# parse the command line arguments
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: debug level: $V_FLAG" 1>&2
fi
#
shift $(( OPTIND - 1 ));
#
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: file argument count: $#" 1>&2
fi
if [[ $# -ne 1 ]]; then
echo "$0: ERROR: expected 1 arg, found: $#" 1>&2
exit 3
fi
#
export ENTRY_PATH="$1"
# verify that we have a topdir directory
#
REPO_NAME=$(basename "$REPO_URL")
export REPO_NAME
if [[ -z $TOPDIR ]]; then
echo "$0: ERROR: cannot find top of git repo directory" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 6
fi
if [[ ! -e $TOPDIR ]]; then
echo "$0: ERROR: TOPDIR does not exist: $TOPDIR" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 6
fi
if [[ ! -d $TOPDIR ]]; then
echo "$0: ERROR: TOPDIR is not a directory: $TOPDIR" 1>&2
echo "$0: Notice: if needed: $GIT_TOOL clone $REPO_URL; cd $REPO_NAME" 1>&2
exit 6
fi
# cd to topdir
#
if [[ ! -e $TOPDIR ]]; then
echo "$0: ERROR: cannot cd to non-existent path: $TOPDIR" 1>&2
exit 6
fi
if [[ ! -d $TOPDIR ]]; then
echo "$0: ERROR: cannot cd to a non-directory: $TOPDIR" 1>&2
exit 6
fi
export CD_FAILED
if [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: about to: cd $TOPDIR" 1>&2
fi
cd "$TOPDIR" || CD_FAILED="true"
if [[ -n $CD_FAILED ]]; then
echo "$0: ERROR: cd $TOPDIR failed" 1>&2
exit 6
fi
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2
fi
# verify that ENTRY_PATH is a entry directory
#
if [[ ! -d $ENTRY_PATH ]]; then
echo "$0: ERROR: arg is not a directory: $ENTRY_PATH" 1>&2
exit 3
fi
if [[ ! -w $ENTRY_PATH ]]; then
echo "$0: ERROR: arg is not a writable directory: $ENTRY_PATH" 1>&2
exit 3
fi
export YEAR_DIR=${ENTRY_PATH%%/*}
if [[ -z $YEAR_DIR ]]; then
echo "$0: ERROR: arg not in YYYY/dir form: $ENTRY_PATH" 1>&2
exit 3
fi
export ENTRY_DIR=${ENTRY_PATH#*/}
if [[ -z $ENTRY_DIR ]]; then
echo "$0: ERROR: arg: $ENTRY_PATH not in $YEAR_DIR/dir form: $ENTRY_PATH" 1>&2
exit 3
fi
if [[ $ENTRY_DIR = */* ]]; then
echo "$0: ERROR: dir from arg: $ENTRY_PATH contains a /: $ENTRY_DIR" 1>&2
exit 3
fi
if [[ ! -d $YEAR_DIR ]]; then
echo "$0: ERROR: YYYY from arg: $ENTRY_PATH is not a directory: $YEAR_DIR" 1>&2
exit 3
fi
export ENTRY_ID="${YEAR_DIR}_${ENTRY_DIR}"
export DOT_YEAR="$YEAR_DIR/.year"
if [[ ! -s $DOT_YEAR ]]; then
echo "$0: ERROR: not a non-empty file: $DOT_YEAR" 1>&2
exit 6
fi
# Now that we have moved to topdir, form and verify YYYY_DIR is a writable directory
export YYYY_DIR="$YEAR_DIR/$ENTRY_DIR"
if [[ ! -e $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY/dir from arg: $ENTRY_PATH does not exist: $YYYY_DIR" 1>&2
exit 7
fi
if [[ ! -d $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY/dir from arg: $ENTRY_PATH is not a directory: $YYYY_DIR" 1>&2
exit 7
fi
if [[ ! -w $YYYY_DIR ]]; then
echo "$0: ERROR: YYYY/dir from arg: $ENTRY_PATH is not a writable directory: $YYYY_DIR" 1>&2
exit 7
fi
# determine the name of our tarball
#
# TARBALL - the same of the compressed tarball to verify and if needed re-build
# REBUILD_TARBALL - if non-empty, we need to re-build TARBALL and update tar timestamps
#
export TARBALL="$YYYY_DIR/$ENTRY_ID.tar.bz2"
# test - if needed - if the tarball is a non-empty writable file
#
if [[ ! -e $TARBALL ]]; then
echo "$0: ERROR: tarball does not exist: $TARBALL" 1>&2
exit 1
fi
if [[ ! -f $TARBALL ]]; then
echo "$0: ERROR: tarball is not a file: $TARBALL" 1>&2
exit 1
fi
if [[ ! -w $TARBALL ]]; then
echo "$0: ERROR: tarball is not a writable file: $TARBALL" 1>&2
exit 1
fi
if [[ ! -s $TARBALL ]]; then
echo "$0: ERROR: tarball is not a non-empty writable file: $TARBALL" 1>&2
exit 1
fi
# parameter debugging
#
if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: VERSION=$VERSION" 1>&2
echo "$0: debug[3]: NAME=$NAME" 1>&2
echo "$0: debug[3]: V_FLAG=$V_FLAG" 1>&2
echo "$0: debug[3]: GIT_TOOL=$GIT_TOOL" 1>&2
echo "$0: debug[3]: GTAR_TOOL=$GTAR_TOOL" 1>&2
echo "$0: debug[3]: TOPDIR=$TOPDIR" 1>&2
echo "$0: debug[3]: REPO_URL=$REPO_URL" 1>&2
echo "$0: debug[3]: NOOP=$NOOP" 1>&2
echo "$0: debug[3]: DO_NOT_PROCESS=$DO_NOT_PROCESS" 1>&2
echo "$0: debug[3]: CAP_W_FLAG_FOUND=$CAP_W_FLAG_FOUND" 1>&2
echo "$0: debug[3]: ENTRY_PATH=$ENTRY_PATH" 1>&2
echo "$0: debug[3]: REPO_NAME=$REPO_NAME" 1>&2
echo "$0: debug[3]: YEAR_DIR=$YEAR_DIR" 1>&2
echo "$0: debug[3]: ENTRY_DIR=$ENTRY_DIR" 1>&2
echo "$0: debug[3]: ENTRY_ID=$ENTRY_ID" 1>&2
echo "$0: debug[3]: TARBALL=$TARBALL" 1>&2
fi
# If -N, time to exit
#
if [[ -n $DO_NOT_PROCESS ]]; then
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: arguments parsed, -N given, exit 0" 1>&2
fi
exit 0
fi
# untar entry compressed tarball
#
if [[ -z $NOOP ]]; then
# case: form the tarball verbosely if -v 5 or more
#
if [[ $V_FLAG -ge 1 ]]; then
echo "$0: debug[1]: about to execute:" \
"$GTAR_TOOL --totals -jxvf $TARBALL" 1>&2
"$GTAR_TOOL" --totals -jxvf "$TARBALL"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR:" \
"$GTAR_TOOL --totals -jxvf $TARBALL failed, error: $status" 1>&2
exit 8
fi
# case: form the tarball silently
#
else
"$GTAR_TOOL" -jxf "$TARBALL"
status="$?"
if [[ $status -ne 0 ]]; then
echo "$0: ERROR:" \
"$GTAR_TOOL -jxf $TARBALL failed, error: $status" 1>&2
exit 8
fi
fi
# case: -n
#
elif [[ $V_FLAG -ge 5 ]]; then
echo "$0: debug[5]: because of -n, did not execute:" \
"$GTAR_TOOL --totals -jxvf $TARBALL" 1>&2
fi
# All Done!!! -- Jessica Noll, Age 2
#
exit 0