fidoip/scripts/helpers/git.sh

34 lines
957 B
Bash
Raw Permalink Normal View History

2023-03-04 00:49:28 +05:00
#!/usr/bin/env bash
function git_source() {
local source_dir_name=$1
local source_dir="${ROOTDIR}/src/${source_dir_name}"
local remote_repo=$2
if [ ! -d "${source_dir}" ]; then
echo "* Creating source directory '${source_dir_name}'..."
if ! mkdir -p "${source_dir}"; then
echo "! Failed to create '${source_dir_name}'!"
exit 1
fi
fi
if ! cd "${source_dir}"; then
echo "! Failed to change current directory to '${source_dir}'!"
exit 1
fi
if [ ! -d ".git" ]; then
echo "* Getting sources in '${source_dir_name}'..."
if ! git clone "${remote_repo}" .; then
echo "! Failed to get sources in '${source_dir_name}'!"
exit 1
fi
else
echo "* Updating sources in '${source_dir_name}'..."
if ! git pull; then
echo "! Failed to update sources in '${source_dir_name}'!"
fi
fi
}