forked from XFY9326/APKAssemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupBuildEnv.sh
146 lines (114 loc) · 3.92 KB
/
setupBuildEnv.sh
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
146
#!/usr/bin/env bash
JDK_VERSION=110
JDK_PKG=openjdk-11-jdk
PROJECT_PATH=.
PATH_PROFILE=/etc/profile
ANDROID_HOME=$HOME/Android/Sdk
ANDROID_HOME_CACHE=$ANDROID_HOME/.cache
# Get JDK Version
javaVersion() {
echo $(java -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;')
}
# Check and install package with APT
checkAndInstall() {
echo "Checking $1 ..."
if [ "$(command -v $1)" = "" ]; then
echo "Installing $1 now!"
apt -qq install -y $1
echo "$1 installed!"
fi
}
initEnv() {
echo "Init environment"
if [ ! -f $PATH_PROFILE ]; then
echo "Path profile '$PATH_PROFILE' not found!"
exit 1
fi
echo "Updating APT index ..."
apt -qq update
checkAndInstall curl
checkAndInstall wget
checkAndInstall unzip
}
checkJDK() {
echo "Checking JDK ..."
if [ "$(javaVersion)" != "$JDK_VERSION" ]; then
echo "Installing $JDK_PKG now!"
apt -qq install -y $JDK_PKG
echo "$JDK_PKG installed!"
fi
}
checkAndroidCmdLineTools() {
echo "Checking Android command line tools ..."
if [ "$(command -v sdkmanager)" = "" ]; then
echo "Installing Android command line tools now!"
DOWNLOAD_LINK=$(curl -s "https://developer.android.com/studio" | grep -Eo "https://dl.google.com/android/repository/commandlinetools-linux-.*_latest.zip")
DOWNLOAD_FILE_PATH=$ANDROID_HOME_CACHE/commandlinetools.zip
wget -q --no-check-certificate -O "$DOWNLOAD_FILE_PATH" "$DOWNLOAD_LINK"
if [ ! -f $DOWNLOAD_FILE_PATH ]; then
echo "Failed to download Android command line tools!"
exit 1
fi
if [ -d $ANDROID_HOME/cmdline-tools ]; then
echo "Removing old Android command line tools ..."
rm -rf $ANDROID_HOME/cmdline-tools
fi
unzip -qq -d $ANDROID_HOME_CACHE/ $DOWNLOAD_FILE_PATH
rm -rf $DOWNLOAD_FILE_PATH
mkdir -p $ANDROID_HOME/cmdline-tools
mv $ANDROID_HOME_CACHE/cmdline-tools $ANDROID_HOME/cmdline-tools/latest
echo "" >> /etc/profile
echo "# Andorid command line tools" >> /etc/profile
echo "export PATH=\$PATH:$ANDROID_HOME/cmdline-tools/latest/bin" >> $PATH_PROFILE
. $PATH_PROFILE
echo "Android command line tools installed!"
fi
}
checkAndroidSdkPath() {
echo "Checking Android sdk path ..."
if [ ! -d $HOME/.android ]; then
mkdir $HOME/.android
fi
if [ ! -f $HOME/.android/repositories.cfg ]; then
touch $HOME/.android/repositories.cfg
fi
if [ ! -d $ANDROID_HOME ]; then
mkdir -p $ANDROID_HOME
fi
if [ ! -d $ANDROID_HOME_CACHE ]; then
mkdir -p $ANDROID_HOME_CACHE
fi
if [ "$ANDROID_SDK_ROOT" != "$ANDROID_HOME" ]; then
echo "" >> /etc/profile
echo "# Android SDK" >> /etc/profile
echo "export ANDROID_SDK_ROOT=$ANDROID_HOME" >> $PATH_PROFILE
. $PATH_PROFILE
fi
}
checkAndroidSdk() {
SDK_MANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
echo "Checking Android SDK Licenses ..."
yes | $SDK_MANAGER --licenses > /dev/null
echo "Checking Android tools ..."
$SDK_MANAGER "tools" > /dev/null
echo "Checking Android platform-tools ..."
$SDK_MANAGER "platform-tools" > /dev/null
}
checkLocalProperties() {
echo "Checking project local.properties ..."
if [ -f $PROJECT_PATH/local.properties ]; then
echo "Removing old local.properties ..."
rm -rf $PROJECT_PATH/local.properties
fi
echo "# This profile is generated by script." >> $PROJECT_PATH/local.properties
echo "# Location of the SDK. This is only used by Gradle." >> $PROJECT_PATH/local.properties
echo "# $(date)" >> $PROJECT_PATH/local.properties
echo "sdk.dir=$ANDROID_HOME" >> $PROJECT_PATH/local.properties
}
initEnv
checkJDK
checkAndroidSdkPath
checkAndroidCmdLineTools
checkAndroidSdk
checkLocalProperties
echo "Setup complete!"