linux_wiki:update_repo

Update Repo

General Information

Script that updates a target repo. Includes a help screen and error checking for the target repo.

Checklist


Script Usage

./update-repo.sh -h

==== Update Repo Usage ====
 
Description: Update a repo's metadata in order for new packages to be made available.
 
--Usage--
-h                    => Display usage.
-r <repo-parent-dir>  => Full path to repo parent directory.
 
--Other Requirements--
-> Run as either root or regular user with sudo privileges to update repo properly.

The Script

update-repo.sh
#!/bin/bash
# Name: update-repo.sh
# Description: Update a repo's metadata in order for new packages to be made available.
# Last Modified: 2016-06-21
# Recent Changes: -Minor formatting
 
#=====================================
# Functions; Main starts after
#=====================================
function show_usage
{
  echo -e "\n==== Update Repo Usage ===="
  echo -e "\nDescripton: Update a repo's metadata in order for new packages to be made available.."
  echo -e "\n--Usage--"
  echo -e "-h                    => Display usage."
  echo -e "-r <repo-parent-dir>  => Full path to repo parent directory."
  echo -e "\n--Other Requirements--"
  echo -e "-> Run as either root or regular user with sudo privileges to update repo properly."
  echo -e
}
 
#=======================
# Get Script Arguments
#=======================
# Reset POSIX variable in case it has been used previously in this shell
OPTIND=1
 
while getopts "hr:" opt; do
  case "${opt}" in
    h) # -h (help) argument
      show_usage
      exit 0
    ;;
    r) # -r repo-directory
      repo_dir=${OPTARG}
    ;;
    *) # invalid argument
      show_usage
      exit 0
    ;;
  esac
done
 
#===================
# Pre-checks: Make sure we have good options set
#===================
 
# Ensure repo directory is passed as an argument
if [[ -z ${repo_dir} ]]; then
  echo -e ">> ERROR! A repo directory must be provided as an argument."
  show_usage
  exit 1
fi
 
# Ensure repo directory is actually a directory
if [[ ! -d ${repo_dir} ]]; then
  echo -e ">> ERROR! Repo directory is not a directory! (${repo_dir})"
  echo -e "-> Exiting..."
  exit 1
fi
 
# Ensure the repo metadata already exists
if [[ ! -f ${repo_dir}/repodata/repomd.xml ]]; then
  echo -e ">> ERROR! Repo xml file doest not exist! (${repo_dir}/repodata/repomd.xml)"
  echo -e "-> Exiting..."
  exit 1
fi
 
#===================
# Main starts here
#===================
 
# Update the repo
echo -e ">> Updating the repo at: ${repo_dir}"
createrepo -v --update ${repo_dir}
 
echo -e "\n============================"
echo -e "=- Update Repo Completed. -="
echo -e "============================"

  • linux_wiki/update_repo.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)