summaryrefslogtreecommitdiffstats
path: root/scripts/install-buildtools
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/install-buildtools')
-rwxr-xr-xscripts/install-buildtools65
1 files changed, 39 insertions, 26 deletions
diff --git a/scripts/install-buildtools b/scripts/install-buildtools
index 2218f3ffac..aa23942858 100755
--- a/scripts/install-buildtools
+++ b/scripts/install-buildtools
@@ -56,9 +56,9 @@ PROGNAME = 'install-buildtools'
56logger = scriptutils.logger_create(PROGNAME, stream=sys.stdout) 56logger = scriptutils.logger_create(PROGNAME, stream=sys.stdout)
57 57
58DEFAULT_INSTALL_DIR = os.path.join(os.path.split(scripts_path)[0],'buildtools') 58DEFAULT_INSTALL_DIR = os.path.join(os.path.split(scripts_path)[0],'buildtools')
59DEFAULT_BASE_URL = 'http://downloads.yoctoproject.org/releases/yocto' 59DEFAULT_BASE_URL = 'https://downloads.yoctoproject.org/releases/yocto'
60DEFAULT_RELEASE = 'yocto-4.1' 60DEFAULT_RELEASE = 'yocto-5.2.1'
61DEFAULT_INSTALLER_VERSION = '4.1' 61DEFAULT_INSTALLER_VERSION = '5.2.1'
62DEFAULT_BUILDDATE = '202110XX' 62DEFAULT_BUILDDATE = '202110XX'
63 63
64# Python version sanity check 64# Python version sanity check
@@ -102,6 +102,16 @@ def sha256_file(filename):
102 import hashlib 102 import hashlib
103 return _hasher(hashlib.sha256(), filename) 103 return _hasher(hashlib.sha256(), filename)
104 104
105def remove_quotes(var):
106 """
107 If a variable starts and ends with double quotes, remove them.
108 Assumption: if a variable starts with double quotes, it must also
109 end with them.
110 """
111 if var[0] == '"':
112 var = var[1:-1]
113 return var
114
105 115
106def main(): 116def main():
107 global DEFAULT_INSTALL_DIR 117 global DEFAULT_INSTALL_DIR
@@ -117,7 +127,8 @@ def main():
117 127
118 parser = argparse.ArgumentParser( 128 parser = argparse.ArgumentParser(
119 description="Buildtools installation helper", 129 description="Buildtools installation helper",
120 add_help=False) 130 add_help=False,
131 formatter_class=argparse.RawTextHelpFormatter)
121 parser.add_argument('-u', '--url', 132 parser.add_argument('-u', '--url',
122 help='URL from where to fetch buildtools SDK installer, not ' 133 help='URL from where to fetch buildtools SDK installer, not '
123 'including filename (optional)\n' 134 'including filename (optional)\n'
@@ -131,6 +142,9 @@ def main():
131 default=DEFAULT_INSTALL_DIR, 142 default=DEFAULT_INSTALL_DIR,
132 help='directory where buildtools SDK will be installed (optional)', 143 help='directory where buildtools SDK will be installed (optional)',
133 action='store') 144 action='store')
145 parser.add_argument('--downloads-directory',
146 help='use this directory for tarball/checksum downloads and do not erase them (default is a temporary directory which is deleted after unpacking and installing the buildtools)',
147 action='store')
134 parser.add_argument('-r', '--release', 148 parser.add_argument('-r', '--release',
135 default=DEFAULT_RELEASE, 149 default=DEFAULT_RELEASE,
136 help='Yocto Project release string for SDK which will be ' 150 help='Yocto Project release string for SDK which will be '
@@ -224,11 +238,14 @@ def main():
224 safe_filename = quote(filename) 238 safe_filename = quote(filename)
225 buildtools_url = "%s/%s/buildtools/%s" % (base_url, args.release, safe_filename) 239 buildtools_url = "%s/%s/buildtools/%s" % (base_url, args.release, safe_filename)
226 240
227 tmpsdk_dir = tempfile.mkdtemp() 241 sdk_dir = args.downloads_directory or tempfile.mkdtemp()
242 os.makedirs(sdk_dir, exist_ok=True)
228 try: 243 try:
229 # Fetch installer 244 # Fetch installer
230 logger.info("Fetching buildtools installer") 245 logger.info("Fetching buildtools installer")
231 tmpbuildtools = os.path.join(tmpsdk_dir, filename) 246 tmpbuildtools = os.path.join(sdk_dir, filename)
247 with open(os.path.join(sdk_dir, 'buildtools_url'), 'w') as f:
248 f.write(buildtools_url)
232 ret = subprocess.call("wget -q -O %s %s" % 249 ret = subprocess.call("wget -q -O %s %s" %
233 (tmpbuildtools, buildtools_url), shell=True) 250 (tmpbuildtools, buildtools_url), shell=True)
234 if ret != 0: 251 if ret != 0:
@@ -238,19 +255,17 @@ def main():
238 # Verify checksum 255 # Verify checksum
239 if args.check: 256 if args.check:
240 logger.info("Fetching buildtools installer checksum") 257 logger.info("Fetching buildtools installer checksum")
241 checksum_type = "" 258 checksum_type = "sha256sum"
242 for checksum_type in ["md5sum", "sha256sum"]: 259 checksum_url = "{}.{}".format(buildtools_url, checksum_type)
243 check_url = "{}.{}".format(buildtools_url, checksum_type) 260 checksum_filename = "{}.{}".format(filename, checksum_type)
244 checksum_filename = "{}.{}".format(filename, checksum_type) 261 tmpbuildtools_checksum = os.path.join(sdk_dir, checksum_filename)
245 tmpbuildtools_checksum = os.path.join(tmpsdk_dir, checksum_filename) 262 with open(os.path.join(sdk_dir, 'checksum_url'), 'w') as f:
246 ret = subprocess.call("wget -q -O %s %s" % 263 f.write(checksum_url)
247 (tmpbuildtools_checksum, check_url), shell=True) 264 ret = subprocess.call("wget -q -O %s %s" %
248 if ret == 0: 265 (tmpbuildtools_checksum, checksum_url), shell=True)
249 break 266 if ret != 0:
250 else: 267 logger.error("Could not download file from %s" % checksum_url)
251 if ret != 0: 268 return ret
252 logger.error("Could not download file from %s" % check_url)
253 return ret
254 regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$") 269 regex = re.compile(r"^(?P<checksum>[0-9a-f]+)\s+(?P<path>.*/)?(?P<filename>.*)$")
255 with open(tmpbuildtools_checksum, 'rb') as f: 270 with open(tmpbuildtools_checksum, 'rb') as f:
256 original = f.read() 271 original = f.read()
@@ -263,10 +278,7 @@ def main():
263 logger.error("Filename does not match name in checksum") 278 logger.error("Filename does not match name in checksum")
264 return 1 279 return 1
265 checksum = m.group('checksum') 280 checksum = m.group('checksum')
266 if checksum_type == "md5sum": 281 checksum_value = sha256_file(tmpbuildtools)
267 checksum_value = md5_file(tmpbuildtools)
268 else:
269 checksum_value = sha256_file(tmpbuildtools)
270 if checksum == checksum_value: 282 if checksum == checksum_value:
271 logger.info("Checksum success") 283 logger.info("Checksum success")
272 else: 284 else:
@@ -280,7 +292,7 @@ def main():
280 os.chmod(tmpbuildtools, st.st_mode | stat.S_IEXEC) 292 os.chmod(tmpbuildtools, st.st_mode | stat.S_IEXEC)
281 logger.debug(os.stat(tmpbuildtools)) 293 logger.debug(os.stat(tmpbuildtools))
282 if args.directory: 294 if args.directory:
283 install_dir = args.directory 295 install_dir = os.path.abspath(args.directory)
284 ret = subprocess.call("%s -d %s -y" % 296 ret = subprocess.call("%s -d %s -y" %
285 (tmpbuildtools, install_dir), shell=True) 297 (tmpbuildtools, install_dir), shell=True)
286 else: 298 else:
@@ -301,7 +313,7 @@ def main():
301 if match: 313 if match:
302 env_var = match.group('env_var') 314 env_var = match.group('env_var')
303 logger.debug("env_var: %s" % env_var) 315 logger.debug("env_var: %s" % env_var)
304 env_val = match.group('env_val') 316 env_val = remove_quotes(match.group('env_val'))
305 logger.debug("env_val: %s" % env_val) 317 logger.debug("env_val: %s" % env_val)
306 os.environ[env_var] = env_val 318 os.environ[env_var] = env_val
307 319
@@ -343,7 +355,8 @@ def main():
343 355
344 finally: 356 finally:
345 # cleanup tmp directory 357 # cleanup tmp directory
346 shutil.rmtree(tmpsdk_dir) 358 if not args.downloads_directory:
359 shutil.rmtree(sdk_dir)
347 360
348 361
349if __name__ == '__main__': 362if __name__ == '__main__':