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.

45 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/usr/bin/bash
  2. export TMPDIR=${TMPDIR:-/tmp/rclone}
  3. mkdir -p "${TMPDIR}"
  4. load_config() {
  5. local config_path=$TMPDIR/rclone_config
  6. local rclone_config_path=/opt/rclone/config
  7. local rclone_config_file=$rclone_config_path/.rclone.conf
  8. (jq -r '.source.config // empty' < "$1") > "$config_path"
  9. config_pass=$(jq -r '.source.password // ""' < "$1")
  10. if [[ -n "${config_pass}" ]]; then
  11. RCLONE_CONFIG_PASS="${config_pass}"
  12. export RCLONE_CONFIG_PASS
  13. fi
  14. if [ -s "$config_path" ]; then
  15. mkdir -p $rclone_config_path
  16. mv "$config_path" $rclone_config_file
  17. chmod 500 $rclone_config_file
  18. else
  19. echo "No config provided"
  20. exit 1
  21. fi
  22. }
  23. load_files() {
  24. set +e
  25. local files
  26. files=$(jq -r '.source.files? | keys? | join(" ") // ""' < "$1")
  27. set -e
  28. if [[ -n "${files}" ]]; then
  29. for fileName in $files; do
  30. local jq_path
  31. local content
  32. jq_path=".source.files.${fileName}"
  33. content=$(jq -r "${jq_path}" < "$1")
  34. echo "$content" > "${TMPDIR}/${fileName}"
  35. echo "Wrote: ${TMPDIR}/${fileName}"
  36. done
  37. ls -alh "${TMPDIR}"
  38. fi
  39. }