2
2
# Copyright (c) Microsoft Corporation.
3
3
# Licensed under the MIT License.
4
4
5
+ # Quit on failure
5
6
set -e
6
7
8
+ PKG_VERSION=" "
9
+ SRC_TARBALL=" "
10
+ OUT_FOLDER=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
11
+
12
+ # parameters:
13
+ #
14
+ # --srcTarball : src tarball file
15
+ # this file contains the 'initial' source code of the component
16
+ # and should be replaced with the new/modified src code
17
+ # --outFolder : folder where to copy the new tarball(s)
18
+ # --pkgVersion : package version
19
+ # --vendorVersion : vendor version
20
+ #
21
+ PARAMS=" "
22
+ while (( "$# " )) ; do
23
+ case " $1 " in
24
+ --srcTarball)
25
+ if [ -n " $2 " ] && [ ${2: 0: 1} != " -" ]; then
26
+ SRC_TARBALL=$2
27
+ shift 2
28
+ else
29
+ echo " Error: Argument for $1 is missing" >&2
30
+ exit 1
31
+ fi
32
+ ;;
33
+ --outFolder)
34
+ if [ -n " $2 " ] && [ ${2: 0: 1} != " -" ]; then
35
+ OUT_FOLDER=$2
36
+ shift 2
37
+ else
38
+ echo " Error: Argument for $1 is missing" >&2
39
+ exit 1
40
+ fi
41
+ ;;
42
+ --pkgVersion)
43
+ if [ -n " $2 " ] && [ ${2: 0: 1} != " -" ]; then
44
+ PKG_VERSION=$2
45
+ shift 2
46
+ else
47
+ echo " Error: Argument for $1 is missing" >&2
48
+ exit 1
49
+ fi
50
+ ;;
51
+ --vendorVersion)
52
+ if [ -n " $2 " ] && [ ${2: 0: 1} != " -" ]; then
53
+ VENDOR_VERSION=$2
54
+ shift 2
55
+ else
56
+ echo " Error: Argument for $1 is missing" >&2
57
+ exit 1
58
+ fi
59
+ ;;
60
+ -* |--* =) # unsupported flags
61
+ echo " Error: Unsupported flag $1 " >&2
62
+ exit 1
63
+ ;;
64
+ * ) # preserve positional arguments
65
+ PARAMS=" $PARAMS $1 "
66
+ shift
67
+ ;;
68
+ esac
69
+ done
70
+
71
+ if [ -z " $SRC_TARBALL " ]; then
72
+ echo " --srcTarball parameter cannot be empty"
73
+ exit 1
74
+ fi
75
+
76
+ if [ -z " $PKG_VERSION " ]; then
77
+ echo " --pkgVersion parameter cannot be empty"
78
+ exit 1
79
+ fi
80
+
81
+ if [ -z " $VENDOR_VERSION " ]; then
82
+ echo " --vendorVersion parameter cannot be empty"
83
+ exit 1
84
+ fi
85
+
86
+ echo " --srcTarball -> $SRC_TARBALL "
87
+ echo " --outFolder -> $OUT_FOLDER "
88
+ echo " --pkgVersion -> $PKG_VERSION "
89
+ echo " --vendorVersion -> $VENDOR_VERSION "
90
+
7
91
temp_dir=$( mktemp -d)
8
92
echo " Working in temporary directory '$temp_dir '."
9
93
function clean-up {
@@ -12,26 +96,19 @@ function clean-up {
12
96
}
13
97
trap clean-up EXIT
14
98
15
- tarball_name=$1
99
+ tarball_name=$( basename " $SRC_TARBALL " )
16
100
17
101
cache_name=${tarball_name% .* }
18
102
if [[ " $cache_name " =~ \. tar$ ]]
19
103
then
20
104
cache_name=${cache_name% .* }
21
105
fi
22
106
23
- cache_tarball_name=" $cache_name -vendor.tar.gz"
24
-
25
- if [[ $# -ge 2 ]]
26
- then
27
- directory_name=$2
28
- else
29
- directory_name=$cache_name
30
- fi
107
+ cache_tarball_name=" $cache_name -$PKG_VERSION -govendor-v$VENDOR_VERSION .tar.gz"
31
108
32
109
if [[ -f " $tarball_name " ]]
33
110
then
34
- cp " $tarball_name " " $temp_dir "
111
+ cp " $SRC_TARBALL " " $temp_dir "
35
112
else
36
113
echo " Tarball '$tarball_name ' doesn't exist. Will attempt to download from blobstorage."
37
114
if ! wget -q " https://azurelinuxsrcstorage.blob.core.windows.net/sources/core/$tarball_name " -O " $temp_dir /$tarball_name "
44
121
45
122
pushd " $temp_dir " & > /dev/null
46
123
echo " Extracting $tarball_name ."
124
+
47
125
tar -xf " $tarball_name "
48
-
126
+
127
+ directory_name=($( ls -d * /) )
128
+
129
+ # assume there is only one directory in the tarball
130
+ directory_name=${directory_name[0]%// }
131
+
49
132
pushd " $directory_name " & > /dev/null
50
- echo " Fetching dependencies to a temporary cache."
133
+ echo " Fetching dependencies to a temporary cache in $directory_name ."
51
134
go mod vendor
52
135
53
136
echo " Compressing the cache."
54
- tar --sort=name --mtime=" 2021-04-26 00:00Z" --owner=0 --group=0 --numeric-owner --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime -cf " $cache_tarball_name " vendor
137
+ tar --sort=name \
138
+ --mtime=" 2021-04-26 00:00Z" \
139
+ --owner=0 --group=0 --numeric-owner \
140
+ --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
141
+ -czf " $cache_tarball_name " vendor
55
142
popd & > /dev/null
56
143
popd & > /dev/null
57
144
58
- mv " $temp_dir /$directory_name /$cache_tarball_name " .
145
+ mv " $temp_dir /$directory_name /$cache_tarball_name " " $OUT_FOLDER "
59
146
60
147
echo " Done:"
61
- sha256sum " $cache_tarball_name "
148
+ sha256sum " $OUT_FOLDER " / " $ cache_tarball_name"
0 commit comments