apt-snapshots-serials 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. BASE_URL=http://time-based.snapshots.deb.tails.boum.org/
  6. CONFIG=config/APT_snapshots.d
  7. ORIGINS=$(cd $CONFIG; ls -d *)
  8. get_latest_serial() {
  9. origin=$1
  10. wget -q $BASE_URL/$origin/project/trace/$origin -O - \
  11. | awk -F': ' '/^Archive serial: / {print $2}'
  12. }
  13. action="${1:-cat}"
  14. case "$action" in
  15. cat)
  16. for origin in $ORIGINS; do
  17. echo -n "$origin: "
  18. cat "$CONFIG/$origin/serial"
  19. done
  20. ;;
  21. get-latest)
  22. for origin in $ORIGINS; do
  23. online=$(get_latest_serial $origin)
  24. echo "$origin: $online"
  25. done
  26. ;;
  27. freeze)
  28. for origin in $ORIGINS; do
  29. serial_file="$CONFIG/$origin/serial"
  30. git=$(cat $serial_file)
  31. case "$origin" in
  32. debian-security)
  33. new=latest
  34. ;;
  35. *)
  36. new=$(get_latest_serial $origin)
  37. esac
  38. printf "Origin $origin:\n old: $git\n new: $new\n"
  39. echo $new > $serial_file
  40. done
  41. printf "\nAll files ($CONFIG/*/serial) have been updated with new serials\n" >&2
  42. ;;
  43. thaw)
  44. for origin in $ORIGINS; do
  45. serial_file="$CONFIG/$origin/serial"
  46. git=$(cat $serial_file)
  47. printf "Origin $origin:\n old: $git\n new: latest\n"
  48. echo 'latest' > $serial_file
  49. done
  50. ;;
  51. prepare-build)
  52. rm -rf tmp/APT_snapshots.d
  53. mkdir -p tmp
  54. cp -r config/APT_snapshots.d tmp/
  55. $0 get-latest > tmp/cached_APT_snapshots_serials
  56. for origin_dir in tmp/APT_snapshots.d/*; do
  57. origin=$(basename $origin_dir)
  58. if grep -qs '^latest$' $origin_dir/serial; then
  59. awk -F': ' "/^$origin: / {print \$2}" \
  60. tmp/cached_APT_snapshots_serials \
  61. > $origin_dir/serial
  62. fi
  63. done
  64. ;;
  65. *)
  66. printf "unknown action ($action), use either 'cat', 'get-latest', 'prepare-build', 'freeze' or 'thaw'\n" >&2
  67. exit 1
  68. ;;
  69. esac