AndroidIDE构建工具安装脚本
#!/data/data/com.itsaky.androidide/files/usr/bin/bash/n/nset -eu/n/nColor_Off='//033[0m'/nBlack='//033[0;30m'/nRed='//033[0;31m'/nGreen='//033[0;32m'/nYellow='//033[0;33m'/nBlue='//033[0;34m'/nPurple='//033[0;35m'/nCyan='//033[0;36m'/nWhite='//033[0;37m'/n/nyes='^(y|Y|yes|Yes)$'/n/nprint_info() {/n printf /'${Blue}$1$Color_Off//n/'/n}/n/nprint_err() {/n printf /'${Red}$1$Color_Off//n/'/n}/n/nprint_success() {/n printf /'${Green}$1$Color_Off//n/'/n}/n/nprint_help() {/n echo /'AndroidIDE build tools installer/'/n echo /'This script helps you easily install build tools in AndroidIDE./'/n echo /'/'/n echo /'Usage:/'/n echo /'${0} -s 33.0.1 -c -j 17/'/n echo /'This will install Android SDK 33.0.1 with command line tools and JDK 17./'/n echo /'/'/n echo /'Options :/'/n echo /'-i Set the installation directory. Defaults to $HOME./'/n echo /'-s Android SDK version to download./'/n echo /'-c Download Android SDK with command line tools./'/n echo /'-m Manifest file URL. Defaults to 'manifest.json' in 'androidide-tools' GitHub repository./'/n echo /'/'/n echo /'For testing purposes:/'/n echo /'-a CPU architecture. Extracted using 'uname -m' by default./'/n echo /'-p Package manager. Defaults to 'pkg'./'/n echo /'-l Name of curl package that will be installed before starting installation process. Defaults to 'libcurl'./'/n echo /'/'/n echo /'-h Prints this message./'/n}/n/ndownload_and_extract() {/n # Display name to use in print messages/n name=$1/n/n # URL to download from/n url=$2/n/n # Directory in which the downloaded archive will be extracted/n dir=$3/n/n # Destination path for downloading the file/n dest=$4/n/n if [ ! -d $dir ]; then/n mkdir -p $dir/n fi/n/n cd $dir/n/n do_download=true/n if [ -f $dest ]; then/n name=$(basename $dest)/n print_info /'File ${name} already exists./'/n printf /'Do you want to skip the download process? ([y]es/[n]o): /'/n read skip/n if [[ $skip =~ $yes ]]; then/n do_download=false/n fi/n echo /'/'/n fi/n/n if [ /'$do_download/' = /'true/' ]; then/n print_info /'Downloading $name.../'/n curl -L -o $dest $url --http1.1/n print_success /'$name has been downloaded./'/n echo /'/'/n fi/n/n if [ ! -f $dest ]; then/n print_err /'The downloaded file $name does not exist. Cannot proceed.../'/n exit 1/n fi/n/n # Extract the downloaded archive/n print_info /'Extracting downloaded archive.../'/n tar xvJf $dest/n print_info /'Extracted successfully/'/n/n echo /'/'/n/n # Delete the downloaded file/n rm -vf $dest/n/n # cd into the previous working directory/n cd -/n}/n/ndownload_comp() {/n nm=$1/n jq_query=$2/n mdir=$3/n dname=$4/n/n # Extract the Android SDK URL/n print_info /'Extracting URL for $nm from manifest.../'/n url=$(jq -r /'${jq_query}/' $downloaded_manifest)/n print_success /'Found URL: $url/'/n echo /'/'/n/n # Download and extract the Android SDK build tools/n download_and_extract /'$nm/' /'$url/' /'$mdir/' /'$mdir/$dname.tar.xz/'/n}/n/narch=$(uname -m)/ninstall_dir=$HOME/nsdkver_org=34.0.4/nwith_cmdline=false/nmanifest=/'https://raw.githubusercontent.com/AndroidIDEOfficial/androidide-tools/main/manifest.json/'/npkgm=/'pkg/'/npkg_curl=/'libcurl/'/n/nOPTIND=1/nwhile getopts /'uch?i:s:j:m:a:p:l:/' opt; do/n case /'$opt/' in/n h|//?) /n print_help/n exit 0/n ;;/n i) install_dir=$OPTARG/n ;;/n s) sdkver_org=$OPTARG/n ;;/n c) with_cmdline=true/n ;;/n m) manifest=$OPTARG/n ;;/n a) arch=$OPTARG/n ;;/n p) pkgm=$OPTARG/n ;;/n l) pkg_curl=$OPTARG/n ;;/n esac/ndone/n/nshift $((OPTIND-1))/n[ /'${1:-}/' = /'--/' ] && shift/n/nif [ /'$arch/' = /'armv7l/' ]; then/n arch=/'arm/'/nfi/n# 64-bit CPU in 32-bit mode/nif [ /'$arch/' = /'armv8l/' ]; then/n arch=/'arm/'/nfi/n/nsdk_version=/'${sdkver_org//'.'/''}/'/n/necho /'------------------------------------------/'/necho /'Installation directory : ${install_dir}/'/necho /'SDK version : ${sdkver_org}/'/necho /'JDK version : 17/'/necho /'With command line tools : ${with_cmdline}/'/necho /'------------------------------------------/'/nprintf /'Confirm configuration ([y]es/[n]o): /'/nread correct/n/nif ! [[ $correct =~ $yes ]]; then/n print_err /'Aborting.../'/n exit 1/nfi/n/nif [ ! -f $install_dir ]; then/n print_info /'Installation directory does not exist. Creating directory.../'/n mkdir -p $install_dir/nfi/n/nif [ ! command -v $pkgm &> /dev/null ]; then/n print_err /''$pkgm' command not found. Try installing 'termux-tools' and 'apt'./'/n exit 1/nfi/n/n# Install required packages/nprint_info /'Installing required packages../'/n$pkgm install $pkg_curl jq tar/nprint_success /'Packages installed/'/necho /'/'/n/n# Download the manifest.json file/nprint_info /'Downloading manifest file.../'/ndownloaded_manifest=/'$install_dir/manifest.json/'/ncurl -L -o $downloaded_manifest $manifest/nprint_success /'Manifest file downloaded/'/necho /'/'/n/n# Install the Android SDK/ndownload_comp /'Android SDK/' /'.android_sdk/' $install_dir /'android-sdk/'/n/n# Install build tools/ndownload_comp /'Android SDK Build Tools/' /'.build_tools | .${arch} | .${sdk_version}/' /'$install_dir/android-sdk/' /'android-sdk-build-tools/'/n/n# Install platform tools/ndownload_comp /'Android SDK Platform Tools/' /'.platform_tools | .${arch} | .${sdk_version}/' /'$install_dir/android-sdk/' /'android-sdk-platform-tools/'/n/nif [ /'$with_cmdline/' = true ]; then/n # Install the Command Line tools/n download_comp /'Command-line tools/' /'.cmdline_tools/' /'$install_dir/android-sdk/' /'cmdline-tools/'/nfi/n/n# Install JDK 17/nprint_info /'Installing package: 'openjdk-17'/'/n$pkgm install openjdk-17/nprint_info /'JDK 17 has been installed./'/n/njdk_dir=/'$SYSROOT/opt/openjdk/'/n/nprint_info /'Updating ide-environment.properties.../'/nprint_info /'JAVA_HOME=$jdk_dir/'/necho /'/'/nprops_dir=/'$SYSROOT/etc/'/nprops=/'$props_dir/ide-environment.properties/'/n/nif [ ! -d $props_dir ]; then/n mkdir -p $props_dir/nfi/n/nif [ ! -e $props ]; then/n printf /'JAVA_HOME=$jdk_dir/' > $props/n print_success /'Properties file updated successfully!/'/nelse/n printf /'$props file already exists. Would you like to overwrite it? (y/n):/'/n read ans/n if [[ $ans =~ $yes ]]; then/n printf /'JAVA_HOME=$jdk_dir/' > $props/n print_success /'Properties file updated successfully!/'/n else/n print_err /'Manually edit $SYSROOT/etc/ide-environment.properties file and set JAVA_HOME and ANDROID_SDK_ROOT./'/n fi/nfi/n/nrm -vf $downloaded_manifest/nprint_success /'Downloads completed. You are ready to go!/
原文地址: https://www.cveoy.top/t/topic/qCea 著作权归作者所有。请勿转载和采集!