@@ -59,127 +59,128 @@ checksum_file() {
5959}
6060
6161do_file () {
62+ type=${1}
63+ shift
6264 uri=${1}
65+ shift
6366 echo " ${uri} "
6467
65- if echo " ${uri} " | grep -qE " ^https?://" ; then
66- # HTTP file
67- checksum=${2}
68- filename=${3}
69- if [ " ${filename} " = " " ]; then
70- filename=$( basename " ${uri} " )
71- fi
72-
73- # Check if the file is already downloaded & the checksum is the same
74- dest_file=${dest} /${filename}
75- if [ -e " ${dest_file} " ]; then
76- existing_checksum=$( checksum_file " ${dest_file} " )
77- if [ " ${checksum} " = " ${existing_checksum} " ]; then
78- # There is nothing we need to do here
79- return
68+ case $type in
69+ f | file)
70+ # HTTP file
71+ checksum=${1}
72+ shift
73+ filename=${1}
74+ if [ " ${filename} " = " " ]; then
75+ filename=$( basename " ${uri} " )
8076 fi
81- fi
82-
83- # Attempt up to 3 times
84- retries=3
85- matching=no
86- while [ " ${retries} " -gt 0 ]; do
87- download_file " ${uri} " " ${dest} /${filename} "
88- my_checksum=$( checksum_file " ${dest_file} " )
89- if [ " ${checksum} " = " ${my_checksum} " ]; then
90- matching=" yes"
91- break
77+
78+ # Check if the file is already downloaded & the checksum is the same
79+ dest_file=${dest} /${filename}
80+ if [ -e " ${dest_file} " ]; then
81+ existing_checksum=$( checksum_file " ${dest_file} " )
82+ if [ " ${checksum} " = " ${existing_checksum} " ]; then
83+ # There is nothing we need to do here
84+ return
85+ fi
86+ fi
87+
88+ # Attempt up to 3 times
89+ retries=3
90+ matching=no
91+ while [ " ${retries} " -gt 0 ]; do
92+ download_file " ${uri} " " ${dest} /${filename} "
93+ my_checksum=$( checksum_file " ${dest_file} " )
94+ if [ " ${checksum} " = " ${my_checksum} " ]; then
95+ matching=" yes"
96+ break
97+ fi
98+ retries=$(( retries - 1 ))
99+ if [ " ${retries} " -gt 0 ]; then
100+ echo " ${uri} : checksum did not match, trying again"
101+ rm " ${dest} /${filename} "
102+ fi
103+ sleep 1
104+ done
105+
106+ if [ " ${matching} " = " no" ]; then
107+ echo " ${uri} : checksums do not match"
108+ exit 1
109+ fi
110+ ;;
111+ g | git)
112+ # Creating a tarball from a git repository
113+ repo=${uri% ~* }
114+ outdir=${state} /git/${repo#*:// }
115+ reference=${uri##* ~}
116+
117+ http_src=${1}
118+ shift
119+ checksum=${1}
120+ shift
121+ tarball=${1:- $(basename " ${http_src} " )}
122+ if [ " ${tarball} " = " _" ]; then
123+ echo " ${uri} : ERROR! Must have tarball name if no http source."
124+ exit 1
92125 fi
93- retries=$(( retries - 1 ))
94- if [ " ${retries} " -gt 0 ]; then
95- echo " ${uri} : checksum did not match, trying again"
96- rm " ${dest} /${filename} "
126+ tarball=${dest} /${tarball}
127+
128+ # Check if tarball already generated + matches checksum
129+ if [ -e " ${tarball} " ]; then
130+ existing_checksum=$( checksum_file " ${tarball} " )
131+ if [ " ${existing_checksum} " = " ${checksum} " ]; then
132+ return
133+ fi
134+ rm " ${tarball} "
97135 fi
98- sleep 1
99- done
100-
101- if [ " ${matching} " = " no" ]; then
102- echo " ${uri} : checksums do not match"
103- exit 1
104- fi
105- elif echo " ${uri} " | grep -qE " ^git://" ; then
106- # Creating a tarball from a git repository
107-
108- # Very unfortunately, different sites have different rules.
109- uri_path=${uri# git:// }
110- # GitHub does not have git:// protocol support
111- if echo " ${uri} " | grep -Eq " ^git://github.com" ; then
112- uri=https://${uri_path}
113- fi
114- repo=${uri% ~* }
115- outdir=${state} /git/${repo#*:// }
116- reference=${uri##* ~}
117-
118- http_src=${2}
119- checksum=${3}
120- tarball=${4:- $(basename " ${http_src} " )}
121- if [ " ${tarball} " = " _" ]; then
122- echo " ${uri} : ERROR! Must have tarball name if no http source."
123- exit 1
124- fi
125- tarball=${dest} /${tarball}
126-
127- # Check if tarball already generated + matches checksum
128- checksum=${3}
129- if [ -e " ${tarball} " ]; then
130- existing_checksum=$( checksum_file " ${tarball} " )
131- if [ " ${existing_checksum} " = " ${checksum} " ]; then
132- return
136+
137+ # Clone the repository, or update it if needed
138+ if [ ! -e " ${outdir} " ]; then
139+ mkdir -p " $( dirname " ${outdir} " ) "
140+ git clone " ${repo} " " ${outdir} "
141+ elif ! git_ref_exists " ${outdir} " " ${reference} " ; then
142+ (
143+ cd " ${outdir} " || exit
144+ git pull
145+ git submodule update --init --recursive
146+ )
147+ fi
148+
149+ # Sanity check: the reference we want exists
150+ if ! git_ref_exists " ${outdir} " " ${reference} " ; then
151+ echo " ${reference} not found in ${repo} (${outdir} )"
152+ exit 1
133153 fi
134- rm " ${tarball} "
135- fi
136-
137- # Clone the repository, or update it if needed
138- if [ ! -e " ${outdir} " ]; then
139- mkdir -p " $( dirname " ${outdir} " ) "
140- git clone " ${repo} " " ${outdir} "
141- elif ! git_ref_exists " ${outdir} " " ${reference} " ; then
154+
155+ # Generate the prefix for the tarball
156+ prefix_ref=${reference}
157+ # All git repositories we already use remove "v"s from the beginning
158+ # of branch/tag names in the tarball prefix
159+ if echo " ${reference} " | grep -Eq " ^v[0-9]" ; then
160+ prefix_ref=$( echo " ${reference} " | sed " s/^v//" )
161+ fi
162+ prefix=$( basename " ${repo} " | sed " s/.git$//" ) -${prefix_ref}
163+
142164 (
143165 cd " ${outdir} " || exit
144- git pull
145- git submodule update --init --recursive
166+ # Some versions of git by default use the internal gzip
167+ # implementation, others use external gzip; standardize this
168+ # -n is used for older versions of git that record gzip creation
169+ # date/time
170+ git config tar.tar.gz.command " gzip -n"
171+ # -T1 avoids non-determinism due to threading
172+ # This may not be correct for forges other than Savannah
173+ git config tar.tar.xz.command " xz -T1"
174+ git archive " ${reference} " -o " ${tarball} " --prefix " ${prefix} /"
146175 )
147- fi
148-
149- # Sanity check: the reference we want exists
150- if ! git_ref_exists " ${outdir} " " ${reference} " ; then
151- echo " ${reference} not found in ${repo} (${outdir} )"
152- exit 1
153- fi
154-
155- # Generate the prefix for the tarball
156- prefix_ref=${reference}
157- # All git repositories we already use remove "v"s from the beginning
158- # of branch/tag names in the tarball prefix
159- if echo " ${reference} " | grep -Eq " ^v[0-9]" ; then
160- prefix_ref=$( echo " ${reference} " | sed " s/^v//" )
161- fi
162- prefix=$( basename " ${repo} " | sed " s/.git$//" ) -${prefix_ref}
163-
164- (
165- cd " ${outdir} " || exit
166- # Some versions of git by default use the internal gzip
167- # implementation, others use external gzip; standardize this
168- # -n is used for older versions of git that record gzip creation
169- # date/time
170- git config tar.tar.gz.command " gzip -n"
171- # -T1 avoids non-determinism due to threading
172- # This may not be correct for forges other than Savannah
173- git config tar.tar.xz.command " xz -T1"
174- git archive " ${reference} " -o " ${tarball} " --prefix " ${prefix} /"
175- )
176-
177- my_checksum=$( sha256sum " ${tarball} " | cut -d' ' -f1)
178- if [ " ${my_checksum} " != " ${checksum} " ]; then
179- echo " ${uri} : generated tarball does not match checksum"
180- exit 1
181- fi
182- fi
176+
177+ my_checksum=$( sha256sum " ${tarball} " | cut -d' ' -f1)
178+ if [ " ${my_checksum} " != " ${checksum} " ]; then
179+ echo " ${uri} : generated tarball does not match checksum"
180+ exit 1
181+ fi
182+ ;;
183+ esac
183184}
184185
185186for src in steps/* /sources; do
0 commit comments