Docker pod for charlesreid1.com: (mediawiki + mysql + phpmyadmin + apache) + gitea + python + nginx. #krash https://pages.charlesreid1.com/pod-charlesreid1
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.

124 lines
2.9KB

  1. #!/bin/bash
  2. #
  3. # This stupid script needs too be scaled back,
  4. # because sudo and ssh can't play nicely together.
  5. #
  6. # This entire idiotic adventure in docker land
  7. # has been chock full of the most inane, stupid
  8. # landmines that containers cannot avoid,
  9. # like this one - if you try and run ssh through sudo,
  10. # you can't deal with keys or passphrases.
  11. function usage {
  12. echo ""
  13. echo "scrape_gitea_as_sudo.sh script:"
  14. echo "This script scrapes repository logs from the "
  15. echo "docker volume holding gitea."
  16. echo ""
  17. echo "It uses git to assemble a commit count,"
  18. echo "and exports the data to a CSV file for"
  19. echo "visualization and analysis."
  20. echo ""
  21. echo " ./scrape_gitea_as_sudo.sh [USER]"
  22. echo ""
  23. echo "The *optional* parameter USER is the"
  24. echo "final owner of the CSV file, via the"
  25. echo "final (chown) command in this script."
  26. echo ""
  27. echo "Also see:"
  28. echo "https://git.charlesreid1.com/data/charlesreid1-data"
  29. echo ""
  30. exit 1;
  31. }
  32. # Make sure running as root
  33. if [ "$(id -u)" != "0" ]; then
  34. echo ""
  35. echo ""
  36. echo "This script should be run as root."
  37. echo ""
  38. echo ""
  39. exit 1;
  40. fi
  41. # Check number of arguments (0 or 1)
  42. if [[ "$#" -eq 0 ]];
  43. then
  44. # default value
  45. USER="charles"
  46. elif [[ "$#" -eq 1 ]];
  47. # user-provided value
  48. USER="$1"
  49. else
  50. # sorry dude
  51. usage
  52. fi
  53. # Let's do it
  54. WORKDIR="/tmp/gitea-temp"
  55. GITDIR="/tmp/gitea-temp/charlesreid1-data"
  56. rm -rf ${WORKDIR}
  57. mkdir -p ${WORKDIR}
  58. sudo chown -R ${USER}:${USER} ${WORKDIR}
  59. rm -rf ${GITDIR}
  60. mkdir -p ${GITDIR}
  61. # Because sudo and ssh are too stupid to play nicely,
  62. # we're forced to use this sudo script to dump out
  63. # information every hour,
  64. # and leave it up to some user script somewhere
  65. # to grab the latest whenever they need it.
  66. #
  67. # This is the most idiotic problem yet.
  68. # don't clone data repo, that's the whole stupid problem
  69. ### sudo -H -u charles git clone ssh://git@gitdatabot:222/data/charlesreid1-data.git ${GITDIR}
  70. # Step 2: extract commit dates
  71. for dir in `find /var/lib/docker/volumes/pod-charlesreid1_stormy_gitea_data/_data/git/repositories -mindepth 2 -maxdepth 2 -type d`; do
  72. git --git-dir=$dir --work-tree=${WORKDIR} \
  73. log \
  74. --all --author="harles" --oneline --pretty="%H %ai" \
  75. | cut -f 2 -d " " >> ${GITDIR}/commit_dates
  76. done
  77. # Step 3: bin commit dates
  78. words=$( cat ${GITDIR}/commit_dates )
  79. echo "date,commits" > ${GITDIR}/commit_counts.csv
  80. echo $words | sort | python -c 'import sys;
  81. from collections import Counter; c=Counter(sys.stdin.read().strip().split(" "));
  82. print("\n".join(("%s,%s"%(k, c[k]) for k in c.keys())));' | sort | awk 'NF' >> ${GITDIR}/commit_counts.csv
  83. rm -f ${GITDIR}/commit_dates
  84. chown charles:charles ${GITDIR}/commit_counts.csv
  85. # Step 4: commit new commit count data as databot
  86. #
  87. # Instead of doing this here,
  88. # run the script
  89. # assemble_gitea_counts.sh
  90. # as a regular user.