2023-09-02 14:38:27 +02:00
#! /bin/bash
2024-03-16 11:54:05 +01:00
DRIVER = 550
2023-09-02 14:38:27 +02:00
2024-04-05 14:06:08 +02:00
DRIVER_BUILT = true
2024-04-05 13:54:43 +02:00
2024-01-28 20:01:33 +01:00
echo " $( apt show kernel-pika 2>& 1 | grep -v "does not have a stable" | grep Depends: | head -n1 | cut -f2 -d":" | cut -f1 -d"," | cut -f3,4 -d"-" | tr -d ' ' ) " > ./linux-nvidia-modules/KERNEL
2024-04-05 14:04:16 +02:00
apt show linux-modules-nvidia-$DRIVER -$( cat ./linux-nvidia-modules/KERNEL) || export DRIVER_BUILT = false && echo "This driver has never been built for this kernel version before."
apt show linux-modules-nvidia-$DRIVER -$( cat ./linux-nvidia-modules/KERNEL) 2>& 1 | grep -v "does not have a stable" | grep Version: | head -n1 | cut -f2 -d":" | tr -d ' ' > ./linux-nvidia-modules/pika_nvidia.txt
2024-01-28 19:43:16 +01:00
2024-01-28 19:04:54 +01:00
rm -rfv /etc/apt/preferences.d/*
2024-04-28 13:35:14 +02:00
echo 'Package: *' >> /etc/apt/preferences.d/0-a
2024-01-28 18:46:50 +01:00
echo 'Pin: release c=ubuntu' >> /etc/apt/preferences.d/0-a
2024-04-28 13:32:27 +02:00
echo 'Pin-Priority: 950' >> /etc/apt/preferences.d/0-a
2024-04-28 13:37:55 +02:00
echo 'Package: *' >> /etc/apt/preferences.d/0-a
2024-04-28 13:38:58 +02:00
echo 'Pin: release c=external' >> /etc/apt/preferences.d/0-a
2024-04-28 13:37:55 +02:00
echo 'Pin-Priority: 1000' >> /etc/apt/preferences.d/0-a
2023-09-28 21:15:18 +02:00
apt update -y
2024-01-28 19:43:16 +01:00
apt show nvidia-driver-$DRIVER 2>& 1 | grep -v "does not have a stable" | grep Version: | head -n1 | cut -f2 -d":" | cut -f1,2,3 -d"." | cut -f1 -d"-" | tr -d ' ' > ./linux-nvidia-modules/new_nvidia.txt
2024-01-26 22:01:52 +01:00
echo " $( apt show nvidia-driver-$DRIVER 2>& 1 | grep -v "does not have a stable" | grep Version: | head -n1 | cut -f2 -d":" | cut -f1,2,3 -d"." | cut -f1 -d"-" | tr -d ' ' ) " > ./linux-nvidia-modules/DRIVER
echo " $( apt show kernel-pika 2>& 1 | grep -v "does not have a stable" | grep Depends: | head -n1 | cut -f2 -d":" | cut -f1 -d"," | cut -f3,4 -d"-" | tr -d ' ' ) " > ./linux-nvidia-modules/KERNEL
echo " $( apt show nvidia-kernel-source-$DRIVER 2>& 1 | grep -v "does not have a stable" | grep Version: | head -n1 | cut -f2 -d":" | tr -d ' ' ) " > ./linux-nvidia-modules/DRIVER_VERSION
2024-01-28 19:04:54 +01:00
echo " $( apt show nvidia-driver-$DRIVER 2>& 1 | grep -v "does not have a stable" | grep Version: | head -n1 | cut -f2 -d":" | tr -d ' ' ) " > ./linux-nvidia-modules/DRIVER_PIKA
2023-09-02 15:33:40 +02:00
2023-09-28 20:48:05 +02:00
cd ./linux-nvidia-modules
2023-09-02 15:33:40 +02:00
2024-03-17 15:26:05 +01:00
VERSION = " $( cat ./DRIVER_VERSION) - $( cat ./KERNEL) -100pika7 "
2024-01-28 18:06:17 +01:00
2024-01-28 18:15:28 +01:00
echo -e "linux-nvidia-modules (" $VERSION ") pikauwu; urgency=medium\n\n * New Release\n\n -- Ward Nakchbandi <hotrod.master@hotmail.com> Sat, 01 Oct 2022 14:50:00 +0200" > debian/changelog
2024-04-28 13:13:53 +02:00
if [ [ $DRIVER_BUILT = = true ] ]
then
if echo $VERSION | grep " $( cat ./pika_nvidia.txt) "
then
echo "driver already built"
exit 0
fi
fi
2024-01-28 19:43:16 +01:00
2024-01-26 21:20:48 +01:00
echo -e " Source: linux-nvidia-modules\nSection: graphics\nPriority: optional\nMaintainer: Ward Nakchbandi <hotrod.master@hotmail.com>\nStandards-Version: 4.6.1\nBuild-Depends: debhelper-compat (= 13), linux-image- $( cat ./KERNEL) , linux-headers- $( cat ./KERNEL) , dkms, fakeroot\nRules-Requires-Root: no\n\nPackage: linux-modules-nvidia- $DRIVER - $( cat ./KERNEL) \nArchitecture: linux-any\nDepends: linux-image- $( cat ./KERNEL) , linux-headers- $( cat ./KERNEL) , $( apt-cache show nvidia-dkms-$DRIVER | grep Depends: | head -n1 | cut -f2 -d":" ) \nConflicts: nvidia-6.5.0-pikaos-module-535, nvidia- $( cat ./KERNEL) -module- $DRIVER , " $( apt list 2>/dev/null | cut -d'/' -f1 | grep linux-modules-nvidia | grep $( cat ./KERNEL) | grep -v linux-modules-nvidia-$DRIVER -$( cat ./KERNEL) | sed ':a;N;$!ba;s/\n/, /g' ) " , nvidia-dkms- $DRIVER (= $( cat DRIVER_VERSION) )\nProvides: linux-modules-nvidia- $( cat ./KERNEL) , nvidia-dkms- $DRIVER (= $( cat DRIVER_VERSION) )\nReplaces: nvidia-dkms- $DRIVER (= $( cat DRIVER_VERSION) )\nDescription: Prebuilt Nvidia module for PikaOS kernel\n\nPackage: nvidia-pika-kernel-module- $DRIVER \nArchitecture: linux-any\nDepends: linux-modules-nvidia- $DRIVER - $( cat ./KERNEL) $( echo '(= ${binary:Version})' ) \nDescription: DKMS NVIDIA PLACEHOLDER " > ./debian/control
2023-11-07 14:25:14 +01:00
echo -e "usr" > ./debian/linux-modules-nvidia-$DRIVER -$( cat ./KERNEL) .install
2023-09-02 15:33:40 +02:00
2023-11-07 14:41:20 +01:00
echo " cp -vf /usr/lib/pika/nvidia- $( cat ./DRIVER) - $( cat ./KERNEL) /blacklist-pika-nouveau.conf /etc/modprobe.d/blacklist-pika-nouveau.conf " >> ./debian/postinst
echo " cp -vf /usr/lib/pika/nvidia- $( cat ./DRIVER) - $( cat ./KERNEL) /pika-nvidia.conf /etc/modules-load.d/pika-nvidia.conf " >> ./debian/postinst
2023-09-02 15:49:27 +02:00
echo -e " DRIVER= $( cat ./DRIVER) \nKERNEL= $( cat ./KERNEL) \nVERSION= $( cat ./DRIVER_VERSION) \nMK_WORKDIR= $( env | grep -w "PWD" | cut -c5-) \nCARCH=x86_64 " > ./Makefile
cat ./Makefiletmp >> ./Makefile
2023-09-02 15:44:58 +02:00
2024-03-17 15:25:10 +01:00
cat << EOF > ./debian/postinst
#! /bin/sh
# Reset kernel modules
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.alias || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.builtin.alias.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.dep || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.devname || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.symbols || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.alias.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.builtin.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.dep.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.softdep || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.symbols.bin || true
# Regenerate kernel module configs
depmod -a " $( cat ./KERNEL) "
# Update initramfs with new module config
update-initramfs -c -k all
EOF
cat << EOF > ./debian/postrm
#! /bin/sh
# Reset kernel modules
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.alias || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.builtin.alias.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.dep || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.devname || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.symbols || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.alias.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.builtin.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.dep.bin || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.softdep || true
rm -rfv /usr/lib/modules/" $( cat ./KERNEL) " /modules.symbols.bin || true
# Regenerate kernel module configs
depmod -a " $( cat ./KERNEL) "
# Update initramfs with new module config
update-initramfs -c -k all
EOF
2023-09-02 15:33:40 +02:00
DEBIAN_FRONTEND = noninteractive
2023-09-02 14:38:27 +02:00
# Get build deps
apt-get build-dep ./ -y
2023-09-02 16:32:17 +02:00
apt download nvidia-kernel-source-$DRIVER -y
dpkg-deb -x ./nvidia-kernel-source-$DRIVER *.deb /
2023-09-02 16:35:04 +02:00
apt download nvidia-dkms-$DRIVER -y
dpkg-deb -x ./nvidia-dkms-$DRIVER *.deb /
2023-09-02 14:38:27 +02:00
# Build package
2023-09-02 16:18:27 +02:00
dpkg-buildpackage --no-sign
echo 'DKMS MAKEFILE LOG:'
2023-09-02 16:22:00 +02:00
cat ./nvidia/$( cat ./DRIVER) /$( cat ./KERNEL) /x86_64/log/make.log || cat ./nvidia/$( cat ./DRIVER) /build/make.log
2023-09-02 14:38:27 +02:00
# Move the debs to output
cd ../
mkdir -p ./output
mv ./*.deb ./output/