@@ -5,8 +5,98 @@ set -euxo pipefail
5
5
IMG=" ${IMG:- } "
6
6
TAG=" ${TAG:- } "
7
7
IMG_TAG=" ${IMG} :${TAG} "
8
+ DOWNLOAD_URL=" https://github.com/fluxcd/golang-with-libgit2/releases/download/${TAG} "
8
9
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 (){
10
100
PLATFORM=$1
11
101
DIR=$2
12
102
@@ -16,14 +106,7 @@ function extract(){
16
106
17
107
tar -xf output.tar.gz " local/${DIR} "
18
108
rm output.tar.gz
19
- }
20
109
21
- function setup() {
22
- PLATFORM=$1
23
- DIR=$2
24
-
25
- extract " ${PLATFORM} " " ${DIR} "
26
-
27
110
NEW_DIR=" $( /bin/pwd) /build/libgit2/${TAG} "
28
111
INSTALLED_DIR=" /usr/local/${DIR} "
29
112
@@ -36,61 +119,34 @@ function setup() {
36
119
find " ${NEW_DIR} " -type f -name " *.pc" | xargs -I {} sed -i " s;${INSTALLED_DIR} ;${NEW_DIR} ;g" {}
37
120
}
38
121
39
- function setup_current() {
122
+ install_libraries () {
40
123
if [ -d " ./build/libgit2/${TAG} " ]; then
41
- echo " Skipping libgit2 setup as it already exists "
124
+ echo " Skipping: libgit2 ${TAG} already installed "
42
125
exit 0
43
126
fi
44
127
45
128
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} "
65
129
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
78
136
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} "
93
137
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} "
94
150
}
95
151
96
- setup_current
152
+ install_libraries
0 commit comments