Last active
February 8, 2022 17:30
-
-
Save ArianK16a/6004709bd8dd46e9668d8c1675d1e119 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Copyright (C) 2019-2020 ArianK16a | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # | |
| export USERNAME=arian | |
| export HOSTNAME=server | |
| LOCAL_PATH="$(pwd)" | |
| signed=true | |
| telegram () { | |
| /home/arian/telegram.sh/telegram "$1" "$2" "$3" "$4" "$5" | |
| } | |
| prepare () { | |
| cd $LOCAL_PATH | |
| source build/envsetup.sh | |
| # Disable CCache, since the compile times don't matter | |
| # much here and we want to support 17.1 and 18.1 builds | |
| #export CCACHE_EXEC=$(which ccache) | |
| #export USE_CCACHE=1 | |
| #ccache -M 100G | |
| if [ -f $LOCAL_PATH/.last_build_time ]; then | |
| rm $LOCAL_PATH/.last_build_time | |
| fi | |
| } | |
| prepare_vanilla () { | |
| rm -rf vendor/extra | |
| git clone https://github.com/ArianK16a/android_vendor_extra.git -b lineage-18.1_vanilla vendor/extra | |
| export TARGET_UNOFFICIAL_BUILD_ID= | |
| } | |
| prepare_gapps () { | |
| rm -rf vendor/extra | |
| git clone https://github.com/ArianK16a/android_vendor_extra.git -b lineage-18.1_gapps vendor/extra | |
| export TARGET_UNOFFICIAL_BUILD_ID=GMS | |
| } | |
| # build device releasetype gapps | |
| build () { | |
| prepare | |
| repo sync --force-sync -q | |
| bash "$LOCAL_PATH"/picks.sh | |
| if [ "$3" = "gapps" ]; then | |
| prepare_gapps | |
| else | |
| prepare_vanilla | |
| fi | |
| breakfast "$1" | |
| make clean | |
| # make installclean | |
| telegram -N -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *started* on "$HOSTNAME"." | |
| build_start=$(date +"%s") | |
| if [ signed ]; then | |
| breakfast "$1" | |
| mka target-files-package otatools | |
| else | |
| brunch "$1" | |
| fi | |
| build_result "$1" "$3" | |
| if [ signed ]; then | |
| sign_target_files | |
| fi | |
| if [ -f $LOCAL_PATH/.last_build_time ] & [ -f "$OUT"/lineage-*-"$1".zip ]; then | |
| upload "$1" "$2" "$3" | |
| else | |
| if [ "$1" = "davinci" ]; then | |
| telegram -c -1001426238293 "Nightlies compilation failed!" | |
| elif [ "$1" = "toco" ]; then | |
| telegram -c -1001443889354 "Nightlies compilation failed!" | |
| else | |
| telegram "Nightlies compilation failed for "$1"!" | |
| fi | |
| exit -1 | |
| fi | |
| } | |
| convertsecs() { | |
| h=$(bc <<< "${1}/3600") | |
| m=$(bc <<< "(${1}%3600)/60") | |
| s=$(bc <<< "${1}%60") | |
| printf "%02d:%02d:%02d\n" $h $m $s | |
| } | |
| # build_result device gapps | |
| build_result () { | |
| result=$(echo $?) | |
| build_end=$(date +"%s") | |
| diff=$(($build_end - $build_start)) | |
| time=$(convertsecs "$diff") | |
| if [ "$2" = "gapps" ]; then | |
| type="GMS" | |
| else | |
| type="VANILLA" | |
| fi | |
| if [ "$result" = "0" ]; then | |
| telegram -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *completed successfully* on "$HOSTNAME". Build variant: \`$type\`. Build time: \`$time\`." | |
| echo "$time" > $LOCAL_PATH/.last_build_time | |
| else | |
| telegram -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *failed* on "$HOSTNAME". Build variant: \`$type\`. Build time: \`$time\`." | |
| fi | |
| } | |
| sign_target_files () { | |
| filename=$(cat "$OUT"/system/build.prop | grep ro.lineage.version=) | |
| filename="${filename#*=}" | |
| filename=lineage-"$filename".zip | |
| ./out/soong/host/linux-x86/bin/sign_target_files_apks -o -d ~/.android-certs \ | |
| $OUT/obj/PACKAGING/target_files_intermediates/*-target_files-*.zip \ | |
| $OUT/signed-target_files-"$filename" | |
| ./out/soong/host/linux-x86/bin/ota_from_target_files -k ~/.android-certs/releasekey \ | |
| --block --backup=true \ | |
| $OUT/signed-target_files-"$filename" \ | |
| $OUT/"$filename" | |
| checksum=$(sha256sum "$OUT"/"$filename" | awk '{print $1}') | |
| echo ""$checksum" "$filename"" > $OUT/"$filename".sha256sum | |
| } | |
| # upload device releasetype gapps | |
| upload () { | |
| if [ "$1" = "" ]; then | |
| echo "specify a device" | |
| fi | |
| project="$(basename $LOCAL_PATH)" | |
| if [[ "$2" = "test" ]]; then | |
| project="$project-experimental" | |
| rsync -Ph out/target/product/"$1"/lineage-*-"$1".zip ariank16a@frs.sourceforge.net:/home/frs/project/ephedraceae/"$1"/"$project"/ | |
| rsync -Ph out/target/product/"$1"/lineage-*-"$1".zip.sha256sum ariank16a@frs.sourceforge.net:/home/frs/project/ephedraceae/"$1"/"$project"/ | |
| release_experimental "$1" "$project" "$3" | |
| else | |
| rsync -Ph out/target/product/"$1"/lineage-*-"$1".zip ariank16a@frs.sourceforge.net:/home/frs/project/ephedraceae/"$1"/"$project"/ | |
| rsync -Ph out/target/product/"$1"/lineage-*-"$1".zip.sha256sum ariank16a@frs.sourceforge.net:/home/frs/project/ephedraceae/"$1"/"$project"/ | |
| release "$1" "$project" "$3" | |
| fi | |
| } | |
| # release device project gapps | |
| release () { | |
| device="$1" | |
| project="$2" | |
| if [ "$3" = "gapps" ]; then | |
| type="GMS" | |
| else | |
| type="VANILLA" | |
| fi | |
| download_link="https://sourceforge.net/projects/ephedraceae/files/"$1"/"$2"/$(basename $(ls out/target/product/"$1"/lineage-*-"$1".zip))" | |
| time="$(cat $LOCAL_PATH/.last_build_time)" | |
| checksum="$(cat "$LOCAL_PATH"/out/target/product/"$1"/lineage-*-"$1".zip.sha256sum | awk '{print $1}')" | |
| checksum_link="$download_link".sha256sum | |
| if [ "$3" = "gapps" ]; then | |
| device_variant="$1_gms" | |
| else | |
| device_variant="$1" | |
| fi | |
| changelog_link=https://raw.githubusercontent.com/arian-ota/changelog/"$project"/"$device_variant".txt | |
| if [ "$device" = "davinci" ]; then | |
| telegram -c -1001426238293 -M " \ | |
| *New LineageOS 18.1 build for Mi 9T available!* | |
| 💬 Variant: \`"$type"\` | |
| *Download* | |
| ⬇️ ["$project"]("$download_link") | |
| ✅ [checksum]("$checksum_link") | |
| 🚧 [Changelog]("$changelog_link") | |
| @StarWarsFlowers | |
| " | |
| elif [ "$device" = "toco" ]; then | |
| telegram -c -1001443889354 -M " \ | |
| *New LineageOS 18.1 build for Mi Note 10 Lite available!* | |
| 💬 Variant: \`"$type"\` | |
| *Download* | |
| ⬇️ ["$project"]("$download_link") | |
| ✅ [checksum]("$checksum_link") | |
| 🚧 [Changelog]("$changelog_link") | |
| @lineage\_toco | |
| " | |
| else | |
| telegram -c -1001159030901 -N -M " \ | |
| *New build available!* | |
| 🏗️ Project: \`"$project"\` | |
| 📱 Device: \`"$device"\` | |
| *Download* | |
| ⬇️ ["$project" for "$device"]("$download_link") | |
| ✅ [checksum]("$checksum_link"): \`"$checksum"\` | |
| *Build stats* | |
| ⌛ Time: \`$time\` | |
| 🗣️ User: \`$USERNAME\` | |
| 💻 Host: \`$HOSTNAME\` | |
| #$device" | |
| fi | |
| update_ota "$device" "$project" "$3" | |
| make clean | |
| } | |
| # release device project gapps | |
| release_experimental () { | |
| device="$1" | |
| project="$2" | |
| if [ "$3" = "gapps" ]; then | |
| type="GMS" | |
| else | |
| type="VANILLA" | |
| fi | |
| download_link="https://sourceforge.net/projects/ephedraceae/files/"$1"/"$2"/$(basename $(ls out/target/product/"$1"/lineage-*-"$1".zip))" | |
| time="$(cat $LOCAL_PATH/.last_build_time)" | |
| checksum="$(cat "$LOCAL_PATH"/out/target/product/"$1"/lineage-*-"$1".zip.sha256sum | awk '{print $1}')" | |
| checksum_link="$download_link".sha256sum | |
| if [ "$3" = "gapps" ]; then | |
| device_variant="$1_gms" | |
| else | |
| device_variant="$1" | |
| fi | |
| changelog_link=https://raw.githubusercontent.com/arian-ota/changelog/"$project"/"$device_variant".txt | |
| if [ "$1" = "davinci" ]; then | |
| telegram -c -1001426238293 -M " \ | |
| *New LineageOS 18.1 build for Mi 9T available!* | |
| 💬 Variant: \`EXPERIMENTAL "$type"\` | |
| *Download* | |
| ⬇️ ["$project"]("$download_link") | |
| ✅ [checksum]("$checksum_link") | |
| 🚧 [Changelog]("$changelog_link") | |
| @StarWarsFlowers | |
| " | |
| elif [ "$1" = "toco" ]; then | |
| telegram -c -1001426238293 -M " \ | |
| *New LineageOS 18.1 build for Mi Note 10 Lite available!* | |
| 💬 Variant: \`EXPERIMENTAL "$type"\` | |
| *Download* | |
| ⬇️ ["$project"]("$download_link") | |
| ✅ [checksum]("$checksum_link") | |
| 🚧 [Changelog]("$changelog_link") | |
| @StarWarsFlowers | |
| " | |
| fi | |
| update_changelog $1 $2 $3 | |
| } | |
| # update_ota device project gapps | |
| update_ota () { | |
| if [ "$1" = "" ]; then | |
| echo "specify a device" | |
| return -1 | |
| fi | |
| if [ "$2" = "" ]; then | |
| echo "specify a project" | |
| return -1 | |
| fi | |
| if [ "$3" = "gapps" ]; then | |
| device="$1_gms" | |
| else | |
| device="$1" | |
| fi | |
| breakfast "$1" | |
| datetime=$(cat "$OUT"/system/build.prop | grep ro.build.date.utc=) | |
| datetime="${datetime#*=}" | |
| filename=$(cat "$OUT"/system/build.prop | grep ro.lineage.version=) | |
| filename="${filename#*=}" | |
| filename=lineage-"$filename".zip | |
| id=$(cat "$OUT"/"$filename".sha256sum | awk '{print $1}') | |
| romtype=$(cat "$OUT"/system/build.prop | grep ro.lineage.releasetype=) | |
| romtype="${romtype#*=}" | |
| size=$(ls -l "$OUT"/"$filename" | awk '{print $5}') | |
| url="https://sourceforge.net/projects/ephedraceae/files/"$1"/"$2"/"$filename"/download" | |
| version=$(cat "$OUT"/system/build.prop | grep ro.lineage.build.version=) | |
| version="${version#*=}" | |
| cd "$LOCAL_PATH"/ota | |
| git add -A && git stash && git reset | |
| git fetch git@github.com:arian-ota/ota.git "$2" | |
| git checkout FETCH_HEAD | |
| if [ -f "$device".json ]; | |
| then | |
| rm "$device".json | |
| fi | |
| echo -e "{ | |
| \"response\": [ | |
| { | |
| \"datetime\": \"$datetime\", | |
| \"filename\": \"$filename\", | |
| \"id\": \"$id\", | |
| \"romtype\": \"$romtype\", | |
| \"size\": \"$size\", | |
| \"url\": \"$url\", | |
| \"version\": \"$version\" | |
| } | |
| ] | |
| }" > "$device".json | |
| git add "$device".json | |
| git commit -m "$device: Automatic OTA update" | |
| git push git@github.com:arian-ota/ota.git HEAD:"$2" | |
| cd $LOCAL_PATH | |
| update_changelog $1 $2 $3 | |
| } | |
| # update_changelog device project gapps | |
| update_changelog () { | |
| if [ "$1" = "" ]; then | |
| echo "specify a device" | |
| return -1 | |
| fi | |
| if [ "$2" = "" ]; then | |
| echo "specify a project" | |
| return -1 | |
| fi | |
| if [ "$3" = "gapps" ]; then | |
| device="$1_gms" | |
| else | |
| device="$1" | |
| fi | |
| cd "$LOCAL_PATH"/changelog | |
| git add -A && git stash && git reset | |
| git fetch git@github.com:arian-ota/changelog.git "$2" | |
| git checkout FETCH_HEAD | |
| cd $LOCAL_PATH | |
| export changelog="$LOCAL_PATH"/changelog/"$device".txt | |
| if [ -f $changelog ]; | |
| then | |
| rm $changelog | |
| fi | |
| touch $changelog | |
| for i in $(seq 7); | |
| do | |
| export After_Date=`date --date="$i days ago" +%F` | |
| k=$(expr $i - 1) | |
| export Until_Date=`date --date="$k days ago" +%F` | |
| echo "====================" >> $changelog; | |
| echo " $Until_Date " >> $changelog; | |
| echo "====================" >> $changelog; | |
| while read path; | |
| do | |
| # https://www.cyberciti.biz/faq/unix-linux-bash-script-check-if-variable-is-empty/ | |
| Git_log=`git --git-dir ./${path}/.git log --after=$After_Date --until=$Until_Date --pretty=tformat:"%h %s [%an]" --abbrev-commit --abbrev=7` | |
| if [ ! -z "${Git_log}" ]; then | |
| printf "\n* ${path}\n${Git_log}\n" >> $changelog; | |
| fi | |
| done < ./.repo/project.list; | |
| done | |
| cd changelog | |
| git add "$device".txt | |
| git commit -m "$device: Automatic changelog update" | |
| git push git@github.com:arian-ota/changelog.git HEAD:"$2" | |
| cd $LOCAL_PATH | |
| } | |
| if [ -f env_overwrite.sh ]; then | |
| source env_overwrite.sh | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment