aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/scripts
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2018-01-27 13:38:57 -0900
committerDavid M. Syzdek <david@syzdek.net>2018-01-27 13:38:57 -0900
commit64e570019a7699738c24dd51dfcff98d0787bbd4 (patch)
treec7cfe18d7c5cc33892727cbf3cc8188e3e461473 /src/scripts
parentba425402f3f6f7c338c4754a77d2cbac1061d990 (diff)
downloadiperd-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.sh112
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
36PROG_NAME="$(basename "${0}")" 42PROG_NAME="$(basename "${0}")"
37if test "x${2}" == "x";then 43
38 echo "Usage: ${PROG_NAME} <source> <file>" 44
45# +-=-=-=-=-=-=-+
46# | |
47# | Functions |
48# | |
49# +-=-=-=-=-=-=-+
50
51cleanup()
52{
53 test -z "${LOOPDEV}" || sudo losetup -d "${LOOPDEV}"
54}
55
56
57catchsig()
58{
59 rm -f "${OUTPUT}"
39 exit 1 60 exit 1
40fi 61}
62
63
64usage()
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
84unset VERBOSE
85PARTSIZE="1900"
86PARTTYPE="hybrid"
87
88
89# parse CLI arguments
90while 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
105done
106shift "$((OPTIND-1))"
41SOURCE="${1}" 107SOURCE="${1}"
42OUTPUT="${2}" 108OUTPUT="${2}"
43 109
44 110
111# check configuration options
112if test -z "${SOURCE}";then
113 echo "${PROG_NAME}: missing source"
114 echo "Try '${PROG_NAME} -h' for more information." 1>&2
115 exit 1
116fi
117if test -z "${OUTPUT}";then
118 echo "${PROG_NAME}: missing file"
119 echo "Try '${PROG_NAME} -h' for more information." 1>&2
120 exit 1
121fi
122if 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;
128fi
129if 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;
133fi
134
135
136# check for required files/directories/devices
45if test ! -f "${SOURCE}/src/scripts/thumbdrive.sh";then 137if 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
52fi 144fi
53 145
54 146
55cleanup() 147# set up exit traps
56{
57 test -z "${LOOPDEV}" || sudo losetup -d "${LOOPDEV}"
58}
59catchsig()
60{
61 rm -f "${OUTPUT}"
62 exit 1
63}
64trap catchsig SIGHUP SIGINT SIGTERM 148trap catchsig SIGHUP SIGINT SIGTERM
65trap cleanup EXIT 149trap 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
83fi 167fi
84 168
85 169
86sudo bash "${SOURCE}/src/scripts/thumbdrive.sh" "${SOURCE}" "${LOOPDEV}" \ 170sudo 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