pthbs

Packaging Through Hashed Build Scripts
git clone https://ccx.te2000.cz/git/pthbs
Log | Files | Refs | Submodules | README

gen-downloadlist-entry-from-sha512 (1091B)


      1 #!/bin/zsh
      2 setopt no_unset warn_create_global
      3 
      4 typeset -g basedir=$0:h
      5 typeset -g dl_dir=$basedir/work/download.$$
      6 
      7 typeset -g hl_fatal hl_reset
      8 if (( $terminfo[colors] >= 8 )); then
      9 	hl_fatal='%F{red}%B'; hl_fatal=${(%)hl_fatal}
     10 	hl_warn='%F{yellow}%B'; hl_warn=${(%)hl_warn}
     11 	hl_reset='%b%f'; hl_reset=${(%)hl_reset}
     12 fi
     13 
     14 # helper that prints out stack, error message and exits
     15 die_ret() {
     16 	set +x
     17 	local ret n
     18 	ret=$1
     19 	shift
     20 	print -r - >&2 "${hl_fatal}Fatal$hl_reset error occurend in:"
     21 	for n in {${#funcfiletrace}..1}; do
     22 		printf >&2 '%d> %s (%s)\n' $n "$funcfiletrace[$n]" "$functrace[$n]"
     23 	done
     24 	printf >&2 '%s\n' "${hl_fatal}*$hl_reset $^@"
     25 	[[ -d $dl_dir ]] && rm -vr $dl_dir
     26 	exit $ret
     27 }
     28 
     29 -() {  # Run command and die on nonzero exitcode
     30 	setopt local_options xtrace
     31 	"$@" || die_ret $? "command failed with exitcode $?: ${(j: :)${(q)@}}"
     32 }
     33 
     34 main() {
     35 	local digest url fname
     36 
     37 	digest=$1
     38 	url=$2
     39 	fname=$dl_dir/${url:t}
     40 
     41 	- mkdir -p $dl_dir
     42 	- wget -O $fname $url
     43 	- sha512sum -c <<<"$digest  $fname"
     44 	- $basedir/gen-downloadlist-entry "$url" "$fname"
     45 	rm -vr $dl_dir
     46 }
     47 
     48 main "$@"