#!/bin/busybox ash # tce-size.sh - Copyright 2010 Brian Smith # Some edits by Curaga # Edited for use by appbrowser by roberts # Licensed under GPLv2 License # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. . /etc/init.d/tc-functions useBusybox K=1024 M=$(($K * $K)) Fixed3Div() { # divide $1 by $2. Return result to 3 decimal places, no rounding. printf "%d.%03d\n" $(($1 / $2)) $(((($1 % $2) * 1000) / $2)) } get_dependencies() { for F in `sed 's/ //g' "$app".tree | sort -f | uniq`; do size=`grep -w "^$F" sizelist | awk '{print $2}'` case $size in [0-9]*) sizemb=`Fixed3Div $size $M` if [ -f "$localtce"/optional/"$F" ]; then totalsize_installed=$(($totalsize_installed + $size)) echo -n " " printf "%-40s" $F printf " %10d, %6.2f MB\n" $size $sizemb else echo -n "+ " totalsize_needed=$(($totalsize_needed + $size)) printf "%-40s %10d, %6.2f MB\n" $F $size $sizemb fi ;; *) printf "%-40s Error, not found \n" $F ;; esac done } app=$1 if [ -n "$app" ]; then app=${app%.tcz} app="$app.tcz" localtce=/etc/sysconfig/tcedir cd /tmp if [ ! -f sizelist ]; then tce-fetch.sh sizelist.gz || exit 1 gunzip -f sizelist.gz touch sizelist else # Check if the file is older than 5 hours age=$((`date +%s` - `date -r sizelist +%s`)) if [ $age -ge 18000 ]; then tce-fetch.sh sizelist.gz || exit 1 gunzip -f sizelist.gz touch sizelist fi fi tce-fetch.sh "$app".tree >/dev/null 2>&1 || echo "$app" > "$app".tree totalsize_needed=0 totalsize_installed=0 get_dependencies $app totalsize=$(($totalsize_needed + $totalsize_installed)) totalsizemb=`Fixed3Div $totalsize $M` totalsize_neededmb=`Fixed3Div $totalsize_needed $M` totalsize_installedmb=`Fixed3Div $totalsize_installed $M` printf "\n %-40s %10d, %6.2f MB\n" "Total size (bytes)" $totalsize $totalsizemb printf "+ %-40s %10d, %6.2f MB\n" "Indicates need to download" $totalsize_needed $totalsize_neededmb else echo "Specify extension in command line:" echo "Example: $0 firefox.tcz" fi