#!/bin/bash
function useage() {
echo "-r install gitlab-runner"
echo "-a install android build system"
exit 1
}
while getopts ":a" opt
do
case $opt in
r)
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh" | sudo bash
yum install -y gitlab-runner
gitlab-runner register
#vi /etc/gitlab-runner/config.toml
;;
a)
rpm -ivh xxx.jdk8.rpm
https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip?utm_source=androiddevtools&utm_medium=website
https://downloads.gradle-dn.com/distributions/gradle-7.0-all.zip
#https://services.gradle.org/distributions/ 5.x版本ANDROID_NDK_HOME需要直接指向ndk-bundle
cat >> "/etc/profile" <<EOF
#android
export JAVA_HOME=/usr/lib/jvm/java-openjdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export GRADLE_HOME=/xxx/android/gradle
export ANDROID_HOME=/xxx/android
export ANDROID_NDK_HOME=/xxx/android/ndk
export PATH=$PATH:${GRADLE_HOME}/bin:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platforms
EOF
source /etc/profile
mkdir -p /home/user/.android
touch /home/user/.android/repositories.cfg
sdkmanager --list --verbose
sdkmanager "add-ons;addon-google_apis-google-24"
sdkmanager "build-tools;29.0.3"
sdkmanager "build-tools;28.0.3"
sdkmanager "cmdline-tools;latest"
sdkmanager "cmake;3.10.2.4988404"
sdkmanager "extras;google;m2repository"
sdkmanager "extras;google;webdriver"
sdkmanager "extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2"
sdkmanager "platforms;android-30"
sdkmanager "ndk-bundle"
#https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner/
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
#sonar 8.9 支持java8 sonar9只支持java11
unzip sonar-scanner-cli-xxx.zip
mv sonar-scanner-cli-xxx sonar-scanner-cli
vi sonar-scanner-cli/conf/sonar-scanner.properties
sonar.host.url=http://xxxx:9000
sonar.sourceEncoding=UTF-8
sonar.verbose=true
cat >> "/etc/profile" <<EOF
#sonar
export SONAR_HOME=/xxx/sonar-scanner-cli
export PATH=$PATH:${SONAR_HOME}/bin
EOF
source /etc/profile
sonar-scanner -h
sonar-scanner -Dsonar.login=token
git clone androidproject.git
cat >> "androidproject/sonar-project.properties" <<EOF
sonar.projectKey=my:sonar项目提示的key
sonar.projectName=指定项目名称,不设置使用projectKey
sonar.projectVersion=项目版本可以不设置
sonar.sources=sonar-project.properties文件在项目工程文件的相对位置,默认是 `.`
sonar.sourceEncoding=UTF-8 默认系统编码
EOF
;;
?)
useage
;;
esac
done
docker export android -o /vdb/android_image.tar
cat android_image.tar | docker import - android:1
useage
#.gitlab-ci.yml
#stages:
# - build
# - deploy
#
#release_build:
# stage: build
# when: manual
# tags:
# - 10-228-130-189
# script:
# - ./gradlew assembleRelease
#
#debug_build:
# stage: build
# when: manual
# tags:
# - 10-228-130-189
# script:
# - ./gradlew assembleDebug
# - cd x/build/outputs/apk/x/debug
# - curl -k -X POST -b 'Token=xxxx' -F 'file=@portal-xx-debug.apk' https://xxx/api/v1/app/upload
#index=0
#for i in $@
#do
# let index+=1
# if [ ${index} -eq 1 ]; then
# continue
# fi
# echo $i
#done
#docker run -itd -p 23:22 -v /vdb/android/sdk:/root/android -v /vdb/android/cache:/root/.android -v /vdb/android/bin:/tools --name centos7_android centos:7