Created
May 8, 2017 23:40
-
-
Save mattkenefick/60496dfed8aaedb4abb104bb3f9ba374 to your computer and use it in GitHub Desktop.
Roku Build
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 | |
# | |
# build.sh | |
# Matt Kenefick | |
# | |
# Written for usage on Apple computers | |
# | |
# Uses a local ".build-env" file to package and upload a new | |
# Roku dev app onto a device. Hooks into Sublime Text build | |
# commands as well. | |
# | |
pushd `dirname $0` > /dev/null | |
SCRIPTPATH=`pwd -P` | |
popd > /dev/null | |
# Get environment variables | |
source $SCRIPTPATH/../tools/.build-env | |
# Override if local env exists | |
if [ -s "$SCRIPTPATH/../tools/.build-env-override" ]; then | |
source $SCRIPTPATH/../tools/.build-env-override | |
fi | |
# Check if it's alive | |
if ! ping -c 1 "$roku_ip" &>/dev/null ; then | |
echo "Roku @ $roku_ip is down. Exiting script." | |
exit | |
fi | |
# Override base build environment variables | |
for i in "$@" | |
do | |
case $i in | |
-t=*|--theme=*) | |
theme="${i#*=}" | |
shift | |
;; | |
-i=*|--ip=*) | |
roku_ip="${i#*=}" | |
shift | |
;; | |
-p=*|--password=*) | |
roku_password="${i#*=}" | |
shift | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
done | |
# Deployment package | |
ROOT=$SCRIPTPATH/../ | |
THEME=$ROOT/bin/$theme/dev.zip | |
# Check if the theme package exists | |
mkdir -p $ROOT/bin/$theme | |
# Check if the theme package exists | |
echo -e $ROOT/src/themes/$theme | |
# Exit script because we don't have a compiled package | |
if ! [ -d $ROOT/src/themes/$theme ] ; | |
then | |
echo -e "roku build > We could not find the theme $theme, exiting." | |
exit | |
fi | |
# Check that we have a theme to save | |
if [ -n "${theme}" ]; | |
then | |
echo -e "roku build > Using theme: $theme" | |
else | |
echo -e "roku build > No theme variable found. Exiting." | |
exit | |
fi | |
# Remove any old packages | |
if [ -f $THEME ]; | |
then | |
rm $THEME | |
echo -e "roku build > Removing old package" | |
else | |
echo "roku build > Old package does not exist." | |
fi | |
# Create a new package | |
pushd $ROOT/src | |
mkdir $theme | |
cp -R ./source ./$theme/source | |
cp -R ./components ./$theme/components | |
cp -R ./global/* ./$theme | |
cp -R ./themes/$theme/* ./$theme | |
cd $theme | |
# Special build variables to insert into application | |
echo -e "build_env=$env" >> "manifest" | |
echo -e "build_theme=$theme" >> "manifest" | |
zip -q -9 -r $THEME . | |
cd ../ | |
rm -rf ./$theme | |
echo -e "roku build > Created new package for theme | $theme" | |
popd > /dev/null | |
echo -e "roku build > About to upload to $roku_ip" | |
# Upload to the Roku | |
output=$(curl --progress-bar --user rokudev:$roku_password --digest -F "mysubmit=Replace" -F "archive=@$THEME" -F "passwd=" http://$roku_ip/plugin_install) | |
if [ -z "$output" ]; then | |
echo -e "roku error > Problem connecting or a timeout. Check host, package, and connectivity." | |
elif [[ $output == *"Received: Compilation Failed"* ]]; then | |
echo -e "roku error > Syntax error in your code. Use the debug.sh to find out what file and line." | |
elif [[ $output == *"Install Failure: Compilation Failed"* ]]; then | |
echo -e "roku error > Syntax error in your code. Use the debug.sh to find out what file and line." | |
elif [[ $output == *"Install timeout. Results unknown"* ]]; then | |
echo -e "roku error > Roku timed out for unknown reasons." | |
elif [[ $output == *"Received: Identical to previous"* ]]; then | |
echo -e "roku error > Package is supposedly identical to last upload." | |
elif [[ $output == *"No space left"* ]]; then | |
echo -e "roku error > No space left on device. Remove old package first." | |
elif [[ $output == *"Install Success"* ]]; then | |
echo -e "roku build > Uploaded to Roku" | |
else | |
echo -e "roku build > Unknown error." | |
echo -e $output | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment