-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·146 lines (116 loc) · 3.82 KB
/
install.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
import platform
import os
import sys
import subprocess
import json
def checkArm():
if platform.machine() == "aarch64":
return True
else:
return False
fileName = "listing.json"
if checkArm():
fileName = "listing-arm.json"
listingFile = open(fileName, "r")
productListing = json.loads(listingFile.read())
supportedProducts = list(productListing.keys())
listingFile.close()
#unsupportedProducts = ['aqua']
# print(supportedProducts)
def safeSearch(array, value):
try:
return array.index(value)
except ValueError:
return -1
def verifyProduct(productName):
if safeSearch(supportedProducts,productName) != -1:
return True
else:
print("Product does not exist")
return False
def getProductDownloadLink(productName):
if (verifyProduct(productName)):
url = productListing[productName]
return url
else:
return "about:blank"
def installLinuxArchive(productName, archivepath):
ceNum = 0
return subprocess.run(["sudo", "/usr/bin/env", "bash", "install_archive.sh", archivepath, productName, str(ceNum)]).returncode
def urlretrieve(url, filename):
return subprocess.run(["wget", "-O", filename, url]).returncode == 0
def getProductList(arguments):
productList = []
if safeSearch(arguments, "@all") != -1:
productList = supportedProducts
if safeSearch(arguments, "@pro") != -1:
for product in supportedProducts:
if (not product.endswith("-ce")) and (safeSearch(productList, product) == -1):
productList = productList + [product]
if safeSearch(arguments, "@ce") != -1:
for product in supportedProducts:
if (product.endswith("-ce")) and (safeSearch(productList, product) == -1):
productList = productList + [product]
for x in range(1, len(arguments)):
if (safeSearch(productList, arguments[x].lower()) == -1) and (not arguments[x].lower().startswith("@")):
productList = productList + [arguments[x].lower()]
#print(productList)
return productList
def installProduct(productName):
url = (getProductDownloadLink(productName))
print("URL: " + url + "")
tarF = "./"+productName+".tar.gz"
if url != "about:blank":
if urlretrieve(url, tarF):
print("Installing " + productName)
if installLinuxArchive(productName, tarF) == 0:
os.remove(tarF)
else:
print("Download Failed!")
def interactive():
print("JetBrains Installer Interactive")
print("ls to list supported products, quit to leave interactive")
if checkArm():
print("Processor: ARM64")
else:
print("Processor: x86_64")
test = ""
while test != "quit":
test = input("Enter JetBrains Product Name: ")
if test == "quit":
break
if (test != "ls") and (verifyProduct(test)):
installProduct(test)
elif test == "ls":
printListing()
def printListing():
print("Supported Products: ")
for product in supportedProducts:
print(product)
print()
#print("Unsupported Product: ")
#print("aqua - IDE in beta, doesn't support ARM Linux")
args = list(sys.argv)
#print(len(args))
if len(args) == 1:
args = args + ['-h']
if args[1] == "-h":
print("Syntax: install.py [-hli] [-e PATH_TO_ARCHIVE] PRODUCT(s) [-c]")
elif args[1] == "-l":
printListing()
elif args[1] == "-i":
interactive()
elif args[1] == "-e":
if len(args) == 4:
args = args + [""]
if len(args) == 5:
if verifyProduct(args[3]):
installLinuxArchive(args[3], args[2].lower())
else:
print("Invalid Arguments")
else:
for product in getProductList(args):
if verifyProduct(product):
#print(product)
installProduct(product)