2 ** DONE Add job control for short buffer length
 
   3    CLOSED: [2020-07-02 Thu 16:04]
 
   4 2020-07-02T14:56Z; bktei> File write operations were bundled into a
 
   5 magicWriteBuffer function that is called then detached from the script
 
   6 shell (job control), but the detached job is not tracked by the main
 
   7 script. A problem may arise if two instances of magicWriteBuffer
 
   8 attempt to write to the same tar simultaneously. Two instances of
 
   9 magicWriteBuffer may exist if the buffer length is low (ex: 1 second);
 
  10 the default buffer length of 60 seconds should reduce the probability
 
  11 of a collision but it should be possible for the main script to track
 
  12 the process ID of a magicWriteBuffer() as soon as it detaches and then
 
  13 checking (via ~$!~ as described [[https://bashitout.com/2013/05/18/Ampersands-on-the-command-line.html][here]]) that the process is still alive.
 
  14 2020-07-02T15:23Z; bktei> I found that the Bash ~wait~ built-in can be
 
  15 used to delay processing until a specified job completes. The ~wait~
 
  16 command will pause script execution until all backgrounded processes
 
  18 2020-07-02T16:03Z; bktei> Added ~wait~.
 
  19 ** DONE Rewrite tar initialization function
 
  20    CLOSED: [2020-07-02 Thu 17:23]
 
  21 2020-07-02T17:23Z; bktei> Simplify tar initialization function so
 
  22 VERSION file is used to test appendability of tar as well as to mark
 
  23 when a new session is started.
 
  24 ** DONE Consolidate tar checking/creation into function
 
  25    CLOSED: [2020-07-02 Thu 18:33]
 
  26 2020-07-02T18:33Z; bktei> Simplify how the output tar file's existence
 
  27 is checked and its status as a valid tar file is validated. This was
 
  28 done using a new function ~checkMakeTar~.
 
  29 ** DONE Add VERSION if output tar deleted between writes
 
  31    CLOSED: [2020-07-02 Thu 20:22]
 
  32 2020-07-02T20:21Z; bktei> Added bkgpslog-specified function
 
  33 magicWriteVersion() to be called whenever a new time-stamped ~VERSION~
 
  34 file needs to be generated and appended to the output tar file
 
  36 ** TODO Rewrite buffer loop to reduce lag between gpspipe runs
 
  37 2020-07-03T17:10Z; bktei> As is, there is still a 5-6 second lag
 
  38 between when ~gpspipe~ times out at the end of a buffer round and when
 
  39 ~gpspipe~ is called by the subsequent buffer round. I believe this can
 
  40 be reduced by moving variable manipulations inside the
 
  41 asynchronously-executed magicWriteBuffer() function. Ideally, the
 
  42 while loop should look like:
 
  45 while( $SECONDS < $SCRIPT_TTL); do
 
  46     gpspipe-r > "$DIR_TMP"/buffer.nmea
 
  52 ** Initialize environment
 
  54 **** Save timeStart (YYYYmmddTHHMMSS±zz)
 
  56 **** Define Debugging functions
 
  57 **** Define Argument Processing function
 
  58 **** Define Main function
 
  61 *** Set output encryption and compression option strings
 
  62 *** Check that critical apps and dirs are available, displag missing ones.
 
  63 *** Set lifespans of script and buffer
 
  64 *** Init temp working dir ~DIR_TMP~
 
  65 Make temporary dir in tmpfs dir: ~/dev/shm/$(nonce)..bkgpslog/~ (~DIR_TMP~)
 
  66 *** Initialize ~tar~ archive
 
  67 **** Write ~bkgpslog~ version to ~$DIR_TMP/VERSION~
 
  68 **** Create empty ~tar~ archive in ~DIR_OUT~ at ~PATHOUT_TAR~
 
  70 Set output file name to:
 
  71 : PATHOUT_TAR="$DIR_OUT/YYYYmmdd..hostname_location.gz.age.tar"
 
  72 Usage: ~iso8601Period $timeStart $timeEnd~ 
 
  74 **** Append ~VERSION~ file to ~PATHOUT_TAR~
 
  76 Append ~$DIR_TMP/VERSION~ to ~PATHOUT_TAR~ via ~tar --append~
 
  78 *** Read/Write Loop (Record gps data until script lifespan ends)
 
  79 **** Determine output file paths
 
  80 **** Define GPS conversion commands
 
  81 **** Fill Bash variable buffer from ~gpspipe~
 
  82 **** Process bufferBash, save secured chunk set to ~DIR_TMP~
 
  83 **** Append each secured chunk to ~PATHOUT_TAR~
 
  84 : tar --append --directory=DIR_TMP --file=PATHOUT_TAR $(basename PATHOUT_{NMEA,GPX,KML} )
 
  85 **** Remove secured chunk from ~DIR_TMP~