#!/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 => 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 "============================"