). Questa è una pagina informativa: http://www.salixos.org/wiki/index.php/B ... h_slkbuildEcco un esempio di processo di costruzione di pacchetti: pacchetto goffice.
questo è il file SLKBUILD (la cui costruzione è lasciata all'utente):
- Codice: Seleziona tutto
#Maintainer: George Vlahavas <vlahavas~at~gmail~dot~com>
pkgname=goffice
pkgver=0.6.6
pkgrel=1gv
arch=i486
source=(http://ftp.gnome.org/pub/GNOME/sources/goffice/0.6/goffice-0.6.6.tar.bz2)
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo" "maintainers" "bugs")
slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"goffice - Gnome Office Library"
"goffice is a library of document-centric objects and utilities used"
"by Gnome Office."
)
build() {
cd $startdir/src/$pkgname-$pkgver
./configure --prefix=/usr --libdir=/usr/lib${LIBDIRSUFFIX} --localstatedir=/var --sysconfdir=/etc --disable-static --disable-gtk-doc
make || return 1
make install DESTDIR=$startdir/pkg
rm -rf $startdir/pkg/usr/share/gtk-doc
}
che si scarica in una directory, si naviga in quella directory e si dà il comando slkbuild, il quale genera il file build-goffice.sh, che altro non è che uno slackbuild (un po' diverso dagli slackbuilds classici), cioè uno script che costruisce il pacchetto:
- Codice: Seleziona tutto
#!/bin/bash
#Automatically Created by slkbuild 0.5
#Maintainer: George Vlahavas <vlahavas~at~gmail~dot~com>
######Begin Redundant Code######################################
check_for_root() {
if [ "$UID" != "0" ]; then
echo "You need to be root"
exit 1
fi
}
clean_dirs () {
for COMPLETED in src pkg; do
if [ -e $COMPLETED ]; then
rm -rf $COMPLETED
fi
done
}
clean_old_builds () {
rm -rf $package.{t[xlgb]z,md5}
clean_dirs
}
set_pre_permissions() {
cd $startdir/src
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
}
gzip_man_and_info_pages() {
for DOCS in man info; do
if [ -d "$startdir/pkg/usr/share/$DOCS" ]; then
mv $startdir/pkg/usr/share/$DOCS $startdir/pkg/usr/$DOCS
if [[ ! "$(ls $startdir/pkg/usr/share)" ]]; then
rm -rf $startdir/pkg/usr/share
fi
fi
if [ -d "$startdir/pkg/usr/$DOCS" ]; then
# I've never seen symlinks in info pages....
if [ "$DOCS" == "man" ]; then
(cd $startdir/pkg/usr/$DOCS
for manpagedir in $(find . -type d -name "man*" 2> /dev/null) ; do
( cd $manpagedir
for eachpage in $( find . -type l -maxdepth 1 2> /dev/null) ; do
ln -s $( readlink $eachpage ).gz $eachpage.gz
rm $eachpage
done )
done)
fi
find $startdir/pkg/usr/$DOCS -type f -exec gzip -9 '{}' \;
fi
done
[ -a $startdir/pkg/usr/info/dir.gz ] && rm -f $startdir/pkg/usr/info/dir.gz
}
set_post_permissions() {
for DIRS in usr/share/icons usr/doc; do
if [ -d "$startdir/pkg/$DIRS" ]; then
if [ "$DIRS" == "usr/doc" ]; then
find $startdir/pkg/$DIRS -type f -exec chmod 644 {} \;
find $startdir/pkg/$DIRS -type d -exec chmod 755 {} \;
fi
fi
[ -d $startdir/pkg/$DIRS ] && chown root:root -R $startdir/pkg/$DIRS
done
[ -d $startdir/pkg/usr/bin ] && find $startdir/pkg/usr/bin -user root -group bin -exec chown root:root {} \;
}
copy_build_script() {
mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver/
cp $startdir/build-$pkgname.sh $startdir/pkg/usr/src/$pkgname-$pkgver/build-$pkgname.sh
[ -f $startdir/SLKBUILD ] && cp $startdir/SLKBUILD $startdir/pkg/usr/src/$pkgname-$pkgver/SLKBUILD
}
create_package() {
ls -lR $startdir/pkg
cd $startdir/pkg
/sbin/makepkg -l y -c n $startdir/$package.txz
cd $startdir
md5sum $package.txz > $startdir/$package.md5
}
strip_binaries() {
cd $startdir/pkg
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \
xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \
xargs strip --strip-unneeded 2> /dev/null
}
#########End Redundant Code#####################################
#########Begin Non Redundant Code##############################
prepare_directory() {
mkdir $startdir/src
mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver
for SOURCES in ${source[@]}; do
protocol=$(echo $SOURCES | sed 's|:.*||')
file=$(basename $SOURCES | awk -F= '{print $NF}')
if [ ! -f "$file" ]; then
if [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
echo -e "\nDownloading $(basename $SOURCES)\n"
wget $SOURCES -O $file
if [ ! "$?" == "0" ]; then
echo "Download failed"
exit 2
fi
else
echo "$SOURCES does not appear to be a url nor is it in the directory"
exit 2
fi
fi
cp -R $file $startdir/src
if ! [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
cp -R $startdir/$(basename $SOURCES) $startdir/pkg/usr/src/$pkgname-$pkgver/
fi
done
}
extract_source() {
cd $startdir/src
if [[ "$(ls $startdir/src)" ]]; then
for FILES in ${source[@]}; do
FILES="$(basename $FILES | awk -F= '{print $NF}')"
file_type=$(file -biz "$FILES")
unset cmd
case "$file_type" in
*application/x-tar*)
cmd="tar -xf" ;;
*application/x-zip*)
cmd="unzip" ;;
*application/zip*)
cmd="unzip" ;;
*application/x-gzip*)
cmd="gunzip -d -f" ;;
*application/x-bzip*)
cmd="bunzip2 -f" ;;
*application/x-xz*)
cmd="xz -d -f" ;;
*application/x-lzma*)
cmd="lzma -d -f" ;;
esac
if [ "$cmd" != "" ]; then
echo "$cmd $FILES"
$cmd $FILES
fi
done
elif [ ! "$source" ]; then
echo -n "" # lame fix
else
echo "no files in the src directory $startdir/src"
exit 2
fi
}
build() {
cd $startdir/src/$pkgname-$pkgver
./configure --prefix=/usr --libdir=/usr/lib${LIBDIRSUFFIX} --localstatedir=/var --sysconfdir=/etc --disable-static --disable-gtk-doc
make || return 1
make install DESTDIR=$startdir/pkg
rm -rf $startdir/pkg/usr/share/gtk-doc
}
create_slackdesc() {
mkdir $startdir/pkg/install
cat <<"EODESC" >$startdir/pkg/install/slack-desc
goffice: goffice - Gnome Office Library
goffice:
goffice: goffice is a library of document-centric objects and utilities used
goffice: by Gnome Office.
goffice:
goffice:
goffice:
goffice:
goffice:
goffice:
goffice:
EODESC
}
copy_docs() {
for stuff in ${docs[@]}; do
if [ ! -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then
mkdir -p $startdir/pkg/usr/doc/$pkgname-$pkgver
fi
find $startdir/src -type f -iname "$stuff" -exec cp -R '{}' $startdir/pkg/usr/doc/$pkgname-$pkgver \;
done
}
create_source_file(){
[ -f $package.src ] && rm $package.src
if [ ! -z $sourcetemplate ]; then
echo $sourcetemplate/SLKBUILD >> $package.src
echo $sourcetemplate/build-$pkgname.sh >> $package.src
for SOURCES in ${source[@]}; do
protocol=$(echo $SOURCES | sed 's|:.*||')
if ! [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
if [ ! -z $sourcetemplate ]; then
echo $sourcetemplate/$(basename $SOURCES) >> $package.src
else
echo $(basename $SOURCES) >> $package.src
fi
else
echo $SOURCES >> $package.src
fi
done
fi
}
post_checks(){
# Ideas taken from src2pkg :)
if [ -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then
for DIRS in usr/doc/$pkgname-$pkgver usr/doc; do
cd $startdir/pkg/$DIRS
if [[ $(find . -type f) = "" ]] ; then
cd ..
rmdir $DIRS
fi
done
fi
# if the docs weren't deleted ...
if [ -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then
cd $startdir/pkg/usr/doc/$pkgname-$pkgver
#remove zero lenght files
if [[ $(find . -type f -size 0) ]]; then
echo "Removing some zero lenght files"
find . -type f -size 0 -exec rm -f {} \;
fi
fi
# check if we need to add code to handle info pages
if [[ -d $startdir/pkg/usr/info ]] && [[ ! $(grep install-info $startdir/pkg/install/doinst.sh &> /dev/null) ]] ; then
echo "Found info files - Adding install-info command to doinst.sh"
INFO_LIST=$(ls -1 $startdir/pkg/usr/info)
echo "" >> $startdir/pkg/install/doinst.sh
echo "if [ -x usr/bin/install-info ] ; then" >> $startdir/pkg/install/doinst.sh
for page in $(echo $INFO_LIST) ; do
echo " usr/bin/install-info --info-dir=usr/info usr/info/$page 2>/dev/null" >> $startdir/pkg/install/doinst.sh
done
echo "fi" >> $startdir/pkg/install/doinst.sh
fi
[[ -e $startdir/pkg/usr/info/dir ]] && rm -f $startdir/pkg/usr/info/dir
if [ -d $startdir/pkg/etc ]; then
cd $startdir/pkg/
for conf in $(find ./etc -type f) ; do
conf=${conf: 2}
dotnew=( "${dotnew[@]}" "$conf" )
done
fi
if [[ "$dotnew" ]]; then
for files in ${dotnew[@]} ; do
fullfile="${startdir}/pkg/${files}"
if [ -e "$fullfile" ]; then
mv $fullfile ${fullfile}.new
else
echo "$fullfile was not found"
exit 2
fi
done
cat<<"EODOTNEW" >>$startdir/pkg/install/doinst.sh
#Added by slkbuild 0.5
dotnew() {
NEW="${1}.new"
OLD="$1"
if [ ! -e $OLD ]; then
mv $NEW $OLD
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
rm $NEW
fi
}
EODOTNEW
for i in ${dotnew[@]}; do
echo "dotnew $i" >> $startdir/pkg/install/doinst.sh
done
fi
}
####End Non Redundant Code############################
#Variables
startdir=$(pwd)
SRC=$startdir/src
PKG=$startdir/pkg
pkgname=goffice
pkgver=0.6.6
pkgrel=1gv
arch=i486
package=$pkgname-$pkgver-$arch-1gv
source=("http://ftp.gnome.org/pub/GNOME/sources/goffice/0.6/goffice-0.6.6.tar.bz2")
docs=(readme install copying changelog authors news todo maintainers bugs)
export CFLAGS="-O2 -march=i486 -mtune=i686"
export CXXFLAGS="-O2 -march=i486 -mtune=i686"
#Execution
check_for_root
clean_old_builds
prepare_directory
extract_source
set_pre_permissions
build
if [ ! "$?" = "0" ]; then
echo "build() failed."
exit 2
fi
create_slackdesc
post_checks
copy_docs
strip_binaries
gzip_man_and_info_pages
set_post_permissions
copy_build_script
create_package
create_source_file
echo "Package has been built."
echo "Cleaning pkg and src directories"
clean_dirs
a questo punto si esegue ed il gioco è fatto. Il pacchetto viene creato nella stessa directory di lavoro.
Chiaramente il file build-nomepacchetto.sh viene creato in base a come è fatto lo SLKBUILD, in particolar modo la sezione "build" dove si gioca tutto. Esistono infatti SLKBUILD anche molto complessi, in cui vengono applicate diverse patch e devono essere eseguiti diversi comandi postinstall, come questo (virtualbox):
- Codice: Seleziona tutto
#Maintainer: Richard Lapointe <richard@laprjns.com>
#Former Maintainer(s): Name <email@address.com>
#Anything commented out is optional and can be deleted.
pkgname=VirtualBox
pkgver=3.0.12
pkgrel=1rl
arch=i486
source=(http://download.virtualbox.org/virtualbox/$pkgver/$pkgname-${pkgver}-OSE.tar.bz2 \
http://download.virtualbox.org/virtualbox/$pkgver/VBoxGuestAdditions_$pkgver.iso \
http://download.virtualbox.org/virtualbox/$pkgver/UserManual.pdf \
vboxusers_to_users.patch \
no_registration.patch)
sourcetemplate=http://people.salixos.org/laprjns/virtualbox/$pkgver/
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo")
url=http://www.virtualbox.org/
#dotnew=()
#CFLAGS=
#CXXFLAGS=
options=('noautodotnew')
doinst() {
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VirtualBox
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxHeadless
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxSDL
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxNetAdpCtl
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxNetDHCP
rmmod vboxnetadp vboxnetflt vboxdrv
depmod
/etc/rc.d/rc.vboxdrv start
}
slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"VirtualBox OSE Edition."
"VirtualBox is a family of powerful x86 virtualization products for"
"enterprise as well as home use. Not only is VirtualBox an extremely"
"feature rich, high performance product for enterprise customers,it is"
"also the only professional solution that is freely available as Open"
"Source Software under the terms of the GNU General Public License."
""
)
build() {
#Prepare the package directories
mkdir -p $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE
mkdir -p $startdir/pkg/usr/bin
mkdir -p $startdir/pkg/etc/vbox
mkdir -p $startdir/pkg/etc/rc.d
mkdir -p $startdir/pkg/lib/modules/$(uname -r)/misc
mkdir -p $startdir/pkg/usr/share/applications
# patch the source tree for change from vboxusers to users
cd $startdir/src/$pkgname-${pkgver}_OSE
patch -p1 < ../../vboxusers_to_users.patch
patch -p1 < ../../no_registration.patch
cat <<EOF >LocalConfig.kmk
# shut up wine complaining about unknown locale
EXEC_X86_WIN32 := wine
# don't build testcases to save time, they are not needed for the package
VBOX_WITH_TESTCASES :=
VBOX_WITH_TESTSUITE :=
VBOX_DOCBOOK_WITH_LATEX :=
VBOX_WITHOUT_DOCS := 1
KBUILD_MSG_STYLE := brief
VBOX_WITH_HARDENING := 1
VBOX_WITH_ORIGIN :=
VBOX_PATH_APP_PRIVATE_ARCH := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_PATH_SHARED_LIBS := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_WITH_RUNPATH := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_PATH_APP_PRIVATE := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_PATH_APP_DOCS := /usr/doc/$pkgname-${pkgver}_OSE
EOF
# Compile the application
cd $startdir/src/$pkgname-${pkgver}_OSE
./configure \
--disable-pulse
source ./env.sh
kmk all || return 1
# Build kernel modules
cd $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/src
make
#Remove unneed stuff
cd $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/
rm -rf sdk tst* testcase SUPInstall SUPUninstall
rm -rf *.png *.desktop *.tar.gz
# Move the binary's and modules to the package directorys
cp -rf $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/src/*.ko $startdir/pkg/lib/modules/$(uname -r)/misc
cp -rf $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/* $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE
cp -rf $startdir/VBoxGuestAdditions_${pkgver}.iso $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE/VBoxGuestAdditions.iso
install -m 755 $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Installer/linux/vboxdrv.sh.in $startdir/pkg/etc/rc.d/rc.vboxdrv
install -m 755 $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Installer/linux/VBox.sh $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE/VBox.sh
cp -rf $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Installer/linux/virtualbox.desktop $startdir/pkg/usr/share/applications/virtualbox.desktop
cp -rf $startdir/UserManual.pdf $startdir/src/$pkgname-${pkgver}_OSE
rm -f $startdir/pkg/usr/src/$pkgname-${pkgver}_OSE/$pkgname-${pkgver}-OSE.tar.bz2
# set
# need to insert package installation path in vboc.cfg
echo "# VirtualBox installation directory" > $startdir/pkg/etc/vbox/vbox.cfg
echo "INSTALL_DIR='/usr/lib/$pkgname-${pkgver}_OSE'" >> $startdir/pkg/etc/vbox/vbox.cfg
# Copy icons to the right place
ICONSIZES="48 32 16"
for i in $ICONSIZES; do
mkdir -p $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps;
mv $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_${i}px.png $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps/VBox.png;
done;
(cd $startdir/pkg/usr/bin/
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VirtualBox
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxManage
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxHeadless
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxSDL
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxVRDP
cd $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE/components
)
}
che genera questo script (build-VirtualBox.sh):
- Codice: Seleziona tutto
#!/bin/bash
#Automatically Created by slkbuild 0.5.1
#Maintainer: Richard Lapointe <richard@laprjns.com>
#Former Maintainer(s): Name <email@address.com>
#url: http://www.virtualbox.org/
######Begin Redundant Code######################################
check_for_root() {
if [ "$UID" != "0" ]; then
echo "You need to be root"
exit 1
fi
}
clean_dirs () {
for COMPLETED in src pkg; do
if [ -e $COMPLETED ]; then
rm -rf $COMPLETED
fi
done
}
clean_old_builds () {
rm -rf $package.{t[xlgb]z,md5}
clean_dirs
}
set_pre_permissions() {
cd $startdir/src
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
}
gzip_man_and_info_pages() {
for DOCS in man info; do
if [ -d "$startdir/pkg/usr/share/$DOCS" ]; then
mv $startdir/pkg/usr/share/$DOCS $startdir/pkg/usr/$DOCS
if [[ ! "$(ls $startdir/pkg/usr/share)" ]]; then
rm -rf $startdir/pkg/usr/share
fi
fi
if [ -d "$startdir/pkg/usr/$DOCS" ]; then
# I've never seen symlinks in info pages....
if [ "$DOCS" == "man" ]; then
(cd $startdir/pkg/usr/$DOCS
for manpagedir in $(find . -type d -name "man*" 2> /dev/null) ; do
( cd $manpagedir
for eachpage in $( find . -type l -maxdepth 1 2> /dev/null) ; do
ln -s $( readlink $eachpage ).gz $eachpage.gz
rm $eachpage
done )
done)
fi
find $startdir/pkg/usr/$DOCS -type f -exec gzip -9 '{}' \;
fi
done
[ -a $startdir/pkg/usr/info/dir.gz ] && rm -f $startdir/pkg/usr/info/dir.gz
}
set_post_permissions() {
for DIRS in usr/share/icons usr/doc; do
if [ -d "$startdir/pkg/$DIRS" ]; then
if [ "$DIRS" == "usr/doc" ]; then
find $startdir/pkg/$DIRS -type f -exec chmod 644 {} \;
find $startdir/pkg/$DIRS -type d -exec chmod 755 {} \;
fi
fi
[ -d $startdir/pkg/$DIRS ] && chown root:root -R $startdir/pkg/$DIRS
done
[ -d $startdir/pkg/usr/bin ] && find $startdir/pkg/usr/bin -user root -group bin -exec chown root:root {} \;
}
copy_build_script() {
mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver/
cp $startdir/build-$pkgname.sh $startdir/pkg/usr/src/$pkgname-$pkgver/build-$pkgname.sh
[ -f $startdir/SLKBUILD ] && cp $startdir/SLKBUILD $startdir/pkg/usr/src/$pkgname-$pkgver/SLKBUILD
}
create_package() {
ls -lR $startdir/pkg
cd $startdir/pkg
/sbin/makepkg -l y -c n $startdir/$package.txz
cd $startdir
md5sum $package.txz > $startdir/$package.md5
}
strip_binaries() {
cd $startdir/pkg
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \
xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \
xargs strip --strip-unneeded 2> /dev/null
}
#########End Redundant Code#####################################
#########Begin Non Redundant Code##############################
prepare_directory() {
mkdir $startdir/src
mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver
for SOURCES in ${source[@]}; do
protocol=$(echo $SOURCES | sed 's|:.*||')
file=$(basename $SOURCES | awk -F= '{print $NF}')
if [ ! -f "$file" ]; then
if [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
echo -e "\nDownloading $(basename $SOURCES)\n"
wget $SOURCES -O $file
if [ ! "$?" == "0" ]; then
echo "Download failed"
exit 2
fi
else
echo "$SOURCES does not appear to be a url nor is it in the directory"
exit 2
fi
fi
cp -R $file $startdir/src
if ! [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
cp -R $startdir/$(basename $SOURCES) $startdir/pkg/usr/src/$pkgname-$pkgver/
fi
done
}
extract_source() {
cd $startdir/src
if [[ "$(ls $startdir/src)" ]]; then
for FILES in ${source[@]}; do
FILES="$(basename $FILES | awk -F= '{print $NF}')"
file_type=$(file -biz "$FILES")
unset cmd
case "$file_type" in
*application/x-tar*)
cmd="tar -xf" ;;
*application/x-zip*)
cmd="unzip" ;;
*application/zip*)
cmd="unzip" ;;
*application/x-gzip*)
cmd="gunzip -d -f" ;;
*application/x-bzip*)
cmd="bunzip2 -f" ;;
*application/x-xz*)
cmd="xz -d -f" ;;
*application/x-lzma*)
cmd="lzma -d -f" ;;
esac
if [ "$cmd" != "" ]; then
echo "$cmd $FILES"
$cmd $FILES
fi
done
elif [ ! "$source" ]; then
echo -n "" # lame fix
else
echo "no files in the src directory $startdir/src"
exit 2
fi
}
build() {
#Prepare the package directories
mkdir -p $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE
mkdir -p $startdir/pkg/usr/bin
mkdir -p $startdir/pkg/etc/vbox
mkdir -p $startdir/pkg/etc/rc.d
mkdir -p $startdir/pkg/lib/modules/$(uname -r)/misc
mkdir -p $startdir/pkg/usr/share/applications
# patch the source tree for change from vboxusers to users
cd $startdir/src/$pkgname-${pkgver}_OSE
patch -p1 < ../../vboxusers_to_users.patch
patch -p1 < ../../no_registration.patch
cat <<EOF >LocalConfig.kmk
# shut up wine complaining about unknown locale
EXEC_X86_WIN32 := wine
# don't build testcases to save time, they are not needed for the package
VBOX_WITH_TESTCASES :=
VBOX_WITH_TESTSUITE :=
VBOX_DOCBOOK_WITH_LATEX :=
VBOX_WITHOUT_DOCS := 1
KBUILD_MSG_STYLE := brief
VBOX_WITH_HARDENING := 1
VBOX_WITH_ORIGIN :=
VBOX_PATH_APP_PRIVATE_ARCH := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_PATH_SHARED_LIBS := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_WITH_RUNPATH := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_PATH_APP_PRIVATE := /usr/lib/$pkgname-${pkgver}_OSE
VBOX_PATH_APP_DOCS := /usr/doc/$pkgname-${pkgver}_OSE
EOF
# Compile the application
cd $startdir/src/$pkgname-${pkgver}_OSE
./configure \
--disable-pulse
source ./env.sh
kmk all || return 1
# Build kernel modules
cd $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/src
make
#Remove unneed stuff
cd $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/
rm -rf sdk tst* testcase SUPInstall SUPUninstall
rm -rf *.png *.desktop *.tar.gz
# Move the binary's and modules to the package directorys
cp -rf $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/src/*.ko $startdir/pkg/lib/modules/$(uname -r)/misc
cp -rf $startdir/src/$pkgname-${pkgver}_OSE/out/linux.x86/release/bin/* $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE
cp -rf $startdir/VBoxGuestAdditions_${pkgver}.iso $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE/VBoxGuestAdditions.iso
install -m 755 $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Installer/linux/vboxdrv.sh.in $startdir/pkg/etc/rc.d/rc.vboxdrv
install -m 755 $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Installer/linux/VBox.sh $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE/VBox.sh
cp -rf $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Installer/linux/virtualbox.desktop $startdir/pkg/usr/share/applications/virtualbox.desktop
cp -rf $startdir/UserManual.pdf $startdir/src/$pkgname-${pkgver}_OSE
rm -f $startdir/pkg/usr/src/$pkgname-${pkgver}_OSE/$pkgname-${pkgver}-OSE.tar.bz2
# set
# need to insert package installation path in vboc.cfg
echo "# VirtualBox installation directory" > $startdir/pkg/etc/vbox/vbox.cfg
echo "INSTALL_DIR='/usr/lib/$pkgname-${pkgver}_OSE'" >> $startdir/pkg/etc/vbox/vbox.cfg
# Copy icons to the right place
ICONSIZES="48 32 16"
for i in $ICONSIZES; do
mkdir -p $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps;
mv $startdir/src/$pkgname-${pkgver}_OSE/src/VBox/Frontends/VirtualBox/images/OSE/VirtualBox_${i}px.png $startdir/pkg/usr/share/icons/hicolor/$i\x$i/apps/VBox.png;
done;
(cd $startdir/pkg/usr/bin/
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VirtualBox
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxManage
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxHeadless
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxSDL
ln -sf ../lib/$pkgname-${pkgver}_OSE/VBox.sh VBoxVRDP
cd $startdir/pkg/usr/lib/$pkgname-${pkgver}_OSE/components
)
}
create_slackdesc() {
mkdir $startdir/pkg/install
cat <<"EODESC" >$startdir/pkg/install/slack-desc
VirtualBox: VirtualBox OSE Edition.
VirtualBox:
VirtualBox: VirtualBox is a family of powerful x86 virtualization products for
VirtualBox: enterprise as well as home use. Not only is VirtualBox an extremely
VirtualBox: feature rich, high performance product for enterprise customers,it is
VirtualBox: also the only professional solution that is freely available as Open
VirtualBox: Source Software under the terms of the GNU General Public License.
VirtualBox:
VirtualBox:
VirtualBox:
VirtualBox:
EODESC
}
setup_doinst() {
cat <<"EODOINST" >>$startdir/pkg/install/doinst.sh
doinst() {
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VirtualBox
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxHeadless
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxSDL
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxNetAdpCtl
chmod 4511 usr/lib/VirtualBox-3.0.12_OSE/VBoxNetDHCP
rmmod vboxnetadp vboxnetflt vboxdrv
depmod
/etc/rc.d/rc.vboxdrv start
}
doinst
EODOINST
}
copy_docs() {
for stuff in ${docs[@]}; do
if [ ! -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then
mkdir -p $startdir/pkg/usr/doc/$pkgname-$pkgver
fi
find $startdir/src -type f -iname "$stuff" -exec cp -R '{}' $startdir/pkg/usr/doc/$pkgname-$pkgver \;
done
}
create_source_file(){
[ -f $package.src ] && rm $package.src
if [ ! -z $sourcetemplate ]; then
echo $sourcetemplate/SLKBUILD >> $package.src
echo $sourcetemplate/build-$pkgname.sh >> $package.src
for SOURCES in ${source[@]}; do
protocol=$(echo $SOURCES | sed 's|:.*||')
if ! [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
if [ ! -z $sourcetemplate ]; then
echo $sourcetemplate/$(basename $SOURCES) >> $package.src
else
echo $(basename $SOURCES) >> $package.src
fi
else
echo $SOURCES >> $package.src
fi
done
fi
}
post_checks(){
# Ideas taken from src2pkg :)
if [ -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then
for DIRS in usr/doc/$pkgname-$pkgver usr/doc; do
cd $startdir/pkg/$DIRS
if [[ $(find . -type f) = "" ]] ; then
cd ..
rmdir $DIRS
fi
done
fi
# if the docs weren't deleted ...
if [ -d "$startdir/pkg/usr/doc/$pkgname-$pkgver" ]; then
cd $startdir/pkg/usr/doc/$pkgname-$pkgver
#remove zero lenght files
if [[ $(find . -type f -size 0) ]]; then
echo "Removing some zero lenght files"
find . -type f -size 0 -exec rm -f {} \;
fi
fi
# check if we need to add code to handle info pages
if [[ -d $startdir/pkg/usr/info ]] && [[ ! $(grep install-info $startdir/pkg/install/doinst.sh &> /dev/null) ]] ; then
echo "Found info files - Adding install-info command to doinst.sh"
INFO_LIST=$(ls -1 $startdir/pkg/usr/info)
echo "" >> $startdir/pkg/install/doinst.sh
echo "if [ -x usr/bin/install-info ] ; then" >> $startdir/pkg/install/doinst.sh
for page in $(echo $INFO_LIST) ; do
echo " usr/bin/install-info --info-dir=usr/info usr/info/$page 2>/dev/null" >> $startdir/pkg/install/doinst.sh
done
echo "fi" >> $startdir/pkg/install/doinst.sh
fi
[[ -e $startdir/pkg/usr/info/dir ]] && rm -f $startdir/pkg/usr/info/dir
}
####End Non Redundant Code############################
#Variables
startdir=$(pwd)
SRC=$startdir/src
PKG=$startdir/pkg
pkgname=VirtualBox
pkgver=3.0.12
pkgrel=1rl
arch=i486
package=$pkgname-$pkgver-$arch-1rl
source=("http://download.virtualbox.org/virtualbox/3.0.12/VirtualBox-3.0.12-OSE.tar.bz2" "http://download.virtualbox.org/virtualbox/3.0.12/VBoxGuestAdditions_3.0.12.iso" "http://download.virtualbox.org/virtualbox/3.0.12/UserManual.pdf" "vboxusers_to_users.patch" "no_registration.patch")
sourcetemplate=http://people.salixos.org/laprjns/virtualbox/3.0.12
docs=(readme install copying changelog authors news todo)
export CFLAGS="-O2 -march=i486 -mtune=i686"
export CXXFLAGS="-O2 -march=i486 -mtune=i686"
#Execution
check_for_root
clean_old_builds
prepare_directory
extract_source
set_pre_permissions
build
if [ ! "$?" = "0" ]; then
echo "build() failed."
exit 2
fi
create_slackdesc
post_checks
setup_doinst
copy_docs
strip_binaries
gzip_man_and_info_pages
set_post_permissions
copy_build_script
create_package
create_source_file
echo "Package has been built."
allora che ne pensate?



