macos/src/install.sh

65 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2024-01-14 15:39:24 +00:00
#!/usr/bin/env bash
2024-01-14 14:19:58 +00:00
set -Eeuo pipefail
2024-06-02 13:23:39 +00:00
# Docker environment variables
2024-06-05 12:16:56 +00:00
: "${VERSION:="sonoma"}" # OSX Version
2024-01-17 02:40:19 +00:00
2024-06-05 12:16:56 +00:00
TMP="$STORAGE/tmp"
BASE_FILE="BaseSystem"
2024-06-02 13:23:39 +00:00
BASE_IMG_ID="InstallMedia"
2024-06-05 12:16:56 +00:00
BASE_IMG="$STORAGE/base.dmg"
BASE_TMP="$TMP/$BASE_FILE.dmg"
2024-06-02 13:23:39 +00:00
downloadImage() {
2024-06-05 12:16:56 +00:00
rm -rf "$TMP"
mkdir -p "$TMP"
2024-06-05 12:16:56 +00:00
local msg="Downloading macOS ($VERSION) image"
info "$msg..." && html "$msg..."
/run/progress.sh "$BASE_TMP" "" "$msg ([P])..." &
if ! /run/fetch-macOS-v2.py --action download -s "$VERSION" -n "$BASE_FILE" -o "$TMP"; then
error "Failed to fetch macOS ($VERSION)!"
fKill "progress.sh"
return 1
fi
2024-06-05 12:16:56 +00:00
fKill "progress.sh"
2024-06-05 12:16:56 +00:00
if [ ! -f "$BASE_TMP" ] || [ ! -s "$BASE_TMP" ]; then
error "Failed to find file $BASE_TMP !"
return 1
fi
echo "$VERSION" > "$STORAGE/$PROCESS.version"
2024-06-05 12:16:56 +00:00
mv "$BASE_TMP" "$BASE_IMG"
rm -rf "$TMP"
return 0
2024-05-10 16:21:41 +00:00
}
2024-06-05 12:16:56 +00:00
if [ ! -f "$BASE_IMG" ] || [ ! -s "$BASE_IMG" ]; then
if ! downloadImage; then
rm -rf "$TMP"
exit 34
fi
fi
2024-01-22 01:56:28 +00:00
2024-06-02 13:23:39 +00:00
STORED_VERSION=$(cat "$STORAGE/$PROCESS.version")
2024-01-19 00:25:39 +00:00
2024-06-02 13:23:39 +00:00
if [ "$VERSION" != "$STORED_VERSION" ]; then
info "Different version detected, switching base image from $STORED_VERSION to $VERSION"
2024-06-05 12:16:56 +00:00
if ! downloadImage; then
rm -rf "$TMP"
exit 34
fi
fi
DISK_OPTS="$DISK_OPTS -device virtio-blk-pci,drive=${BASE_IMG_ID},scsi=off,bus=pcie.0,addr=0x6,iothread=io2"
2024-06-05 12:16:56 +00:00
DISK_OPTS="$DISK_OPTS -drive file=$BASE_IMG,id=$BASE_IMG_ID,format=dmg,cache=$DISK_CACHE,aio=$DISK_IO,readonly=on,if=none"
2024-01-20 16:03:59 +00:00
2024-01-14 14:19:58 +00:00
return 0