Integrate longitudinal high-dimensional data in a data warehouse using the git commit graph to store temporal information and git annex to store large data in a content-addressable fashion.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
5.7KB

  1. #!/bin/env bash
  2. # © Copyright 2024 Maxime Wack
  3. # This file is part of git ommix.
  4. # Git ommix is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  5. # Git ommix is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. # You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
  7. ###############################################################################
  8. # Use bash "strict mode"
  9. set -uo pipefail
  10. IFS=$'\n\t'
  11. ###############################################################################
  12. # Load git ommix functions
  13. # Load global and local settings if they exist
  14. # Save env variables
  15. envs=$(env | grep ^GIT_OMMIX)
  16. TEST_OMMIX="${TEST_OMMIX:-}"
  17. if [[ "$TEST_OMMIX" ]]; then
  18. source $(dirname $0)/functions
  19. else
  20. source /usr/share/git-ommix/functions
  21. fi
  22. [[ -f "/etc/gitommix.conf" ]] && source "/etc/gitommix.conf"
  23. [[ -f "$HOME/.config/gitommix.conf" ]] && source "$HOME/.config/gitommix.conf"
  24. # Restore env variables after config load
  25. eval $envs
  26. ###############################################################################
  27. # Parse arguments
  28. # Initialize default values
  29. # If no arg, full help
  30. (( $# > 0 )) || usage root
  31. VERB="$1"
  32. # If no object, help for the verb
  33. (( $# > 1 )) || usage "$VERB"
  34. OBJECT="$2"
  35. shift 2
  36. # Default values
  37. PROVIDER="${PROVIDER:-}"
  38. METHOD=
  39. PATIENT="${PATIENT:-}"
  40. SAMPLE="${SAMPLE:-}"
  41. DATE="${DATE:-$(date +'%Y-%m-%dT%H:%M:%S')}"
  42. ID=$(base64 /dev/urandom | tr --delete "/+=" | head --bytes=10)
  43. INVALIDATE=()
  44. USE=()
  45. REVISION_OF=
  46. MESSAGE2=
  47. DEBUG="${DEBUG:-}"
  48. # Declare global vars
  49. HASH=()
  50. NAME=()
  51. ###############################################################################
  52. # GETOPT
  53. #
  54. # Test getopt
  55. # Allow a command to fail with !’s side effect on errexit
  56. # Use return value from ${PIPESTATUS[0]}, because ! hosed $?
  57. #
  58. # Set getopt short and long options
  59. # -temporarily store output to be able to check for errors
  60. # -activate quoting/enhanced mode (e.g. by writing out “--options”)
  61. # -pass arguments only via -- "$@" to separate them correctly
  62. #
  63. # Read getopt’s quoted output
  64. ! getopt --test > /dev/null
  65. [[ ${PIPESTATUS[0]} -eq 4 ]] || die 'I’m sorry, `getopt --test` failed in this environment.'
  66. OPTIONS=p:s:m:dv
  67. LONGOPTS=provider:,method:,patient:,sample:,date:,id:,invalidate:,use:,revision_of:,message:,debug,dry,verbose
  68. ! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "git-ommix" -- "$@")
  69. [[ ${PIPESTATUS[0]} -eq 0 ]] || usage root
  70. eval set -- "$PARSED"
  71. ###############################################################################
  72. # Read the options and set the parameters values
  73. # USE and INVALIDATE can be called multiple times
  74. # and the values are stored in an array
  75. while true; do
  76. case "$1" in
  77. --provider)
  78. PROVIDER="$2"
  79. shift 2
  80. ;;
  81. --method)
  82. METHOD="$2"
  83. shift 2
  84. ;;
  85. -p|--patient)
  86. PATIENT="$2"
  87. shift 2
  88. ;;
  89. -s|--sample)
  90. SAMPLE="$2"
  91. shift 2
  92. ;;
  93. --date)
  94. DATE="$2"
  95. shift 2
  96. ;;
  97. --id)
  98. ID="$2"
  99. shift 2
  100. ;;
  101. --use)
  102. USE+=("$2")
  103. shift 2
  104. ;;
  105. --invalidate)
  106. INVALIDATE+=("$2")
  107. shift 2
  108. ;;
  109. --revision_of)
  110. REVISION_OF="$2"
  111. shift 2
  112. ;;
  113. -m|--message)
  114. MESSAGE2="$2"
  115. shift 2
  116. ;;
  117. -d|--debug)
  118. DEBUG="debug"
  119. shift
  120. ;;
  121. --dry)
  122. DEBUG="dry"
  123. shift
  124. ;;
  125. -v|--verbose)
  126. DEBUG="verbose"
  127. shift
  128. ;;
  129. --)
  130. shift
  131. break
  132. ;;
  133. *)
  134. echo "Programming error"
  135. exit 3
  136. ;;
  137. esac
  138. done
  139. # Replace AUTHOR with PROVIDER if given
  140. AUTHOR="${PROVIDER:-$GIT_OMMIX_DEFAULT_AUTHOR}"
  141. PROVIDER="${PROVIDER%% <*}"
  142. PROVIDER="${PROVIDER/ /_}"
  143. # The remaining arguments will be files when adding data|result
  144. # or a list of commit hashes or name when listing
  145. # If no file is given, use '*'
  146. QUERY=("${1:-}")
  147. FILES=("${@:-*}")
  148. HASHES=("${@:-}")
  149. [[ "$HASHES" == "-" ]] && HASHES="$(cat /dev/stdin)"
  150. # Output parameter values for debug
  151. [[ "$DEBUG" == "debug" ]] && echo "####################################
  152. Verb: $VERB
  153. Object: $OBJECT
  154. Provider: $PROVIDER
  155. Author: $AUTHOR
  156. Method: $METHOD
  157. Patient: $PATIENT
  158. Sample: $SAMPLE
  159. Date: $DATE
  160. Id: $ID
  161. Use: ${USE[@]}
  162. Invalidate: ${INVALIDATE[@]}
  163. Revision_of: $REVISION_OF
  164. Message: $MESSAGE2
  165. Files: ${FILES[@]}
  166. Hashes: ${HASHES[@]}
  167. "
  168. ###############################################################################
  169. # Setup git ommix
  170. # Record the current directory for file operations
  171. # Create the git ommix directory if it doesn't exist yet and cd
  172. CURRENT_DIR="$PWD"
  173. mkdir -p "$GIT_OMMIX_REPO_DIR" || die "Unable to create the git ommix base directory at: $GIT_OMMIX_REPO_DIR
  174. Please check your permissions"
  175. cd "$GIT_OMMIX_REPO_DIR" || die "Unable to access the git ommix base directory at: $GIT_OMMIX_REPO_DIR
  176. Please check your permissions"
  177. ###############################################################################
  178. # Run the given verb
  179. case "$VERB" in
  180. add) add;;
  181. list) list;;
  182. get) get;;
  183. # Unknown verb -> usage root
  184. *) usage root;;
  185. esac