Skip to content

Instantly share code, notes, and snippets.

@ArianK16a
Last active December 26, 2020 19:21
Show Gist options
  • Save ArianK16a/5d808dc64329942523305e9ebf0aec93 to your computer and use it in GitHub Desktop.
Save ArianK16a/5d808dc64329942523305e9ebf0aec93 to your computer and use it in GitHub Desktop.
#!/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)"
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
}
prepare_vanilla () {
rm -rf vendor/extra
git clone https://github.com/ArianK16a/android_vendor_extra.git -b 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 gapps vendor/extra
export TARGET_UNOFFICIAL_BUILD_ID=GMS
}
# build device releasetype gapps
build () {
prepare
breakfast "$1"
repo sync --force-sync -q
bash "$LOCAL_PATH"/picks.sh
if [ "$3" = "gapps" ]; then
prepare_gapps
else
prepare_vanilla
fi
make clean
# make installclean
telegram -N -M "*(i)* \`"$(basename $LOCAL_PATH)"\` compilation for \`"$1"\` *started* on "$HOSTNAME"."
build_start=$(date +"%s")
brunch "$1"
build_result "$1" "$3"
if [ -f $LOCAL_PATH/.last_build_time ] & [ -f "$OUT"/lineage-*-"$1".zip ]; then
upload "$1" "$2" "$3"
else
telegram -c -1001426238293 "Nightlies compilation failed!"
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\`."
# exit -1
fi
}
# 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.md5sum 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.md5sum 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)"
md5sum="$(cat "$LOCAL_PATH"/out/target/product/"$1"/lineage-*-"$1".zip.md5sum | awk '{print $1}')"
md5sum_link="$download_link".md5sum
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
telegram -c -1001426238293 -M " \
*New LineageOS 17.1 build for Mi 9T available!*
💬 Variant: \`"$type"\`
*Download*
⬇️ ["$project"]("$download_link")
✅ [md5sum]("$md5sum_link")
🚧 [Changelog]("$changelog_link")
@StarWarsFlowers
"
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)"
md5sum="$(cat "$LOCAL_PATH"/out/target/product/"$1"/lineage-*-"$1".zip.md5sum | awk '{print $1}')"
md5sum_link="$download_link".md5sum
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
telegram -c -1001426238293 -M " \
*New LineageOS 17.1 build for Mi 9T available!*
💬 Variant: \`EXPERIMENTAL "$type"\`
*Download*
⬇️ ["$project"]("$download_link")
✅ [md5sum]("$md5sum_link")
🚧 [Changelog]("$changelog_link")
@StarWarsFlowers
"
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".md5sum | 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