Commit 6154fe2e1c6c4c09aaba3dad7e20ef56d3a19480
Committed by
Phil Elwell
1 parent
d1ad0579
make-boot-image: Fix unmount and set GID
Delete the target file before attempting to replace it, sync before unmount and set the ownership to be that of the sudo user and not just root.
Showing
1 changed file
with
18 additions
and
9 deletions
tools/make-boot-image
| ... | ... | @@ -68,11 +68,13 @@ mountfs() { |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | unmount_image() { |
| 71 | - image="$1" | |
| 72 | - if [ -f "${LOOP}" ]; then | |
| 73 | - umount "${LOOP}" > /dev/null || true | |
| 71 | + if [ -d "${BOOT_MOUNT}" ]; then | |
| 72 | + umount "${BOOT_MOUNT}" > /dev/null || true | |
| 73 | + fi | |
| 74 | + | |
| 75 | + if [ -n "${LOOP}" ]; then | |
| 76 | + losetup -d "${LOOP}" | |
| 74 | 77 | fi |
| 75 | - losetup -d "${LOOP}" | |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | |
| ... | ... | @@ -189,11 +191,13 @@ checkDependencies |
| 189 | 191 | [ -d "${SOURCE_DIR}" ] || usage |
| 190 | 192 | [ -n "${OUTPUT}" ] || usage |
| 191 | 193 | [ "$(id -u)" = "0" ] || die "\"${NAME}\" must be run as root. Try \"sudo ${NAME}\"" |
| 194 | +[ -n "${SUDO_UID}" ] || die "SUDO_UID not defined" | |
| 195 | +[ -n "${SUDO_GID}" ] || die "SUDO_GID not defined" | |
| 192 | 196 | |
| 193 | 197 | trap cleanup EXIT |
| 194 | 198 | TMP_DIR="$(mktemp -d)" |
| 195 | 199 | STAGING="${TMP_DIR}/staging" |
| 196 | - | |
| 200 | +rm -f "${OUTPUT}" | |
| 197 | 201 | echo "Processing source files" |
| 198 | 202 | createstaging "${SOURCE_DIR}" "${STAGING}" "${BOARD}" |
| 199 | 203 | |
| ... | ... | @@ -201,14 +205,19 @@ echo "Creating FAT file system" |
| 201 | 205 | TMP_IMAGE="${TMP_DIR}/boot.img" |
| 202 | 206 | createfs ${IMAGE_SIZE} "${TMP_IMAGE}" |
| 203 | 207 | |
| 204 | -echo "Copying files" | |
| 208 | +echo "Copying files to temporary mount ${BOOT_MOUNT}" | |
| 205 | 209 | mountfs "${TMP_IMAGE}" |
| 206 | 210 | cp -rv "${staging}"/* "${BOOT_MOUNT}" |
| 211 | +sync | |
| 207 | 212 | |
| 208 | 213 | echo "Sync" |
| 209 | -unmount_image "${IMAGE}" | |
| 214 | +sync | |
| 215 | + | |
| 216 | +echo "Unmount" | |
| 217 | +unmount_image | |
| 218 | + | |
| 210 | 219 | cp -f "${TMP_IMAGE}" "${OUTPUT}" |
| 220 | +chown "${SUDO_UID}:${SUDO_GID}" "${OUTPUT}" | |
| 211 | 221 | |
| 212 | -echo "Created image" | |
| 222 | +echo "Created image ${OUTPUT}" | |
| 213 | 223 | file "${OUTPUT}" |
| 214 | -ls -l "${OUTPUT}" | ... | ... |