LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-26-2016, 11:38 PM   #1
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
Script to check for SBo updates


EDIT: The script became more than just an update checker. It will be kept updated in post #14 in case anyone wants to use it. Last update: 5/2/16.

Hey all,

I know a lot of people use sbopkg to keep their Slackbuilds up-to-date. I don't use it, as I like to maintain them a little more manually. I made a simple script to check whether new versions are available. It's definitely not intended to be a replacement for sbopkg or anything like that. It's just something that I threw together in the last couple hours, and it fills my need so I thought I would share it. First, a few facts about how it works:

1) The basic mechanism is to download the {slackbuild}.info file and compare it to the current one that you must have stored on your system. It doesn't check to see if the package is actually installed.
2) You have to maintain a directory tree mimicking the one on SBo, and the {slackbuild}.info files are stored there. For example, I have desktop/screenfetch/screenfetch.info and system/wine/wine.info. I personally keep this directory tree under /var/cache/packages/SBo.
3) The repo variable is used to point to either the official SBo site (if you are on -stable) or ponce's github repository (if you are on -current). Just uncomment the appropriate line.

Here is the script:
Code:
#!/bin/bash                                                                                                                                                                                           
                                                                                                                                                                                                      
cdir=/var/cache/packages/SBo                                                                                                                                                                          
#repo=https://slackbuilds.org/slackbuilds/14.1                                                                                                                                                        
repo=https://github.com/Ponce/slackbuilds/raw/current                                                                                                                                                 
                                                                                                                                                                                                      
# Go to top-level SBo directory                                                                                                                                                                       
cd $cdir                                                                                                                                                                                              
                                                                                                                                                                                                      
# Initialize counters                                                                                                                                                                                 
oldcount=0                                                                                                                                                                                            
currentcount=0                                                                                                                                                                                        
                                                                                                                                                                                                      
# Loop through directories (these are the categories)                                                                                                                                                 
for category in $(find . -type d -maxdepth 1)                                                                                                                                                         
do                                                                                                                                                                                                    
                                                                                                                                                                                                      
  # Skip '.' directory                                                                                                                                                                                
  if [ "$category" != "." ]; then

    # Strip off leading ./ characters
    category=${category:2}

    # Go to category directory
    cd $cdir/$category    

    # Loop through build directories within each category
    for build in $(find . -type d -maxdepth 1)
    do

      # Skip '.' directory
      if [ "$build" != "." ]; then

        # Strip off ./ characters
        build=${build:2}

        echo "Checking $build for updates..."

        # Go to build directory and download .info file
        # Suppress stdout and stderr, but print any 404 messages
        cd $cdir/$category/$build
        wget -O $build.info.tmp $repo/$category/$build/$build.info 2>&1 > /dev/null | grep -i "404"

        # Compare installed version and version from repo
        installed=$(grep VERSION $build.info | sed 's/VERSION=//')
        current=$(grep VERSION $build.info.tmp | sed 's/VERSION=//')

        # Notify whether up-to-date and store in arrays
        if [ "$installed" != "$current" ]; then
          echo "$build is outdated."
          echo "Installed version: $installed"
          echo "Current version: $current"
          outdated["$oldcount"]=$build
          oldver["$oldcount"]=$installed
          newver["$oldcount"]=$current
          oldcount=$(expr $oldcount + 1)
          echo
        else
          echo "$build is up-to-date."
          uptodate["$currentcount"]=$build
          currentcount=$(expr $currentcount + 1)
          echo
        fi

        # Remove temporary .info file
        rm $build.info.tmp

      fi
    done
  fi
done

# Print summaries

echo "Summary:"
echo
echo "$currentcount Slackbuilds are up-to-date."
echo "-------------------------------------------------------------------------"
i=0
while [ $i -lt $currentcount ]
do
  echo "Name: ${uptodate[$i]}"
  i=$(expr $i + 1)
done

echo
echo "$oldcount Slackbuilds are outdated."
echo "-------------------------------------------------------------------------"
i=0
while [ $i -lt $oldcount ]
do
  echo "Name: ${outdated[$i]}"
  echo "Installed version: ${oldver[$i]}"
  echo "Current version: ${newver[$i]}"
  echo
  i=$(expr $i + 1)
done
Here is sample output:
Code:
Checking acpica for updates...
acpica is up-to-date.

Checking jdk for updates...
jdk is outdated.
Installed version: "8u77"
Current version: "8u92"

Checking screenfetch for updates...
screenfetch is up-to-date.

Checking kfaenza-icon-theme for updates...
kfaenza-icon-theme is up-to-date.

Checking QtCurve-Gtk2 for updates...
QtCurve-Gtk2 is up-to-date.

Checking kde-gtk-config for updates...
kde-gtk-config is up-to-date.

Checking homerun for updates...
homerun is up-to-date.

Checking QtCurve-KDE4 for updates...
QtCurve-KDE4 is up-to-date.

Checking keepassx for updates...
keepassx is up-to-date.

Checking libreoffice for updates...
libreoffice is up-to-date.

Checking google-droid-fonts for updates...
google-droid-fonts is up-to-date.

Checking cabextract for updates...
cabextract is up-to-date.

Checking winetricks for updates...
winetricks is up-to-date.

Checking wine for updates...
wine is up-to-date.

Checking virtualbox for updates...
virtualbox is up-to-date.

Checking virtualbox-kernel for updates...
virtualbox-kernel is up-to-date.

Checking TLP for updates...
TLP is up-to-date.

Checking qupzilla for updates...
qupzilla is outdated.
Installed version: "1.8.9"
Current version: "1.8.6"

Checking libmpeg2 for updates...
libmpeg2 is up-to-date.

Checking qt5 for updates...
qt5 is up-to-date.

Checking yajl for updates...
yajl is up-to-date.

Checking libmicrohttpd for updates...
libmicrohttpd is up-to-date.

Checking tinyxml for updates...
tinyxml is up-to-date.

Checking libass for updates...
libass is up-to-date.

Checking flashplayer-plugin for updates...
flashplayer-plugin is up-to-date.

Checking kodi for updates...
kodi is up-to-date.

Summary:

24 Slackbuilds are up-to-date.
-------------------------------------------------------------------------
Name: acpica
Name: screenfetch
Name: kfaenza-icon-theme
Name: QtCurve-Gtk2
Name: kde-gtk-config
Name: homerun
Name: QtCurve-KDE4
Name: keepassx
Name: libreoffice
Name: google-droid-fonts
Name: cabextract
Name: winetricks
Name: wine
Name: virtualbox
Name: virtualbox-kernel
Name: TLP
Name: libmpeg2
Name: qt5
Name: yajl
Name: libmicrohttpd
Name: tinyxml
Name: libass
Name: flashplayer-plugin
Name: kodi

2 Slackbuilds are outdated.
-------------------------------------------------------------------------
Name: jdk
Installed version: "8u77"
Current version: "8u92"

Name: qupzilla
Installed version: "1.8.9"
Current version: "1.8.6"
You may notice that it says that qupzilla is outdated, when I actually have installed a newer version than is on SBo. That's because if the two VERSION= strings are different, it assumes the local one is outdated. One other thing is that the wget output is suppressed, but if there are any 404 errors in downloading the {slackbuild}.info file, they will be displayed. (This would occur if you misspelled a package name or placed it in the wrong category.)

I'm open to suggestions for how to improve the script. One idea is to also display which Slackbuilds depend on an outdated version. Or, if you think this is useless, that's fine too, but I hope not.

Last edited by montagdude; 05-01-2016 at 11:10 PM.
 
Old 04-27-2016, 02:56 AM   #2
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Wat?

Use git dude
 
Old 04-27-2016, 04:53 AM   #3
ChrisAbela
Member
 
Registered: Mar 2008
Location: Malta
Distribution: Slackware
Posts: 572

Rep: Reputation: 154Reputation: 154
I do meddle in SBo-experience-enhancing scripts myself and so I admire your effort. Indeed the SBo repository (like Slackware itself) is highly enticing to individuals with some programming skills especially for shell enthusiasts. This is something very unique to Slackware (I think).

It appears that your script manages to perform its intended function. However do appreciate that sbopkg already provides this function and it considers only installed packages. Nevertheless, you decided to implement your own solution and that is still fun. Your specific scenario is unique as you replicate the SBo tree and compare it with an "official" one. Normally I expect users to sync their tree with an "official" one, and then implement dependency customisation in their SBo queue files. Your solution is intersting but I expect that it is quite labour intensive to manage, perhaps that is what led to this script.

The script is fine for me. My comments are purely subjective so please do not loose sleep on any of them.

1. I would have preferred to exclude the expr command.

Consider this: let 'oldcount+=1'

2. I would have named all my variables in CAPITALS. This seems to be standard practice.

2. I would also have included some functions rather than duplicate code (if possible).

3. I would have avoided temporary files if possible. This is rather challenging but you may try.

4. I think that you included dimensions, right? I would have avoided dimensions unless you really need them.

5. I would have included a function to check if a package is installed, like this:

Quote:

function check_installed() {
# Check if the package is installed
VLP=$( basename $( ls /var/log/packages/${1}* 2>/dev/null |\
grep "${1}-[^-]*-[^-]*-[^-]*$" |\
sed "s/-[^-]*-[^-]*-[^-]*$//" ) 2>/dev/null )
if [ "$VLP" != "$1" ]; then
# $1 is not installed
echo "$1 is not installed"
fi
}

check_installed package_name

Chris

Last edited by ChrisAbela; 04-27-2016 at 04:58 AM.
 
2 members found this post helpful.
Old 04-27-2016, 07:17 AM   #4
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Original Poster
Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
Quote:
Originally Posted by 55020 View Post
Wat?

Use git dude
I use git for my own projects, but didn't think it would be the best choice for what I wanted to do. The main reason is that I don't want to mirror the whole repository with thousands of packages, but rather just the few that I actually use. Is there a way to do that with git? And if you can, would you just do a git pull and git diff to determine which ones are out of date? It still seems like a simple script would be better for this particular task, but I'm trying to learn here.
 
Old 04-27-2016, 07:27 AM   #5
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Original Poster
Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
Quote:
Originally Posted by ChrisAbela View Post
I do meddle in SBo-experience-enhancing scripts myself and so I admire your effort. Indeed the SBo repository (like Slackware itself) is highly enticing to individuals with some programming skills especially for shell enthusiasts. This is something very unique to Slackware (I think).

It appears that your script manages to perform its intended function. However do appreciate that sbopkg already provides this function and it considers only installed packages. Nevertheless, you decided to implement your own solution and that is still fun. Your specific scenario is unique as you replicate the SBo tree and compare it with an "official" one. Normally I expect users to sync their tree with an "official" one, and then implement dependency customisation in their SBo queue files. Your solution is intersting but I expect that it is quite labour intensive to manage, perhaps that is what led to this script.
I do have a bit of experience programming in several different languages, but my BASH scripting knowledge is rather limited in comparison. That was one of the reasons I wanted to do this. It is definitely not intended to replace sbopkg, and I realize sbopkg will already do this function and probably better than my script does. But this works for me, and not using a more automated tool for managing the Slackbuilds gives me a little more room to tinker. It is definitely more work, though, but it's not really that bad for me considering I only have a couple dozen Slackbuilds installed.

Quote:
Originally Posted by ChrisAbela View Post
The script is fine for me. My comments are purely subjective so please do not loose sleep on any of them.

1. I would have preferred to exclude the expr command.

Consider this: let 'oldcount+=1'

2. I would have named all my variables in CAPITALS. This seems to be standard practice.

2. I would also have included some functions rather than duplicate code (if possible).

3. I would have avoided temporary files if possible. This is rather challenging but you may try.

4. I think that you included dimensions, right? I would have avoided dimensions unless you really need them.

5. I would have included a function to check if a package is installed, like this:




Chris
Thanks for the advice. Part of the reason I posted this is to get feedback on such things, since admittedly my BASH scripting knowledge is rather basic. I definitely should learn about regular expressions, because they seem to be rather powerful but look like gobbly-gook to me.
 
Old 04-27-2016, 08:31 AM   #6
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Unrequested advice: do not learn bash. Learn the Shell Command Language and also the other volumes of the POSIX specification.

Why?
  • It's always preferable to know the specification of a language before studying a specific implementation
  • It will make easier to read "man bash" then as this manual assumes the knowledge of the former
  • Partly for that reason the specification is lot easier to digest. And some examples are provided that at least helped my own understanding
  • Even though bash has a lot of extensions, the features and syntax of the specification suffice to do most shell scripting
  • The scripts you will write using only what is specified will run on *BSD and OS X, not only Linux (even using bash, provided that its posix mode be set with the option --posix)
Just my

Last edited by Didier Spaier; 04-27-2016 at 08:45 AM.
 
3 members found this post helpful.
Old 04-27-2016, 09:35 AM   #7
lems
Member
 
Registered: May 2004
Distribution: BSD
Posts: 269

Rep: Reputation: 119Reputation: 119
One script that might be of interest to sbopkg users is sbodeps. It's a well-written bash-optimized script, really fast. It assumes a configured sbopkg installation, and since some time has an update checker:

Quote:
New in 1.1: Fast update checker: sbodeps -c is roughly 100 times as fast as sbopkg -c. Not only that, it will automatically add any new dependencies to the update queue. Installing all available updates (plus any new dependencies) is as simple as saying sbodeps -ci.
 
2 members found this post helpful.
Old 04-27-2016, 12:47 PM   #8
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by montagdude View Post
I use git for my own projects, but didn't think it would be the best choice for what I wanted to do. The main reason is that I don't want to mirror the whole repository with thousands of packages, but rather just the few that I actually use. Is there a way to do that with git? And if you can, would you just do a git pull and git diff to determine which ones are out of date? It still seems like a simple script would be better for this particular task, but I'm trying to learn here.
Well it would be more useful to consider two things, (1) what would put more load on the SBo server and your network, and (2) how easy it would be to tell whether something has been updated. Git wins both, IMO, though you might want to benchmark how much data is transferred using rsync vs. using git.

Here's one possible git version.

Code:
cd $REPOROOT
git fetch --all
for pkg in /var/log/packages/*SBo; do
  pkgbase=$(basename $pkg | rev | cut -f4- -d- | rev)
  for pkgdir in */$pkgbase; do
    if [ -n "$(git diff origin/$BRANCH $pkgdir)" ]; then
      echo "$pkgbase has been updated"
    fi
  done
done
git merge --ff-only origin/$BRANCH
As you can see it's quite a bit easier with git we don't need to care about VERSION or BUILD, git already just *knows* when stuff has been updated.
 
1 members found this post helpful.
Old 04-27-2016, 12:49 PM   #9
kjhambrick
Senior Member
 
Registered: Jul 2005
Location: Round Rock, TX
Distribution: Slackware64 15.0 + Multilib
Posts: 2,159

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
Speaking of SlackBuilds and Slackware Current and git and hand-rolled parsers and ...

Is there a SLACKBUILDS.TXT.gz File that I can rsync ( or git ) from the SlackBuilds Current Repository ?

If access is limited to a git client, how would I download only SLACKBUILDS.TXT.gz and not the entire Repository ?

Thanks.

-- kjh

This is what I do / did for the 14.1 SLACKBUILDS.TXT File:

cd /home/dld/slackbuilds/14.1 && rsync -av rsync://slackbuilds.org/slackbuilds/14.1/SLACKBUILDS.TXT.gz .

Once I've got that file, everything I need to know is just a `less` away.
 
Old 04-27-2016, 03:42 PM   #10
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by kjhambrick View Post
Is there a SLACKBUILDS.TXT.gz File that I can rsync ( or git ) from the SlackBuilds Current Repository ?
No. As far as I know, it's created when a Public Update is released, so when there is a 14.2 branch Public Update, you will get a 14.2 branch SLACKBUILDS.TXT.gz. Until then, you can get everything that's in SLACKBUILDS.TXT from the .info and slack-desc files in the master branch in git.

It would probably upset everybody if I described the ChangeLog.txt and SLACKBUILDS.TXT and individual .tar.gz files as a legacy interface, but ...

It's irrelevant to your question (since SLACKBUILDS.TXT does not exist in the SBo git repo), but git itself provides no way of downloading individual files [1]. However, you can use the cgit interface at https://slackbuilds.org/cgit/slackbuilds/ to get individual files.

For example, to get the libraries/exiftool slack-desc file from the 14.0 branch:

https://slackbuilds.org/cgit/slackbu...ck-desc?h=14.0

[1] The whole idea of git is that it is blazingly fast and efficient at handling large-scale trees of changes. Just clone the whole thing and work on that. Wanting less than the whole SBo git repo is a bit like a noob not wanting to install the whole of Slackware "because bloat".

Last edited by 55020; 04-27-2016 at 03:53 PM.
 
1 members found this post helpful.
Old 04-27-2016, 06:41 PM   #11
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Original Poster
Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
Quote:
Originally Posted by 55020 View Post
Well it would be more useful to consider two things, (1) what would put more load on the SBo server and your network, and (2) how easy it would be to tell whether something has been updated. Git wins both, IMO, though you might want to benchmark how much data is transferred using rsync vs. using git.

Here's one possible git version.

Code:
cd $REPOROOT
git fetch --all
for pkg in /var/log/packages/*SBo; do
  pkgbase=$(basename $pkg | rev | cut -f4- -d- | rev)
  for pkgdir in */$pkgbase; do
    if [ -n "$(git diff origin/$BRANCH $pkgdir)" ]; then
      echo "$pkgbase has been updated"
    fi
  done
done
git merge --ff-only origin/$BRANCH
As you can see it's quite a bit easier with git we don't need to care about VERSION or BUILD, git already just *knows* when stuff has been updated.
Thanks for that. There are definitely some commands and options for commands in there that I didn't know about before.
 
Old 04-27-2016, 07:09 PM   #12
kjhambrick
Senior Member
 
Registered: Jul 2005
Location: Round Rock, TX
Distribution: Slackware64 15.0 + Multilib
Posts: 2,159

Rep: Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512Reputation: 1512
Quote:
Originally Posted by 55020 View Post
No. As far as I know, it's created when a Public Update is released, so when there is a 14.2 branch Public Update, you will get a 14.2 branch SLACKBUILDS.TXT.gz. Until then, you can get everything that's in SLACKBUILDS.TXT from the .info and slack-desc files in the master branch in git.
Thanks 55020 !

Quote:
It would probably upset everybody if I described the ChangeLog.txt and SLACKBUILDS.TXT and individual .tar.gz files as a legacy interface, but ...
Ouch ! I feel so old ! <G>

Quote:
It's irrelevant to your question (since SLACKBUILDS.TXT does not exist in the SBo git repo), but git itself provides no way of downloading individual files [1]. However, you can use the cgit interface at https://slackbuilds.org/cgit/slackbuilds/ to get individual files.
Yes, I knew about the cgit url but I was trying to avoid the Gooey DubDubDub Interface by 'finding' a secret copy of SLACKBUILD.TXT File somewhere in the tree and then I would be able to use my ole-time shell tools...<G><G>

Time for me to `git clone` the Whole Tree, I supose.

Quote:
For example, to get the libraries/exiftool slack-desc file from the 14.0 branch:

https://slackbuilds.org/cgit/slackbu...ck-desc?h=14.0

[1] The whole idea of git is that it is blazingly fast and efficient at handling large-scale trees of changes. Just clone the whole thing and work on that. Wanting less than the whole SBo git repo is a bit like a noob not wanting to install the whole of Slackware "because bloat".
Thanks again 55020 !

-- kjh
 
Old 04-27-2016, 08:30 PM   #13
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Original Poster
Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
Alright, so I improved the script a bit. Most notably, it now checks whether each Slackbuild in the local directory tree is actually installed, and there's also an option to check which Slackbuilds depend on another (useful to know when performing an update). I also improved the style a bit, using functions wherever sensible, putting variables in all caps, and using let instead of expr to increment counters. I know it's not perfect but it's pretty simple in concept and works for me. Plus it has been a good learning experience.

Here's the updated script (and yes, it's a bit long now, but I like to use lots of comments and generally favor readability over conciseness):
Code:
#!/bin/bash

CDIR=/var/cache/packages/SBo
#REPO=https://slackbuilds.org/slackbuilds/14.1
REPO=https://github.com/Ponce/slackbuilds/raw/current

################################################################################
# Gets name of slackbuild from path of .info file
function name_from_path ()
{ 
  local FILEPATH=$1
  
  # Strip off leading ./ and trailing file name
  local SLACKBUILD=${FILEPATH#./}
  SLACKBUILD=${SLACKBUILD%/*}
  
  echo $SLACKBUILD
}

################################################################################
# Lists Slackbuilds that depend on another one by scanning .info file
function list_deps ()
{ 
  local BUILD=$1
  
  # Go to top-level SBo directory
  cd $CDIR

  # List of .info files that have REQUIRES.*$BUILD pattern
  local DEPFILES=$(find . -name *.info | xargs grep -El "REQUIRES.*$BUILD")
  
  # List them
  if [ "$DEPFILES" != "" ]; then
    echo "The following Slackbuilds depend on $BUILD:"
    for FILE in $DEPFILES
    do
      name_from_path $FILE
    done
  fi
}

################################################################################
# Checks if a Slackbuild is actually installed
function check_installed ()
{
  local BUILD=$1
  local CHECK=$(ls /var/log/packages | grep -E "$BUILD.*SBo")
  if [ "$CHECK" == "" ]; then
    echo false
  else
    echo true
  fi
}

################################################################################
# Removes quotes around string
function remove_quotes ()
{
  local STRING=$1
  STRING=${STRING#\"}
  STRING=${STRING%\"}
  echo $STRING
}

################################################################################
# Gets Slackbuild version from VERSION string in *.info file
function get_version ()
{
  INFILE=$1
  VERSION=$(grep VERSION "$INFILE" | sed 's/VERSION=//')
  VERSION=$(remove_quotes "$VERSION")
  echo $VERSION
}

################################################################################
# Checks *.info files to see which Slackbuilds can be updated
function check_all_updates ()
{
  # Go to top-level SBo directory
  cd $CDIR
  
  # Initialize iterators
  local OLDCOUNT=0
  local CURRENTCOUNT=0
  local UNINSTCOUNT=0
  local CATEGORY=""
  local BUILD=""

  echo "Downloading *.info files to check for updates..."
  echo
  
  # Loop through directories (these are the categories)
  for CATEGORY in $(find . -type d -maxdepth 1)
  do
  
    # Skip '.' directory
    if [ "$CATEGORY" != "." ]; then
  
      # Strip off leading ./ characters
      CATEGORY=${CATEGORY#./}
  
      # Go to category directory
      cd $CDIR/$CATEGORY    
  
      # Loop through build directories within each category
      for BUILD in $(find . -type d -maxdepth 1)
      do
  
        # Skip '.' directory
        if [ "$BUILD" == "." ]; then
          continue
        fi
  
        # Strip off ./ characters
        BUILD=${BUILD#./}

        # Check if the Slackbuild is actually installed

        if ! $(check_installed "$BUILD"); then
          local UNINSTALLED["$UNINSTCOUNT"]="$CATEGORY/$BUILD"
          let "UNINSTCOUNT+=1"
          continue
        fi

        # Go to build directory and download .info file
        # Suppress stdout and stderr, but print any 404 messages
        cd $CDIR/$CATEGORY/$BUILD
        wget -O $BUILD.info.tmp $REPO/$CATEGORY/$BUILD/$BUILD.info 2>&1 > /dev/null | grep "404"

        # Compare installed version and version from repo
        local INSTALLED=$(get_version "$BUILD".info)
        local CURRENT=$(get_version "$BUILD".info.tmp) 

        # Store outdated and up-to-date in arrays
        if [ "$INSTALLED" != "$CURRENT" ]; then
          local OUTDATED["$OLDCOUNT"]="$CATEGORY/$BUILD"
          local OLDVER["$OLDCOUNT"]=$INSTALLED
          local NEWVER["$OLDCOUNT"]=$CURRENT
          let "OLDCOUNT+=1"
        else
          local UPTODATE["$CURRENTCOUNT"]="$CATEGORY/$BUILD"
          let "CURRENTCOUNT+=1"
        fi

        # Remove temporary .info file
        rm $BUILD.info.tmp

      done
    fi
  done
  
  # Print summaries

  echo "$UNINSTCOUNT Slackbuilds are in the directory tree but not installed."
  echo "-------------------------------------------------------------------------"
  local I=0
  while [ $I -lt $UNINSTCOUNT ]
  do
    echo "Name: ${UNINSTALLED[$I]}"
    let "I+=1"
  done
  
  echo
  echo "$CURRENTCOUNT Slackbuilds are up-to-date."
  echo "-------------------------------------------------------------------------"
  local I=0
  while [ $I -lt $CURRENTCOUNT ]
  do
    echo "Name: ${UPTODATE[$I]}"
    let "I+=1"
  done
  
  echo
  echo "$OLDCOUNT Slackbuilds are outdated."
  echo "-------------------------------------------------------------------------"
  I=0
  while [ $I -lt $OLDCOUNT ]
  do
    echo "Name: ${OUTDATED[$I]}"
    echo "Installed version: ${OLDVER[$I]}"
    echo "Current version: ${NEWVER[$I]}"
    echo
    let "I+=1"
  done
}

################################################################################
# Provides info on program usage
function print_usage ()
{
  if [ $# -eq 1 ]; then
    echo "Error: $1"
  fi
  echo "Usage: sbo_update_checker OPTIONS"
  echo "OPTIONS"
  echo "       -u              Checks for updated Slackbuilds."
  echo "       -d {Slackbuild} Lists dependencies of specified Slackbuild."
  echo "       --help          Shows this usage information."
}

################################################################################
# Main program

# Check for valid option
if [ $# -lt 1 ]; then
  print_usage "must specify an option (-u, -d, or --help)."
elif [ "$1" == "-u" ]; then
  check_all_updates
elif [ "$1" == "-d" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify a Slackbuild with -d option."
  else
    list_deps $2
  fi
elif [ "$1" == "--help" ]; then
  print_usage
else
  print_usage "unrecognized option."
fi
And here are sample outputs:
Code:
root@Thinkpad-T430:~# sbo_update_checker -u
Downloading *.info files to check for updates...

2 Slackbuilds are in the directory tree but not installed.
-------------------------------------------------------------------------
Name: office/gnucash
Name: multimedia/ffmpeg

24 Slackbuilds are up-to-date.
-------------------------------------------------------------------------
Name: development/acpica
Name: desktop/screenfetch
Name: desktop/kfaenza-icon-theme
Name: desktop/QtCurve-Gtk2
Name: desktop/kde-gtk-config
Name: desktop/homerun
Name: desktop/QtCurve-KDE4
Name: office/keepassx
Name: office/libreoffice
Name: system/google-droid-fonts
Name: system/cabextract
Name: system/winetricks
Name: system/wine
Name: system/virtualbox
Name: system/virtualbox-kernel
Name: system/TLP
Name: libraries/libmpeg2
Name: libraries/qt5
Name: libraries/yajl
Name: libraries/libmicrohttpd
Name: libraries/tinyxml
Name: libraries/libass
Name: multimedia/flashplayer-plugin
Name: multimedia/kodi

2 Slackbuilds are outdated.
-------------------------------------------------------------------------
Name: development/jdk
Installed version: 8u77
Current version: 8u92

Name: network/qupzilla
Installed version: 1.8.9
Current version: 1.8.6

root@Thinkpad-T430:~# sbo_update_checker -d jdk
The following Slackbuilds depend on jdk:
office/libreoffice
multimedia/kodi
I reckon now I should go update jdk.
 
Old 04-30-2016, 11:37 PM   #14
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 2,011

Original Poster
Rep: Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619Reputation: 1619
So, I decided I wanted my script not only to show dependencies and check for updates but also be able to install and remove packages. I quickly ran into the issue of not being able to download all files in the directory for a given SlackBuild using wget. At this point, it seemed the only practical way was to use git and just clone the whole thing, like you guys suggested. So that's what I did, and I'm glad I did, because it gives a lot more flexibility. My script has now transformed into a full-fledged SlackBuild installation manager. Here are the available functions:

Code:
root@Thinkpad-T430:~# sbomgr --help

Usage: sbomgr OPTIONS

OPTIONS
       sync-repo              Syncs git repo with local copy. Use
                                before updating.

       install SLACKBUILD     Installs or reinstalls the specified
                                  SlackBuild.

       install SLACKBUILD sources=DIRECTORY
                              Copies source code from specified
                                directory instead of downloading.

       remove PATTERN         Optionally removes installed SlackBuilds
                                matching PATTERN.

       check-update SLACKBUILD
                              Checks the specified SlackBuild for
                                updates.

       check-all-updates      Checks all installed SlackBuilds for                               
                                updates.                                                         
                                                                                                 
       requires SLACKBUILD    Lists packages required by the                                     
                                specified SlackBuild.                                            
                                                                                                 
       requirement-of SLACKBUILD                                                                 
                              Lists installed SlackBuilds that depend                            
                                on the specified SlackBuild.                                     
                                                                                                 
       search PATTERN         Searches for SlackBuilds matching PATTERN                          
                                in git tree. Shows installed status.                             
                                                                                                 
       search-descriptions PATTERN                                                               
                              Searches README files in git tree for                              
                                specified pattern.                                               
                                                                                                 
       info SLACKBUILD        Displays info about the SlackBuild from                            
                                README and README.SLACKWARE.                                     
                                                                                                 
       list-installed         Lists installed SlackBuilds and versions.                          
                                                                                                 
       list-groups            Lists groups in git tree.                                          
                                                                                                 
       browse-group GROUP     Lists SlackBuilds in specified GROUP.

       --help                 Shows this usage information.
Is it better than sbopkg? Probably not, especially considering sbopkg is a pretty mature tool and I've only been working on this for a few days. But this is simple and gets the job done, and it was a good learning experience for me. Here is the new script, just in case anyone wants it:

Code:
#!/bin/bash

# Uncomment to use master git repo (for -stable or -current)
REPO=git://slackbuilds.org/slackbuilds.git
BRANCH=master
#BRANCH=14.1

# Uncomment to use Ponce's git repo (for -current only)
#REPO=git://github.com/Ponce/slackbuilds.git

# Local git directory
CDIR=/var/cache/packages/SBo

################################################################################
# Removes quotes around string
function remove_quotes ()
{
  local STRING=$1
  STRING=${STRING#\"}
  STRING=${STRING%\"}
  echo $STRING
}

################################################################################
# Gets SlackBuild name from installed package name in /var/log/packages
function get_installed_name ()
{
  local PKG=$1

  # Get rid of trailing stuff
  local BUILD=${PKG%*_SBo}
  BUILD=${BUILD%*-*}  # Architecture-number
  BUILD=${BUILD%*-*}  # Architecture
  BUILD=${BUILD%*-*}  # Version
  echo $BUILD
}

################################################################################
# Gets SlackBuild version from installed package name in /var/log/packages
function get_installed_version ()
{
  local PKG=$1

  # Get rid of trailing stuff
  local VERSION=${PKG%*_SBo}
  VERSION=${VERSION%*-*}  # Architecture-number
  VERSION=${VERSION%*-*}  # Architecture

  # Get rid of leading package name
  local TEMP=${VERSION%*-*}
  VERSION=${VERSION#$TEMP-*}
  echo $VERSION
}

################################################################################
# Gets SlackBuild version from VERSION string in *.info file
function get_current_version ()
{
  local BUILD=$1

  # Make sure we are at the top of the git tree
  cd $CDIR

  # Get path of SlackBuild.info
  local INFILE=$(find . -maxdepth 3 -mindepth 3 -name "$BUILD".info)

  # Get version number from SlackBuild.info
  local VERSION=$(grep VERSION "$INFILE" | sed 's/VERSION=//')
  VERSION=$(remove_quotes "$VERSION")

  echo $VERSION
}

################################################################################
# Checks if Ponce's git repo is being used
function check_ponce_repo ()
{
  if [ "$REPO" == "git://github.com/Ponce/slackbuilds.git" ]; then
    echo true
  else
    echo false
  fi
}

################################################################################
# Returns the git branch name that is currently being used
function get_git_branch ()
{
  # Go to top-level git tree
  cd $CDIR
 
  # Parse git status string
  local STAT=$(git status | head -1)
  local BRANCH=$(echo "$STAT" | cut -d' ' -f3)
  echo $BRANCH
}

################################################################################
# Switches to specified git branch
function checkout_git_branch ()
{
  local GITBRANCH="$1"

  # Go to top-level git tree
  cd $CDIR

  # Get branch currently being used
  local CURRBRANCH=$(get_git_branch)

  # Checkout new branch if needed
  if [ "$CURRBRANCH" != "$GITBRANCH" ]; then
    git checkout $GITBRANCH
  fi
}

################################################################################
# Syncs git repo with local copy
function sync_repo ()
{
  # Check if Ponce's git repo is being used
  local PONCEREPO=$(check_ponce_repo)
  
  # Create local git directory if needed
  if [ ! -d "$CDIR" ]; then
    mkdir $CDIR
    cd $CDIR/../
    rm -rf SBo
    git clone $REPO SBo
    if ! $PONCEREPO; then
      cd SBo
      checkout_git_branch $BRANCH
    fi

  # Master branch can just use git pull, but Ponce's must be re-downloaded
  # http://www.linuxquestions.org/questions/slackware-14/what-is-the-correct-url-and-command-to-git-clone-slackbuilds-current-4175578557/
      rm -rf SBo
      git clone $REPO SBo 
    fi
  fi
}

################################################################################
# Checks if a SlackBuild is actually installed. Returns package name if so.
function check_installed ()
{
  local BUILD=$1
  local PKGLIST=$(find /var/log/packages -maxdepth 1 -name "$BUILD*_SBo")
  local INSTALLED=false

  # There can be multiple packages fitting the pattern, so loop through them
  # and check against requested
  if [ "$PKGLIST" != "" ]; then
    local PKG=""
    local BUILDNAME=""
    for PKG in $PKGLIST
    do
      PKG=$(basename "$PKG")
      BUILDNAME=$(get_installed_name "$PKG")
      if [ "$BUILDNAME" == "$BUILD" ]; then
        INSTALLED=true
        break
      fi
    done
  fi

  if $INSTALLED; then
    echo $PKG
  else
    echo "Not installed"
  fi
}

################################################################################
# Gets y/n choice
function user_choice ()
{
  local __MSG=$1
  local __CHOICE=$2
  local TEMPCHOICE=""
  local VALIDCHOICE=false

  while ! $VALIDCHOICE
  do
    echo $__MSG
    read TEMPCHOICE
    if [[ "$TEMPCHOICE" == "y" || "$TEMPCHOICE" == "Y" ]]; then
      TEMPCHOICE="y"
      VALIDCHOICE=true
    elif [[ "$TEMPCHOICE" == "n" || "$TEMPCHOICE" == "N" ]]; then
      TEMPCHOICE="n"
      VALIDCHOICE=true
    else
     echo "Please enter y or n."
    fi
  done

  # This trick is needed to echo to stdout. See usage in remove_slackbuild.
  eval $__CHOICE="'$TEMPCHOICE'"
}

################################################################################
# Removes a package with SlackBuild containing a given string
function remove_slackbuild ()
{
  local PATTERN=$1
  local PKGLIST=$(find /var/log/packages -maxdepth 1 -name "$PATTERN*_SBo")

  # Return if no matching packages were found
  if [ "$PKGLIST" == "" ]; then
    echo "No installed SlackBuilds matching pattern $PATTERN."

  # Loop through list of packages matching BUILD string
  else
    local PKG=""
    local CHOICE=""
    local MSG=""
    for PKG in $PKGLIST
    
    # Ask for confirmation before removing
    do
      PKG=$(basename "$PKG")
      MSG="Found package $PKG. Remove? (y/n): "
      user_choice "$MSG" CHOICE
      if [ "$CHOICE" == "y" ]; then
        removepkg "$PKG"
      fi 
    done
  fi
}

################################################################################
# Extracts URLs of source files to download
function sources_from_info ()
{
  local INFILE=$1
  local SOURCES=""
  local ARCH=$(uname -m)

  # Read variables from .info file
  source $INFILE

  # First try to use DOWNLOAD_x86_64 link for 64-bit
  if [ "$ARCH" == "x86_64" ]; then
    SOURCES=$DOWNLOAD_x86_64
  fi

  # Use regular DOWNLOAD= line for x86 architecture or if there's no 64-bit
  # download
  if [[ "$ARCH" != "x86_64" || "$SOURCES" == "" ]]; then
    SOURCES=$DOWNLOAD
  fi

  echo $SOURCES
}

################################################################################
# Extracts MD5sums of source files to download
function md5sums_from_info ()
{
  local INFILE=$1
  local MD5SUMS=""
  local ARCH=$(uname -m)

  # Read variables from .info file
  source $INFILE

  # First try to use MD5SUM_x86_64 link for 64-bit
  if [ "$ARCH" == "x86_64" ]; then
    MD5SUMS=$MD5SUM_x86_64
  fi

  # Use regular MD5SUM= line for x86 architecture or if there's no 64-bit
  # download
  if [[ "$ARCH" != "x86_64" || "$MD5SUMS" == "" ]]; then
    MD5SUMS=$MD5SUM
  fi

  echo $MD5SUMS
}

################################################################################
# Installs or reinstalls SlackBuild
function install_slackbuild ()
{
  local BUILD=$1

  # Get directory for source files if specified by user
  local SOURCEOPT=$2
  local SOURCEDIR=${SOURCEOPT#*=}
  local SOURCESPEC=${SOURCEOPT%=*}

  if [[ "$SOURCEDIR" != "" && "$SOURCESPEC" != "sources" ]]; then
    echo "Error: unrecognized command line option. Try sbomgr --help."
    return
  fi

  # Get SlackBuild path
  cd $CDIR
  local BUILDPATH=$(find . -maxdepth 2 -mindepth 2 -name "$BUILD")
  if [ "$BUILDPATH" == "" ]; then
    echo "Error: there is no SlackBuild named $BUILD."
    return
  fi

  # Check if SlackBuild is installed on system and get package name
  local INSTALLEDPKG=$(check_installed "$BUILD")

  # Offer removal or reinstallation if it is already installed
  if [ "$INSTALLEDPKG" != "Not installed" ]; then
    local INSTALLEDVERSION=$(get_installed_version "$INSTALLEDPKG")
    local CURRENTVERSION=$(get_current_version "$BUILD")
    local MSG=""
    local CHOICE=""

    # Current version already installed - ask for reinstallation
    if [ "$INSTALLEDVERSION" == "$CURRENTVERSION" ]; then
      MSG="$BUILD is already at the most recent version.  Reinstall? (y/n): "

    # Installed version out of date - ask for reinstallation
    else
      MSG="$BUILD is already installed but out of date. Reinstall? (y/n): "
    fi

    # Remove package or return
    user_choice "$MSG" CHOICE
    if [ "$CHOICE" == "y" ]; then
      removepkg $INSTALLEDPKG
    else
      return
    fi
  fi

  # Remove any package in /tmp with $BUILD in the name (could mess up
  # installation later)
  local PKG=$(find /tmp -maxdepth 1 -name "*$BUILD*")
  if [ "$PKG" != "" ]; then
    rm $PKG
  fi

  # Go to SlackBuild directory
  cd $BUILDPATH

  # Get MD5sums for source downloads and put them into an array
  local MD5SUMS=$(md5sums_from_info "$BUILD".info)
  local MD5ARRAY=""
  local ITEM=""
  local COUNT=0
  for ITEM in $MD5SUMS
  do
    MD5ARRAY["$COUNT"]=$ITEM
    let "COUNT+=1"
  done

  # Download or copy sources
  local SOURCES=$(sources_from_info "$BUILD".info)
  local CHKDNLD=""
  local MD5CHK=""
  COUNT=0
  for SOURCE in $SOURCES
  do
    if [ -f "$SOURCE" ]; then
      rm "$SOURCE"
    fi

    # Copy sources from specified directory
    if [ "$SOURCEDIR" != "" ]; then
      SOURCE=$(basename "$SOURCE")
      if [ "$(find "$SOURCEDIR" -maxdepth 1 -name "$SOURCE")" == "" ]; then
        echo "Error: source file $SOURCE not present in $SOURCEDIR."
        return
      else
        cp "$SOURCEDIR/$SOURCE" .
      fi

    # Download and check for error ($? is the return value)
    else
      CHKDNLD=$(wget "$SOURCE")
      if [ $? != 0 ]; then         
        echo "There was an error downloading the source file."
        return
      fi
    fi

    # Check MD5sum
    SOURCE=$(basename "$SOURCE")
    MD5CHK=$(md5sum "$SOURCE")
    MD5CHK=$(echo $MD5CHK | cut -d' ' -f1)
    if [ "$MD5CHK" != "${MD5ARRAY[$COUNT]}" ]; then
      echo "Error: md5sum check failed on $SOURCE."
      return
    fi
 
    let "COUNT+=1"
  done

  # Execute install script
  chmod +x $BUILD.SlackBuild
  ./$BUILD.SlackBuild

  # Exit if not successful
  PKG=$(find /tmp -maxdepth 1 -name "*$BUILD*")
  if [ "$PKG" == "" ]; then
    echo "An error occurred. $BUILD was not installed."
    return
  fi

  # Install compiled package
  installpkg $PKG

  # Remove temporary files and source code
  rm $PKG
  for SOURCE in $SOURCES
  do
    rm $(basename "$SOURCE")
  done
}

################################################################################
# Checks for update of specified Slackbuild
function check_update ()
{
  local BUILD=$1

  # Check first if it is installed and get installed version
  local INSTALLEDPKG=$(check_installed "$BUILD")
  if [ "$INSTALLEDPKG" == "Not installed" ]; then
    echo "$BUILD is not installed."
    return
  else
    local INSTALLEDVERSION=$(get_installed_version "$INSTALLEDPKG") 
  fi

  # Go to top-level git directory
  cd $CDIR

  # Check if SlackBuild exists and get current version
  BUILDPATH=$(find . -maxdepth 2 -mindepth 2 -name "$BUILD")
  if [ "$BUILDPATH" == "" ]; then
    echo "Error: there is no SlackBuild named $BUILD."
    return
  fi
  local CURRENTVERSION=$(get_current_version "$BUILD")

  # Compare version
  if [ "$INSTALLEDVERSION" == "$CURRENTVERSION" ]; then
    echo "$BUILD is up to date."
  else
    echo "$BUILD can be updated."
    echo "Installed version: $INSTALLEDVERSION"
    echo "Current version: $CURRENTVERSION"
  fi
}

################################################################################
# Checks all installed SlackBuilds for updates
function check_all_updates ()
{
  # Get list of installed SlackBuilds
  local PKGLIST=$(find /var/log/packages -maxdepth 1 -name "*_SBo")

  # Loop through installed packages and check for updates
  local PKG=""
  local BUILD=""
  local INSTALLEDVERSION=""
  local CURRENTVERSION=""
  local UPDATELIST=""
  local UPTODATELIST=""
  local UPDATECOUNT=0
  local UPTODATECOUNT=0
  local INSTALLEDVERSIONLIST=""
  local CURRENTVERSIONLIST=""
  for PKG in $PKGLIST
  do
    PKG=$(basename "$PKG")

    # Get SlackBuild name and version
    BUILD=$(get_installed_name "$PKG")
    INSTALLEDVERSION=$(get_installed_version "$PKG")

    # Get current version
    CURRENTVERSION=$(get_current_version "$BUILD")

    # Compare versions and tally up-to-date and out-of-date
    if [ "$INSTALLEDVERSION" == "$CURRENTVERSION" ]; then
      UPTODATELIST["$UPTODATECOUNT"]="$BUILD"
      let "UPTODATECOUNT+=1"
    else
      UPDATELIST["$UPDATECOUNT"]="$BUILD"
      INSTALLEDVERSIONLIST["$UPDATECOUNT"]="$INSTALLEDVERSION"
      CURRENTVERSIONLIST["$UPDATECOUNT"]="$CURRENTVERSION"
      let "UPDATECOUNT+=1"
    fi
  done

  # Print a summary

  echo ""
  echo "$UPTODATECOUNT SlackBuilds are up-to-date."
  echo "-----------------------------------------------------------------------"
  local I=0
  while [ $I -lt $UPTODATECOUNT ];
  do
    echo "Name: ${UPTODATELIST[$I]}"
    let "I+=1"
  done

  echo ""
  echo "$UPDATECOUNT SlackBuilds are can be updated."
  echo "-----------------------------------------------------------------------"
  I=0
  while [ $I -lt $UPDATECOUNT ];
  do
    echo "Name: ${UPDATELIST[$I]}"
    echo "Installed version: ${INSTALLEDVERSIONLIST[$I]}"
    echo "Current version: ${CURRENTVERSIONLIST[$I]}"
    echo ""
    let "I+=1"
  done
}

################################################################################
# Lists dependencies of specified SlackBuild by scanning .info file
function list_reqs ()
{
  local BUILD=$1

  # Get the directory for the requested SlackBuild
  local BUILDPATH=$(find "$CDIR" -maxdepth 2 -mindepth 2 -name "$BUILD")
  if [ "$BUILDPATH" == "" ]; then
    echo "There is no SlackBuild named $BUILD."
    return
  fi

  # Read dependencies from *.info file
  cd $BUILDPATH
  source "$BUILD".info
  if [ "$REQUIRES" != "" ]; then
    echo "$BUILD requires: $REQUIRES"
  else
    echo "No required packages for $BUILD."
  fi
}

################################################################################
# Lists installed SlackBuilds that require specified SlackBuild
function list_inv_reqs ()
{
  local BUILD=$1

  # Loop through list of installed packages
  local PKGLIST=$(find /var/log/packages -maxdepth 1 -name "*_SBo")
  local PKG=""
  local NAME=""
  local BUILDPATH=""
  local INVREQLIST=""
  local INVREQCOUNT=0
  local REQ=""
  for PKG in $PKGLIST
  do
    # Go to top of git tree
    cd $CDIR

    # Go to directory of requested SlackBuild
    PKG=$(basename "$PKG")
    NAME=$(get_installed_name "$PKG")
    BUILDPATH=$(find . -maxdepth 2 -mindepth 2 -name "$NAME")
    cd $BUILDPATH

    # Read requirements from *.info file
    source "$NAME".info
    
    # Loop through and see if specified SlackBuild is mentioned
    if [ "$REQUIRES" != "" ]; then
      for REQ in $REQUIRES
      do
        if [ "$REQ" == "$BUILD" ]; then
          INVREQLIST["$INVREQCOUNT"]="$NAME"
          let "INVREQCOUNT+=1"
          break
        fi
      done
    fi
  done

  # List SlackBuilds that require specified SlackBuild
  if [ $INVREQCOUNT -eq 0 ]; then
    echo "No installed SlackBuilds require $BUILD."
  else
    echo "The following SlackBuilds require $BUILD:"
    local I=0
    while [ $I -lt $INVREQCOUNT ]
    do
      echo "${INVREQLIST[$I]}"
      let "I+=1"
    done
  fi
}

################################################################################
# Shows info from README and README.SLACKWARE
function show_info ()
{
  local BUILD=$1

  # Go to the top of the git tree
  cd $CDIR

  # Get the directory for the requested SlackBuild
  echo "Searching for $BUILD ..."
  local BUILDPATH=$(find . -maxdepth 2 -mindepth 2 -name "$BUILD")
  if [ "$BUILDPATH" == "" ]; then
    echo "There is no SlackBuild named $BUILD."
    return
  fi

  # Go the the SlackBuild directory
  cd $BUILDPATH
  BUILDPATH=${BUILDPATH#./*}
  local NAME=${BUILDPATH#*/*}

  # Get current version
  local VERSION=$(get_current_version "$NAME")
  echo "In local git repository:"
  echo "$NAME-$VERSION"
  echo ""
  echo "-----------------------------Description-----------------------------"
  cat 'README'
  if [ -f 'README.Slackware' ]; then
    echo ""
    echo "---------------------------Slackware notes---------------------------"
    cat 'README.Slackware'
  elif [ -f 'README.SLACKWARE' ]; then
    echo ""
    echo "---------------------------Slackware notes---------------------------"
    cat 'README.SLACKWARE'
  fi
}

################################################################################
# Searches for SlackBuilds with given pattern
function search ()
{
  local PATTERN=$1

  # Go to the top of the git tree
  cd $CDIR

  echo "Searching for $PATTERN ..."
  local BUILDS=$(find . -maxdepth 2 -mindepth 2 -type d | grep -i "$PATTERN")

  if [ "$BUILDS" == "" ]; then
    echo "There is no SlackBuild matching the pattern $PATTERN."
  else
    # Get GROUP/NAME/STATUS
    local BUILD=""
    local STATUS=""
    for BUILD in $BUILDS
    do
      BUILD=${BUILD#./*}
      local GROUP=${BUILD%/*}
      local NAME=${BUILD#*/*}
      if [ "$(check_installed $NAME)" != "Not installed" ]; then
        STATUS="installed"
      else
        STATUS="not installed"
      fi
      echo "$GROUP/$NAME  [$STATUS]"
    done
  fi
}

################################################################################
# Searches README files for given pattern
function search_descriptions ()
{
  # Make sure spaces in the search string are resolved
  local PATTERN="$*"

  # Go to the top of the git tree
  cd $CDIR

  echo "Searching README files for $PATTERN ..."
  local PTRNFILES=$(find . -maxdepth 3 -mindepth 3 -name README | xargs grep -il "$PATTERN" | sort -t "/" -k 3)

  # Display list of SlackBuilds
  if [ "$PTRNFILES" != "" ]; then
    echo "The following SlackBuilds have $PATTERN in the README file:"
    local BUILD=""
    for BUILD in $PTRNFILES
    do
      BUILD=${BUILD#./*/*}  # Remove leading ./ and group
      BUILD=${BUILD%*/*}    # Remove trailing /README
      echo $BUILD
    done
  else
    echo "No SlackBuilds have $PATTERN in the README file."
  fi
}      

################################################################################
# Lists installed SlackBuilds and versions
function list_installed ()
{
  local PKGLIST=$(find /var/log/packages -maxdepth 1 -name "$BUILD*_SBo" | sort)

  # Loop through installed packages and list name-version
  local PKG=""
  for PKG in $PKGLIST
  do
    echo $(basename "$PKG")
  done
}

################################################################################
# Lists groups in git tree
function list_groups ()
{
  # Go to top-level git tree
  cd $CDIR

  # Print list of groups
  local GROUPLIST=$(find . -maxdepth 1 -type d | sort)
  local GROUP=""
  for GROUP in $GROUPLIST
  do
    if [[ "$GROUP" != "." && "$GROUP" != "./.git" ]]; then
      echo ${GROUP#./*}
    fi
  done
}

################################################################################
# Browses SlackBuilds in requested group
function browse_group ()
{
  local GROUP=$1

  # Go to top-level git tree
  cd $CDIR

  # Check if group exists
  if [ ! -d $GROUP ]; then
    echo "No group called $GROUP."
    return
  fi

  # List packages in GROUP
  cd $GROUP
  local PKGLIST=$(find . -maxdepth 1 -type d | sort)
  local PKG=""
  for PKG in $PKGLIST
  do
    if [ "$PKG" != "." ]; then
      echo ${PKG#./*}
    fi
  done
}  

################################################################################
# Provides info on program usage
function print_usage ()
{
  echo ""
  if [ $# -eq 1 ]; then
    echo "Error: $1"
  fi
  echo "Usage: sbomgr OPTIONS"
  echo ""
  echo "OPTIONS"
  echo "       sync-repo              Syncs git repo with local copy. Use"
  echo "                                before updating."
  echo ""
  echo "       install SLACKBUILD     Installs or reinstalls the specified"
  echo "                                  SlackBuild."
  echo ""
  echo "       install SLACKBUILD sources=DIRECTORY"
  echo "                              Copies source code from specified"
  echo "                                directory instead of downloading."
  echo ""
  echo "       remove PATTERN         Optionally removes installed SlackBuilds"
  echo "                                matching PATTERN."
  echo ""
  echo "       check-update SLACKBUILD"
  echo "                              Checks the specified SlackBuild for"
  echo "                                updates."
  echo ""
  echo "       check-all-updates      Checks all installed SlackBuilds for"
  echo "                                updates."
  echo ""
  echo "       requires SLACKBUILD    Lists packages required by the"
  echo "                                specified SlackBuild."
  echo ""
  echo "       requirement-of SLACKBUILD"
  echo "                              Lists installed SlackBuilds that depend"
  echo "                                on the specified SlackBuild."
  echo ""
  echo "       search PATTERN         Searches for SlackBuilds matching PATTERN"
  echo "                                in git tree. Shows installed status."
  echo ""
  echo "       search-descriptions PATTERN"
  echo "                              Searches README files in git tree for"
  echo "                                specified pattern."
  echo ""
  echo "       info SLACKBUILD        Displays info about the SlackBuild from"
  echo "                                README and README.SLACKWARE."
  echo ""
  echo "       list-installed         Lists installed SlackBuilds and versions."
  echo ""
  echo "       list-groups            Lists groups in git tree."
  echo ""
  echo "       browse-group GROUP     Lists SlackBuilds in specified GROUP."
  echo ""
  echo "       --help                 Shows this usage information."
  echo ""
}

################################################################################
# Main program

# Not enough command line arguments
if [ $# -lt 1 ]; then
  print_usage "must specify an option."

# sync-repo
elif [ "$1" == "sync-repo" ]; then
  sync_repo 

# install SLACKBUILD and
# install SLACKBUILD sources={DIRECTORY}
elif [ "$1" == "install" ]; then
  if [ $# -eq 1 ]; then
    print_usage "must specify SlackBuild with install option."
  else
    if [ $# -eq 2 ]; then
      install_slackbuild $2
    else
      install_slackbuild $2 $3
    fi
  fi

# remove PATTERN
elif [ "$1" == "remove" ]; then
  if [ $# -eq 1 ]; then
    print_usage "must specify PATTERN with remove option."
  else
    remove_slackbuild $2
  fi 

# check-update SLACKBUILD
elif [ "$1" == "check-update" ]; then
  if [ $# -eq 1 ]; then
    print_usage "must specify a SlackBuild with update option."
  else
    check_update $2
  fi

# check-all-updates
elif [ "$1" == "check-all-updates" ]; then
  check_all_updates

# requires SLACKBUILD
elif [ "$1" == "requires" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify a SlackBuild with requires option."
  else
    list_reqs $2
  fi

# requirement-of SLACKBUILD
elif [ "$1" == "requirement-of" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify a SlackBuild with requirement-of option."
  else
    list_inv_reqs $2
  fi

# search PATTERN
elif [ "$1" == "search" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify PATTERN with search option."
  else
    search $2
  fi

# search-descriptions PATTERN
elif [ "$1" == "search-descriptions" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify PATTERN with search-descriptions option."
  else
    search_descriptions $2
  fi

# info SLACKBUILD
elif [ "$1" == "info" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify a SlackBuild with info option."
  else
    show_info $2
  fi

# list-installed
elif [ "$1" == "list-installed" ]; then
  list_installed

# list-groups
elif [ "$1" == "list-groups" ]; then
  list_groups

# browse-group GROUP
elif [ "$1" == "browse-group" ]; then
  if [ $# -lt 2 ]; then
    print_usage "must specify a SlackBuild with browse-group option."
  else
    browse_group $2
  fi

# --help
elif [ "$1" == "--help" ]; then
  print_usage

# Unrecognized option
else
  print_usage "unrecognized option."
fi
One question I had is, is the master githib branch at the top of the script the correct one for -stable? I've been using Ponce's github for -current, but I tried switching to the master branch and running sbomgr check-all-updates and the result was no different than with Ponce's repository. (Maybe that's not unusual, but on the SlackBuilds.org website at least, a lot of the 14.1 SlackBuilds are on older versions.) If that's not the right one, is there a github meant for -stable?

Last edited by montagdude; 05-01-2016 at 11:11 PM.
 
Old 04-30-2016, 11:52 PM   #15
willysr
Senior Member
 
Registered: Jul 2004
Location: Jogja, Indonesia
Distribution: Slackware-Current
Posts: 4,661

Rep: Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784Reputation: 1784
Ponce's repository is always rebased on top of SBo's master branch.

Stable repository will be released after Slackware 14.2 gets released
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SBo script for medusa USUARIONUEVO Slackware 2 03-13-2016 11:40 AM
Questions for Robby, ponce, or anyone from SBo about SBo submission requirements. ReaperX7 Slackware 4 06-07-2015 11:30 AM
Nvidia-driver.SlackBuild from SBo (or: I am a bad and sloppy SBo maintainer) kingbeowulf Slackware 8 08-31-2012 02:41 AM
Creating a script that will check possible updates Echo Kilo Programming 12 05-14-2008 09:46 AM
yum check-update says no updates when there are updates? MarkEHansen Linux - General 7 12-29-2006 05:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration