Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

Commit c8bfaf1

Browse files
authored
Merge pull request #1 from SenseTime-FVG/fix/macos-installer-scripts
fix(macos): make pkg installer scripts run reliably
2 parents 83c6331 + ef76ba9 commit c8bfaf1

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

macos/build-pkg.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,30 @@ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
99
BUILD_DIR="$SCRIPT_DIR/build"
1010
DIST_DIR="$PROJECT_ROOT/dist"
1111
VERSION="1.0.0"
12+
SCRIPTS_DIR="$BUILD_DIR/scripts"
1213

1314
rm -rf "$BUILD_DIR"
1415
mkdir -p "$BUILD_DIR/payload/usr/local/lib/agent-pack"
1516
mkdir -p "$DIST_DIR"
17+
mkdir -p "$SCRIPTS_DIR"
1618

1719
# Copy project files into payload
1820
cp -R "$PROJECT_ROOT/shared" "$BUILD_DIR/payload/usr/local/lib/agent-pack/shared"
1921
cp -R "$PROJECT_ROOT/config" "$BUILD_DIR/payload/usr/local/lib/agent-pack/config"
2022
mkdir -p "$BUILD_DIR/payload/usr/local/lib/agent-pack/linux"
2123
cp -R "$PROJECT_ROOT/linux/lib" "$BUILD_DIR/payload/usr/local/lib/agent-pack/linux/lib"
2224

25+
# pkgbuild requires runnable preinstall/postinstall scripts. Stage them in a
26+
# temp directory with executable permissions so the macOS package runs
27+
# reliably regardless of repo mode bits.
28+
cp "$SCRIPT_DIR/scripts/preinstall.sh" "$SCRIPTS_DIR/preinstall"
29+
cp "$SCRIPT_DIR/scripts/postinstall.sh" "$SCRIPTS_DIR/postinstall"
30+
chmod 755 "$SCRIPTS_DIR/preinstall" "$SCRIPTS_DIR/postinstall"
31+
2332
# Build component package
2433
pkgbuild \
2534
--root "$BUILD_DIR/payload" \
26-
--scripts "$SCRIPT_DIR/scripts" \
35+
--scripts "$SCRIPTS_DIR" \
2736
--identifier "com.agentpack.pkg" \
2837
--version "$VERSION" \
2938
"$BUILD_DIR/AgentPack.pkg"

macos/scripts/postinstall.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
set -e
66

7+
POSTINSTALL_LOG="/private/tmp/agent-pack-postinstall.log"
8+
mkdir -p "$(dirname "$POSTINSTALL_LOG")"
9+
exec >>"$POSTINSTALL_LOG" 2>&1
10+
echo ""
11+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting Agent Pack macOS postinstall"
12+
713
INSTALL_DIR="/usr/local/lib/agent-pack"
814
SHARED_DIR="$INSTALL_DIR/shared"
915
CONFIG_DIR="$INSTALL_DIR/config"

macos/scripts/preinstall.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ set -e
66

77
echo "[Agent Pack] Pre-install: checking prerequisites..."
88

9+
# Installer runs with a stripped PATH on many macOS systems, so expose common
10+
# Homebrew locations before checking for brew.
11+
if [ -x /opt/homebrew/bin/brew ]; then
12+
eval "$(/opt/homebrew/bin/brew shellenv)"
13+
elif [ -x /usr/local/bin/brew ]; then
14+
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
15+
fi
16+
917
# Xcode Command Line Tools
1018
if ! xcode-select -p &>/dev/null; then
1119
echo ""

0 commit comments

Comments
 (0)