Even more problems came to bite me. I had intended to use wget with some options like -r to easily download all the images that I have listed on the front page of my CakePHP backend. However, Kindle's busybox wget is quite primitive; it does not have so many options, and I am forced to perform grep, awk and a lot more scripting to download the pictures that I uploaded. Here's the code:
lipc-set-prop com.lab126.cmd wirelessEnable 1 | |
sleep 20 | |
url=http://insertyourownURLhere.com | |
rm index | |
# get list of images to download | |
wget $url/images/index || error_exit "Cannot download list of images!" | |
grep "/img/uploads" index | awk -F\" '{print $2}' > images.txt | |
# download all queued images into pics/ folder | |
cd pics | |
while read line | |
do | |
wget $url$line | |
done < ../images.txt | |
# mark all images as downloaded, do not download them again | |
wget $url/images/reset | |
rm reset | |
lipc-set-prop com.lab126.cmd wirelessEnable 0 |
In addition, Kindle renames screensavers after restart. All the photos inside the screensavers folder will be renamed to bg_xsmall_ssXX.png. That implies that a maximum of 100 photos are allowed. In addition, if the order of the photos is to be randomized via creating a file called "random", all the photos' filenames will be randomized again upon bootup, meaning I won't be able to tell if /var/local/blanket/screensaver/last_ss points to a photo or downloaded image.
In view of these, I decided to rotate the photos myself by placing one 1 photo inside the screensavers directory: bg_small_ss00.png, and replace that file everytime I change my screensaver. As usual, Busybox is so limited in functionality that I have to go through massive scripting just to choose a random photo or determine a random number. This is my updated screensaver-changing script:
lipc-set-prop com.lab126.powerd wakeUp 1 | |
mntroot rw | |
sleep 3 | |
# randomize order of photos | |
for f in /mnt/us/photos/* | |
do | |
newfile=`mktemp -p /mnt/us/photos` | |
mv -f $f $newfile | |
done | |
# if pics are downloaded, then choose between a pic and a photo | |
if [ "$(ls -A /mnt/us/pics)" ] | |
then | |
# 50% probability of displaying pic or photo | |
if [ `sed 's/[^[:digit:]]\+//g' < /dev/urandom | head -n 1 | awk '{print substr($0,0,2);}'` -lt 50 ] | |
then | |
# display a downloaded pic | |
echo displaying a downloaded pic | |
mv -f "/mnt/us/pics/`ls /mnt/us/pics -1 | head -n 1`" /mnt/us/linkss/screensavers/bg_xsmall_ss00.png | |
else | |
# display a photo | |
echo displaying a photo | |
cp "/mnt/us/photos/`ls /mnt/us/photos | sort | head -n 1`" /mnt/us/linkss/screensavers/bg_xsmall_ss00.png | |
fi | |
else | |
# no pics currently, just change to a photo | |
cp "/mnt/us/photos/`ls /mnt/us/photos | sort | head -n 1`" /mnt/us/linkss/screensavers/bg_xsmall_ss00.png | |
fi | |
# show the screensaver | |
/usr/bin/powerd_test -p | |
# suspend the Kindle in "Ready to suspend" mode indefinitely | |
a=0 | |
while [ $a -lt 50 ] | |
do | |
lipc-set-prop com.lab126.powerd deferSuspend 86400 | |
sleep 2 | |
a=`expr $a + 1` | |
done |
No comments:
Post a Comment