scripts/repo_sync.sh

45 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Script to sync repos
CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BOOTSTRAP=${CURR_DIR}/bootstrap.sh
CONFIG_FILE=${CURR_DIR}/repo_sync.conf
YUM_LOCK=/var/run/yum.pid
if [ ! -e ${BOOTSTRAP} ];then
echo 'EXITING: boostrap.sh must be in the same directory as this script'
exit 1
fi
. $BOOTSTRAP
if [ ! -e ${CONFIG_FILE} ]; then
echo 'EXITING: repo_sync.conf must be in the same directory as this script'
exit 1
fi
. $CONFIG_FILE
debug "Current directory: $PWD"
debug "Changing directory to ${REPO_DIR}"
test ! -d $REPO && err "${REPO_DIR} directory doesn't exists!"
cd $REPO_DIR
debug "Current directory: $PWD"
for repo_id in "${!REPOS[@]}"; do
## Avoid running while yum is already running
if test -e $YUM_LOCK; then
err "Yum appears to be running, if this is not the case\nplease delete $YUM_LOCK"
fi
IFS=":" read -r -a array <<< "${REPOS[$repo_id]}"
name=${array[0]}
path=${array[1]}
echo "Processing repository '${name}'..."
run_cmd "reposync" "-n --repoid=${name}"
_path=${REPO_DIR}/$path
run_cmd "createrepo" "--update ${_path}"
unset name
unset path
done