-
Notifications
You must be signed in to change notification settings - Fork 8
/
additional_packaging.py
47 lines (41 loc) · 1.38 KB
/
additional_packaging.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# SPDX-FileCopyrightText: 2021 Splunk, Inc. <[email protected]>
# SPDX-License-Identifier: LicenseRef-Splunk-1-2020
#
#
import os
import glob
import shutil
import logging
from pathlib import Path
import requests
import tarfile
from tempfile import NamedTemporaryFile
def additional_packaging(ta_name=None, outputdir="output"):
noshipdirs = ["aiohttp/.hash"]
libdir = os.path.join(outputdir, ta_name, "lib")
for nsd in noshipdirs:
try:
o = os.path.join(libdir, nsd)
# Glob can return FileNotFoundError exception if no match
logging.info(f" removing directory {o} from output must not ship")
shutil.rmtree(o)
except FileNotFoundError:
pass
p = "geoipupdate_4.8.0_linux_amd64"
url = f"https://github.com/maxmind/geoipupdate/releases/download/v4.8.0/{p}.tar.gz"
response = requests.get(url, stream=True)
if response.status_code == 200:
f = NamedTemporaryFile(delete=False)
f.write(response.raw.read())
f.close()
# open file
file = tarfile.open(f.name)
# extracting file
file.extractall("output/SecKit_SA_geolocation/bin/geoipupdate/")
file.close()
os.rename(
f"output/SecKit_SA_geolocation/bin/geoipupdate/{p}",
"output/SecKit_SA_geolocation/bin/geoipupdate/linux_amd64",
)
os.unlink(f.name)