blender module build script

Here is a place for your projects which are not officially supported by the Porteus Team. For example: your own kernel patched with extra features; desktops not included in the standard ISO like Gnome; base modules that are different than the standard ISO, etc...
Post Reply
User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 2255
Joined: 20 Mar 2012, 03:42
Distribution: 5.0rc1-64bit all-DE+more
Location: australia
Contact:

blender module build script

Post#1 by ncmprhnsbl » 07 Sep 2019, 05:26

here is a script that fetches and makes a module for porteus-5.0 and porteus-4.0 from the latest stable blender binary release or nightly development release(64bit only, 32bit offers only the latest stable) or from a binary tar.bz2 placed in /tmp or a (POSIX) dir of your choice.
Suitable binary tar.bz2 s include those from blender.community/c/graphicall/
Most of the bundled python is removed, since porteus 5.0 includes python3.7, which blender is tricked into using via links.
For porteus-4.0 the bundled python is included
Opengl stuff is also left out.
Unused language packs are also removed.
A module is here: update-blender-20191123.xzm
contents:

Code: Select all

update-blender-20191123
└── usr
    └── local
        └── bin
            └── update-blender
to use: open a terminal and type "update-blender"
options are: -h (shows usage info)
-v (shows version number(date))
and -d (which makes all build operations done in current directory instead of /tmp(must be POSIX ie.not fat or ntfs... useful for limited RAM)

update-blender:

Code: Select all

#!/bin/bash
## update-blender
## A script to make a module for porteus-5.0 from the latest stable blender binary release
## or from a binary tar.bz2 placed in /tmp or a (POSIX) dir of your choice
## suitable binary tar.bz2 include the development builds from builder.blender.org/download/ or blender.community/c/graphicall/
## Most of the bundled python is removed, since porteus 5.0 includes python3.7, which blender is tricked into using via links.
## 
## Use at your own risk!! Possible negative outcomes: wasted bandwidth and an useless module. The puppies may survive.
##
## by ncmprhnsbl  forum.porteus.org
SVER=20191123

# Source porteus-functions
. /usr/share/porteus/porteus-functions
get_colors

txtbld=$(tput bold)
txtred=${txtbld}$(tput setaf 1)
txtgreen=${txtbld}$(tput setaf 2)
txtwhite=${txtbld}$(tput setaf 7)
txtcyan=${txtbld}$(tput setaf 6)
rst=$(tput sgr0)
function bold(){ echo -e $txtbld "$1" $rst; }
function green() { echo -e $txtgreen "$1" $rst; }
function red(){ echo $txtred "$1" $rst; }	
function cyan(){ echo $txtcyan "$1" $rst; }

saypass(){ echo "[${txtgreen}PASS$rst] $1"; }
sayfail(){ echo "[${txtred}FAIL$rst] $1"; }

# Check for root
if [ `whoami` != "root" ]; then
	   if [ `whoami` != "root" ]; then
      echo "Please enter root's password below"
      su - -c "update-blender $1"
      exit
   fi
fi

## Variables
URL1=https://download.blender.org/release/
URL2=https://builder.blender.org/download/
PORTVER=`cat /etc/porteus-version | cut -d- -f2`

# functions set work directory(default is /tmp) to current work directory
set_tmp() {
WRKDIR=/tmp 
}

set_pwd() {
WRKDIR=`pwd` 
}

# echo usage
show_help() {
        echo " update-blender "        
        echo " This script will download the latest stable release of blender "
        echo " and create a porteus module. "
        echo " A predownloaded tarball can also be used by placing it in /tmp" 
        echo " or your chosen directory(-d) which needs to be POSIX compatible."
        echo
	echo " options:  -d : do operations in the present directory, instead of /tmp . "
	echo "           -h : show this usage. " 
}

# echo script version
show_version() {
	echo " update-blender version: $SVER "
}

while getopts ":-d:-h:-v:" o; do
case "$1" in
 
    -d)
       set_pwd;;
    
    -h)
      show_help
      exit 0;;

    -v)
      show_version
      exit 0;;	
              
     *)
      show_help
      exit 1;;
    
esac
done
case "$1" in
      
    "")
      set_tmp;;
      
esac

# tell us where the work will be done
echo "Work will be done in: $WRKDIR "
 
## Check if there's enough working space
[ `df -l --output=avail $WRKDIR | tail -1` -lt 384000 ] && { red "There's not enough space to run this script"; exit 1; }

case `uname -m` in
	x86_64)
	ARCH=x86_64
	SUFFIX=64
	SARCH=x86_64
	;;
	*)
	ARCH=i686
	SUFFIX=
	SARCH=i586
	;;
esac


## functions for setting locale
array_menu(){
echo
echo "$1"
echo "$2"
select LOCALE in ${ARESULT[@]}; do
    if [ -z "$LOCALE" ]; then
        bold "English locale chosen." && echo
			else
		bold "$LOCALE locale chosen"
    fi
    break
done
}

get_locale(){
# Set locales in array
for a in ab ar ca cs de eo en-US es es_ES eu fa fr ha he hi hr hu id it ja ko ky nl pl pt pt-BR ru sk sr sr@latin sv th tr uk vi zh-CN zh-TW; do
	ARESULT+=( $a )
done
array_menu "Choose a locale from the list." 
unset ARESULT 
}

array_menu2(){
echo
echo "$1"
echo "$2"
select CHOICE1 in ${RESULT2[@]}; do
    if [ -z "$CHOICE1" ]; then
        bold "? release chosen." && echo
			else
		bold "$CHOICE1 release chosen"
    fi
    break
done
}

get_release_type(){
array_menu2 "Please choose a release from the menu." 
case $CHOICE1 in
	stable) URL=$URL1 ;;
    nightly-alpha) URL=$URL2 ;;
	nightly-beta) URL=$URL2 ;;
	*)
	echo "Invalid choice"
	$FUNCNAME
	;;
esac
}

cleanup(){
echo
rm -rf $TARG
[ -d $TMPDIR ] && rm -rf $TMPDIR
exit	
}
trap cleanup SIGHUP SIGINT SIGTERM

## (soft)checksum check
checksum () {
if [ -z $CHOICE ]; then	
echo "Verifying download integrity.."
echo "Server  : $SUM1"
echo "Download: $SUM2"
if [ "$SUM1" = "$SUM2" ]; then 
     echo "Download verified." 
else 
     echo "Warnig: Integrity check failed."
     echo "Continuing anyway.. if there's a problem, this could be it."
fi
fi
}

## Check for tarball in $WRKDIR
if [ `find ${WRKDIR}/blender* 2>/dev/null | wc -l` -ge 1 ]; then
	# Make sure it is a tarball
	cfile=( `find $WRKDIR/blender-*.bz2 2>/dev/null | awk -F/ '{print$NF}' ` )
	if [ ${#cfile[@]} -gt 0 ]; then
		RESULT=${cfile[@]}
		echo
		green "A blender tarball was found in $WRKDIR"
		echo " We will use this archive to create blender."
		menu_from_array "Choose the blender file you want to process."
		echo "CHOICE:$txtgreen $CHOICE $rst"
	fi
fi

TMPDIR=$WRKDIR/.blen.$$
CWD=`pwd`

## if x86_64 offer a choice of stable or nightly build, if not , don't
if [ -z $CHOICE ]; then
	if [ "$ARCH" = "x86_64" ]; then
		RESULT2+=( 'stable' 'nightly-alpha' 'nightly-beta' )
		get_release_type
	else
		CHOICE1="stable"
                URL=$URL1
	fi
fi
	
## get relevent version info
if [ -z $CHOICE ]; then		
	echo " Fetching latest Blender version info.."
	if [ "$CHOICE1" = "stable" ]; then
		VER=`lynx -dump --nonumbers --listonly $URL | grep -o "[0-9].[0-9][0-9]" | sort | tail -n1` 
		echo " Latest version is:" $txtgreen "$VER" $rst

	elif [ "$CHOICE1" = "nightly-alpha" ]; then 
		LVER=`lynx -dump --nonumbers --listonly $URL  | grep "linux" | sort | tail -n1 | cut -d"-" -f2,3`
		VER=${LVER%-*}
		echo " Latest version is:" $txtgreen "$LVER" $rst

        elif [ "$CHOICE1" = "nightly-beta" ]; then 
		LVER=`lynx -dump --nonumbers --listonly $URL  | grep "linux" | sort | head -n1 | cut -d"-" -f2,3`
		VER=${LVER%-*}
		echo " Latest version is:" $txtgreen "$LVER" $rst
	fi	
	
else
   if [ "`tr -dc '-' <<< $CHOICE | wc -c`" = "5" ]; then
      LVER=`cut -d"-" -f2,3 <<< $CHOICE`
      VER=${LVER%-*}
   elif [ "`tr -dc '-' <<< $CHOICE | wc -c`" = "4" ]; then
      LVER=`cut -d"-" -f2 <<< $CHOICE`
      VER=${LVER}
   else
      echo " Unable to get version info.. "
      echo " The tarball's name does not conform to known parameters. "
      echo " Exiting.."
      exit 1 
   fi      
fi

### some idea about 'rc' versions
#if [ `wc -m <<< $VER` -gt 4 ]; then
#	cut -c 1-4 <<< $VER
#fi 

## Determine glibc version supplied
if [ -z $CHOICE ]; then
	if [ "$ARCH" = "x86_64" ]; then
		GLIBC="-glibc217";
	else  
		GLIBC="-glibc224";
	fi
elif [ -n "`grep -o "glibc" <<< $CHOICE`" ]; then 
	GLIBC="-`awk -F"linux-" '{print$2}' <<< $CHOICE | cut -d- -f1`"
else 
	GLIBC=
fi


if [ -z $CHOICE ]; then
  read -p " Would you like to create a module of the latest version? [y/n]" -n 1 -r -s && echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then cleanup; fi  
else
  read -p " Would you like to continue with this tarball? [y/n]" -n 1 -r -s && echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then cleanup; fi
fi

get_locale

if [ -z $CHOICE ]; then 
	if [ "$URL" = "$URL1" ]; then
		EXT="tar.bz2"
		TAR="blender-${VER}-linux${GLIBC}-${ARCH}.${EXT}"
		SRC="blender-${VER}-linux${GLIBC}-${ARCH}"
		DURL="${URL}Blender${VER}/${TAR}"
		#VER2=`echo $VER | tr -d '.'` 
		SUM1=`lynx -dump --dont_wrap_pre $DURL/release${VER//./}.md5 | grep $TAR | cut -d" " -f1`
	elif [ "$URL" = "$URL2" ]; then
		EXT="tar.bz2"
		TAR="blender-${LVER}-linux${GLIBC}-${ARCH}.${EXT}"
		SRC="blender-${LVER}-linux${GLIBC}-${ARCH}"
	fi
fi

## Create temp dir
[ ! -d $TMPDIR ] && mkdir -p $TMPDIR || rm -rf "${TMPDIR:?}"
## download choice or copy existing
if [ -z $CHOICE ]; then
	if [ "$URL" = "$URL1" ]; then
		download $DURL $TMPDIR
	elif [ "$URL" = "$URL2" ]; then
	    download $URL/$TAR $TMPDIR
	fi
else 
   cp -a $WRKDIR/$CHOICE $TMPDIR
fi

## Check that we have an archive in TMPDIR
if [ -z $CHOICE ]; then
    if [ ! -f $TMPDIR/$TAR ]; then
		echo
		sayerror "File $TAR not found"
		cleanup
	fi
elif [ ! -f $TMPDIR/$CHOICE ]; then
	echo
	sayerror "File $CHOICE not found"
	cleanup    
fi

## checksum check
if [ -z "$URL" ] && [ "$URL" = "$URL1" ]; then 
	SUM2=`md5sum $TMPDIR/$TAR | cut -d" " -f1`
	checksum 
fi

## go to module build dir
cd $TMPDIR

if [ -z $CHOICE ]; then 
   tar xvf $TAR
else
   tar xvf $CHOICE
   SRC="blender-${LVER}-linux${GLIBC}-${ARCH}"
fi

echo " Locale is $LOCALE"
echo " Removing unwanted locales ..."
if [ "$LOCALE" != "en-US" ]; then
   find $SRC/$VER/datafiles/locale -type f -name "*" | egrep -v "${LOCALE}" | xargs -n1 -i rm {}
else      
   rm -rvf $SRC/$VER/datafiles/locale
fi

chown -R root:root $SRC
find -L . \
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
-o -perm 511 \) -exec chmod 755 {} \; -o \
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;


echo "making build directories.."
mkdir -p $TMPDIR/build/usr/share/applications
mkdir -p $TMPDIR/build/usr/bin
if [ "$PORTVER" = "v5.0" ]; then
	mkdir -p $TMPDIR/build/usr/lib$SUFFIX/python3.7
	mkdir -p $TMPDIR/build/opt/blender-$VER/$VER/python
else
	mkdir -p $TMPDIR/build/opt/blender-$VER/$VER
fi	

cd $TMPDIR/build

echo " copying the files we want.."
cp -a $TMPDIR/$SRC/$VER/datafiles opt/blender-$VER/$VER/
cp -a $TMPDIR/$SRC/$VER/scripts opt/blender-$VER/$VER/
cp -a $TMPDIR/$SRC/blender opt/blender-$VER/
cp -a $TMPDIR/$SRC/blender* opt/blender-$VER/
cp -a $TMPDIR/$SRC/*.txt opt/blender-$VER/
cp -a $TMPDIR/$SRC/readme.html opt/blender-$VER/
cp -a $TMPDIR/$SRC/icons opt/blender-$VER/
## don't use shipped libgl
#cp -a $TMPDIR/$SRC/lib opt/blender-$VER/
## move the .desktop to somewhere useful
mv opt/blender-$VER/blender.desktop usr/share/applications/

## use only the site-packages (porteus has the rest of python3.7) ..this is potentially messy if the user has some of these installed already...
## only do for porteus-v5.0
if [ "$PORTVER" = "v5.0" ]; then
	cp -a $TMPDIR/$SRC/$VER/python/lib/python3.7/site-packages usr/lib$SUFFIX/python3.7/
	echo " linking some stuff so blender can find them.."
	ln -s /usr/lib$SUFFIX opt/blender-$VER/$VER/python/lib
	ln -s /usr/bin opt/blender-$VER/$VER/python/bin
fi
## only do for porteus-v4.0
if [ "$PORTVER" = "v4.0" ]; then
	cp -a $TMPDIR/$SRC/$VER/python opt/blender-$VER/$VER/
fi

ln -s /opt/blender-$VER/blender usr/bin/blender

cd ${WRKDIR}

echo " Making module"
if [ -z $CHOICE ]; then 
	[ "$URL" = "$URL1" ] && dir2xzm $TMPDIR/build ${WRKDIR}/blender-${VER}-${ARCH}-${LOCALE}.xzm
	[ "$URL" = "$URL2" ] && dir2xzm $TMPDIR/build ${WRKDIR}/blender-${LVER}-${ARCH}-${LOCALE}.xzm
else
	dir2xzm $TMPDIR/build ${WRKDIR}/blender-${LVER}-${ARCH}-${LOCALE}.xzm
fi
echo " Your module is ready at ${WRKDIR}"
echo " Please move it to somewhere safe.."

cleanup

example contents of a blender module(for porteus 5):

Code: Select all

$ tree -L 5
.
├── opt
│   └── blender-2.81
│       ├── 2.81
│       │   ├── datafiles
│       │   │   ├── colormanagement
│       │   │   ├── fonts
│       │   │   ├── icons
│       │   │   └── studiolights
│       │   ├── python
│       │   │   ├── bin -> /usr/bin
│       │   │   └── lib -> /usr/lib64
│       │   └── scripts
│       │       ├── addons
│       │       ├── addons_contrib
│       │       ├── freestyle
│       │       ├── modules
│       │       ├── presets
│       │       ├── startup
│       │       ├── templates_osl
│       │       └── templates_py
│       ├── GPL-license.txt
│       ├── GPL3-license.txt
│       ├── LICENSE-bfont.ttf.txt
│       ├── LICENSE-bmonofont-i18n.ttf.txt
│       ├── LICENSE-droidsans.ttf.txt
│       ├── Python-license.txt
│       ├── blender
│       ├── blender-softwaregl
│       ├── blender-symbolic.svg
│       ├── blender-thumbnailer.py
│       ├── blender.svg
│       ├── copyright.txt
│       ├── icons
│       │   ├── scalable
│       │   │   └── apps
│       │   └── symbolic
│       │       └── apps
│       ├── jemalloc-license.txt
│       ├── ocio-license.txt
│       └── readme.html
└── usr
    ├── bin
    │   └── blender -> /opt/blender-2.81/blender
    ├── lib64
    │   └── python3.7
    │       └── site-packages
    │           ├── certifi
    │           ├── chardet
    │           ├── idna
    │           ├── libextern_draco.so
    │           ├── numpy
    │           ├── requests
    │           └── urllib3
    └── share
        └── applications
            └── blender.desktop
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 2255
Joined: 20 Mar 2012, 03:42
Distribution: 5.0rc1-64bit all-DE+more
Location: australia
Contact:

blender module build script

Post#2 by ncmprhnsbl » 23 Nov 2019, 05:51

updated to version 20191123 (see first post)
changes:
now offers choice of stable, nightly-alpha, nightly-beta(64 bit only, 32bit fetchs stable only)
note: alpha and beta will be the same after a stable release and then closer to the next release a new alpha will appear eg. 2.81(stable) 2.83-alpha and 2.82-beta
now supports porteus-4.0 (bundled python3 is included in the module)
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

Post Reply