Script "download_latest_linux_libre.sh"
#!/bin/sh

# ----------------------------------
# download_latest_linux_libre.sh
# version 0.9.1.4
# ----------------------------------

# check for parameters

_usage_str="Usage: ${0}"

if [ "${1}" = "--help" ] || [ "${1}" = "--usage" ]; then
  printf "%s\n" "${_usage_str}"
  exit 0
fi

for arg in $@
do
  is_option=`echo "${arg}" | grep -- '\-\-'`
  if [ -z "${is_option}" ]; then
    printf "%s: skipped '%s'\n" "${0}" "${arg}"
  else
    echo "${0}: unknown option '${arg}'"
  fi
done

# check for required binaries
REQD_BINS=""
which wget >/dev/null 2>&1 || type wget >/dev/null 2>&1 || REQD_BINS="wget,${REQD_BINS}"
which lynx >/dev/null 2>&1 || type lynx >/dev/null 2>&1 || REQD_BINS="lynx,${REQD_BINS}"
if [ -n "${REQD_BINS}" ]; then
  echo -e `basename ${0}`: "Required binaries (${REQD_BINS}\010) are not present."
  exit 1
fi

# get kernel's version and the link to tarball

lynx -dump http://www.fsfla.org/svnwiki/selibre/linux-libre/download/releases/ 1>./linux-libre-releases.dump 2>./.lynx_error
if [ $? -ne 0 ]; then
  cat ./.lynx_error
  echo "OOPS: 'lynx -dump' error. Abort."
  rm -f ./linux-libre-releases.dump 2>/dev/null
  rm -f ./.lynx_error 2>/dev/null
  exit 1
fi
LINUX_RELEASES=`cat ./linux-libre-releases.dump`
rm -f ./linux-libre-releases.dump 2>/dev/null
rm -f ./.lynx_error 2>/dev/null

echo "---- Linux-libre, Free as in Freedo ----"

LINUX_RELEASE_PATH=`echo "${LINUX_RELEASES}" | grep "LATEST" | tail -1 | tr ' ' '\n' | tail -1`
LINUX_VERSION=`echo "${LINUX_RELEASE_PATH}" | tr '/' '\n' | tail -1`
[ -z "${LINUX_VERSION}" ] && LINUX_VERSION=`echo "${LINUX_RELEASE_PATH}" | tr '/' '\n' | sed -e '1{$d;}' -e '$!{h;d;}' -e x`

lynx -dump "${LINUX_RELEASE_PATH}" 1>./linux-libre-current.dump 2>./.lynx_error
if [ $? -ne 0 ]; then
  cat ./.lynx_error
  echo "OOPS: 'lynx -dump' error. Abort."
  rm -f ./linux-libre-current.dump 2>/dev/null
  rm -f ./.lynx_error 2>/dev/null
  exit 1
fi
LINUX_CURRENT_FILES=`cat ./linux-libre-current.dump | tr ' ' '\n' | grep "LATEST" | grep "http" | grep -v "="`
rm -f ./linux-libre-current.dump 2>/dev/null
rm -f ./.lynx_error 2>/dev/null

MAIN_LINUX_TARBALL=`echo "${LINUX_CURRENT_FILES}" | grep "linux" | grep "libre\." | grep -v "patch" | \
  grep -v "\.log" | grep -v "\.sign" | grep -v "xdelta" | grep -v "\.xz" | grep -v "\.lz" | tail -1 | tr ' ' '\n' | tail -1`
REAL_KERNEL_VERSION=`basename "${MAIN_LINUX_TARBALL}" | sed -e 's/.tar//' -e 's/.bz2//' -e 's/.gz//' -e 's/.lz//' -e 's/linux-//'`

# print package information

echo "version:" "${REAL_KERNEL_VERSION}"
echo "files to download:"
echo "${LINUX_CURRENT_FILES}" | while read curr_file
do
  printf "\t%s\n" "${curr_file}"
done

LOCAL_DST_DIR="./${REAL_KERNEL_VERSION}"
if [ -d "${LOCAL_DST_DIR}" ]; then
  printf "removing existing directory ('%s')... " "${LOCAL_DST_DIR}"
  rm -rf "${LOCAL_DST_DIR}" 2>/dev/null
  echo "ok"
fi
mkdir -p "${LOCAL_DST_DIR}" && printf "destination directory: '%s'\n" "${LOCAL_DST_DIR}"

if [ -d "${LOCAL_DST_DIR}" ]; then
  cd "${LOCAL_DST_DIR}"
  _counter=1
  echo "${LINUX_CURRENT_FILES}" | while read curr_file; do
    printf "\t%d. " $_counter
    wget -nv "${curr_file}"
    _counter=`expr $_counter + 1`
  done
  chmod +x ./deblob*
  cd ..
else
  printf "ERROR: cannot create destination directory ('%s'). Abort.\n" "${LOCAL_DST_DIR}"
  exit 1
fi

echo "Done!"
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.