diff options
| author | David M. Syzdek <david@syzdek.net> | 2018-01-27 13:38:57 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2018-01-27 13:38:57 -0900 |
| commit | 64e570019a7699738c24dd51dfcff98d0787bbd4 (patch) | |
| tree | c7cfe18d7c5cc33892727cbf3cc8188e3e461473 /src/scripts | |
| parent | ba425402f3f6f7c338c4754a77d2cbac1061d990 (diff) | |
| download | iperd-64e570019a7699738c24dd51dfcff98d0787bbd4.tar.gz iperd-64e570019a7699738c24dd51dfcff98d0787bbd4.tar.bz2 iperd-64e570019a7699738c24dd51dfcff98d0787bbd4.tar.xz iperd-64e570019a7699738c24dd51dfcff98d0787bbd4.zip | |
Adding support for multiple partition types
Diffstat (limited to 'src/scripts')
| -rw-r--r-- | src/scripts/diskimage.sh | 112 |
1 files changed, 98 insertions, 14 deletions
diff --git a/src/scripts/diskimage.sh b/src/scripts/diskimage.sh index 47cc72c..907811e 100644 --- a/src/scripts/diskimage.sh +++ b/src/scripts/diskimage.sh | |||
| @@ -33,15 +33,107 @@ | |||
| 33 | # @SYZDEK_BSD_LICENSE_END@ | 33 | # @SYZDEK_BSD_LICENSE_END@ |
| 34 | # | 34 | # |
| 35 | 35 | ||
| 36 | # +-=-=-=-=-=-+ | ||
| 37 | # | | | ||
| 38 | # | Headers | | ||
| 39 | # | | | ||
| 40 | # +-=-=-=-=-=-+ | ||
| 41 | |||
| 36 | PROG_NAME="$(basename "${0}")" | 42 | PROG_NAME="$(basename "${0}")" |
| 37 | if test "x${2}" == "x";then | 43 | |
| 38 | echo "Usage: ${PROG_NAME} <source> <file>" | 44 | |
| 45 | # +-=-=-=-=-=-=-+ | ||
| 46 | # | | | ||
| 47 | # | Functions | | ||
| 48 | # | | | ||
| 49 | # +-=-=-=-=-=-=-+ | ||
| 50 | |||
| 51 | cleanup() | ||
| 52 | { | ||
| 53 | test -z "${LOOPDEV}" || sudo losetup -d "${LOOPDEV}" | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | catchsig() | ||
| 58 | { | ||
| 59 | rm -f "${OUTPUT}" | ||
| 39 | exit 1 | 60 | exit 1 |
| 40 | fi | 61 | } |
| 62 | |||
| 63 | |||
| 64 | usage() | ||
| 65 | { | ||
| 66 | printf "Usage: %s [OPTIONS] <source> <file>\n" "$PROG_NAME" | ||
| 67 | printf "OPTIONS:\n" | ||
| 68 | printf " -h display this message\n" | ||
| 69 | printf " -q quiet\n" | ||
| 70 | printf " -s size size of image in megabytes (default: 1900)" | ||
| 71 | printf " -t type partition type (mbr, hybrid [default], or gpt)\n" | ||
| 72 | printf " -v verbose\n" | ||
| 73 | printf "\n" | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | # +-=-=-=-=-=-=-+ | ||
| 78 | # | | | ||
| 79 | # | Main Body | | ||
| 80 | # | | | ||
| 81 | # +-=-=-=-=-=-=-+ | ||
| 82 | |||
| 83 | # set defaults | ||
| 84 | unset VERBOSE | ||
| 85 | PARTSIZE="1900" | ||
| 86 | PARTTYPE="hybrid" | ||
| 87 | |||
| 88 | |||
| 89 | # parse CLI arguments | ||
| 90 | while getopts :hqs:t:v OPT; do | ||
| 91 | case ${OPT} in | ||
| 92 | h) usage; exit 0;; | ||
| 93 | s) PARTSIZE="${OPTARG}";; | ||
| 94 | t) PARTTYPE="${OPTARG}";; | ||
| 95 | v) VERBOSE="1";; | ||
| 96 | q) unset VERBOSE;; | ||
| 97 | ?) | ||
| 98 | echo "${PROG_NAME}: illegal option -- ${OPTARG}" 1>&2 | ||
| 99 | echo "Try '${PROG_NAME} -h' for more information." 1>&2 | ||
| 100 | exit 1; | ||
| 101 | ;; | ||
| 102 | *) | ||
| 103 | ;; | ||
| 104 | esac | ||
| 105 | done | ||
| 106 | shift "$((OPTIND-1))" | ||
| 41 | SOURCE="${1}" | 107 | SOURCE="${1}" |
| 42 | OUTPUT="${2}" | 108 | OUTPUT="${2}" |
| 43 | 109 | ||
| 44 | 110 | ||
| 111 | # check configuration options | ||
| 112 | if test -z "${SOURCE}";then | ||
| 113 | echo "${PROG_NAME}: missing source" | ||
| 114 | echo "Try '${PROG_NAME} -h' for more information." 1>&2 | ||
| 115 | exit 1 | ||
| 116 | fi | ||
| 117 | if test -z "${OUTPUT}";then | ||
| 118 | echo "${PROG_NAME}: missing file" | ||
| 119 | echo "Try '${PROG_NAME} -h' for more information." 1>&2 | ||
| 120 | exit 1 | ||
| 121 | fi | ||
| 122 | if test "x${PARTTYPE}" != "xhybrid" && | ||
| 123 | test "x${PARTTYPE}" != "xmbr" && | ||
| 124 | "x${PARTTYPE}" != "xgpt";then | ||
| 125 | echo "${PROG_NAME}: invalid partition type" | ||
| 126 | echo "Try '${PROG_NAME} -h' for more information." 1>&2 | ||
| 127 | exit 1; | ||
| 128 | fi | ||
| 129 | if test ! -z "${PARTSIZE//[0-9]/}";then | ||
| 130 | echo "${PROG_NAME}: invalid partition size" | ||
| 131 | echo "Try '${PROG_NAME} -h' for more information." 1>&2 | ||
| 132 | exit 1; | ||
| 133 | fi | ||
| 134 | |||
| 135 | |||
| 136 | # check for required files/directories/devices | ||
| 45 | if test ! -f "${SOURCE}/src/scripts/thumbdrive.sh";then | 137 | if test ! -f "${SOURCE}/src/scripts/thumbdrive.sh";then |
| 46 | echo "${PROG_NAME}: thumbdrive.sh: file not found" | 138 | echo "${PROG_NAME}: thumbdrive.sh: file not found" |
| 47 | exit 1 | 139 | exit 1 |
| @@ -52,15 +144,7 @@ if test -f "${OUTPUT}";then | |||
| 52 | fi | 144 | fi |
| 53 | 145 | ||
| 54 | 146 | ||
| 55 | cleanup() | 147 | # set up exit traps |
| 56 | { | ||
| 57 | test -z "${LOOPDEV}" || sudo losetup -d "${LOOPDEV}" | ||
| 58 | } | ||
| 59 | catchsig() | ||
| 60 | { | ||
| 61 | rm -f "${OUTPUT}" | ||
| 62 | exit 1 | ||
| 63 | } | ||
| 64 | trap catchsig SIGHUP SIGINT SIGTERM | 148 | trap catchsig SIGHUP SIGINT SIGTERM |
| 65 | trap cleanup EXIT | 149 | trap cleanup EXIT |
| 66 | 150 | ||
| @@ -71,7 +155,7 @@ dd \ | |||
| 71 | of="${OUTPUT}" \ | 155 | of="${OUTPUT}" \ |
| 72 | count=0 \ | 156 | count=0 \ |
| 73 | bs=512 \ | 157 | bs=512 \ |
| 74 | seek=$((2048*1900)) \ | 158 | seek=$((2048*${PARTSIZE})) \ |
| 75 | || { rm -f "${OUTPUT}"; exit 1; } | 159 | || { rm -f "${OUTPUT}"; exit 1; } |
| 76 | 160 | ||
| 77 | 161 | ||
| @@ -83,7 +167,7 @@ if test -z "${LOOPDEV}";then | |||
| 83 | fi | 167 | fi |
| 84 | 168 | ||
| 85 | 169 | ||
| 86 | sudo bash "${SOURCE}/src/scripts/thumbdrive.sh" "${SOURCE}" "${LOOPDEV}" \ | 170 | sudo bash "${SOURCE}/src/scripts/thumbdrive.sh" -t ${PARTTYPE} "${SOURCE}" "${LOOPDEV}" \ |
| 87 | || { rm -f "${OUTPUT}"; exit 1; } | 171 | || { rm -f "${OUTPUT}"; exit 1; } |
| 88 | 172 | ||
| 89 | 173 | ||
