#!/bin/sh
# SBo_get.sh - copyleft Fabio Zorba 2015
# rev. 0.3 2015-01-23 - checks up to 50 dependencies, now
# get SlackBuilds and sources from SBo,
# make and install Slackware packages
 
if test $# -ne 1
then
 echo "Usage: $0 http://slackbuilds.org/repository/{slackware-version}/{category}/{slackbuild_name}"
 exit 1
fi
 
SITEBASE=http://slackbuilds.org
 
if [ ! -d ./slackbuilds ] ; then
 mkdir -p ./slackbuilds
fi
 
IFS=
INDEX_HTML=`wget -q -O - $1/`
 
N=1
while [ $N -le 50 ]
do
 K=$(($N*2))
 REQU[$N]=`echo $INDEX_HTML  | grep requires | grep -o -P '(?<=href=).*(?=</a>)' | cut -d"'" -f$K`
 N=$(($N+1))
done
 
SLACKBUILD=`echo $INDEX_HTML | grep "Download SlackBuild" | grep -o -P '(?<=href=).*(?=</a>)' | cut -d'"' -f2`
FILE_NAME=`echo $SLACKBUILD | rev | cut -d'/' -f1 | rev`
BUILD_DIR=`echo $FILE_NAME | cut -d'.' -f1`
 
SLACKBUILD=`echo $INDEX_HTML | grep "Download SlackBuild" | grep -o -P '(?<=href=).*(?=</a>)' | cut -d'"' -f2`
 
SOURCE=`echo $INDEX_HTML | grep "Source Download" | grep -o -P '(?<=href=).*(?=</a>)' | cut -d'"' -f2`
 
echo "Package: $BUILD_DIR"
echo "---------------------------------------------"
echo "Slackbuild: $SLACKBUILD $FILE_NAME"
echo "Source: $SOURCE"
echo
 
N=1
while [ $N -le 50 ]
do
 if [ "a${REQU[$N]}" != "a" ] ; then
  echo "Require: $SITEBASE${REQU[$N]}"
  $0 $SITEBASE${REQU[$N]}
 fi
 N=$(($N+1))
done
 
PKG=`ls -1 ./slackbuilds/$BUILD_DIR/$BUILD_DIR-*.tgz 2>/dev/null`
 
if [ "a$PKG" != "a" ] ; then
 echo  "Package: $BUILD_DIR exists. Skipping ..."
 exit
fi
 
wget --no-check-certificate -c $SLACKBUILD -P ./slackbuilds
 
tar -C ./slackbuilds -xzf ./slackbuilds/$FILE_NAME
 
wget --no-check-certificate -c $SOURCE -P ./slackbuilds/$BUILD_DIR
 
cd ./slackbuilds/$BUILD_DIR
./$BUILD_DIR.SlackBuild
 
PKG=`ls -1 /tmp/$BUILD_DIR-*.tgz`
 
cp $PKG .
 
upgradepkg --install-new $PKG
Retrieved from "http://www.zoros.org/wiki/index.php?title=Slackbuilds_get_source_code"