Changeset 2376


Ignore:
Timestamp:
Sep 17, 2014, 8:04:56 PM (4 years ago)
Author:
matthijs
Message:

build-system: Fix fmg building

For building an fmg image, an ext2 filesystem is built in a file and
mounted using the Linux loopback device to add files to it. Mounting
happens using sudo, but before files were installed without sudo.
Before, this didn't cause any problems, for some reason the non-root
user had permission to write into the loopback-mounted filesystem.
Recently, it seems something changed (perhaps in the kernel or mount
userspace), resulting in permission errors when creating an fmg error.

This commit changes the build procedure to first collect all files in a
normal directory and then, using sudo, copy them into the
loopback-mounted filesystem at once.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openwrt/include/package-fon.mk

    r2030 r2376  
    155155    SHORTNAME_$(1):=$(1:plugin-%=%)
    156156    FPKG_FMG_$(1):=$(FON_PLUGINS_DIR)/$$(SHORTNAME_$(1))_$(VERSION)_$(BOARD).fmg
    157     # Directory to prepare the .tgz contents in
     157    # Directory to prepare the image contents in
    158158    # Don't put this inside $(BUILD_DIR), since the build step will be
    159159    # redone when anything inside $(BUILD_DIR) changes.
    160160    PLUGIN_DIR_$(1):=$(TMP_DIR)/fon-pkg-$(1)-$(VERSION)
     161    MOUNT_DIR_$(1):=$(TMP_DIR)/fon-pkg-$(1)-$(VERSION)-mount
    161162
    162163    # Disable compilation by default (Build/Compile/Default runs make
     
    177178        mkdir -p $(FON_PLUGINS_DIR)
    178179
    179         # Create the image file. Sized is hardcoded to just under 5M
    180         # for now. Use a full path to
    181         dd if=/dev/zero of=$$(FPKG_FMG_$(1)) count=1152 bs=4096
    182         /sbin/mkfs.ext2 -F -m 0 $$(FPKG_FMG_$(1))
    183180        mkdir $$(PLUGIN_DIR_$(1))
    184 
    185         # Mount the newly created image so we can put files in
    186         $(SUDO) mount -o loop -t ext2 $$(FPKG_FMG_$(1)) $$(PLUGIN_DIR_$(1))
    187181
    188182        # Install the package and all of its dependencies
     
    202196        mkdir $$(PLUGIN_DIR_$(1))/var
    203197
     198
     199        # Create the image file. Sized is hardcoded to just under 5M
     200        # for now.
     201        dd if=/dev/zero of=$$(FPKG_FMG_$(1)) count=1152 bs=4096
     202        /sbin/mkfs.ext2 -F -m 0 $$(FPKG_FMG_$(1))
     203
     204        mkdir $$(MOUNT_DIR_$(1))
     205
     206        # Mount the newly created image so we can put files in
     207        $(SUDO) mount -o loop -t ext2 $$(FPKG_FMG_$(1)) $$(MOUNT_DIR_$(1))
     208
     209        # Copy the files. Append /. to the source directory to copy the
     210        # contents of the directory, not the directory itself.
     211        $(SUDO) cp --recursive --preserve=mode,links $$(PLUGIN_DIR_$(1))/. $$(MOUNT_DIR_$(1))
     212
    204213        # If unmounting does not work, retry after a few seconds in case
    205         # # something is still using it...
    206         $(SUDO) umount $$(PLUGIN_DIR_$(1)) || { lsof $$(PLUGIN_DIR_$(1)) ; sleep 5 ; $(SUDO) umount $$(PLUGIN_DIR_$(1)); }
    207 
     214        # something is still using it...
     215        $(SUDO) umount $$(MOUNT_DIR_$(1)) || { lsof $$(MOUNT_DIR_$(1)) ; sleep 5 ; $(SUDO) umount $$(MOUNT_DIR_$(1)); }
    208216
    209217        # Clean up
    210         rmdir $$(PLUGIN_DIR_$(1))
     218        rmdir $$(MOUNT_DIR_$(1))
     219        rm -rf $$(PLUGIN_DIR_$(1))
    211220
    212221    clean: $(1)-clean
Note: See TracChangeset for help on using the changeset viewer.