1
- #! /bin/bash -i
2
1
3
2
4
3
clean_download () {
@@ -10,13 +9,13 @@ clean_download() {
10
9
# The above steps will minimize the leftovers being created while installing the downloader
11
10
# Supported distros:
12
11
# debian/ubuntu/alpine
13
-
12
+
14
13
url=$1
15
14
output_location=$2
16
15
tempdir=$( mktemp -d)
17
16
downloader_installed=" "
18
17
19
- function _apt_get_install() {
18
+ _apt_get_install () {
20
19
tempdir=$1
21
20
22
21
# copy current state of apt list - in order to revert back later (minimize contianer layer size)
@@ -25,7 +24,7 @@ clean_download() {
25
24
apt-get -y install --no-install-recommends wget ca-certificates
26
25
}
27
26
28
- function _apt_get_cleanup() {
27
+ _apt_get_cleanup () {
29
28
tempdir=$1
30
29
31
30
echo " removing wget"
@@ -36,15 +35,15 @@ clean_download() {
36
35
rm -r /var/lib/apt/lists && mv $tempdir /lists /var/lib/apt/lists
37
36
}
38
37
39
- function _apk_install() {
38
+ _apk_install () {
40
39
tempdir=$1
41
40
# copy current state of apk cache - in order to revert back later (minimize contianer layer size)
42
41
cp -p -R /var/cache/apk $tempdir
43
42
44
43
apk add --no-cache wget
45
44
}
46
45
47
- function _apk_cleanup() {
46
+ _apk_cleanup () {
48
47
tempdir=$1
49
48
50
49
echo " removing wget"
@@ -100,45 +99,39 @@ ensure_nanolayer() {
100
99
local variable_name=$1
101
100
102
101
local required_version=$2
103
- # normalize version
104
- if ! [[ $required_version == v* ]]; then
105
- required_version=v$required_version
106
- fi
107
102
108
- local nanolayer_location =" "
103
+ local __nanolayer_location =" "
109
104
110
105
# If possible - try to use an already installed nanolayer
111
- if [[ -z " ${NANOLAYER_FORCE_CLI_INSTALLATION} " ] ]; then
112
- if [[ -z " ${NANOLAYER_CLI_LOCATION} " ] ]; then
106
+ if [ -z " ${NANOLAYER_FORCE_CLI_INSTALLATION} " ]; then
107
+ if [ -z " ${NANOLAYER_CLI_LOCATION} " ]; then
113
108
if type nanolayer > /dev/null 2>&1 ; then
114
109
echo " Found a pre-existing nanolayer in PATH"
115
- nanolayer_location =nanolayer
110
+ __nanolayer_location =nanolayer
116
111
fi
117
112
elif [ -f " ${NANOLAYER_CLI_LOCATION} " ] && [ -x " ${NANOLAYER_CLI_LOCATION} " ] ; then
118
- nanolayer_location =${NANOLAYER_CLI_LOCATION}
119
- echo " Found a pre-existing nanolayer which were given in env variable: $nanolayer_location "
113
+ __nanolayer_location =${NANOLAYER_CLI_LOCATION}
114
+ echo " Found a pre-existing nanolayer which were given in env variable: $__nanolayer_location "
120
115
fi
121
116
122
117
# make sure its of the required version
123
- if ! [[ -z " ${nanolayer_location } " ] ]; then
118
+ if ! [ -z " ${__nanolayer_location } " ]; then
124
119
local current_version
125
- current_version=$( $nanolayer_location --version)
126
- if ! [[ $current_version == v* ]]; then
127
- current_version=v$current_version
128
- fi
120
+ current_version=$( $__nanolayer_location --version)
121
+
129
122
130
123
if ! [ $current_version == $required_version ]; then
131
124
echo " skipping usage of pre-existing nanolayer. (required version $required_version does not match existing version $current_version )"
132
- nanolayer_location =" "
125
+ __nanolayer_location =" "
133
126
fi
134
127
fi
135
128
136
129
fi
137
130
138
131
# If not previuse installation found, download it temporarly and delete at the end of the script
139
- if [[ -z " ${nanolayer_location } " ] ]; then
132
+ if [ -z " ${__nanolayer_location } " ]; then
140
133
141
- if [ " $( uname -sm) " == " Linux x86_64" ] || [ " $( uname -sm) " = = " Linux aarch64" ]; then
134
+ if [ " $( uname -sm) " = ' Linux x86_64' ] || [ " $( uname -sm) " = " Linux aarch64" ]; then
142
135
tmp_dir=$( mktemp -d -t nanolayer-XXXXXXXXXX)
143
136
144
137
clean_up () {
@@ -162,7 +155,7 @@ ensure_nanolayer() {
162
155
163
156
tar xfzv $tmp_dir /$tar_filename -C " $tmp_dir "
164
157
chmod a+x $tmp_dir /nanolayer
165
- nanolayer_location =$tmp_dir /nanolayer
158
+ __nanolayer_location =$tmp_dir /nanolayer
166
159
167
160
168
161
else
@@ -172,7 +165,7 @@ ensure_nanolayer() {
172
165
fi
173
166
174
167
# Expose outside the resolved location
175
- declare -g ${variable_name} =$nanolayer_location
168
+ export ${variable_name} =$__nanolayer_location
176
169
177
170
}
178
171
0 commit comments