Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- declare -a options="$(getopt -o f:,s:,t: --long input-file:size:,type: -- "$@")"
- eval set --"$options"
- while [ $# -gt 0 ]; do
- case "$1" in
- -f|--input-file)
- rwbranch=$2;
- shift 2; ;;
- -s|--size)
- size=$2;
- shift 2; ;;
- -t|--type) #Not Yet implemented
- size=$2;
- shift 2; ;;
- *)
- shift; ;; #This should never happen
- esac
- done
- TMPFILE=$(mktemp -p /tmp)
- if [ -z "$rwbranch" ]; then
- echo "create"
- dialog --backtitle "rw image sandbox" --title "Specify name and path of new the file" --fselect `pwd` 8 60 2> $TMPFILE
- rwbranch=`cat $TMPFILE`
- rm $TMPFILE
- fi
- if [ -z "$size" ]; then
- dialog --title "Create new rw image" --inputbox "Specify size (in megabytes)" 0 40 100 2> $TMPFILE
- size=`cat $TMPFILE`
- rm $TMPFILE
- fi
- if [ -n "$rwbranch" ]; then
- if [ -f "$rwbranch" ]; then
- echo "$rwbranch already exist - exiting."
- exit
- else
- # get the size
- if [ -n "$size" ]; then
- dialog --title "Create new rw image" --inputbox "Specify size (in megabytes)" 0 40 100 2> $TMPFILE
- size=`cat $TMPFILE`
- rm $TMPFILE
- fi
- if [ -n "$size" ]; then
- if dd if=/dev/zero of="$rwbranch" bs=1 count=0 seek="$size"M; then
- if ! mke2fs -F "$rwbranch"; then
- echo "I fail to make an ext2 filesystem at $rwbranch, exiting."
- exit
- fi
- else
- echo "I fail to create a ${size}M file at $rwbranch, exiting."
- exit
- fi
- else
- echo "You didn't specify the size or your press cancel. Exiting."
- exit
- fi
- fi
- else
- echo "You didn't specify any file or you pressed cancel. Exiting."
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment