Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Code Readability and Maintainability of build.sh #234

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 24 additions & 39 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,29 @@

set -e

cd "$(dirname "$0")"

PYTHON_VER=3.9.6
PYTHON_PKG=python-$PYTHON_VER-macos11.pkg
PYTHON_URI="https://www.python.org/ftp/python/$PYTHON_VER/$PYTHON_PKG"

M1N1="$PWD/m1n1"
ARTWORK="$PWD/artwork"
AFW="$PWD/asahi_firmware"
SRC="$PWD/src"
VENDOR="$PWD/vendor"
DL="$PWD/dl"
PACKAGE="$PWD/package"
RELEASES="$PWD/releases"
RELEASES_DEV="$PWD/releases-dev"

# Define directory variables
SCRIPT_DIR="$(dirname "$0")"
M1N1="$SCRIPT_DIR/m1n1"
ARTWORK="$SCRIPT_DIR/artwork"
AFW="$SCRIPT_DIR/asahi_firmware"
SRC="$SCRIPT_DIR/src"
VENDOR="$SCRIPT_DIR/vendor"
DL="$SCRIPT_DIR/dl"
PACKAGE="$SCRIPT_DIR/package"
RELEASES="$SCRIPT_DIR/releases"
RELEASES_DEV="$SCRIPT_DIR/releases-dev"

# Create necessary directories
rm -rf "$PACKAGE"
mkdir -p "$DL" "$PACKAGE" "$RELEASES" "$RELEASES_DEV" "$PACKAGE/bin"

mkdir -p "$DL" "$PACKAGE" "$RELEASES" "$RELEASES_DEV"
mkdir -p "$PACKAGE/bin"

echo "Determining version..."

# Determine version
VER=$(git describe --always --dirty --tags)

echo "Version: $VER"

if [ -z "$VER" ]; then
if [ -e version.tag ]; then
VER="$(cat version.tag)"
if [ -e "$SCRIPT_DIR/version.tag" ]; then
VER="$(cat "$SCRIPT_DIR/version.tag")"
else
echo "Could not determine version!"
exit 1
Expand All @@ -43,14 +36,16 @@ echo "Downloading installer components..."

cd "$DL"

PYTHON_VER=3.9.6
PYTHON_PKG="python-$PYTHON_VER-macos11.pkg"
PYTHON_URI="https://www.python.org/ftp/python/$PYTHON_VER/$PYTHON_PKG"

wget -Nc "$PYTHON_URI"

echo "Building m1n1..."

make -C "$M1N1" RELEASE=1 CHAINLOADING=1 -j4

echo "Copying files..."

cp -r "$SRC"/* "$PACKAGE/"
rm "$PACKAGE/asahi_firmware"
cp -r "$AFW" "$PACKAGE/"
Expand All @@ -59,37 +54,29 @@ mkdir -p "$PACKAGE/boot"
cp "$M1N1/build/m1n1.bin" "$PACKAGE/boot"

echo "Extracting Python framework..."

mkdir -p "$PACKAGE/Frameworks/Python.framework"

7z x -so "$DL/$PYTHON_PKG" Python_Framework.pkg/Payload | zcat | \
cpio -i -D "$PACKAGE/Frameworks/Python.framework"

7z x -so "$DL/$PYTHON_PKG" Python_Framework.pkg/Payload | zcat | cpio -i -D "$PACKAGE/Frameworks/Python.framework"

cd "$PACKAGE/Frameworks/Python.framework/Versions/Current"

echo "Copying vendored libffi into Python framework..."

cp -P "$VENDOR"/libffi/* lib/
cp -P "$VENDOR/libffi"/* lib/

echo "Slimming down Python..."

rm -rf include share
cd lib
rm -rf -- tdb* tk* Tk* libtk* *tcl*
cd python3.*
rm -rf test ensurepip idlelib
cd lib-dynload
rm -f _test* _tkinter*


echo "Copying certificates..."

certs="$(python3 -c 'import certifi; print(certifi.where())')"
certs="$(python3 -c 'import certifi; print(certifi.where()')"
cp "$certs" "$PACKAGE/Frameworks/Python.framework/Versions/Current/etc/openssl/cert.pem"

echo "Packaging installer..."

cd "$PACKAGE"

echo "$VER" > version.tag
Expand All @@ -106,7 +93,5 @@ else
fi

tar czf "$PKGFILE" .
echo "$VER" > "$LATEST"

echo
echo "Built package: $(basename "$PKGFILE")"
2 changes: 2 additions & 0 deletions src/step2/step2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ if [ -e "$system_dir/System/Library/CoreServices/SystemVersion-disabled.plist" ]
mv -f "$system_dir/System/Library/CoreServices/SystemVersion"{-disabled,}".plist"
fi

chflags hidden "$system_dir"

echo
echo "Installation complete! Press enter to reboot."
read
Expand Down