Last active
May 15, 2020 09:25
-
-
Save ArianK16a/821fce83d50aafa19537e970af61d04a to your computer and use it in GitHub Desktop.
This file contains 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. | |
# | |
LOCAL_PATH="$(pwd)" | |
telegram () { | |
/home/arian/jenkins/jobs/lineage/telegram/telegram "$1" "$2" "$3" "$4" "$5" | |
} | |
prepare () { | |
source build/envsetup.sh | |
export CCACHE_EXEC=$(which ccache) | |
export USE_CCACHE=1 | |
ccache -M 100G | |
} | |
build () { | |
prepare | |
breakfast "$1" | |
make installclean | |
telegram -N -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *started* on "$HOSTNAME"." | |
build_start=$(date +"%s") | |
brunch "$1" | |
build_result "$1" | |
} | |
convertsecs() { | |
h=$(bc <<< "${1}/3600") | |
m=$(bc <<< "(${1}%3600)/60") | |
s=$(bc <<< "${1}%60") | |
printf "%02d:%02d:%02d\n" $h $m $s | |
} | |
build_result () { | |
result=$(echo $?) | |
build_end=$(date +"%s") | |
diff=$(($build_end - $build_start)) | |
time=$(convertsecs "$diff") | |
if [ "$result" = "0" ]; then | |
telegram -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *completed successfully* on "$HOSTNAME". Build time: \`$time\`" | |
# exit 0 | |
else | |
telegram -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *failed* on "$HOSTNAME". Build time: \`$time\`" | |
# exit -1 | |
fi | |
echo "$time" > $LOCAL_PATH/.last_build_time | |
} | |
adb-push () { | |
if [ "$1" = "" ]; then | |
echo "specify a device" | |
else | |
adb push out/target/product/"$1"/lineage-*-"$1".zip sdcard/ | |
fi | |
} | |
upload () { | |
if [ "$1" = "" ]; then | |
echo "specify a device" | |
fi | |
project="$(basename $LOCAL_PATH)" | |
telegram -N -M "*(i)* Uploading \`$(basename $(ls out/target/product/"$1"/lineage-*-"$1".zip))\` to [Sourceforge](https://sourceforge.net/projects/ephedraceae/files/"$1"/"$project")" | |
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.md5sum ariank16a@frs.sourceforge.net:/home/frs/project/ephedraceae/"$1"/"$project"/ | |
telegram -M "#release"$'\n'"*(i)* Uploaded [$(basename $(ls out/target/product/"$1"/lineage-*-"$1".zip))](https://sourceforge.net/projects/ephedraceae/files/"$1"/"$project"/$(basename $(ls out/target/product/"$1"/lineage-*-"$1".zip))/download)." | |
release "$1" "$project" | |
} | |
release () { | |
device="$1" | |
project="$2" | |
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)" | |
md5sum="$(cat "$LOCAL_PATH"/out/target/product/"$1"/lineage-*-"$1".zip.md5sum | awk '{print $1}')" | |
md5sum_link="$download_link".md5sum | |
telegram -c -1001159030901 -N -M " \ | |
*New build available!* | |
🏗️ Project: \`"$project"\` | |
📱 Device: \`"$device"\` | |
*Download* | |
⬇️ ["$project" for "$device"]("$download_link") | |
✅ [md5sum]("$md5sum_link"): \`"$md5sum"\` | |
*Build stats* | |
⌛️ Time: \`$time\` | |
🗣️ User: \`$USERNAME\` | |
💻 Host: \`$HOSTNAME\` | |
#$device" | |
update_ota "$device" "$project" | |
} | |
update_ota () { | |
if [ "$1" = "" ]; then | |
echo "specify a device" | |
return -1 | |
fi | |
if [ "$2" = "" ]; then | |
echo "specify a project" | |
return -1 | |
fi | |
builddate=$(cat "$OUT"/system/build.prop | grep ro.build.date.utc) | |
builddate="${builddate#*=}" | |
ota_link="https://sourceforge.net/projects/ephedraceae/files/"$1"/"$2"/$(basename $(ls out/target/product/"$1"/lineage-*-"$1".zip))/download" | |
cd "$LOCAL_PATH"/OTA | |
git add -A && git stash && git reset | |
git fetch git@github.com:ArianK16a/OTA.git "$2" | |
git checkout FETCH_HEAD | |
rm "$1".json | |
echo -e "{ | |
\"response\": [ | |
{ | |
\"datetime\": \"$builddate\", | |
\"filename\": \"$(basename $(ls $LOCAL_PATH/out/target/product/"$1"/lineage-*-"$1".zip))\", | |
\"id\": \"$(cat $LOCAL_PATH/out/target/product/"$1"/lineage-*-"$1".zip.md5sum | awk '{print $1}')\", | |
\"romtype\": \"UNOFFICIAL\", | |
\"size\": \"$(ls -l $LOCAL_PATH/out/target/product/"$1"/lineage-*-"$1".zip | awk '{print $5}')\", | |
\"url\": \"$ota_link\", | |
\"version\": \"17.1\" | |
} | |
] | |
}" > "$1".json | |
git add "$1".json | |
git commit -m "$1: Automatic OTA update" | |
git push git@github.com:ArianK16a/OTA.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