Adding casper 1.81+debian-1.
[live-boot-grml.git] / bin / casper-snapshot
old mode 100644 (file)
new mode 100755 (executable)
index d2cb9e8..e912493
@@ -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 ()
 {
@@ -92,10 +91,10 @@ 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)"
+       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}"
-       ARGUMENTS="`getopt --longoptions cow:,destination:,output:,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:,h,u,v --shell sh -- ${ARGS}`"
+       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,19 +223,26 @@ 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 ':')
                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" ;;
@@ -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 "$@"