-#!/bin/bash
+#! /bin/bash
# casper-snapshot - utility to manage Debian Live systems snapshots
#
# 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
# 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 ()
{
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
}
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
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
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)
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
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 ':')
#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 ()
Main ()
{
- Parse_args "${@}"
+ Parse_args "$@"
Defaults
Do_snapshot
Clean
}
-Main "${@}"
+Main "$@"