You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
if [ $# -eq 0 ]; then
|
|
echo "No arguments provided. Aborting..."
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
echo "usage: ./getsauce.sh [-h] [mode <URL|repoName> [checkout]]
|
|
|
|
Retrieves the source for you.
|
|
|
|
Possible values for the arguments:
|
|
|
|
mode git, github-tar
|
|
URL url of the repo
|
|
repoName name of the repo with user/org included (e.g. username/repo or organization/repo)
|
|
checkout tag, branch or complete hash of a commit
|
|
|
|
Dependencies: curl jq ca-certificates git
|
|
"
|
|
exit 0
|
|
fi
|
|
|
|
if [ $# -lt 3 ]; then
|
|
echo "Arguments \"mode\" and \"URL/repoName\" not provided. Aborting..."
|
|
exit 1
|
|
fi
|
|
|
|
|
|
GET_SRC_MODE=$1
|
|
URL_REPONAME=$2
|
|
[ ! -z ${3+x} ] && CHECKOUT=$3
|
|
[ -z ${REPO_PATH+x} ] && REPO_PATH="project"
|
|
SRC_DIR_PATH="./"
|
|
TMP_DIR="tmp_extract"
|
|
|
|
if [ $GET_SRC_MODE = "github-tar" ]; then
|
|
mkdir "${TMP_DIR}"
|
|
curl --silent --fail -L "https://api.github.com/repos/${URL_REPONAME}/tarball/${CHECKOUT}" -o - | tar xvz -f - -C "$SRC_DIR_PATH" || rm -rf "${TMP_DIR}" && exit 1
|
|
mv "${TMP_DIR}"/* "${REPO_PATH}/"
|
|
elif [ $GET_SRC_MODE = "git" ]; then
|
|
TMP_POSITION="${PWD}"
|
|
git clone "${URL_REPONAME}" "${REPO_PATH}"
|
|
cd "${REPO_PATH}"
|
|
[ ! -z ${CHECKOUT+x} ] && git checkout "${CHECKOUT}"
|
|
cd "${TMP_POSITION}"
|
|
else
|
|
echo "Not valid mode"
|
|
exit 1
|
|
fi
|
|
|