Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # dit script zet alle /configs die naar de nfs share gezonden worden in subversion,
- # zodat we altijd een backlog hebben welke wijzigingen er op de machines gedaan zijn.
- # flip hess 2012
- # Global variables:
- PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
- SCRIPT_PATH="${0}"
- ARGS="${#}"
- REPO_DIR="/data/subversion/machines"
- SOURCE_DIR="/data/config/machines"
- LOG="/var/log/svn-update.log"
- # Functions:
- # exit function
- function die()
- {
- echo -e "Error in ${SCRIPT_PATH}:\n${1}"
- exit 1
- }
- # Shows usage function.
- function fShowUsage()
- {
- echo "Usage: ${SCRIPT_PATH}"
- exit 0
- }
- # check for.......
- function fCheck()
- {
- # script depends on:
- [ -x /usr/bin/svn ] || die "This script depends on /usr/bin/svn"
- # user must be root:
- [ "$(whoami)" = root ] || die "User must be root!"
- # check for arguments:
- [ "${ARGS}" = 0 ] || fShowUsage
- # check for directories
- [ -d "${SOURCE_DIR}" ] || die "Failed to find ${SOURCE_DIR} directory!"
- [ -d "${REPO_DIR}" ] || die "Failed to find ${REPO_DIR} directory!"
- # remove pem's from source
- find "${SOURCE_DIR}" -type l -name '*\.pem' -delete || die "Failed to delete pem symlinks from config"
- find "${SOURCE_DIR}" -type f -name '*\.pem' -delete || die "Failed to delete pem symlinks from config"
- return 0
- }
- # The main function.
- function fMain()
- {
- # check if
- for HOST in $( ls "${SOURCE_DIR}" );
- do
- # check if repo is present
- if [ -d "${REPO_DIR}/${HOST}" ] ; then
- # if so run update
- cd "${SOURCE_DIR}/${HOST}" || { echo "Failed to cd to \"${SOURCE_DIR}/${HOST}\""; continue; }
- # force add all files
- svn add --force ./* >> ${LOG} || { echo "Failed to add \"${SOURCE_DIR}/${HOST}\" to repository"; continue; }
- # remove from svn everything that has been locally removed
- svn status | grep "^\!" | sed 's/! *//' | xargs -I% svn rm % || { echo "Failed to remove deleted dirs for \"${SOURCE_DIR}/${HOST}\" from revision"; continue; }
- # commit
- svn commit -m "$(date)" >> ${LOG} || { echo "Failed to commit to \"${REPO_DIR}/${HOST}\""; continue; }
- else
- # if no create repo and import
- svnadmin create "${REPO_DIR}/${HOST}" || { echo "Failed to create svn repository \"${REPO_DIR}/${HOST}\""; continue; }
- # go to dir
- cd "${SOURCE_DIR}/${HOST}" || { echo "Failed to cd to \"${SOURCE_DIR}/${HOST}\""; continue; }
- # checkout new repository
- svn co file://${REPO_DIR}/${HOST} "${SOURCE_DIR}/${HOST}" >> ${LOG} || { echo "Failed to checkout \"file://${REPO_DIR}/${HOST}\""; continue; }
- # add files
- svn add ./* >> ${LOG} || die "Failed to add \"${SOURCE_DIR}/${HOST}\" to repository"; continue; }
- # commit to repository
- svn commit -m "initial commit" >> ${LOG} || { echo "Failed commity changes to repository \"file://${REPO_DIR}/${HOST}\""; continue; }
- fi
- done
- # klaar
- return 0
- }
- # check environment:
- fCheck
- # Start the program:
- fMain "${@}"
- # Exit with previous return code:
- exit "${?}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement