Archief

Archief voor juli 2006

Mees heeft zijn B diploma!

15 juli 2006 Reacties uit

Vandaag, zaterdag 15 juli 2006 heeft Mees afgezwommen voor zijn B-Diploma.



Bekijk alle filmpjes …

Bekijk de foto’s …  
























Categorie├źn:Diverse artikelen Tags:

CD/DVD layout maker

5 juli 2006 Reacties uit

Sometimes you have to write lots of CD’s/DVD’s of even more files. This scripts loops through files in a target directory and creates new “virtual disks” and places symbolic links in it to the found file. If a “virtual disk” is full it will create another one. You can define your own pattern for the disknames.

#!/bin/bash

# sizes in Megabytes
CDSIZE=750
DVDSIZE=4380

if [ "$(basename $0)" == "make-dvd" ]; then
let "DISKSIZE=$DVDSIZE*1024*1024"
else
let "DISKSIZE=$CDSIZE*1024*1024"
fi

VERBOSE=1
usage ()
{
echo "usage: $0 [OPTIONS] source target, where options can be:"
echo "  -s START      number of 1st disk"
echo "  -v            print usefull messages"
echo "  -V            print usefull and less usefull messages"
echo "  -d BYTES      disksize of the writable media (default $DISKSIZE)"
echo "  -r            puts all symlinks in corresponding directory"
echo "                without this option all symbolic links are placed directly under disk"
echo "  -p            pattern to use for diskname (default DISK_%03d), see man printf"
echo "                example pattern: \"MY_CD_%03d\" for MY_CD_001, MY_CD_002, etc ..."
if [ "$1" != "" ]; then
echo "ERROR: $1"
exit 9
fi
exit 8
}

myprint ()
{
if [ "$VERBOSE" == "$1" ]; then
echo $2;
fi
}

integertest ()
{
stringTest=$(echo $1 | sed 's/[0-9]+//g');
if [ ${#stringTest} -gt 0 ]; then
usage "argument for $2 must be an integer"
fi

}

if [ $# -lt 2 ]; then usage; fi

START=1
VERBOSE=0
INTREE=0
PATTERN="DISK_%03d"

while getopts ":s:t:p:rvVd:" Option; do
OPTARG=$(echo $OPTARG | sed 's/^W+//')
case $Option in
s ) START=$OPTARG;;
v ) VERBOSE=1;;
V ) VERBOSE=2;;
r ) INTREE=1;;
d ) DISKSIZE=$OPTARG;;
p ) PATTERN=$OPTARG;;
* ) usage "unkown option";;
esac
done
shift $(($OPTIND - 1))

SOURCE=$(cd "$1" && pwd)
TARGET=$(cd "$2" && pwd)
integertest $START "-s"
integertest $DISKSIZE "-d"

DISKNAME=$(printf $PATTERN $START)
if [ $? -gt 0 ]; then usage "wrong argument for pattern"; fi

if [ ! -d "$SOURCE" ]; then usage "source \"$SOURCE\" is not a directory"; fi
if [ ! -d "$TARGET" ]; then usage "target \"$TARGET\" is not a directory"; fi
if [ ! -w "$TARGET" ]; then usage "target directory \"$TARGET\" is not writable"; fi

OLDIFS=$IFS
IFS=:
CURRENTSIZE=0

FIRSTRUN=1
echo -n "fetching filelist from $SOURCE ... "
for file in $(find -L $SOURCE -type f -printf "%P$IFS"); do
if [ "$FIRSTRUN" == "1" ]; then
echo "done"
myprint 1 "making 1st disk $DISKNAME"
if [ -d "$TARGET/$DISKNAME" ]; then usage "can not make disk $TARGET/$DISKNAME"; fi
mkdir -p $TARGET/$DISKNAME
FIRSTRUN=0
fi

filesize=$(du -b "$SOURCE/$file" 2> /dev/null | sed 's/W+.*//')
myprint 2 $(printf "%s [%10d - %10d] %s" $DISKNAME $CURRENTSIZE $filesize $file 2>/dev/null)
if [ "$filesize" == "" ]; then echo "can not get filesize of file $SOURCE/$file, skipping it"; continue; fi
let "newsize=$CURRENTSIZE+$filesize"
if [ $newsize -gt $DISKSIZE ]; then
let "START=START+1"
DISKNAME=$(printf $PATTERN $START)
myprint 1 "disk full, making new one: $DISKNAME"
CURRENTSIZE=$filesize
if [ -d "$TARGET/$DISKNAME" ]; then usage "can not make disk $TARGET/$DISKNAME"; fi
mkdir -p $TARGET/$DISKNAME
else
let "CURRENTSIZE=$CURRENTSIZE+$filesize"
fi
DIRNAME=$(dirname "$file")
FILENAME=$(basename "$file")
if [ "$INTREE" == "1" ]; then
if [ ! -d "$TARGET/$DISKNAME/$DIRNAME" ]; then mkdir -p "$TARGET/$DISKNAME/$DIRNAME"; fi
LINKTARGET="$TARGET/$DISKNAME/$DIRNAME/$FILENAME"
else
LINKTARGET="$TARGET/$DISKNAME/$FILENAME"
fi
ln -s "$SOURCE/$file" "$LINKTARGET"
if [ $? -gt 0 ]; then
let "CURRENTSIZE=$CURRENTSIZE-$filesize"
fi
done
IFS=$OLDIFS
Categorie├źn:Linux Tips & Trics Tags: