Skip to content

Instantly share code, notes, and snippets.

@carloslack
Created August 10, 2016 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carloslack/5f9261a5cfd752f0cdb34c1f9255f1cb to your computer and use it in GitHub Desktop.
Save carloslack/5f9261a5cfd752f0cdb34c1f9255f1cb to your computer and use it in GitHub Desktop.
#!/bin/bash
# No execution (syntax check)
#set -n
# Debug
#set -x
# Deploy RDK image & rootfs into NFS directory
#
# The script gets the latest built RDK rootFS & zImage.pkg from
# the deploy directory and move them to their places
# so the STB will reach them.
# Change the variables below if you need
# Location of the build (see below)
OE_BUILD=build_1
# Deploy directory
DEPLOY_BUILD_DIR=$HOME/rdk/oe-builds/$OE_BUILD/onemw/build-brcm97449svms-refboard/tmp/deploy/images/brcm97449svms-refboard
do_some_checks()
{
tftpdir=$1
nfsdir=$2
if [ ! -d $tftpdir ] ; then
echo "Directory $tftpdir not found"
return
fi
if [ ! -d $nfsdir ] ; then
echo "Directory $nfsdir not found"
return
fi
if [ ! -d "$DEPLOY_BUILD_DIR" ] ; then
echo "Directory $DEPLOY_BUILD_DIR not found"
return
fi
}
do_copy()
{
tftpdir=$1
nfsdir=$2
# cd into build dir where build files are store
cd "$DEPLOY_BUILD_DIR"
if [ ! -f zImage.pkg ] ; then
echo "zImage.pkg file not found"
return
fi
# Locate last modified rootfs file, excluding its debug version
nfsroot=$(stat --printf="%n\n" $(ls -t\
$(find rdk-onemw-image-brcm97449svms-refboard-*.rootfs.tar.gz\
! -name "*-dbg*" -type f)) 2>/dev/null) ; nfsroot=$(cut -d " " -f1 <<< $nfsroot)
echo "RDK file: '$nfsroot'"
echo -n "Is that correct? (n/Y)? "
read answer
if [ "$answer" != "Y" ] ; then
echo "Abort!"
return
fi
# Be careful at this point
echo -n "WARNING: Command to execute: 'sudo rm -rf $nfsdir/*', continue? (n/Y) "
read answer
if [ "$answer" == "Y" ] && [ ! -z "$nfsdir" ] ; then
for i in $(seq 1 3) ; do
# Doesn't matter if the directory is already empty,
# the point here is to ask for the password because of the
# rm command below.
echo "---> 'sudo rm -rf $nfsdir/*'"
su -c "sudo rm -rf $nfsdir/*" "$USER"
status=$?
if [ $status -eq 0 ] ; then
echo "Done removing contents from $nfsdir"
echo "Copying files..."
cp -f zImage.pkg "$tftpdir"
# use runqemu-extract-sdk instead (if it is installed)
run=$(which runqemu-extract-sdk)
if [ $? --eq 0 ] ; then
sudo $run "$nfsroot" "$nfsdir"
else
sudo tar -xzf "$nfsroot" -C "$nfsdir"
fi
break
fi
done
if [ "$i" -eq 3 ] && [ $status -ne 0 ] ; then
echo "Error: You've failed to provide the correct password, abort!"
return
fi
else
echo "Abort!"
return
fi
echo "Kernel image updated: $tftpdir/zImage.pkg"
echo "RootFS updated at: $nfsdir"
return
}
do_some_checks "/tftpboot" "/srv/nfs/wayland"
do_copy "/tftpboot" "/srv/nfs/wayland"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment