s243a

mk_save_file.sh

Nov 14th, 2020
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.81 KB | None | 0 0
  1. #!/bin/bash
  2. declare -a options="$(getopt -o f:,s:,t: --long input-file:size:,type: -- "$@")"
  3. eval set --"$options"
  4. while [ $# -gt 0 ]; do
  5.   case "$1" in
  6.   -f|--input-file)
  7.      rwbranch=$2;
  8.      shift 2; ;;
  9.    -s|--size)
  10.      size=$2;
  11.      shift 2; ;;  
  12.    -t|--type) #Not Yet implemented
  13.      size=$2;
  14.      shift 2; ;;
  15.    *)
  16.      shift; ;; #This should never happen
  17.   esac
  18. done
  19. TMPFILE=$(mktemp -p /tmp)
  20. if [ -z "$rwbranch" ]; then
  21.   echo "create"
  22.   dialog --backtitle "rw image sandbox" --title "Specify name and path of new the file" --fselect `pwd` 8 60 2> $TMPFILE
  23.   rwbranch=`cat $TMPFILE`
  24.   rm $TMPFILE
  25. fi
  26. if [ -z "$size" ]; then
  27.  
  28.   dialog --title "Create new rw image" --inputbox "Specify size (in megabytes)" 0 40 100 2> $TMPFILE
  29.   size=`cat $TMPFILE`
  30.   rm $TMPFILE
  31. fi
  32. if [ -n "$rwbranch" ]; then
  33.     if [ -f "$rwbranch" ]; then
  34.         echo "$rwbranch already exist - exiting."
  35.         exit
  36.     else
  37.         # get the size
  38.         if [ -n "$size" ]; then
  39.           dialog --title "Create new rw image" --inputbox "Specify size (in megabytes)" 0 40 100 2> $TMPFILE
  40.           size=`cat $TMPFILE`
  41.           rm $TMPFILE
  42.         fi
  43.         if [ -n "$size" ]; then
  44.             if dd if=/dev/zero of="$rwbranch" bs=1 count=0 seek="$size"M; then
  45.                 if ! mke2fs -F "$rwbranch"; then
  46.                     echo "I fail to make an ext2 filesystem at $rwbranch, exiting."
  47.                     exit
  48.                 fi
  49.             else
  50.                 echo "I fail to create a ${size}M file at $rwbranch, exiting."
  51.                 exit
  52.             fi
  53.         else
  54.             echo "You didn't specify the size or your press cancel. Exiting."
  55.             exit
  56.         fi                  
  57.     fi
  58. else
  59.     echo "You didn't specify any file or you pressed cancel. Exiting."
  60.     exit
  61. fi
  62.  
Advertisement
Add Comment
Please, Sign In to add comment