#!/bin/sh # rc.d Script to download and update DSLinux # WARNING: This script relies heavily on the format of: # $MIRROR/index.html # It MUST contain the following: # Updated to revision X # X being the current revision of $MIRROR/dslinux-dldi.tgz # You can set the following in rc.conf: # MIRROR="http://yourmirror.com/ # DOWNLOADTO="/path/to/save/dslinux-dldi.tgz # # TODO # General tidy up, it's a bit of a mess really # Maybe use dialog? # An option to force install [ -e /etc/rc.defaults ] && . /etc/rc.defaults [ -e /etc/rc.conf ] && . /etc/rc.conf # Set default mirror to Kineox DEFAULTMIRROR="http://kineox.free.fr/DS/" # Set $ARG1 as $1 gets overwritten later ARG1=$1 case "$ARG1" in check) # Check for extra RAM exec 0 /tmp/update.mirror # Clear out previous temp file if found if [ -f /tmp/update.downloadto ]; then rm /tmp/update.downloadto fi if [ -z "$DOWNLOADTO" ]; then echo "No download location specified, downloading to /media" DOWNLOADTO="/media" else echo "Downloading to $DOWNLOADTO" fi #Write $DOWNLOADTO to tmp file as export doesn't seem to work echo $DOWNLOADTO > /tmp/update.downloadto if [ ! -f /etc/revision ]; then echo "No /etc/revision found!" exit 2 fi # Strip revision from /etc/revision LOCALVER=`sed -n "/^Revision*/s/Revision: //p" /etc/revision` # Strip revision from web page echo "Retrieving remote version information from $MIRROR" REMOTEVER=`wget -q $MIRROR -O - | sed -n "/revision/{s/Updated to revision //;s/\.//p}"` echo "Remote version = $REMOTEVER, Local version = $LOCALVER" if [ $LOCALVER -lt $REMOTEVER ]; then echo "New update available" elif [ $LOCALVER -gt $REMOTEVER ]; then echo "Local version is newer than remote version?" echo "Only Kineox should be creating builds with:" echo "CONFIG_DEFAULTS_RELEASE_BUILD=y" exit 3 else echo "Already at latest update" exit 4 fi ;; download) # Check for update $0 check # Download # Get MIRROR from temp file as export doesn't seem to work if [ -f /tmp/update.mirror ]; then MIRROR=`cat /tmp/update.mirror` rm /tmp/update.mirror else echo "Could not find /tmp/update.mirror" exit 5 fi # Get DOWNLOADTO from file if [ -f /tmp/update.downloadto ]; then DOWNLOADTO=`cat /tmp/update.downloadto` else echo "Could not find /tmp/update.downloadto" exit 6 fi if [ -f $DOWNLOADTO/dslinux-dldi.tgz ]; then echo "Previous download detected" fi wget -c --progress=bar -O $DOWNLOADTO/dslinux-dldi.tgz $MIRROR/dslinux-dldi.tgz echo "Download complete" echo "Checking MD5 checksum" if [ `wget -q $MIRROR/dslinux-dldi.tgz.md5 -O -` = `md5sum $DOWNLOADTO/dslinux-dldi.tgz` ]; then echo "Everything okay." else echo "Looks like the file is corrupted." exit 7 fi ;; install) # Download (checks for update also) $0 download # Unpack # Get DOWNLOADTO from file if [ -f /tmp/update.downloadto ]; then DOWNLOADTO=`cat /tmp/update.downloadto` rm /tmp/update.downloadto else echo "Could not find /tmp/update.downloadto" exit 7 fi echo "Calculating disk space" set -- `gzip -l dslinux-dldi.tgz | grep dslinux-dldi.tar` FILE="$2" set -- `df | grep dldi1` if [ $FILE -gt $4 ]; then echo "The file is $FILE bytes big, but there are only $4 free." exit 8 else echo "Enough disk space free." fi echo "Unpacking, may take a long time. Do not switch off!" gzip -d -c $DOWNLOADTO/dslinux-dldi.tgz | tar xv --no-same-owner -C /media echo "Unpacking complete" echo "syncing disk" sync echo "Update complete!" echo "If your firmware does not support Autopatching," echo "please patch /media/dslinux.nds before restarting" echo "eg: dlditool /path/to/dldi /media/dslinux.nds" exit 9 ;; *) echo "Usage:" echo "'update check' - Checks for update" echo "'update download' - Checks for update and downloads" echo "'update install' - Checks for update, downloads and installs" exit 10 ;; esac