Skip to content

Commit

Permalink
Cleanup and improve rpm generation (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpenedblade authored May 19, 2024
1 parent de0fb7e commit b28be06
Showing 1 changed file with 46 additions and 50 deletions.
96 changes: 46 additions & 50 deletions docs/tools/firmware.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -117,74 +117,70 @@ create_rpm () {
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Extract firmware
python3 "$0" /usr/share/firmware $HOME/rpmbuild/firmware.tar
python3 "$0" /usr/share/firmware $HOME/rpmbuild/SOURCES/firmware.tar
cd $HOME/rpmbuild/BUILD
tar -xf $HOME/rpmbuild/firmware.tar ${verbose}
cd - >/dev/null
rm ${verbose} $HOME/rpmbuild/firmware.tar

if [[ (${identifier} = iMac19,1) || (${identifier} = iMac19,2) || (${identifier} = iMacPro1,1) ]]
then
nvramfile=$(ioreg -l | grep RequestedFiles | cut -d "/" -f 5 | rev | cut -c 4- | rev)
txcapblob=$(ioreg -l | grep RequestedFiles | cut -d "/" -f 3 | cut -d "\"" -f 1)
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${nvramfile} "$HOME/rpmbuild/BUILD/brcmfmac4364b2-pcie.txt"
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${txcapblob} "$HOME/rpmbuild/BUILD/brcmfmac4364b2-pcie.txcap_blob"
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${nvramfile} brcmfmac4364b2-pcie.txt
cp ${verbose} /usr/share/firmware/wifi/C-4364__s-B2/${txcapblob} brcmfmac4364b2-pcie.txcap_blob
tar --append ${verbose} -f $HOME/rpmbuild/SOURCES/firmware.tar brcmfmac4364b2-pcie.txt
tar --append ${verbose} -f $HOME/rpmbuild/SOURCES/firmware.tar brcmfmac4364b2-pcie.txcap_blob
rm brcmfmac4364b2-pcie.txcap_blob brcmfmac4364b2-pcie.txt
fi

# Create the spec file
echo "Name: apple-firmware" > $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Version: ${ver}" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Release: 1" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Summary: Wi-Fi and Bluetooth firmware for T2 Macs" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "License: Proprietary" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%description" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "Wi-Fi and Bluetooth firmware for T2 Macs" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%install" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "mkdir -p %{buildroot}/usr/lib/firmware/brcm" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "install -m 644 * %{buildroot}/usr/lib/firmware/brcm" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%post" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe -r brcmfmac_wcc || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe -r brcmfmac || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe brcmfmac || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe -r hci_bcm4377 || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "modprobe hci_bcm4377 || true" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

echo -e "\n%files" >> $HOME/rpmbuild/SPECS/apple-firmware.spec
echo "/usr/lib/firmware/brcm/*" >> $HOME/rpmbuild/SPECS/apple-firmware.spec

# Set OS to Linux
if [ -f "$HOME/.rpmrc" ]
then
echo -e "\nBacking up existing .rpmrc"
cp ${verbose} $HOME/.rpmrc $HOME/.rpmrc_orj
fi
echo "buildostranslate: Darwin: Linux" > $HOME/.rpmrc
cat <<- EOF > $HOME/rpmbuild/SPECS/apple-firmware.spec
Name: apple-firmware
Version: ${ver}
Release: 1
Summary: Wi-Fi and Bluetooth firmware for T2 Macs
License: Proprietary
BuildArch: noarch
Source1: firmware.tar
%description
Wi-Fi and Bluetooth firmware for T2 Macs
%prep
tar -xf %{SOURCE1}
%build
%install
mkdir -p %{buildroot}/usr/lib/firmware/brcm
install -m 644 * %{buildroot}/usr/lib/firmware/brcm
%posttrans
modprobe -r brcmfmac_wcc || true
modprobe -r brcmfmac || true
modprobe brcmfmac || true
modprobe -r hci_bcm4377 || true
modprobe hci_bcm4377 || true
%files
/usr/lib/firmware/brcm/*
EOF

# Build
# For some reason bash doesn't like rpmbuild. Use zsh.
if [[ ${verbose} = -v ]]
then
/bin/zsh -c "rpmbuild -bb $HOME/rpmbuild/SPECS/apple-firmware.spec"
rpmbuild -bb --define '_target_os linux' $HOME/rpmbuild/SPECS/apple-firmware.spec
else
/bin/zsh -c "rpmbuild -bb $HOME/rpmbuild/SPECS/apple-firmware.spec >/dev/null 2&>/dev/null || echo \"Failed to make rpm package. Run the script with -v to get logs.\""
rpmbuild -bb --define '_target_os linux' $HOME/rpmbuild/SPECS/apple-firmware.spec >/dev/null 2>&1 || echo "Failed to make rpm package. Run the script with -v to get logs."
fi

# Copy and Cleanup
cp ${verbose} $HOME/rpmbuild/RPMS/x86_64/apple-firmware-${ver}-1.x86_64.rpm $HOME/Downloads
cp ${verbose} $HOME/rpmbuild/RPMS/noarch/apple-firmware-${ver}-1.noarch.rpm $HOME/Downloads
echo -e "\nCleaning up"
sudo rm -r ${verbose} $HOME/rpmbuild
sudo rm $HOME/.rpmrc
if [ -f $HOME/.rpmrc_orj ]
then
echo -e "\nRestoring backed up .rpmrc"
mv $HOME/.rpmrc_orj $HOME/.rpmrc
fi
rm -r ${verbose} $HOME/rpmbuild

echo -e "\nRpm package apple-firmware-${ver}-1.x86_64.rpm has been saved to Downloads!"
echo "Copy it to Linux and install using rpm."
echo -e "\nRpm package apple-firmware-${ver}-1.noarch.rpm has been saved to Downloads!"
echo "Copy it to Linux and install it by running the following in a terminal:"
echo " sudo dnf install --disablerepo=* /path/to/apple-firmware-14.4.1-1.noarch.rpm"
}

create_arch_pkg () {
Expand Down Expand Up @@ -326,7 +322,7 @@ case "$os" in
(3)
echo -e "\nWhat package manager does your Linux distribution use?"
echo -e "\n1. apt"
echo "2. rpm"
echo "2. dnf"
echo "3. pacman"
read package
case ${package} in
Expand Down

0 comments on commit b28be06

Please sign in to comment.