slitaz-arm rev 191

piboot: add bittorrent support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jun 29 10:00:00 2014 +0200 (2014-06-29)
parents 968eda0ad1cf
children e0ff291ac6e2
files rpi/piboot
line diff
     1.1 --- a/rpi/piboot	Thu May 15 22:59:58 2014 +0100
     1.2 +++ b/rpi/piboot	Sun Jun 29 10:00:00 2014 +0200
     1.3 @@ -22,7 +22,6 @@
     1.4  EOT
     1.5  [ -s $LOG ] && exec /init
     1.6  
     1.7 -
     1.8  cmdlinearg()
     1.9  {
    1.10  	grep -q $1= /proc/cmdline && sed "s/.*$1=\([^ ]*\).*/\1/" </proc/cmdline
    1.11 @@ -110,16 +109,42 @@
    1.12  	/etc/init.d/network.sh start
    1.13  	webpath=$(get webpath $mnt/menu.txt)
    1.14  	[ "$webpath" ] || webpath=http://mirror.slitaz.org/pxe/arm/boot.php
    1.15 -	wget -O /root/webboot.sh $webpath 2>&1 > /dev/null
    1.16 +	wget -O /root/webboot.sh $webpath?mac=$(cat /sys/class/net/eth0/address) 2>&1 > /dev/null
    1.17  	[ -s /root/webboot.sh ] || return
    1.18  	. /root/webboot.sh
    1.19  	webprefix=$(dirname $webpath)
    1.20  	editbutton=""
    1.21  }
    1.22  
    1.23 +web_get()
    1.24 +{
    1.25 +	case "$1" in
    1.26 +	*torrent) # See http://sl-lab.it/dokuwiki/doku.php/tesi:boottorrent_en
    1.27 +		[ -z "$(which aria2)" ] &&
    1.28 +			echo "Can't find aria2." >> $LOG &&
    1.29 +			exec /init
    1.30 +
    1.31 +		wget -O /root/webboot.torrent $1
    1.32 +		aria2c --enable-dht=false --disable-ipv6=true --seed-time=0 \
    1.33 +			--file-allocation=none -j5 /root/webboot.torrent
    1.34 +
    1.35 +		if ls | grep -q rootfs; then
    1.36 +			file=$(ls | grep -q rootfs)
    1.37 +			cat $file >> $2
    1.38 +			rm -f $file
    1.39 +		else
    1.40 +			mv $(ls *mage* *linu* 2> /dev/null) $2
    1.41 +		fi
    1.42 +		rm -f /root/webboot.torrent ;;
    1.43 +	*)
    1.44 +		wget -O - $1 >> $2
    1.45 +	esac
    1.46 +}
    1.47 +
    1.48  : ${DIALOG=dialog}
    1.49  
    1.50  mount -t proc proc /proc
    1.51 +mount -t sysfs sys /sys
    1.52  BOOTDEV=$(cmdlinearg bootdev)
    1.53  mnt=/mnt
    1.54  mount -t devtmpfs /dev /dev
    1.55 @@ -207,6 +232,7 @@
    1.56  			*timeout) break ;;
    1.57  			esac
    1.58  			umount $mnt
    1.59 +			umount /sys
    1.60  			umount /proc
    1.61  			poweroff -f ;;
    1.62  		3)
    1.63 @@ -220,9 +246,7 @@
    1.64  case "$KEYWORD" in
    1.65  
    1.66  ''|Continue)
    1.67 -	umount $mnt
    1.68 -	umount /proc
    1.69 -	exec /init ;;
    1.70 +	KEXEC= ;;
    1.71  
    1.72  *)
    1.73  	eval KERNEL="\$KERNEL_$n"
    1.74 @@ -231,13 +255,14 @@
    1.75  
    1.76  	if [ "$webprefix" ]; then
    1.77  		cd /root
    1.78 -		wget $webprefix/$KEYWORD/$KERNEL
    1.79 +		web_get $webprefix/$KEYWORD/$KERNEL vmlinuz
    1.80 +		KERNEL=vmlinuz
    1.81  		for i in ${INITRD//,/ }; do
    1.82 -			wget -O - $webprefix/$KEYWORD/$i >> /root/rootfs.gz
    1.83 -			n=$(stat -c %s /root/rootfs.gz)
    1.84 +			web_get $webprefix/$KEYWORD/$i rootfs.gz
    1.85 +			n=$(stat -c %s rootfs.gz)
    1.86  			n=$(($n % 4))
    1.87  			[ $n -eq 0 ] && continue
    1.88 -			dd if=/dev/zero bs=1 count=$((4 - $n)) >> /root/rootfs.gz
    1.89 +			dd if=/dev/zero bs=1 count=$((4 - $n)) >> rootfs.gz
    1.90  		done
    1.91  	else
    1.92  		cd $mnt/$KEYWORD
    1.93 @@ -255,8 +280,12 @@
    1.94  	[ "$CMDLINE" ] && CMDLINE="--command-line \"$CMDLINE\""
    1.95  
    1.96  	kexec -l $(basename $KERNEL) $INITRD $CMDLINE --atags
    1.97 -	umount $mnt
    1.98 -	umount /proc
    1.99 -	kexec -e ;;
   1.100 +	KEXEC="kexec -e" ;;
   1.101  
   1.102  esac
   1.103 +
   1.104 +umount $mnt
   1.105 +umount /sys
   1.106 +umount /proc
   1.107 +$KEXEC
   1.108 +exec /init