From 40c6f4508ec0868d331e346e9d7b1c44cce01966 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 23 Sep 2007 14:46:27 +0200 Subject: [PATCH] Adding casper 1.77+debian-3. --- bin/casper-snapshot | 10 +++++----- debian/changelog | 8 ++++++++ scripts/casper | 45 +++++++++++++++++++-------------------------- scripts/casper-helpers | 37 +++++++++++++++++++++++++++++-------- 4 files changed, 61 insertions(+), 39 deletions(-) diff --git a/bin/casper-snapshot b/bin/casper-snapshot index d2cb9e8..4c9dcd6 100644 --- a/bin/casper-snapshot +++ b/bin/casper-snapshot @@ -92,7 +92,7 @@ Help () echo echo "Options:" echo " -c, --cow: specifies the copy on write directory (default: /cow)." - echo " -d, --destination: specifies the output snapshot directory (default: /home/\$USERNAME/Desktop/casper-snapshot)." + echo " -d, --device: specifies the output snapshot device (default: none)." echo " -o, --output: specifies the output image file (default: $type dependent)." echo " -r, --resync-string: internally used to resync previous made snapshots." echo " -t,--type: specifies the snapshot type between \'squashfs\', \'ext2\' or \'cpio\'.gz archive (default: cpio)" @@ -166,7 +166,7 @@ Parse_args () { # Parse command line ARGS="${1}" - ARGUMENTS="`getopt --longoptions cow:,destination:,output:,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:,h,u,v --shell sh -- ${ARGS}`" + ARGUMENTS="`getopt --longoptions cow:,device:,output,resync-string:,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:r:,h,u,v --shell sh -- ${ARGS}`" if [ "${?}" != "0" ]; then echo "Terminating." >&2 @@ -230,13 +230,13 @@ Defaults () DEST=$(echo "${SNAP_RSTRING}" | cut -f3 -d ':') case "${DEST}" in - *.cpio.gz|*.cpz|*.gz) + *.cpio.gz) TYPE="cpio" ;; - *.squashfs|*.squ}) + *.squashfs) TYPE="squashfs" ;; "") TYPE="ext2" ;; - *.ext2|*.ext) + *.ext2) TYPE="ext2" ;; *) Usage "Unregognized String" ;; diff --git a/debian/changelog b/debian/changelog index c2ca6ca..b634c5a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +casper (1.77+debian-3) unstable; urgency=medium + + * Fixed "todisk=" parsing. + * Urgency is set to medium to try reaching Etch with important + features/bugfixes. + + -- Marco Amadori Wed, 1 Nov 2006 11:15:56 +0100 + casper (1.77+debian-2) unstable; urgency=medium [ Marco Amadori ] diff --git a/scripts/casper b/scripts/casper index 558a29b..32c4517 100644 --- a/scripts/casper +++ b/scripts/casper @@ -44,7 +44,7 @@ parse_cmdline () export NETBOOT=${x#netboot=} ;; toram) export TORAM=1 ;; - todisk=) + todisk=*) export TODISK=${x#todisk=} ;; showmounts) export SHOWMOUNTS=1 ;; @@ -141,17 +141,6 @@ mount_images_in_directory() { fi } -get_fstype() { - local FSTYPE - local FSSIZE - eval $(fstype < $1) - if [ "$FSTYPE" != "unknown" ]; then - echo $FSTYPE - return 0 - fi - /lib/udev/vol_id -t $1 2>/dev/null -} - is_nice_device() { sysfs_path="${1#/sys}" if /lib/udev/path_id "${sysfs_path}" | grep -E -q "ID_PATH=(usb|pci-[^-]*-[ide|scsi|usb])"; then @@ -177,7 +166,7 @@ copy_live_to() { copytodev="${2}" copyto="${copyfrom}_swap" - size=$(used_fs_size "null" "${copyfrom}") + size=$(fs_size "" ${copyfrom} "used") if [ "${copytodev}" = "ram" ]; then # copying to ram: @@ -189,29 +178,28 @@ copy_live_to() { else # it should be a writable block device if [ -b "${copytodev}" ]; then - free_string="space" - freespace="$(df -k ${copytodev} | grep -s ${copytodev} | awk '{print $4}')" - fstype="$(get_fstype ${devname})" dev="${copytodev}" + free_string="space" + fstype=$(get_fstype "${dev}") + freespace=$(fs_size "${dev}") else + [ "$quiet" != "y" ] && log_warning_msg "${copytodev} is not a block device." return 1 fi fi - if [ ! ${freespace} -lt ${size} ] ; then - [ "$quiet" != "y" ] && log_begin_msg "Not enough free ${free_string} to copy live media in ${copytodev}." - [ "$quiet" != "y" ] && log_end_msg + if [ "${freespace}" -lt "${size}" ] ; then + [ "$quiet" != "y" ] && log_warning_msg "Not enough free ${free_string} (${freespace}k > ${size}k) to copy live media in ${copytodev}." return 1 fi # begin copying.. - [ "$quiet" != "y" ] && log_begin_msg "Copying live media to ${copytodev}..." mkdir "${copyto}" + echo "mount -t ${fstype} ${mount_options} ${dev} ${copyto}" mount -t "${fstype}" ${mount_options} "${dev}" "${copyto}" cp -a ${copyfrom}/* ${copyto} # "cp -a" from busybox also copies hidden files umount ${copyfrom} mount -r -o move ${copyto} ${copyfrom} rmdir ${copyto} - [ "$quiet" != "y" ] && log_end_msg return 0 } @@ -281,7 +269,7 @@ do_snap_copy () todir="${2}" snap_type="${3}" - #size=$(used_fs_size "${fromdev}") + size=$(fs_size "${fromdev}" "" "used") if [ -b "${fromdev}" ]; then # look for free mem @@ -578,10 +566,15 @@ mountroot() { panic "Unable to find a medium containing a live file system" fi - if [ ! -z "${TORAM}" ]; then - copy_live_to "${livefs_root}" "ram" - elif [ ! -z "${TODISK}" ]; then - copy_live_to "${livefs_root}" "${TODISK}" + if [ -n "${TORAM}" ]; then + live_dest="ram" + elif [ -n "${TODISK}" ]; then + live_dest="${TODISK}" + fi + if [ -n "${live_dest}" ]; then + [ "$quiet" != "y" ] && log_begin_msg "Copying live_media to ${live_dest}" + copy_live_to "${livefs_root}" "${live_dest}" + [ "$quiet" != "y" ] && log_end_msg fi mount_images_in_directory "${livefs_root}" "${rootmnt}" diff --git a/scripts/casper-helpers b/scripts/casper-helpers index 61d8019..cfbc3c6 100644 --- a/scripts/casper-helpers +++ b/scripts/casper-helpers @@ -6,6 +6,11 @@ else MP_QUIET="-q" fi +if [ ! -x "/bin/fstype" ]; then + # klibc not in path -> not in initramfs + export PATH="${PATH}:/usr/lib/klibc/bin" +fi + sys2dev() { sysdev=${1#/sys} echo "/dev/$(udevinfo -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})" @@ -22,6 +27,17 @@ subdevices() { echo ${r} } +get_fstype() { + local FSTYPE + local FSSIZE + eval $(fstype < $1) + if [ "$FSTYPE" != "unknown" ]; then + echo $FSTYPE + return 0 + fi + /lib/udev/vol_id -t $1 2>/dev/null +} + where_is_mounted() { device=$1 if grep -q "^$device " /proc/mounts; then @@ -56,33 +72,38 @@ base_path () done } -used_fs_size () +fs_size () { - # Returns used fs kbytes + 5% more + # Returns used/free fs kbytes + 5% more # You could pass a block device as $1 or the mount point as $2 dev="${1}" mountp="${2}" + used="${3}" if [ -z "${mountp}" ]; then mountp=$(where_is_mounted "${dev}") if [ "$?" -gt 0 ]; then - mountp=/mnt/tmp_fs_size + mountp="/mnt/tmp_fs_size" mkdir -p "${mountp}" mount -t $(get_fstype "${dev}") -o ro "${dev}" "${mountp}" doumount=1 fi fi - size=$(du -ks ${mountp} | cut -f1) - size=$(expr ${size} + ${size}/20 ) # FIXME: 5% more to be sure - needed_space=$(expr ${size} * 1024) + if [ "${used}" = "used" ]; then + size=$(du -ks ${mountp} | cut -f1) + size=$(expr ${size} + ${size} / 20 ) # FIXME: 5% more to be sure + else + # free space + size="$(df -k | grep -s ${mountp} | awk '{print $4}')" + fi - if [ ! -z "${doumount}" ]; then + if [ -n "${doumount}" ]; then umount "${mountp}" rmdir "${mountp}" fi - echo "${needed_space}" + echo "${size}" } setup_loop() { -- 2.1.4