X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=bin%2Fcasper-snapshot;h=e9124931e8309edc218f7e61cdb11f942c7813df;hb=c972c6eea545add125883eaaeea459551e54589c;hp=4c9dcd682782e754355e0746d189b8022aaf5e42;hpb=40c6f4508ec0868d331e346e9d7b1c44cce01966;p=live-boot-grml.git diff --git a/bin/casper-snapshot b/bin/casper-snapshot old mode 100644 new mode 100755 index 4c9dcd6..e912493 --- a/bin/casper-snapshot +++ b/bin/casper-snapshot @@ -1,4 +1,4 @@ -#!/bin/bash +#! /bin/bash # casper-snapshot - utility to manage Debian Live systems snapshots # @@ -25,7 +25,7 @@ # On Debian systems, the complete text of the GNU General Public License # can be found in /usr/share/common-licenses/GPL file. -PROGRAM="`basename ${0}`" +PROGRAM="`basename $0`" VERSION=0.0.1 @@ -53,13 +53,12 @@ fi # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions -# Some defaults: -MOUNTP="/mnt/casper-snapshot" -COW="/cow" +MOUNTP="" +COW="" DEV="" -DEST="${MOUNTP}/casper-sn.cpio.gz" -TYPE="cpio" -DESKTOP_LINK=/home/$USERNAME/Desktop/casper-snapshot +DEST="" +TYPE="" +DESKTOP_LINK="" Header () { @@ -95,7 +94,7 @@ Help () 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)" + echo " -t, --type: specifies the snapshot type between \"squashfs\", \"ext2\" or \"cpio\".gz archive (default: cpio)" echo -e "\nLook at casper-snapshot(1) man page for more information." exit 0 } @@ -153,8 +152,8 @@ Do_snapshot () Is_same_mount () { - dir1="`Base_path ${1}`" - dir2="`Base_path ${2}`" + dir1="`Base_path $1`" + dir2="`Base_path $2`" if [ "${dir1}" == "${dir2}" ]; then return 0 else @@ -165,10 +164,10 @@ Is_same_mount () Parse_args () { # Parse command line - ARGS="${1}" + ARGS="$1" 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 + if [ "$?" != "0" ]; then echo "Terminating." >&2 exit 1 fi @@ -176,17 +175,17 @@ Parse_args () eval set -- "${ARGUMENTS}" while true; do - case "${1}" in + case "$1" in -c|--cow) - SNAP_COW="${2}"; shift 2 ;; + SNAP_COW="$2"; shift 2 ;; -d|--device) - SNAP_DEV="${2}"; shift 2 ;; + SNAP_DEV="$2"; shift 2 ;; -o|--output) - SNAP_OUTPUT="${2}"; shift 2 ;; + SNAP_OUTPUT="$2"; shift 2 ;; -t|--type) - SNAP_TYPE="${2}"; shift 2 ;; + SNAP_TYPE="$2"; shift 2 ;; -r|--resync-string) - SNAP_RSTRING="${2}"; break ;; + SNAP_RSTRING="$2"; break ;; -h|--help) Help; shift ;; -u|--usage) @@ -203,13 +202,13 @@ Parse_args () Mount_device () { - dev="${1}" + dev="$1" if [ ! -d "${MOUNTP}" ]; then mkdir -p "${MOUNTP}" fi - if [ -n "${dev}" ]; then + if [ -z "${dev}" ]; then # create a temp mount -t tmpfs -o rw tmpfs "${MOUNTP}" if [ ! -L /home/$USERNAME/Desktop/casper-snapshot ]; then @@ -224,6 +223,13 @@ Mount_device () Defaults () { + MOUNTP="/mnt/casper-snapshot" + COW="/cow" + DEV="" + DEST="${MOUNTP}/casper-sn.cpio.gz" + TYPE="cpio" + DESKTOP_LINK=/home/$USERNAME/Desktop/casper-snapshot + if [ -n "${SNAP_RSTRING}" ]; then COW=$(echo "${SNAP_RSTRING}" | cut -f1 -d ':') DEV=$(echo "${SNAP_RSTRING}" | cut -f2 -d ':') @@ -264,13 +270,13 @@ Defaults () #if Is_same_mount fi - Mount_device $DEV - DEST="${MOUNTP}/${DEST}" - # check vars if [ ! -d "${COW}" ]; then Usage "Error: ${COW} is not a directory" fi + + Mount_device $DEV + } Clean () @@ -284,10 +290,10 @@ Clean () Main () { - Parse_args "${@}" + Parse_args "$@" Defaults Do_snapshot Clean } -Main "${@}" +Main "$@"