summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debeagle.sh42
1 files changed, 31 insertions, 11 deletions
diff --git a/debeagle.sh b/debeagle.sh
index ecb7588..1a35986 100644
--- a/debeagle.sh
+++ b/debeagle.sh
@@ -52,17 +52,7 @@ main()
;;
esac
- if [ "x${target}" = 'x' ]; then
- target="/dev/$(prompt_block_dev)"
- elif [ -e "/sys/block/${target#/dev/}" ]; then
- printf 'Installing to %s\n' \
- "$(get_block_dev_name "${target#/dev/}")"
- else
- error 1 'Device %s not found\n' "${target}"
- fi
- if grep "^${target}" /proc/mounts; then
- error 1 'Device %s mounted\n' "${target}"
- fi
+ make_parts_and_fs "${target}"
}
print_usage()
@@ -201,4 +191,34 @@ prompt_block_dev()
EOF
}
+make_parts_and_fs()
+{
+ local target="${1}"
+ local part_prefix=''
+
+ if [ "x${target}" = 'x' ]; then
+ target="/dev/$(prompt_block_dev)"
+ elif [ -e "/sys/block/${target#/dev/}" ]; then
+ printf 'Installing to %s\n' \
+ "$(get_block_dev_name "${target#/dev/}")"
+ else
+ error 1 'Device %s not found\n' "${target}"
+ fi
+ if grep "^${target}" /proc/mounts; then
+ error 1 'Device %s mounted\n' "${target}"
+ fi
+
+ dd if=/dev/zero of="${target}" bs=512 count=1
+ sfdisk "${target}" <<-EOF
+ ,102400,0x0E,*
+ ,,0x83,-
+ EOF
+
+ case "${target}" in
+ /dev/mmcblk*) part_prefix='p';;
+ esac
+ mkdosfs -F 16 "${target}${part_prefix}1"
+ mke2fs -t ext2 "${target}${part_prefix}2"
+}
+
main "${@}"