ezbuild/libraries/repositories

100 lines
3.3 KiB
Plaintext
Raw Normal View History

2012-01-08 12:09:21 +01:00
#!/bin/bash
# Copyright 2010-2012, Asio Software Technologies
# Distributed under the terms of the GNU General Public License v3
2012-01-13 11:29:27 +01:00
#-------------------------------------------------------------------------------
# Creates SSH Wrapper for use with unknown hosts (requires key authentication)
#-------------------------------------------------------------------------------
function makeSshWrapper() {
echo "#!/bin/bash" > ${BINDIR}/ssh_wrapper.sh
echo "exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
\"\$@\"" >> ${BINDIR}/ssh_wrapper.sh
chmod +x ${BINDIR}/ssh_wrapper.sh || return 1
export GIT_SSH="${BINDIR}/ssh_wrapper.sh"
export SVN_SSH="${BINDIR}/ssh_wrapper.sh"
return 0
}
2012-01-09 11:13:46 +01:00
#-------------------------------------------------------------------------------
# Downloads or updates specified GIT repository
# Parameters: %dest_directory% %address% [%branch%]
#-------------------------------------------------------------------------------
2012-01-13 11:29:27 +01:00
function pullGit() {
2012-01-09 11:13:46 +01:00
local DIRECTORY="${1}"
local ADDRESS="${2}"
local BRANCH="${3:-master}"
if [ -d ${DIRECTORY} ]; then
cd ${DIRECTORY}
run "git reset --hard origin/${BRANCH}" || return 1
run "git clean --force" || return 1
run "git pull --no-stat" || return 1
else
run "git clone ${ADDRESS} ${DIRECTORY}" || return 1
if [ ${BRANCH} != "master" ]; then
cd ${DIRECTORY}
run "git checkout ${BRANCH}" || return 1
fi
fi
return 0
}
2012-01-13 11:29:27 +01:00
#-------------------------------------------------------------------------------
# Synchronizes specified repository regardless its protocol
# Parameters: %dest_directory% %protocol% %address% [%branch%]
#-------------------------------------------------------------------------------
function pullRepository() {
for ((i=0; $i<${FETCHTRIES}; i++)); do
case "${2}" in
[Gg][Ii][Tt])
pullGit ${1} ${3} ${4} && return 0
;;
[Rr][Ss][Yy][Nn][Cc])
pullRsync ${1} ${3} && return 0
;;
[Ss][Vv][Nn])
pullSubversion ${1} ${3} && return 0
;;
*)
printWarn "Tried to fetch repository using unsupported protocol!"
return 1
;;
esac
sleep ${FETCHTIMEOUT}
done
return 1
}
2012-01-08 12:09:21 +01:00
#-------------------------------------------------------------------------------
# Downloads or updates specified RSYNC repository
# Parameters: %dest_directory% %address%
#-------------------------------------------------------------------------------
2012-01-13 11:29:27 +01:00
function pullRsync() {
2012-01-08 12:09:21 +01:00
DIRECTORY="${1}"
ADDRESS="${2}"
run "rsync --compress --delete --delete-after --devices --force --links \
--partial --perms --recursive --safe-links --stats --times \
2012-01-12 20:11:59 +01:00
--timeout=${FETCHTIMEOUT} --whole-file --exclude=/.git --exclude=/.hg \
--exclude=/.svn --exclude=CVS --exclude=/distfiles --exclude=/local \
--exclude=/metadata/cache --exclude=/packages ${ADDRESS} \
${DIRECTORY}" || return 1
2012-01-08 12:09:21 +01:00
return 0
}
2012-01-08 18:55:12 +01:00
#-------------------------------------------------------------------------------
# Downloads or updates specified SVN repository
# Parameters: %dest_directory% %address%
#-------------------------------------------------------------------------------
2012-01-13 11:29:27 +01:00
function pullSubversion() {
2012-01-08 18:55:12 +01:00
local DIRECTORY="${1}"
local ADDRESS="${2}"
if [ -d ${DIRECTORY} ]; then
cd ${DIRECTORY}
run "svn cleanup" || return 1
run "svn update" || return 1
else
run "svn checkout ${ADDRESS} ${DIRECTORY}" || return 1
fi
return 0
}