mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-05 04:06:33 +02:00
build_image: clean up emit_gpt_scripts a bit
Looks like the func was copy & pasted, so delete the first one (which doesn't get used). Then expand on the existing func to also generate a mount and an umount script. BUG=None TEST=ran build_image, then tested the mount/umount and unpack/pack scripts Change-Id: I34a372c7b4858b8e9057a29b2eb58c38d547eadd Reviewed-on: https://gerrit.chromium.org/gerrit/33929 Reviewed-by: Liam McLoughlin <lmcloughlin@chromium.org> Tested-by: Liam McLoughlin <lmcloughlin@chromium.org> Commit-Ready: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
0915c1e100
commit
b344800aa6
@ -16,45 +16,6 @@ get_disk_layout_path() {
|
||||
done
|
||||
}
|
||||
|
||||
emit_gpt_scripts() {
|
||||
local image="$1"
|
||||
local dir="$2"
|
||||
|
||||
local pack="${dir}/pack_partitions.sh"
|
||||
local unpack="${dir}/unpack_partitions.sh"
|
||||
|
||||
cat >"$unpack" <<HEADER
|
||||
#!/bin/bash -eu
|
||||
HEADER
|
||||
|
||||
echo "# File automatically generated by $(basename $0)." >> "$unpack"
|
||||
|
||||
cat >>"${unpack}" <<HEADER
|
||||
# Do not edit.
|
||||
TARGET=\${1:-}
|
||||
if [[ -z "\$TARGET" ]]; then
|
||||
echo "Usage: \$0 DEVICE" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
set -x
|
||||
HEADER
|
||||
|
||||
$GPT show "${image}" | sed -e 's/^/# /' >>"${unpack}"
|
||||
cp "${unpack}" "${pack}"
|
||||
|
||||
$GPT show -q "${image}" |
|
||||
while read start size part x; do
|
||||
local file="part_${part}"
|
||||
local target="\"\${TARGET}\""
|
||||
local dd_args="bs=512 count=${size}"
|
||||
echo "dd if=${target} of=${file} ${dd_args} skip=${start}" >>"${unpack}"
|
||||
echo "dd if=${file} of=${target} ${dd_args} seek=${start} conv=notrunc" \
|
||||
>>"${pack}"
|
||||
done
|
||||
|
||||
chmod +x "${unpack}" "${pack}"
|
||||
}
|
||||
|
||||
write_partition_script() {
|
||||
local image_type=$1
|
||||
local partition_script_path=$2
|
||||
@ -139,32 +100,54 @@ emit_gpt_scripts() {
|
||||
|
||||
local pack="${dir}/pack_partitions.sh"
|
||||
local unpack="${dir}/unpack_partitions.sh"
|
||||
local mount="${dir}/mount_image.sh"
|
||||
local umount="${dir}/umount_image.sh"
|
||||
|
||||
cat >"${unpack}" <<HEADER
|
||||
local start size part x
|
||||
|
||||
cat >"${unpack}" <<EOF
|
||||
#!/bin/bash -eu
|
||||
# File automatically generated. Do not edit.
|
||||
TARGET=\${1:-}
|
||||
if [[ -z "\$TARGET" ]]; then
|
||||
echo "Usage: \$0 DEVICE" 1>&2
|
||||
if [[ -z \${TARGET} ]]; then
|
||||
echo "Usage: \$0 <image>" 1>&2
|
||||
echo "Example: \$0 chromiumos_image.bin" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
set -x
|
||||
HEADER
|
||||
$(${GPT} show "${image}" | sed -e 's/^/# /')
|
||||
EOF
|
||||
|
||||
$GPT show "${image}" | sed -e 's/^/# /' >>"${unpack}"
|
||||
cp "${unpack}" "${pack}"
|
||||
for x in "${pack}" "${mount}" "${umount}"; do
|
||||
cp "${unpack}" "${x}"
|
||||
done
|
||||
|
||||
$GPT show -q "${image}" |
|
||||
while read start size part x; do
|
||||
local file="part_${part}"
|
||||
local target="\"\$TARGET\""
|
||||
local dd_args="bs=512 count=${size}"
|
||||
echo "dd if=${target} of=${file} ${dd_args} skip=${start}" >>"${unpack}"
|
||||
echo "dd if=${file} of=${target} ${dd_args} seek=${start} conv=notrunc" \
|
||||
>>"${pack}"
|
||||
done
|
||||
while read start size part x; do
|
||||
local file="part_${part}"
|
||||
local dir="dir_${part}"
|
||||
local target='"${TARGET}"'
|
||||
local dd_args="bs=512 count=${size}"
|
||||
local start_b=$(( start * 512 ))
|
||||
local size_b=$(( size * 512 ))
|
||||
echo "dd if=${target} of=${file} ${dd_args} skip=${start}" >>"${unpack}"
|
||||
echo "dd if=${file} of=${target} ${dd_args} seek=${start} conv=notrunc" \
|
||||
>>"${pack}"
|
||||
if [[ ${size} -gt 1 ]]; then
|
||||
cat <<-EOF >>"${mount}"
|
||||
mkdir -p ${dir}
|
||||
sudo mount -o loop,offset=${start_b},sizelimit=${size_b} ${target} ${dir} || \
|
||||
rmdir ${dir}
|
||||
EOF
|
||||
cat <<-EOF >>"${umount}"
|
||||
if [[ -d ${dir} ]]; then
|
||||
sudo umount ${dir} || :
|
||||
rmdir ${dir}
|
||||
fi
|
||||
EOF
|
||||
fi
|
||||
done < <(${GPT} show -q "${image}")
|
||||
|
||||
chmod +x "${unpack}" "${pack}"
|
||||
chmod +x "${unpack}" "${pack}" "${mount}" "${umount}"
|
||||
}
|
||||
|
||||
build_gpt() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user