Differences
This shows you the differences between two versions of the page.
linux_wiki:update_repo [2016/11/30 21:56] billdozor created |
linux_wiki:update_repo [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Update Repo ====== | ||
- | |||
- | **General Information** | ||
- | |||
- | Script that updates a target repo. Includes a help screen and error checking for the target repo. | ||
- | |||
- | **Checklist** | ||
- | * [[linux_wiki: | ||
- | |||
- | ---- | ||
- | |||
- | ====== Script Usage ====== | ||
- | |||
- | ./ | ||
- | <code bash> | ||
- | ==== Update Repo Usage ==== | ||
- | |||
- | Descripton: Update a repo's metadata in order for new packages to be made available.. | ||
- | |||
- | --Usage-- | ||
- | -h => Display usage. | ||
- | -r < | ||
- | |||
- | --Other Requirements-- | ||
- | -> Run as either root or regular user with sudo privileges to update repo properly. | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ====== The Script ====== | ||
- | |||
- | <code bash update-repo.sh> | ||
- | #!/bin/bash | ||
- | # Name: update-repo.sh | ||
- | # Description: | ||
- | # Last Modified: 2016-06-21 | ||
- | # Recent Changes: -Minor formatting | ||
- | |||
- | # | ||
- | # Functions; Main starts after | ||
- | # | ||
- | function show_usage | ||
- | { | ||
- | echo -e " | ||
- | echo -e " | ||
- | echo -e " | ||
- | echo -e " | ||
- | echo -e "-r < | ||
- | echo -e " | ||
- | 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 " | ||
- | case " | ||
- | 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 ">> | ||
- | show_usage | ||
- | exit 1 | ||
- | fi | ||
- | |||
- | # Ensure repo directory is actually a directory | ||
- | if [[ ! -d ${repo_dir} ]]; then | ||
- | echo -e ">> | ||
- | echo -e "-> Exiting..." | ||
- | exit 1 | ||
- | fi | ||
- | |||
- | # Ensure the repo metadata already exists | ||
- | if [[ ! -f ${repo_dir}/ | ||
- | echo -e ">> | ||
- | echo -e "-> Exiting..." | ||
- | exit 1 | ||
- | fi | ||
- | |||
- | # | ||
- | # Main starts here | ||
- | # | ||
- | |||
- | # Update the repo | ||
- | echo -e ">> | ||
- | createrepo -v --update ${repo_dir} | ||
- | |||
- | echo -e " | ||
- | echo -e "=- Update Repo Completed. -=" | ||
- | echo -e " | ||
- | </ | ||
- | |||
- | ---- | ||