-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKrakenPrebuilts.sh
68 lines (57 loc) · 2.13 KB
/
KrakenPrebuilts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#Constants
CUR_DIR=$(pwd)
DOWN_PATH="$ANDROID_BUILD_TOP/packages/apps/KrakenPrebuilts"
commit_msg=()
#jq check
is_jq=$(which jq)
if [[ -z $is_jq ]]; then
echo "please install jq"
if [ $(command -v apt) ]; then
echo "sudo apt install jq"
elif [ $(command -v pacman) ]; then
echo "sudo pacman -S jq"
fi
exit 0
fi
function fetchPrebuilts() {
if ping -q -c 1 -W 1 8.8.8.8 >/dev/null; then
gh_json=$(curl -s "$2")
file_last_update=$(echo $gh_json | jq -r '.assets[0].updated_at' | date -d `cut -f1 -d"T"` +"%Y%m%d")
apk_down_url=$(echo $gh_json | jq -r '.assets[0].browser_download_url')
if [[ -f "${DOWN_PATH}/${1}/${1}.apk" ]]; then
FILE_DATE=$(/bin/date +%Y%m%d -d "$(/usr/bin/stat -c %x "${DOWN_PATH}/${1}/${1}.apk")")
else
FILE_DATE=000000
fi
if [[ $FILE_DATE -ge $file_last_update ]]; then
echo "We already have the latest version of ${1}"
else
echo "Grabbing the latest version of ${1}"
wget -q -O "${DOWN_PATH}/${1}/${1}.apk" $apk_down_url
commit_msg+=("- ${1}: Updated to latest build [$file_last_update]\n")
echo "${1} updated to latest version"
cd $CUR_DIR
fi
else
echo "Looks like theres no internet connection"
if [[ -f "${DOWN_PATH}/${1}/${1}.apk" ]]; then
echo "An old version of ${1} exists, using it for now."
else
echo "Nothing found! ${1} won't be available in this build!"
fi
fi
}
# parameters
# 1 - App name
# 2 - App apk url
fetchPrebuilts DuckDuckGo https://api.github.com/repos/duckduckgo/Android/releases/latest
fetchPrebuilts SimpleCalendar https://api.github.com/repos/SimpleMobileTools/Simple-Calendar/releases/latest
fetchPrebuilts SimpleGallery https://api.github.com/repos/SimpleMobileTools/Simple-Gallery/releases/latest
# git commit stage
if [ ${#commit_msg[@]} -ne 0 ]; then
cd $DOWN_PATH
git add .
git commit -m "KrakenPrebuilts: Update [check description]" -m "$(echo -e ${commit_msg[*]})"
echo "Committed locally, push to gerrit!"
fi