@@ -19,37 +19,124 @@ update_dockerfile_sha() {
1919 local ARG=" $2 "
2020 local DOCKERFILES=(" ${@: 3} " )
2121 local SHA
22- curl -fLs " $URL " -o curl.resp || echo " Request failed with exit code $? "
23- SHA=$( shasum -a 256 curl.resp | awk ' {print $1}' )
22+ local DOWNLOAD
23+ local dockerfile
24+ DOWNLOAD=$( mktemp)
25+
26+ if ! curl \
27+ --fail \
28+ --location \
29+ --retry 3 \
30+ --retry-all-errors \
31+ --connect-timeout 20 \
32+ --max-time 600 \
33+ --silent \
34+ --show-error \
35+ --output " $DOWNLOAD " \
36+ " $URL " ; then
37+ rm -f " $DOWNLOAD "
38+ echo " Failed to download release artifact: $URL " >&2
39+ return 1
40+ fi
2441
25- if [[ " $OSTYPE " == " darwin" * ]]; then
26- sed -i ' ' ' s|^ARG ' " $ARG " ' =.*|ARG ' " $ARG " ' ="' " $SHA " ' "|g' " ${DOCKERFILES[@]} "
27- else
28- sed -i ' s|^ARG ' " $ARG " ' =.*|ARG ' " $ARG " ' ="' " $SHA " ' "|g' " ${DOCKERFILES[@]} "
42+ SHA=$( shasum -a 256 " $DOWNLOAD " | awk ' {print $1}' )
43+ if [[ ! " $SHA " =~ ^[0-9a-f]{64}$ ]]; then
44+ rm -f " $DOWNLOAD "
45+ echo " Failed to calculate SHA256 for release artifact: $URL " >&2
46+ return 1
2947 fi
30- rm curl.resp
48+
49+ for dockerfile in " ${DOCKERFILES[@]} " ; do
50+ if [[ $( grep -Ec " ^[[:space:]]*(ARG[[:space:]]+)?${ARG} =\" ?[[:xdigit:]]{64}\" ?" " ${dockerfile} " ) -ne 1 ]]; then
51+ rm -f " $DOWNLOAD "
52+ echo " Expected exactly one existing ${ARG} checksum in ${dockerfile} " >&2
53+ return 1
54+ fi
55+
56+ if [[ " $OSTYPE " == " darwin" * ]]; then
57+ sed -E -i ' ' " s|^([[:space:]]*(ARG[[:space:]]+)?${ARG} =)\" ?[[:xdigit:]]{64}\" ?(.*)$|\\ 1\" ${SHA} \"\\ 3|" " ${dockerfile} "
58+ else
59+ sed -E -i " s|^([[:space:]]*(ARG[[:space:]]+)?${ARG} =)\" ?[[:xdigit:]]{64}\" ?(.*)$|\\ 1\" ${SHA} \"\\ 3|" " ${dockerfile} "
60+ fi
61+
62+ if ! grep -Eq " ^[[:space:]]*(ARG[[:space:]]+)?${ARG} =\" ${SHA} \" " " ${dockerfile} " ; then
63+ rm -f " $DOWNLOAD "
64+ echo " Failed to update ${ARG} in ${dockerfile} " >&2
65+ return 1
66+ fi
67+ done
68+ rm -f " $DOWNLOAD "
3169}
3270
3371update_readme () {
3472 local README=" $1 "
3573 local OLD_VERSION=" $2 "
3674 local NEW_VERSION=" $3 "
37- # update the README to specify the new version
38- if [ " $README " != " " ]; then
39- if [[ " $OSTYPE " == " darwin" * ]]; then
40- sed -i ' ' " s/${OLD_VERSION} \.$/${NEW_VERSION} \./" " $README "
41- else
42- sed -i " s/${OLD_VERSION} \.$/${NEW_VERSION} \./" " $README "
43- fi
75+ local match_count
76+ local new_match_count
77+ local replacement
78+
79+ if [ -z " $README " ]; then
80+ return 0
81+ fi
82+ if [ ! -f " $README " ]; then
83+ echo " Configured README does not exist: $README " >&2
84+ return 1
85+ fi
86+
87+ match_count=$( awk -v suffix=" ${OLD_VERSION} ." '
88+ length($0) >= length(suffix) && substr($0, length($0) - length(suffix) + 1) == suffix { count++ }
89+ END { print count + 0 }
90+ ' " $README " )
91+ if [ " $match_count " -ne 1 ]; then
92+ echo " Expected exactly one README line ending in ${OLD_VERSION} . in ${README} ; found ${match_count} " >&2
93+ return 1
94+ fi
95+
96+ replacement=$( mktemp)
97+ if ! awk -v old_suffix=" ${OLD_VERSION} ." -v new_suffix=" ${NEW_VERSION} ." '
98+ length($0) >= length(old_suffix) && substr($0, length($0) - length(old_suffix) + 1) == old_suffix {
99+ print substr($0, 1, length($0) - length(old_suffix)) new_suffix
100+ next
101+ }
102+ { print }
103+ ' " $README " > " $replacement " ; then
104+ rm -f " $replacement "
105+ echo " Failed to prepare README update for ${README} " >&2
106+ return 1
107+ fi
108+ if cmp -s " $README " " $replacement " ; then
109+ rm -f " $replacement "
110+ echo " README replacement did not change ${README} " >&2
111+ return 1
112+ fi
113+ command cat " $replacement " > " $README "
114+ rm -f " $replacement "
115+
116+ new_match_count=$( awk -v suffix=" ${NEW_VERSION} ." '
117+ length($0) >= length(suffix) && substr($0, length($0) - length(suffix) + 1) == suffix { count++ }
118+ END { print count + 0 }
119+ ' " $README " )
120+ if [ " $new_match_count " -ne 1 ]; then
121+ echo " Failed to verify README version ${NEW_VERSION} in ${README} " >&2
122+ return 1
44123 fi
45124}
46125
126+ if [ " ${UPDATE_SHA_LIBRARY_ONLY:- false} " = " true" ]; then
127+ if [[ " ${BASH_SOURCE[0]} " == " $0 " ]]; then
128+ exit 0
129+ fi
130+ return 0
131+ fi
132+
47133echo " Updating SHA for $DEP @$NEW_VERSION "
48134
49135if [ " $DEP " = " alpaca" ] ; then
50136 URL=" https://github.com/islandora/alpaca/archive/refs/tags/${NEW_VERSION} .tar.gz"
51137 ARG=ALPACA_SHA256
52138 DOCKERFILES=(" images/alpaca/Dockerfile" )
139+ README=" images/alpaca/README.md"
53140
54141elif [ " $DEP " = " apache-tomcat9" ]; then
55142 URL=" https://downloads.apache.org/tomcat/tomcat-9/v$NEW_VERSION /bin/apache-tomcat-$NEW_VERSION .tar.gz"
@@ -109,10 +196,19 @@ elif [ "$DEP" = "fcrepo7" ]; then
109196 DOCKERFILES=(" images/fcrepo7/Dockerfile" )
110197 README=" images/fcrepo7/README.md"
111198
112- elif [ " $DEP " = " islandora-syn" ]; then
199+ elif [ " $DEP " = " islandora-syn-fcrepo6 " ]; then
113200 URL=" https://github.com/Islandora/Syn/releases/download/v${NEW_VERSION} /islandora-syn-${NEW_VERSION} -all.jar"
114201 ARG=" SYN_SHA256"
115- DOCKERFILES=(" images/fcrepo6/Dockerfile" " images/fcrepo7/Dockerfile" )
202+ DOCKERFILES=(" images/fcrepo6/Dockerfile" )
203+
204+ elif [ " $DEP " = " islandora-syn-fcrepo7" ]; then
205+ URL=" https://github.com/Islandora/Syn/releases/download/v${NEW_VERSION} /islandora-syn-${NEW_VERSION} -all.jar"
206+ ARG=" SYN_SHA256"
207+ DOCKERFILES=(" images/fcrepo7/Dockerfile" )
208+
209+ elif [ " $DEP " = " islandora-syn" ]; then
210+ echo " Use islandora-syn-fcrepo6 or islandora-syn-fcrepo7 so Syn major lines remain independent" >&2
211+ exit 1
116212
117213elif [ " $DEP " = " fcrepo-import-export" ]; then
118214 URL=" https://github.com/fcrepo-exts/fcrepo-import-export/releases/download/fcrepo-import-export-${NEW_VERSION} /fcrepo-import-export-${NEW_VERSION} .jar"
@@ -214,8 +310,8 @@ elif [ "$DEP" = "s6-overlay" ]; then
214310
215311 exit 0
216312else
217- echo " DEP not found "
218- exit 0
313+ echo " Unsupported dependency: $DEP " >&2
314+ exit 1
219315fi
220316
221317update_dockerfile_sha " $URL " " $ARG " " ${DOCKERFILES[@]} "
0 commit comments