@@ -5,8 +5,98 @@ set -euxo pipefail
55IMG=" ${IMG:- } "
66TAG=" ${TAG:- } "
77IMG_TAG=" ${IMG} :${TAG} "
8+ DOWNLOAD_URL=" https://github.com/fluxcd/golang-with-libgit2/releases/download/${TAG} "
89
9- function extract(){
10+ TMP_DIR=$( mktemp -d)
11+
12+ function cleanup(){
13+ rm -rf " ${TMP_DIR} "
14+ }
15+ trap cleanup EXIT
16+
17+ fatal () {
18+ echo ' [ERROR] ' " $@ " >&2
19+ exit 1
20+ }
21+
22+ download () {
23+ [[ $# -eq 2 ]] || fatal ' download needs exactly 2 arguments'
24+
25+ curl -o " $1 " -sfL " $2 "
26+
27+ [[ $? -eq 0 ]] || fatal ' Download failed'
28+ }
29+
30+ download_files () {
31+ [[ $# -eq 1 ]] || fatal ' download_files needs exactly 1 arguments'
32+
33+ FILE_NAMES=" checksums.txt checksums.txt.sig checksums.txt.pem $1 "
34+
35+ for FILE_NAME in ${FILE_NAMES} ; do
36+ download " ${TMP_DIR} /${FILE_NAME} " " ${DOWNLOAD_URL} /${FILE_NAME} "
37+ done
38+ }
39+
40+ cosign_verify (){
41+ [[ $# -eq 3 ]] || fatal ' cosign_verify needs exactly 3 arguments'
42+
43+ cosign verify-blob --cert " $1 " --signature " $2 " " $3 "
44+
45+ [[ $? -eq 0 ]] || fatal ' signature verification failed'
46+ }
47+
48+ assure_provenance () {
49+ [[ $# -eq 1 ]] || fatal ' assure_provenance needs exactly 1 arguments'
50+
51+ cosign_verify " ${TMP_DIR} /checksums.txt.pem" \
52+ " ${TMP_DIR} /checksums.txt.sig" \
53+ " ${TMP_DIR} /checksums.txt"
54+
55+ pushd " ${TMP_DIR} " || exit
56+ if command -v sha256sum; then
57+ grep " $1 " " checksums.txt" | sha256sum --check
58+ else
59+ grep " $1 " " checksums.txt" | shasum -a 256 --check
60+ fi
61+ popd || exit
62+
63+ [[ $? -eq 0 ]] || fatal ' integrity verification failed'
64+ }
65+
66+ extract_libraries (){
67+ [[ $# -eq 2 ]] || fatal ' extract_libraries needs exactly 2 arguments'
68+
69+ tar -xf " ${TMP_DIR} /$1 "
70+
71+ rm " ${TMP_DIR} /$1 "
72+ mv " ${2} " " ${TAG} "
73+ mv " ${TAG} /" " ./build/libgit2"
74+ }
75+
76+ fix_pkgconfigs (){
77+ DIR=" $1 "
78+ NEW_DIR=" $( /bin/pwd) /build/libgit2/${TAG} "
79+
80+ # Update the prefix paths included in the .pc files.
81+ if [[ $OSTYPE == ' darwin' * ]]; then
82+ INSTALLED_DIR=" /Users/runner/work/golang-with-libgit2/golang-with-libgit2/build/${DIR} "
83+
84+ # This will make it easier to update to the location in which they will be used.
85+ # sed has a sight different behaviour in MacOS
86+ # NB: Some macOS users may override their sed with gsed. If gsed is the PATH, use that instead.
87+ if command -v gsed & > /dev/null; then
88+ find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} gsed -i " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
89+ else
90+ find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} sed -i " " " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
91+ fi
92+ else
93+ INSTALLED_DIR=" /home/runner/work/golang-with-libgit2/golang-with-libgit2/build/${DIR} "
94+
95+ find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} sed -i " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
96+ fi
97+ }
98+
99+ extract_from_image (){
10100 PLATFORM=$1
11101 DIR=$2
12102
@@ -16,14 +106,7 @@ function extract(){
16106
17107 tar -xf output.tar.gz " local/${DIR} "
18108 rm output.tar.gz
19- }
20109
21- function setup() {
22- PLATFORM=$1
23- DIR=$2
24-
25- extract " ${PLATFORM} " " ${DIR} "
26-
27110 NEW_DIR=" $( /bin/pwd) /build/libgit2/${TAG} "
28111 INSTALLED_DIR=" /usr/local/${DIR} "
29112
@@ -36,61 +119,34 @@ function setup() {
36119 find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} sed -i " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
37120}
38121
39- function setup_current() {
122+ install_libraries () {
40123 if [ -d " ./build/libgit2/${TAG} " ]; then
41- echo " Skipping libgit2 setup as it already exists "
124+ echo " Skipping: libgit2 ${TAG} already installed "
42125 exit 0
43126 fi
44127
45128 mkdir -p " ./build/libgit2"
46- if [[ $OSTYPE == ' darwin' * ]]; then
47- # For MacOS development environments, download the amd64 static libraries released from from golang-with-libgit2.
48- curl -o output.tar.gz -LO " https://github.com/fluxcd/golang-with-libgit2/releases/download/${TAG} /darwin-libs.tar.gz"
49-
50- DIR=libgit2-darwin
51- NEW_DIR=" $( /bin/pwd) /build/libgit2/${TAG} "
52- INSTALLED_DIR=" /Users/runner/work/golang-with-libgit2/golang-with-libgit2/build/${DIR} -amd64"
53-
54- tar -xf output.tar.gz
55- rm output.tar.gz
56- mv " ${DIR} " " ${TAG} "
57- mv " ${TAG} /" " ./build/libgit2"
58-
59- LIBGIT2_SED=" s;-L/Applications/Xcode_.* ;;g"
60- LIBGIT2PC=" $( /bin/pwd) /build/libgit2/${TAG} /lib/pkgconfig/libgit2.pc"
61- # Some macOS users may override their sed with gsed. If gsed is the PATH, use that instead.
62- if command -v gsed & > /dev/null; then
63- # Removes abs path from build machine, and let iconv be resolved automatically by default search paths.
64- gsed -i " ${LIBGIT2_SED} " " ${LIBGIT2PC} "
65129
66- # Update the prefix paths included in the .pc files.
67- # This will make it easier to update to the location in which they will be used.
68- # sed has a sight different behaviour in MacOS
69- find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} gsed -i " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
70- else
71- # Removes abs path from build machine, and let iconv be resolved automatically by default search paths.
72- sed -i " " " ${LIBGIT2_SED} " " ${LIBGIT2PC} "
73-
74- # Update the prefix paths included in the .pc files.
75- # This will make it easier to update to the location in which they will be used.
76- # sed has a sight different behaviour in MacOS
77- find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} sed -i " " " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
130+ # Linux ARM support is still based on the container image libraries.
131+ if [[ $OSTYPE == ' linux' * ]]; then
132+ if [ " $( uname -m) " = " arm64" ] || [ " $( uname -m) " = " aarch64" ]; then
133+ extract_from_image " linux/arm64" " aarch64-alpine-linux-musl"
134+ fix_pkgconfigs " aarch64-alpine-linux-musl"
135+ exit 0
78136 fi
79- else
80- # for linux development environments, use the static libraries from the official container images.
81- DIR=" x86_64-alpine-linux-musl"
82- PLATFORM=" linux/amd64"
83-
84- if [[ " $( uname -m) " == armv7* ]]; then
85- DIR=" armv7-alpine-linux-musleabihf"
86- PLATFORM=" linux/arm/v7"
87- elif [ " $( uname -m) " = " arm64" ] || [ " $( uname -m) " = " aarch64" ]; then
88- DIR=" aarch64-alpine-linux-musl"
89- PLATFORM=" linux/arm64"
90- fi
91-
92- setup " ${PLATFORM} " " ${DIR} "
93137 fi
138+
139+ FILE_NAME=" linux-$( uname -m) -all-libs.tar.gz"
140+ DIR=" libgit2-linux-all-libs"
141+ if [[ $OSTYPE == ' darwin' * ]]; then
142+ FILE_NAME=" darwin-all-libs.tar.gz"
143+ DIR=" darwin-all-libs"
144+ fi
145+
146+ download_files " ${FILE_NAME} "
147+ assure_provenance " ${FILE_NAME} "
148+ extract_libraries " ${FILE_NAME} " " ${DIR} "
149+ fix_pkgconfigs " ${DIR} "
94150}
95151
96- setup_current
152+ install_libraries
0 commit comments