2013-10-16 17:32:43 +02:00
#!/bin/sh
2013-10-16 19:04:33 +02:00
#prevent being run as root (which is dangerous)
if [ " $( id -u) " = = "0" ] ; then
echo "Don't run this script as root, it is potentially dangerous." 1>& 2
exit 1
fi
2013-10-16 17:32:43 +02:00
OPENWRT_BASE = .
PKG_SRC_DIR = $OPENWRT_BASE /bin/ar71xx/packages
PKG_DEST_SUBPATH = updates
MAKE_INDEX_SCRIPT = $OPENWRT_BASE /scripts/ipkg-make-index.sh
INDEX_FILE = Packages
INDEX_GZ_FILE = Packages.gz
2013-10-16 19:04:33 +02:00
DEVICE_TYPES = "tl-mr3020 tl-wr703"
MAX_GOOD_IMAGE_SIZE = 3500000
IMAGE_BASENAME = "doodle3d-wifibox"
2013-10-16 17:32:43 +02:00
COMPRESS_RESULT = 0
PKG_DEST_BASE = .
for arg in " $@ " ; do
case $arg in
-h)
echo "This script creates a directory with wifibox and ultifi ipk files found in the openWrt build environment."
echo " The feed dir is called $PKG_DEST_DIR and will be created in the current directory. (currently `pwd`) "
echo "If specified, the -z option also compresses the result for easier transfer to a webserver."
exit
; ;
-z)
COMPRESS_RESULT = 1
; ;
-*)
echo " Unrecognized option ' $arg ' "
exit 1
; ;
*)
PKG_DEST_BASE = $arg
; ;
esac
done
grep " ^This is the buildsystem for the OpenWrt Linux distribution\. $" README >/dev/null 2>& 1
if [ $? -ne 0 ] ; then
echo "Please run this script from the Openwrt build root (on OSX this is probably an image mounted under /Volumes)."
exit 1
fi
2013-10-17 21:45:23 +02:00
#determine the wifibox root path
my_rel_dir = ` dirname $0 `
pushd " $my_rel_dir " > /dev/null
WIFIBOX_DIR = "`pwd`/../.."
popd > /dev/null
FW_VERSION = ` cat $WIFIBOX_DIR /src/FIRMWARE-VERSION`
echo " Compiling firmware update files for version ${ FW_VERSION } "
2013-10-16 17:32:43 +02:00
#setup paths
PKG_DEST_DIR = $PKG_DEST_BASE /$PKG_DEST_SUBPATH
PKG_FEED_DIR = $PKG_DEST_DIR /feed
PKG_IMG_DIR = $PKG_DEST_DIR /images
2013-10-17 21:45:23 +02:00
IMG_INDEX_FILE = $PKG_IMG_DIR /wifibox-image.index
2013-10-16 17:32:43 +02:00
if [ ! -d $PKG_DEST_DIR ] ; then mkdir -p $PKG_DEST_DIR ; fi
echo " Using $PKG_DEST_DIR as target directory "
#clear directory and copy package files
if [ ! -d $PKG_FEED_DIR ] ; then mkdir $PKG_FEED_DIR ; fi
cp $PKG_SRC_DIR /wifibox*.ipk $PKG_FEED_DIR
cp $PKG_SRC_DIR /ultifi*.ipk $PKG_FEED_DIR
cp $PKG_SRC_DIR /print3d*.ipk $PKG_FEED_DIR
rm -f $PKG_FEED_DIR /$INDEX_FILE
rm -f $PKG_FEED_DIR /$INDEX_GZ_FILE
2013-10-16 19:04:33 +02:00
#copy and rename images
if [ ! -d $PKG_IMG_DIR ] ; then mkdir $PKG_IMG_DIR ; fi
2013-10-17 21:45:23 +02:00
rm -f $IMG_INDEX_FILE
2013-10-16 19:04:33 +02:00
for devtype in $DEVICE_TYPES ; do
IMG_SRC_PATH = $OPENWRT_BASE /bin/ar71xx
if [ -f $IMG_SRC_PATH /openwrt-ar71xx-generic-${ devtype } -v1-squashfs-sysupgrade.bin ] ; then
sysupgrade_name = $IMG_SRC_PATH /openwrt-ar71xx-generic-${ devtype } -v1-squashfs-sysupgrade.bin
factory_name = $IMG_SRC_PATH /openwrt-ar71xx-generic-${ devtype } -v1-squashfs-factory.bin
sysupgrade_size = ` stat -f %z $sysupgrade_name `
factory_size = ` stat -f %z $factory_name `
2013-10-17 21:45:23 +02:00
sysupgrade_out_basename = $IMAGE_BASENAME -${ FW_VERSION } -${ devtype } -sysupgrade.bin
factory_out_basename = $IMAGE_BASENAME -${ FW_VERSION } -${ devtype } -factory.bin
2013-10-16 19:04:33 +02:00
echo " Copying images for device ' ${ devtype } ' (sysupgrade size: ${ sysupgrade_size } , factory size: ${ factory_size } ) "
2013-10-17 21:45:23 +02:00
#TODO: replace 'wc -c' with something more efficient (stat? ls?)
sysupgrade_filesize = ` wc -c < ${ sysupgrade_name } | tr -d ' ' `
factory_filesize = ` wc -c < ${ factory_name } | tr -d ' ' `
sysupgrade_md5sum = ` md5 -q ${ sysupgrade_name } `
factory_md5sum = ` md5 -q ${ factory_name } `
echo " Version: ${ FW_VERSION } " >> $IMG_INDEX_FILE
echo " Files: ${ sysupgrade_out_basename } ; ${ factory_out_basename } " >> $IMG_INDEX_FILE
echo " FileSize: ${ sysupgrade_filesize } ; ${ factory_filesize } " >> $IMG_INDEX_FILE
echo " MD5: ${ sysupgrade_md5sum } ; ${ factory_md5sum } " >> $IMG_INDEX_FILE
2013-10-16 19:04:33 +02:00
if [ $sysupgrade_size -gt $MAX_GOOD_IMAGE_SIZE ] ; then
2013-10-17 21:45:23 +02:00
echo " WARNING: the sysupgrade image is larger than $MAX_GOOD_IMAGE_SIZE bytes, which probably means it will cause read/write problems when flashed to a device "
2013-10-16 19:04:33 +02:00
fi
2013-10-17 21:45:23 +02:00
cp $sysupgrade_name $PKG_IMG_DIR /$sysupgrade_out_basename
cp $factory_name $PKG_IMG_DIR /$factory_out_basename
2013-10-16 19:04:33 +02:00
fi
done
2013-10-16 17:32:43 +02:00
# NOTE: the aliasing construct in the indexing script does not work (and even then, the md5 command defaults to a different output format), so we hack around it here.
MD5_HACK_ENABLED = 0
which md5sum >/dev/null 2>& 1
if [ $? -eq 1 ] ; then
MD5_HACK_ENABLED = 1
TEMPBIN_DIR = /tmp/tempbin23QQDBR
mkdir $TEMPBIN_DIR
cat <<EOF > $TE MPBIN_DIR/md5sum
` type -p md5` -q \$ 1
EOF
chmod +x $TEMPBIN_DIR /md5sum
PATH = $PATH :$TEMPBIN_DIR
fi
#this cwd juggling is required to have the package indexer generate correct paths (i.e. no paths) in the Packages file
OPENWRT_DIR = ` pwd `
2013-10-16 19:04:33 +02:00
pushd $PKG_FEED_DIR > /dev/null
2013-10-16 17:32:43 +02:00
$OPENWRT_DIR /$MAKE_INDEX_SCRIPT . > $PKG_FEED_DIR /$INDEX_FILE
2013-10-16 19:04:33 +02:00
popd > /dev/null
2013-10-16 17:32:43 +02:00
if [ $MD5_HACK_ENABLED -eq 1 ] ; then
rm $TEMPBIN_DIR /md5sum
rmdir $TEMPBIN_DIR
fi
gzip -c $PKG_FEED_DIR /$INDEX_FILE > $PKG_FEED_DIR /$INDEX_GZ_FILE
if [ $COMPRESS_RESULT -eq 1 ] ; then
cd $PKG_DEST_BASE
echo "Compressing generated package directory..."
tar czvf "doodle3d-wifibox-update-dist.tgz" $PKG_DEST_SUBPATH
fi