#!/bin/sh set -e while [ $# -ge 1 ]; do key="$1" case $key in --debug) set -x ;; --path) path="$2" shift # past argument ;; --size) size="$2" shift # past argument ;; --encrypt) ENCRYPT=true ;; --condition) CONDITIONS="$CONDITIONS $2" shift ;; *) echo "Unknown option passed to swapmaker: $key" # unknown option exit 1 ;; esac shift # past argument or value done function disksize_to_count { local blocksize=$1 local origsize=$2 local ret case $origsize in *G) ret=$(( ${origsize%%G} * 1024 * 1024 * 1024 )) ;; *M) ret=$(( ${origsize%%M} * 1024 * 1024 )) ;; *K) ret=$(( ${origsize%%K} * 1024 )) ;; *) ret=$origsize ;; esac ret=$(( $ret / $blocksize )) echo $ret } ## make sure path is valid if [ -z "${path}" ]; then echo "swap: --file must be defined" exit 1 fi if [ "${path:0:5}" != "/var/" -o ${#path} -lt 6 ]; then echo "--file option must be under /var" exit 1 fi if [ -z "${size}" ]; then echo "swap: --size must be defined" exit 1 fi ## check each of our conditions for cond in $CONDITIONS; do # split the condition parts IFS=: read condtype arg1 arg2 arg3 arg4 <