LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 09-30-2008, 05:06 PM   #1
El Nigromante
Member
 
Registered: Aug 2008
Distribution: Slackware 12.2, Slackware 13.0
Posts: 40

Rep: Reputation: 17
Searching for SlackBuilds packages


Hello,

I include here a very stupid script to automate the process of checking updates for packages in SlackBuilds.org. I store all my slack-built packages in /usr/local/src/packages.

Just in case it is of any use for you:

Code:
#!/bin/bash
#
# /usr/local/sbin/sbupdate

PKGS_PATH="/usr/local/src/packages"
SLACK_VERSION="12.1"
SB_BASE_URL="http://slackbuilds.org/slackbuilds"
SB_CATEGORIES="academic \
  accessibility \
  audio \
  business \
  desktop \
  development \
  games \
  graphics \
  libraries \
  misc \
  multimedia \
  network \
  office \
  system"

# List local packages to search for:
PKGS=`find ${PKGS_PATH} -name "*" -type f -printf "%f\n" | sort`

# Indexes for reports 
index_UPDATED=0
index_UPTODATE=0
index_UNAVAILABLE=0

echo "Searching for packages at SlackBuilds..."
echo ""

# Search for all listed packages:
for PKG in ${PKGS}; do
  PKG_NAME=`echo ${PKG} | sed -n 's/\(.*\)[-]\(.*\)[-]\(.*\)[-].*/\1/p'`
  PKG_VERSION=`echo ${PKG} | sed -n 's/\(.*\)[-]\(.*\)[-]\(.*\)[-].*/\2/p'`
  # Search for each category in SlackBuilds:
  for SB_CATEGORY in ${SB_CATEGORIES}; do
     PKG_URL="${SB_BASE_URL}/${SLACK_VERSION}/${SB_CATEGORY}/${PKG_NAME}"
     PKG_INFO=`wget -q -O - ${PKG_URL}/${PKG_NAME}.info`
     if [ ! -z "${PKG_INFO}" ]; then
       break
     fi
  done
  # Adds report info depending on package availability and information:
  if [ ! -z "${PKG_INFO}" ]; then
    # Package is available:
    PKG_NEW_VERSION=`echo ${PKG_INFO} | sed -n 's/.*VERSION=["]\([^"]*\)["].*/\1/p'`
    if [ ${PKG_VERSION} != ${PKG_NEW_VERSION} ]; then
      # Package updated:
      REPORT_UPDATED_PKG_NAME[${index_UPDATED}]=${PKG_NAME}
      REPORT_UPDATED_PKG_VERSION[${index_UPDATED}]=${PKG_VERSION}
      REPORT_UPDATED_PKG_NEW_VERSION[${index_UPDATED}]=${PKG_NEW_VERSION}
      REPORT_UPDATED_PKG_URL[${index_UPDATED}]=${PKG_URL}
      index_UPDATED=$(($index_UPDATED + 1))
    else
      # Package is up to date:
      REPORT_UPTODATE_PKG_NAME[${index_UPTODATE}]=${PKG_NAME}
      index_UPTODATE=$(($index_UPTODATE + 1))
    fi
  else
    # Package not available:
    REPORT_UNAVAILABLE_PKG_NAME[${index_UNAVAILABLE}]=${PKG_NAME}
    index_UNAVAILABLE=$(($index_UNAVAILABLE + 1))
  fi
done

# Print search results:

# Unavailable packages:
if [ ${index_UNAVAILABLE} -ne 0 ]; then
  echo "The following packages are not available:"
  echo ""
  for index in `seq 0 $(($index_UNAVAILABLE - 1))`; do
    echo "  ${REPORT_UNAVAILABLE_PKG_NAME[$index]}"
  done
  echo ""
fi

# Up to date packages:
if [ ${index_UPTODATE} -ne 0 ]; then
  echo "The following packages are up to date:"
  echo ""
  for index in `seq 0 $(($index_UPTODATE - 1))`; do
    echo "  ${REPORT_UPTODATE_PKG_NAME[$index]}"
  done
  echo ""
fi

# Updated packages:
if [ ${index_UPDATED} -ne 0 ]; then
  echo "The following packages have new versions available:"
  echo ""
  for index in `seq 0 $(($index_UPDATED - 1))`; do
    echo "  ${REPORT_UPDATED_PKG_NAME[$index]} :"
    echo "     Current version:  ${REPORT_UPDATED_PKG_VERSION[$index]}"
    echo "     New version:      ${REPORT_UPDATED_PKG_NEW_VERSION[$index]}"
    echo "     URL: ${REPORT_UPDATED_PKG_URL[$index]}"
  done
  echo ""
fi
 
Old 09-30-2008, 05:58 PM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
Thank you for sharing that with us.

I don't know if you are aware of this but you may find sbopkg of interest. It is a package developed by Chess Griffin who was the host of the excellent Linux Reality podcasts which are sadly no longer produced. The package seems to offer the functionality of your script, although I have not really played with it yet, and may be useful to you.

Oh - I am no in way affiliated with the package or the author I just thought you may be interested.
 
Old 02-17-2009, 04:28 PM   #3
El Nigromante
Member
 
Registered: Aug 2008
Distribution: Slackware 12.2, Slackware 13.0
Posts: 40

Original Poster
Rep: Reputation: 17
Lightbulb Improved script for searching SlackBuilds updates

Hello, here I post an improved version of my initial script to automatically search for updates of SlackBuilds packages.

The new script is made out of 2 files:

Code:
/usr/local/sbin/sbupdate
/usr/local/etc/sbupdate.conf
The first one is the script, and the second one is configuration file required for the script to work. You do not need to touch any of them.

To search for updates at SlackBuilds.org, you just invoke:

Code:
# sbupdate
It will show a progress indicator while searching for updates, and will print a report when the search has finished.

You can also invoke the script with the "-d" option, which will create in the current working directory a file called sbdownload.sh, which allows you to download the needed files to rebuild packages which have been updated, in a single step:

Code:
# sbupdate -d
Sample created sbdownload.sh:

Code:
#!/bin/bash
#
# sbdownload.sh:
# Downloads slackbuilds files for updated packages

# Files for updated package faac (1.26 --> 1.28):
wget http://slackbuilds.org/slackbuilds/12.2/audio/faac.tar.gz
wget http://downloads.sourceforge.net/faac/faac-1.28.tar.bz2

# Files for updated package faad2 (2.6.1 --> 2.7):
wget http://slackbuilds.org/slackbuilds/12.2/audio/faad2.tar.gz
wget http://downloads.sourceforge.net/faac/faad2-2.7.tar.bz2
A useful invocation may be also:

Code:
# sbupdate -d > report.txt
Which will create both sbdownload.sh and report.txt, the latter containing the report for SlackBuilds packages installed in your system.

-----

/usr/local/sbin/sbupdate:
Code:
#!/bin/bash
#
# /usr/local/sbin/sbupdate
#
# Searches for updates of SlackBuilds packages


# Load configuration
function load_config {
  CONFIG_FILE="/usr/local/etc/sbupdate.conf"
  if [ -f "${CONFIG_FILE}" ]; then
    . "${CONFIG_FILE}"
  else
    echo "Configuration file not found"
    exit 1
  fi
}


# Get list of local packages to search for:
function get_packages {
  PKGS_PATH="/var/log/packages/"
  PKGS=`find ${PKGS_PATH} -name "*_SBo" -type f -printf "%f\n" | sort`
}


# Show progress indicator
function show_progress {
  PROGRESS_BAR_FULL="=================================================>"
  PROGRESS_BAR_EMPT="                                                  "
  PARTIAL="$1"
  TOTAL="$2"
  PROGRESS_PERCENT="$(($PARTIAL * 100 / $TOTAL))"
  FULL_PER="$(((100 - $PROGRESS_PERCENT) / 2))"
  EMPT_PER="$((50 - $FULL_PER))"
  echo -ne "\r ${PROGRESS_PERCENT}% [${PROGRESS_BAR_FULL:$FULL_PER}${PROGRESS_BAR_EMPT:$EMPT_PER}]" 1>&2
}


# Search for packages:
function search_packages {

  # Search variables
  TOTAL=`echo ${PKGS} | wc -w`
  index_TOTAL=0 
  index_UPDATED=0
  index_UPTODATE=0
  index_UNAVAILABLE=0

  # Start search
  echo "Searching for packages at ${SB_BASE_URL}..." 1>&2
  echo "" 1>&2

  # search loop
  for PKG in ${PKGS}; do

    # Print progress indicator
    show_progress $index_TOTAL $TOTAL

    # Get package's name and version
    PKG_NAME=`echo ${PKG} | sed -n 's/\(.*\)[-]\(.*\)[-]\(.*\)[-].*/\1/p'`
    PKG_VERSION=`echo ${PKG} | sed -n 's/\(.*\)[-]\(.*\)[-]\(.*\)[-].*/\2/p'`

    # Search for the package at SlackBuilds
    # (first remove problematic characters from package name)
    PKG_NNAME=`echo ${PKG_NAME} | sed 's/+//g'`  
    PKG_SEARCH_URL="${SB_BASE_URL}/${SB_SEARCH_FOLDER}/?search=${PKG_NNAME}&sv=${SLACK_VERSION}"
    PKG_SEARCH_RESULTS=`${SB_DOWNLOAD_PROGRAM} ${SB_DOWNLOAD_FLAGS} "${PKG_SEARCH_URL}"`

    # Get package's category
    PKG_CATEGORY=`echo ${PKG_SEARCH_RESULTS} | sed -n 's/.*[/]'${SB_REPOSITORY_FOLDER}'[/]'${SLACK_VERSION}'[/]\([^/]*\)[/]'${PKG_NAME}'[/].*/\1/p'`

    # Get package's info file
    PKG_INFO_URL="${SB_BASE_URL}/${SB_SLACKBUILDS_FOLDER}/${SLACK_VERSION}/${PKG_CATEGORY}/${PKG_NAME}/${PKG_NAME}.info"
    PKG_INFO=`${SB_DOWNLOAD_PROGRAM} ${SB_DOWNLOAD_FLAGS} "${PKG_INFO_URL}"`

    # Adds report info depending on package availability and information:
    if [ ! -z "${PKG_INFO}" ]; then
      # Package is available:
      PKG_NEW_VERSION=`echo "${PKG_INFO}" | sed -n 's/.*VERSION=["]\([^"]*\)["].*/\1/p'`
      if [ "${PKG_VERSION}" \< "${PKG_NEW_VERSION}" ]; then
        # Package updated:
        PKG_SLACKBUILD_URL="${SB_BASE_URL}/${SB_SLACKBUILDS_FOLDER}/${SLACK_VERSION}/${PKG_CATEGORY}/${PKG_NAME}.tar.gz"
        PKG_DOWNLOAD_URL=`echo "${PKG_INFO}" | sed -n 's/.*DOWNLOAD=["]\([^"]*\)["].*/\1/p'`
        REPORT_UPDATED_PKG_NAME[${index_UPDATED}]=${PKG_NAME}
        REPORT_UPDATED_PKG_VERSION[${index_UPDATED}]=${PKG_VERSION}
        REPORT_UPDATED_PKG_NEW_VERSION[${index_UPDATED}]=${PKG_NEW_VERSION}
        REPORT_UPDATED_PKG_SLACKBUILD_URL[${index_UPDATED}]=${PKG_SLACKBUILD_URL}
        REPORT_UPDATED_PKG_DOWNLOAD_URL[${index_UPDATED}]=${PKG_DOWNLOAD_URL}
        index_UPDATED=$(($index_UPDATED + 1))
      else
        # Package is up to date:
        REPORT_UPTODATE_PKG_NAME[${index_UPTODATE}]=${PKG_NAME}
        index_UPTODATE=$(($index_UPTODATE + 1))
      fi
    else
      # Package not available:
      REPORT_UNAVAILABLE_PKG_NAME[${index_UNAVAILABLE}]=${PKG_NAME}
      index_UNAVAILABLE=$(($index_UNAVAILABLE + 1))
    fi

    # Update progress index
    index_TOTAL=$(($index_TOTAL + 1))

  # end search loop
  done

  # Update progress indicator
  show_progress $index_TOTAL $TOTAL

  # Update statistics
  TOTAL_UNAVAILABLE=${index_UNAVAILABLE}
  TOTAL_UPTODATE=${index_UPTODATE}
  TOTAL_UPDATED=${index_UPDATED}

  echo "" 1>&2
  echo "" 1>&2
  echo "" 1>&2
}


# Print report for unavailable packages:
function print_report_unavailable {
  if [ "${TOTAL_UNAVAILABLE}" -ne 0 ]; then
    echo "The following packages are not available:"
    echo ""
    for index in `seq 0 $(($TOTAL_UNAVAILABLE - 1))`; do
      echo "  ${REPORT_UNAVAILABLE_PKG_NAME[$index]}"
    done
    echo ""
  fi
}


# Print report for up to date packages:
function print_report_uptodate {
  if [ "${TOTAL_UPTODATE}" -ne 0 ]; then
    echo "The following packages are up to date:"
    echo ""
    for index in `seq 0 $(($TOTAL_UPTODATE - 1))`; do
      echo "  ${REPORT_UPTODATE_PKG_NAME[$index]}"
    done
    echo ""
  fi
}


# Print report for updated packages:
function print_report_updated {
  if [ "${TOTAL_UPDATED}" -ne 0 ]; then
    echo "The following packages have new versions available:"
    echo ""
    for index in `seq 0 $(($TOTAL_UPDATED - 1))`; do
      echo "  ${REPORT_UPDATED_PKG_NAME[$index]} :"
      echo "     Current version:  ${REPORT_UPDATED_PKG_VERSION[$index]}"
      echo "     New version:      ${REPORT_UPDATED_PKG_NEW_VERSION[$index]}"
      echo "     Slackbuild: ${REPORT_UPDATED_PKG_SLACKBUILD_URL[$index]}"
      echo "     Download:   ${REPORT_UPDATED_PKG_DOWNLOAD_URL[$index]}" 
      echo ""
    done
    echo ""
  fi
}


# Print search reports
function print_reports {
  echo "SlackBuilds search results:"
  echo "==========================="
  echo ""
  print_report_unavailable
  print_report_uptodate
  print_report_updated
}


# Write download file
function write_download_file {
  if [ "${WRITE_SB_DOWNLOAD_FILE}" == "yes" ] && [ "${TOTAL_UPDATED}" -ne 0 ]; then
    echo "#!/bin/bash" > "${SB_DOWNLOAD_FILE}"
    chmod a+x "${SB_DOWNLOAD_FILE}"
    echo "#" >> "${SB_DOWNLOAD_FILE}"
    echo "# ${SB_DOWNLOAD_FILE}:" >> "${SB_DOWNLOAD_FILE}"
    echo "# Downloads slackbuilds files for updated packages" >> "${SB_DOWNLOAD_FILE}"
    echo "" >> "${SB_DOWNLOAD_FILE}"
    for index in `seq 0 $(($index_UPDATED - 1))`; do
      echo "# Files for updated package ${REPORT_UPDATED_PKG_NAME[$index]} (${REPORT_UPDATED_PKG_VERSION[$index]} --> ${REPORT_UPDATED_PKG_NEW_VERSION[$index]}):" >> "${SB_DOWNLOAD_FILE}"
      echo "${SB_DOWNLOAD_PROGRAM} ${REPORT_UPDATED_PKG_SLACKBUILD_URL[$index]}" >> "${SB_DOWNLOAD_FILE}" 
      echo "${SB_DOWNLOAD_PROGRAM} ${REPORT_UPDATED_PKG_DOWNLOAD_URL[$index]}" >> "${SB_DOWNLOAD_FILE}"
      echo "" >> "${SB_DOWNLOAD_FILE}"
    done
  fi
}


# Main function
function main {

  # Load configuration
  load_config
 
  # Ensure variable defaults
  WRITE_SB_DOWNLOAD_FILE="no"

  # Check command line parameters
  case "$1" in
    "-d")
      WRITE_SB_DOWNLOAD_FILE="yes"
    ;;
    ?*)
      echo "Usage: $0 [options]"
      echo "Options:"
      echo "   -d      create \"${SB_DOWNLOAD_FILE}\" file in $PWD"
      exit 1
    ;;
  esac

  # Variables for reports
  PKGS=""
  TOTAL=""
  TOTAL_UNAVAILABLE=""
  TOTAL_UPTODATE=""
  TOTAL_UPDATED=""
  REPORT_UNAVAILABLE_PKG_NAME=""
  REPORT_UPTODATE_PKG_NAME=""
  REPORT_UPDATED_PKG_NAME=""
  REPORT_UPDATED_PKG_VERSION=""
  REPORT_UPDATED_PKG_NEW_VERSION=""
  REPORT_UPDATED_PKG_SLACKBUILD_URL=""
  REPORT_UPDATED_PKG_DOWNLOAD_URL=""

  # Get packages
  get_packages

  # Search packages
  search_packages 

  # Print reports
  print_reports

  # If needed write download file
  write_download_file

  exit 0
}


# Execute main function
main $@
/usr/local/etc/sbupdate.conf:
Code:
# 
# Preferences for sbupdate:
#

# Slackware version
SLACK_VERSION="12.2"

# Base URL for SlackBuilds.org
SB_BASE_URL="http://slackbuilds.org"

# Slackbuilds folder
SB_SLACKBUILDS_FOLDER="slackbuilds"

# Repository folder
SB_REPOSITORY_FOLDER="repository"

# Search folder
SB_SEARCH_FOLDER="result"

# Download program
SB_DOWNLOAD_PROGRAM="wget"

# Download program flags used by sbupdate
SB_DOWNLOAD_FLAGS="-q -O -"

# Default download file name
SB_DOWNLOAD_FILE="sbdownload.sh"
Please let me know any problems or comments you may have.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Searching linspire packages DCboi Linspire/Freespire 4 08-11-2007 02:58 PM
Searching For Packages (Up2date) carlosinfl Red Hat 2 05-15-2007 02:41 PM
Use SlackBuilds.org or my own hosting to offer up SlackBuilds? hollywoodb Slackware 6 11-30-2006 09:56 PM
Searching for tool to install debian packages for RPM based distro (Fedora) LiNuXkOlOnIe Linux - Software 2 04-22-2006 08:31 AM
"searching for available packages" lockup mrobins3 Mandriva 3 02-21-2004 09:00 AM


All times are GMT -5. The time now is 05:30 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration