Register
It is currently Wed Oct 01, 2014 2:18 pm

sizing a dir for dvd


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Sun Dec 13, 2009 11:48 pm   

Joined: Thu May 14, 2009 1:22 am
Posts: 5
I am trying to duplicate the functionality of a program called "sizeme" for windows. The purpose for this program is to feed it a file list and it will arrange the files for disk storage.


The goal is to have totally customizable output, ie.:
1. make subdirs like disk01, disk02....disk23 with symbolic links inside.
2. Make an ISO for each disk to be made
3. variable disk sizes
and complain (with list) of files too large for the target media.
I would also like to implement CLI and GUI versions (maybe by switch?).

Here's what I have so far (and I'm sure that a lot could be optimized). As you can see, I did all the easy work ;). If you have the skills to assist me, would you kindly?

Code:
#!/bin/bash
#
#  "optisizer" written by Josh Dotson
#
#

# DISKS TO USE ARE: DVD5 DVD9 DVD10 DVD18 BLUERAY CD650 CD700 F144M F720K

target=DVD5

function populate {
# this reads in the current dir and populates the (N)ame and (S)ize arrays

dirS=( `ls -l | grep -v ^d | grep -v ^l | sed s/\ \ */\ /g | cut -d" " -f5 ` )
dirN=( `ls -l | grep -v ^d | grep -v ^l | sed s/\ \ */\ /g | cut -d" " -f9- ` )

count="$(( ${#dirS[@]} - 1 ))"
seq="`seq 0 $count`"

for S in $seq; do
totS=$(( $totS + ${dirS[$S]} ))
done

}

function padnum {
# GNU sort doesn't work as I desire without this...

olen=$1
itxt="$2"

if [ $olen -le ${#itxt} ];then exit 1; fi

for s in `seq 1 $(( $olen - ${#itxt} ))`; do stxt="$stxt""0"; done

echo "$stxt$itxt"

}

function pad {
# I guess that this is here to help aesthetics in the output...

lr=$1
olen=$2
itxt="$3"
stxt=""
otxt=""

if [ $olen -le ${#itxt} ];then
exit 1
fi

for s in `seq 1 $(( $olen - ${#itxt} ))`; do stxt="$stxt "; done

case $lr in
    -l) otxt="$itxt$stxt";;
    -L) otxt="$itxt$stxt";;
    -r) otxt="$stxt$itxt";;
    -R) otxt="$stxt$itxt";;
    *)exit 2;;
esac

if [ `set | grep "^padded="` ];then
padded=$otxt
else
echo "$otxt"
fi

}

function a_sort {
#I had to pad the front of the numbers so that sort would work correctly...

for n in $seq; do
   dirS[$n]="`padnum 15 ${dirS[$n]}`"" $n"
done

dirS=( `echo "${dirS[*]}" | sort -r | sed -e s/^00*//g` )
order=( `echo "${dirS[*]}" | cut -d" " -f2` )
dirS=( `echo "${dirS[*]}" | cut -d" " -f1` )

for n in $seq; do
   oldn=${order[$n]}
   data=${dirN[$oldn]}
   tmp[$n]="$data"
done

for n in $seq; do
   dirN[$n]="${tmp[$n]}"
done
tmp=

}

function vdel {
# this function will remove an entry in both main arrays
# and collapse the array so that there is no empty spot

val=$1
dirN[$val]=""
dirS[$val]=""
now=$val
next=$(( $val + 1 ))
until [ "${dirN[$next]}" == "" ];do
dirN[$now]="${dirN[$next]}"
unset dirN[$next]
now=$(( $now + 1 ))
next=$(( $next + 1 ))
done
now=$val
next=$(( $val + 1 ))
until [ "${dirS[$next]}" == "" ];do
dirS[$now]="${dirS[$next]}"
unset dirS[$next]
now=$(( $now + 1 ))
next=$(( $next + 1 ))
done

count="$(( ${#dirS[@]} - 1 ))"
seq="`seq 0 $count`"

}


# DO NOT TOUCH, UNLESS YOU *KNOW*!!!
IFS=$'\n'
DVD5=4700000000
DVD9=8540000000
DVD10=$(( $DVD5 * 2 ))
DVD18=$(( $DVD9 * 2 ))
B_RAY=
CD650=
CD700=
F144M=
F720K=
target=$[target]

# MAIN ##################################


populate
a_sort

# everything below is just a test of what is present so far...

echo ""
for n in $seq; do
   echo "`pad -l 35 ${dirN[$n]}` == `pad -r 12 ${dirS[$n]}` byte(s)"
done
echo ${#dirN[@]}
echo ""

vdel 1
vdel 5

echo "after 2 del'd:"
for n in $seq; do
   echo "`pad -l 35 ${dirN[$n]}` == `pad -r 12 ${dirS[$n]}` byte(s)"
done
echo ${#dirN[@]}
echo ""


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP