I some optimized my script. Please test it on your real iron
Code: Select all
#!/bin/bash
# Build of NVIDIA video driver, cleaning and compressing to xzm module for Porteus by Blaze
# You can use this script for both architectures i586 or x86_64
# Version 2019-04-20
TMP=${TMP:-/tmp/nvidia-$$}
NV=${NV:-08-nvidia-$(ls /tmp/*.run | basename -s .run *.run | cut -d '-' -f4 | sed -n 1p)-k.$(uname -r)-$(cat /etc/porteus-version | cut -d '-' -f2)-$(arch).xzm}
# Root check
if [ `whoami` != "root" ]; then
echo -e "\n\e[1m\e[31mOnly root can run this.\e[0m\n"
exit 1
fi
# Check blacklist.xzm in $PORTDIR/{base,optional}
if [[ -f "$PORTDIR/base/blacklist.xzm" ]]; then
mkdir $TMP
xzm2dir "$PORTDIR/base/blacklist.xzm" $TMP &>/dev/null
elif [[ -f "$PORTDIR/optional/*blacklist.xzm" ]]; then
mkdir $TMP
xzm2dir "$PORTDIR/optional/*blacklist.xzm" $TMP &>/dev/null
else
ls "$PORTDIR/base/blacklist.xzm" > /dev/null
ls "$PORTDIR/optional/*blacklist.xzm" > /dev/null
echo -e "\n\e[1m\e[31m"'blacklist.xzm not found in Porteus /base or /optional. Abort!'"\e[0m\n"
unset TMP
exit 1
fi
# Selective compression and extraction of memory changes for NVIDIA
cd /tmp
sync; echo 3 > /proc/sys/vm/drop_caches
echo -e '\n\033[1m\e[32m[*]\e[0m\033[1m Compression of memory changes for NVIDIA to /tmp/nvidia.tar.gz\033[0m'
tar czf nvidia.tar.gz --exclude={"*/.*","*/.wh.*",".cache","dev","home","mnt","opt","root","run","tmp","var","etc/bootcmd.cfg","etc/ld.so.cache","etc/fstab","etc/random-seed","etc/cups","etc/udev","etc/profile.d","etc/porteus","etc/X11/xorg.conf.nvidia-xconfig-original","lib/firmware","lib/modules/*porteus/modules.*","usr/man","usr/src","usr/bin/gnome-keyring-daemon","usr/lib/gio","usr/lib/gtk-2.0","usr/lib/gtk-3.0","usr/lib/libXvMCgallium.so.1","usr/lib/libbrscandec2.so.1","usr/lib/libgsm.so.1","usr/lib/libudev.so.1","usr/lib/libunrar.so.5","usr/lib64/gio","usr/lib64/gtk-2.0","usr/lib64/gtk-3.0","usr/lib64/libXvMCgallium.so.1","usr/lib64/libbrscandec2.so.1","usr/lib64/libgsm.so.1","usr/lib64/libudev.so.1","usr/lib64/libunrar.so.5","usr/local","usr/share/glib-2.0","usr/share/mime","usr/share/pixmaps","usr/share/applications/mimeinfo.cache","usr/local/share/applications/mimeinfo.cache","usr/share/doc/NVIDIA_GLX-1.0/html","usr/share/doc/NVIDIA_GLX-1.0/sample","usr/share/doc/NVIDIA_GLX-1.0/LICENSE","usr/share/doc/NVIDIA_GLX-1.0/NVIDIA_Changelog","usr/share/doc/NVIDIA_GLX-1.0/README.txt"} -C /mnt/live/memory changes
echo -e "\n\033[1m\e[32m[*]\e[0m\033[1m Extraction of memory changes for NVIDIA from /tmp/nvidia.tar.gz to $TMP\033[0m\n"
tar xf nvidia.tar.gz --strip 1 -C $TMP
rm -f /tmp/nvidia.tar.gz
# Сleaning and compressing to xzm module
echo -e "\n\033[1m\e[32m[*]\e[0m\033[1m Сleaning $TMP directory from junk files\033[0m\n"
rm -rf $TMP/{.cache,dev,home,mnt,opt,root,run,tmp,var}
find $TMP -type f -maxdepth 1 -delete
find $TMP -type l -maxdepth 1 -delete
find $TMP/etc/ -type f -maxdepth 1 -delete
find $TMP/etc/ -type d ! -iname 'modprobe.d' ! -iname 'OpenCL' ! -iname 'vulkan' ! -iname 'X11' ! -iname 'etc' -maxdepth 1 -exec rm -rf '{}' '+'
rm -f $TMP/etc/X11/xorg.conf.nvidia-xconfig-original
rm -rf $TMP/lib/firmware
rm -f $TMP/lib/modules/*porteus/modules.*
rm -rf $TMP/usr/{man,src}
rm -f $TMP/usr/bin/gnome-keyring-daemon
rm -rf $TMP/usr/lib/{gio,gtk-2.0,gtk-3.0}
rm -f $TMP/usr/lib/{libXvMCgallium.so.1,libbrscandec2.so.1,libgsm.so.1,libudev.so.1,libunrar.so.5}
rm -rf $TMP/usr/lib64/{gio,gtk-2.0,gtk-3.0}
rm -f $TMP/usr/lib64/{libXvMCgallium.so.1,libbrscandec2.so.1,libgsm.so.1,libudev.so.1,libunrar.so.5}
rm -rf $TMP/usr/local
rm -rf $TMP/usr/share/{glib-2.0,mime,pixmaps}
rm -f $TMP/usr/{,local/}share/applications/mimeinfo.cache
rm -rf $TMP/usr/share/doc/NVIDIA_GLX-1.0/{html,sample,LICENSE,NVIDIA_Changelog,README.txt}
echo -e "\n\033[1m\e[32m[*]\e[0m\033[1m Compressing $TMP to $MODDIR/$NV module\033[0m\n"
dir2xzm $TMP $MODDIR/$NV 2>/dev/null
rm -rf $TMP
# Removing $PORTDIR/base/blacklist.xzm
if [[ -f "$PORTDIR/base/blacklist.xzm" ]]; then
echo -e "\n\033[1m\e[32m[*]\e[0m\033[1m Removing $PORTDIR/base/blacklist.xzm\033[0m\n"
rm -f $PORTDIR/base/blacklist.xzm
fi
echo -e "\n\e[1m\e[32m[DONE]\e[0m \e[1mYou can find your nvidia xzm module in \e[96m$MODDIR\e[0m"
echo -e "\e[1m>>> Now you can reboot Porteus via \e[92mreboot\e[0m \e[1mcommand <<<\e[0m\n"
unset TMP
unset NV