devinteske

freebsd_dist_fetch

Nov 3rd, 2018
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  1. #!/bin/sh
  2. DEVICE_SELF_SCAN_ALL=NO
  3. [ "$_SCRIPT_SUBR" ] || . /usr/share/bsdconfig/script.subr
  4. usage(){ echo "Usage: ${0##*/} [-r releaseName] [dists ...]" >&2; exit 1; }
  5. while getopts hr: flag; do
  6.     case "$flag" in
  7.     r) releaseName="$OPTARG" ;;
  8.     *) usage
  9.     esac
  10. done
  11. shift $(( $OPTIND - 1 ))
  12. nonInteractive=1
  13. MEDIA_TIMEOUT=3 # because ftp.f.o has no SRV records
  14. _ftpPath=ftp://ftp.freebsd.org
  15. mediaSetFTP
  16. mediaOpen
  17. set -e
  18. #debug=1
  19. REL_DIST=/usr/freebsd-dist/$releaseName
  20. download() # $src to $dest
  21. {
  22.     size=$( f_device_get device_media "$1" $PROBE_SIZE )
  23.     f_device_get device_media "$1" | dpv -kb "$DIALOG_BACKTITLE" \
  24.         -t "$DIALOG_TITLE" -p "Downloading $releaseName" \
  25.         -o "$3" "$size:$1"
  26. }
  27. sign() # $file
  28. {
  29.     dpv -kb "$DIALOG_BACKTITLE" -t "$DIALOG_TITLE" \
  30.         -p "Signing $releaseName" -mx "sha256 >&2" \
  31.         "$size:${1##*/}" "$1" 2>&1 >&$TERMINAL_STDOUT_PASSTHRU
  32. }
  33. mkdir -p $REL_DIST
  34. MANIFEST=$REL_DIST/MANIFEST
  35. download MANIFEST to $MANIFEST
  36. dists="$*"
  37. for dist in ${dists:-$( awk '$0=$4' $MANIFEST )}; do
  38.     eval "$( awk -v dist=$dist '$4 == dist {
  39.         print "distfile=" $1
  40.         print "sig=" $2
  41.         exit found = 1
  42.     } END { exit ! found }' $MANIFEST )"
  43.     destfile=$REL_DIST/$distfile
  44.     download $distfile to $destfile
  45.     [ "$( sign $destfile )" = $sig ] ||
  46.         f_die "$distfile signature mismatch!"
  47. done
  48. f_dialog_info "All dists successfully downloaded/verified."
Add Comment
Please, Sign In to add comment