-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·143 lines (109 loc) · 4.35 KB
/
install
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
#!/usr/bin/env python3
import requests
import subprocess
import os
import shutil
from zipfile import ZipFile
from stat import S_IEXEC
from json import loads
from sys import stderr
from os.path import exists, realpath, split as pathsplit
config = loads(open('config.json', 'r').read())
# Real path, symlink resolved
full_path, _ = pathsplit(realpath(__file__))
full_path = full_path + '/'
APKTOOLURL = config["url"]["apktool"]
BUILDTOOLSURL = config["url"]["build-tools"]
TOOLSDIR = full_path + config["directory"]["tools"]
APKTOOLDIR = config["directory"]["apktool"]
BUILDTOOLSDIR = config["directory"]["build-tools"]
JSCOMMAND = "jarsigner -verify " + TOOLSDIR + APKTOOLDIR + "apktool.jar"
SHORTCUTLOCATION = "/usr/local/bin"
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def queryYesNo(question, default="yes"):
valid = {"yes": True, "y": True, "ye": True,
"no": False, "n": False}
if default is None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
print(question + prompt, end='', flush=True)
choice = input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
print("Please respond with 'yes' or 'no' "
"(or 'y' or 'n').")
# Remove previous dependencies
if exists(TOOLSDIR):
shutil.rmtree(TOOLSDIR)
os.makedirs(TOOLSDIR)
print(bcolors.OKBLUE + "Preparing dependencies" + bcolors.ENDC)
print("Downloading: apktools", end='', flush=True)
apktoolDownloadLink = requests.get(APKTOOLURL).json()[
"assets"][0]["browser_download_url"]
apktoolFile = requests.get(apktoolDownloadLink, allow_redirects=True)
os.makedirs(TOOLSDIR + APKTOOLDIR)
open(TOOLSDIR + APKTOOLDIR + "apktool.jar", 'wb').write(apktoolFile.content)
print(" [" + bcolors.OKGREEN + '*' + bcolors.ENDC + ']')
print("Checking: jarsigner", end='', flush=True)
jsProcess = subprocess.Popen(JSCOMMAND.split(), stdout=subprocess.PIPE)
jsOutput, _ = jsProcess.communicate()
jsOutput = jsOutput.decode('utf-8')
if "jar is" not in jsOutput:
stderr(" [" + bcolors.FAIL + '!' + bcolors.ENDC + ']')
stderr("jarsigner is not installed, please download the java sdk")
stderr("https://openjdk.java.net/install/")
exit()
print(" [" + bcolors.OKGREEN + '*' + bcolors.ENDC + ']')
if not os.path.exists(TOOLSDIR + BUILDTOOLSDIR):
os.makedirs(TOOLSDIR + BUILDTOOLSDIR)
print("Downloading: android build-tools", end='', flush=True)
buildToolsFile = requests.get(BUILDTOOLSURL, allow_redirects=True)
open(TOOLSDIR + BUILDTOOLSDIR + "tmpTools.zip",
'wb').write(buildToolsFile.content)
print(" [" + bcolors.OKGREEN + '*' + bcolors.ENDC + ']')
print("Preparing: android build-tools", end='', flush=True)
btZip = ZipFile(TOOLSDIR + BUILDTOOLSDIR + "tmpTools.zip")
btZipMainDir = btZip.namelist()[0]
btZip.extractall(TOOLSDIR + BUILDTOOLSDIR)
# Remove the main directory extracted from the archive (move the files up a dir)
fileList = os.listdir(TOOLSDIR + BUILDTOOLSDIR + btZipMainDir)
fileList = [TOOLSDIR + BUILDTOOLSDIR +
btZipMainDir + filename for filename in fileList]
for f in fileList:
shutil.move(f, TOOLSDIR + BUILDTOOLSDIR)
os.rmdir(TOOLSDIR + BUILDTOOLSDIR + btZipMainDir)
os.remove(TOOLSDIR + BUILDTOOLSDIR + "tmpTools.zip")
# Chmod +x zipalign
zaStat = os.stat(TOOLSDIR + BUILDTOOLSDIR + "zipalign")
os.chmod(TOOLSDIR + BUILDTOOLSDIR + "zipalign", zaStat.st_mode | S_IEXEC)
print(" [" + bcolors.OKGREEN + '*' + bcolors.ENDC + ']')
if queryYesNo("Do you want to install a shortcut?"):
shortcutpath = ""
while not exists(shortcutpath):
shortcutpath = input(
"Please specify a location.\nIf None the shortcut will be created on: " + SHORTCUTLOCATION + "\nLocation: ")
# Default
if shortcutpath == "":
shortcutpath = SHORTCUTLOCATION
# Require root for symlink
symlinkCommand = "sudo ln -s " + zfull_path + "aru " + shortcutpath + "/aru"
subprocess.call(symlinkCommand.split())
print("Done!")
print("Run ./aru -h to start using aru")