Search code examples
macosshellpkgbuildpkg-file

Zero-byte Application being installed from pkgbuild generated .pkg installer


this is the shell script that I use to generate the .pkg installer.

#!/bin/bash

APP_PATH=$1
DSYM_PATH=$2
PKG_PATH=$3
IDENTIFIER=$4
VERSION=$5
TARGET_DIR=$(dirname "$APP_PATH")/temp

echo "Deleting old Pkg File."
rm -rf $PKG_PATH
rm -rf $TARGET_DIR
mkdir $TARGET_DIR
echo "Done."

echo "Copying APP \"$APP_PATH\" and dSYM \"$DSYM_PATH \" to temp folder."

cp -a $APP_PATH $TARGET_DIR
cp -a $DSYM_PATH $TARGET_DIR

echo "Done."


echo "Generating .Pkg file with dSYM folder"

/usr/bin/pkgbuild \
  --root "$TARGET_DIR" \
  --install-location "/Applications" \
  --identifier "$IDENTIFIER" \
  --version "$VERSION" \
  "$PKG_PATH"

echo "Done Generating \"$APP_PATH\" with dSYM folder"

This .pkg is installed to /Applications folder but it's zero byte in size.

I've tried to change the permission of the files but it's no use.


Solution

  • To solve this issue, I had to change the permissions for files.

    I've added the following line in the script.

    chmod -R 755 $TARGET_DIR

    The file with wrong permission will result a zero-bytes installation.

    #!/bin/bash
    
    APP_PATH=$1
    DSYM_PATH=$2
    PKG_PATH=$3
    IDENTIFIER=$4
    VERSION=$5
    TARGET_DIR=$(dirname "$APP_PATH")/temp
    
    echo "Deleting old Pkg File."
    rm -rf $PKG_PATH
    rm -rf $TARGET_DIR
    mkdir $TARGET_DIR
    echo "Done."
    
    echo "Copying APP \"$APP_PATH\" and dSYM \"$DSYM_PATH \" to temp folder."
    
    cp -a $APP_PATH $TARGET_DIR
    cp -a $DSYM_PATH $TARGET_DIR
    
    echo "Done."
    
    chmod -R 755 $TARGET_DIR
    
    echo "Generating .Pkg file with dSYM folder"
    
    /usr/bin/pkgbuild \
      --root "$TARGET_DIR" \
      --install-location "/Applications" \
      --identifier "$IDENTIFIER" \
      --version "$VERSION" \
      "$PKG_PATH"
    
    echo "Done Generating \"$APP_PATH\" with dSYM folder"