Last active
September 22, 2021 18:47
-
-
Save Iristyle/6c34e0a62970ad3cf8ca 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 | |
# Mostly taken from http://forum.kodi.tv/showthread.php?tid=212971 | |
############################################################################### | |
# Download and update latest Kodi build (nightly or stable) and install to a connected device. | |
# - tested using a Mac OSX and Fire TV Stick | |
############################################################################### | |
function progressbar() | |
{ | |
bar="================================================================================" | |
barlength=${#bar} | |
n=$(($1*barlength/100)) | |
printf "\r[%-${barlength}s] %d%%" "${bar:0:n}" "$1" | |
# echo -ne "\b$1" | |
} | |
export -f progressbar | |
which adb >/dev/null 2>&1 || { \ | |
echo "adb doesn't exist in your path"; \ | |
exit 3; \ | |
} | |
############################################################################### | |
# get latest versions (nightly and stable) | |
############################################################################### | |
NIGHTLY_URL=http://mirrors.kodi.tv/nightlies/android/arm/ | |
STABLE_URL=http://mirrors.xbmc.org/releases/android/arm/ | |
# get latest nightly build (NOTE: sed syntax could be better but works) | |
NIGHTLY=`curl -s $NIGHTLY_URL | grep -o '<a .*href=.*>' | grep apk | head -1 | sed -e 's/<a /<a /g' | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d'` | |
if [[ "$NIGHTLY" == "" ]] | |
then | |
echo "Error fetching latest nightly version" | |
exit | |
fi | |
# get latest nightly build (NOTE: sed syntax could be better but works) | |
STABLE=`curl -s $STABLE_URL | grep -o '<a .*href=.*>' | grep apk | head -1 | sed -e 's/<a /<a /g' | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d'` | |
if [[ "$STABLE" == "" ]] | |
then | |
echo "Error fetching latest stable version" | |
exit | |
fi | |
echo "latest nightly: $NIGHTLY" | |
echo "latest stable: $STABLE" | |
############################################################################### | |
# detect device connected via adb (NOTE: does not support multiple devices) | |
############################################################################### | |
adb start-server | |
((NUM_DEVICES = `adb devices | wc -l` - 2)) | |
if [[ "$NUM_DEVICES" == 0 ]] | |
then | |
echo "No devices connected.." | |
read -p "Enter device IP address: " IP | |
adb connect $IP | |
# check again and exit if no devices | |
((NUM_DEVICES = `adb devices | wc -l` - 2)) | |
if [[ "$NUM_DEVICES" == 0 ]] | |
then | |
echo "No devices connected.." | |
exit; | |
fi | |
fi | |
############################################################################### | |
# choose nightly or stable version | |
############################################################################### | |
echo 'Select Download Option:' | |
select download in "Nightly" "Stable" "Exit" ; do | |
case $download in | |
"Nightly" ) break;; | |
"Stable" ) break;; | |
"Exit" ) echo "Exiting.."; exit;; | |
esac | |
done | |
if [[ "$download" == "Nightly" ]] | |
then | |
FILE=$NIGHTLY | |
DOWNLOAD_URL=$NIGHTLY_URL | |
elif [[ "$download" == "Stable" ]] | |
then | |
FILE=$STABLE | |
DOWNLOAD_URL=$STABLE_URL | |
fi | |
# save to /tmp | |
TMP_FILE=/tmp/$FILE | |
rm $TMP_FILE 2>/dev/null | |
############################################################################### | |
# download | |
############################################################################### | |
echo "downloading: $FILE" | |
curl -# -L -o $TMP_FILE $DOWNLOAD_URL/$FILE | |
if [ ! -f $TMP_FILE ] | |
then | |
echo "download failed!" | |
exit | |
fi | |
############################################################################### | |
# install options | |
############################################################################### | |
echo 'Select Install Option:' | |
select result in "Upgrade" "Clean Install" "Exit" ; do | |
case $result in | |
"Upgrade" ) break;; | |
"Clean Install" ) break;; | |
"Exit" ) echo "Exiting.."; exit;; | |
esac | |
done | |
############################################################################### | |
# clean install | |
############################################################################### | |
if [[ "$result" == "Clean Install" ]] | |
then | |
echo "uninstalling.." | |
adb uninstall org.xbmc.xbmc | |
fi | |
############################################################################### | |
# install with progress | |
# progressbar code: http://stackoverflow.com/questions/6595374/adb-push-pull-with-progress-bar | |
############################################################################### | |
echo "installing $TMP_FILE" | |
SIZE=$(ls -l $TMP_FILE | awk '{print $5}') | |
export ADB_TRACE=all | |
adb $device install -r $TMP_FILE 2>&1 \ | |
| sed -n '/DATA/p' \ | |
| awk -v T=$SIZE 'BEGIN{FS="[=:]"}{t+=$7;system("progressbar " sprintf("%d\n", t/T*100))}' | |
############################################################################### | |
# cleanup | |
############################################################################### | |
rm $TMP_FILE | |
export ADB_TRACE= | |
echo | |
echo 'press any key to exit' | |
read n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment