2020-05-26 13:20:25 +00:00
|
|
|
#!/bin/bash
|
2020-04-01 11:49:29 +00:00
|
|
|
|
2020-05-26 14:59:51 +00:00
|
|
|
set -e -o pipefail
|
|
|
|
|
2020-04-29 16:00:24 +00:00
|
|
|
# In case no value is specified, default values will be used.
|
|
|
|
gitrepo="https://github.com/ceph/ceph-csi"
|
|
|
|
workdir="tip/"
|
|
|
|
ref="master"
|
2020-05-27 07:35:07 +00:00
|
|
|
base="master"
|
2020-04-29 16:00:24 +00:00
|
|
|
|
|
|
|
ARGUMENT_LIST=(
|
|
|
|
"ref"
|
|
|
|
"workdir"
|
|
|
|
"gitrepo"
|
2020-05-27 07:35:07 +00:00
|
|
|
"base"
|
2020-04-29 16:00:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
opts=$(getopt \
|
|
|
|
--longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")help" \
|
|
|
|
--name "$(basename "${0}")" \
|
|
|
|
--options "" \
|
|
|
|
-- "$@"
|
|
|
|
)
|
2020-05-26 13:22:58 +00:00
|
|
|
ret=$?
|
2020-04-29 16:00:24 +00:00
|
|
|
|
2020-05-26 13:22:58 +00:00
|
|
|
if [ ${ret} -ne 0 ]
|
2020-05-07 07:45:49 +00:00
|
|
|
then
|
2020-05-26 14:59:51 +00:00
|
|
|
echo "Try '--help' for more information."
|
|
|
|
exit 1
|
2020-05-07 07:45:49 +00:00
|
|
|
fi
|
|
|
|
|
2020-05-26 14:59:51 +00:00
|
|
|
eval set -- "${opts}"
|
2020-04-29 16:00:24 +00:00
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "${1}" in
|
2020-05-26 14:59:51 +00:00
|
|
|
--help)
|
2020-04-29 16:00:24 +00:00
|
|
|
shift
|
|
|
|
echo "Options:"
|
|
|
|
echo "--help|-h specify the flags"
|
|
|
|
echo "--ref specify the reference of pr"
|
|
|
|
echo "--workdir specify the working directory"
|
2020-05-26 14:59:51 +00:00
|
|
|
echo "--gitrepo specify the git repository"
|
2020-05-27 07:35:07 +00:00
|
|
|
echo "--base specify the base branch to checkout"
|
2020-04-29 16:00:24 +00:00
|
|
|
echo " "
|
|
|
|
echo "Sample Usage:"
|
|
|
|
echo "./prepare.sh --gitrepo=https://github.com/example --workdir=/opt/build --ref=pull/123/head"
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-05-26 14:59:51 +00:00
|
|
|
--gitrepo)
|
2020-04-29 16:00:24 +00:00
|
|
|
shift
|
|
|
|
gitrepo=${1}
|
|
|
|
;;
|
2020-05-26 14:59:51 +00:00
|
|
|
--workdir)
|
2020-04-29 16:00:24 +00:00
|
|
|
shift
|
|
|
|
workdir=${1}
|
|
|
|
;;
|
2020-05-26 14:59:51 +00:00
|
|
|
--ref)
|
2020-04-29 16:00:24 +00:00
|
|
|
shift
|
|
|
|
ref=${1}
|
2020-05-26 14:59:51 +00:00
|
|
|
echo "${ref}"
|
2020-04-29 16:00:24 +00:00
|
|
|
;;
|
2020-05-27 07:35:07 +00:00
|
|
|
--base)
|
|
|
|
shift
|
|
|
|
base=${1}
|
|
|
|
;;
|
2020-04-29 16:00:24 +00:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2020-04-01 11:49:29 +00:00
|
|
|
set -x
|
|
|
|
|
2020-07-31 13:02:11 +00:00
|
|
|
dnf -y install git podman make
|
2020-04-01 11:49:29 +00:00
|
|
|
|
2020-05-27 07:35:07 +00:00
|
|
|
git clone --depth=1 --branch="${base}" "${gitrepo}" "${workdir}"
|
2020-05-26 14:59:51 +00:00
|
|
|
cd "${workdir}"
|
2020-05-27 07:35:07 +00:00
|
|
|
git fetch origin "${ref}:tip/${ref}"
|
2020-04-29 16:00:24 +00:00
|
|
|
git checkout "tip/${ref}"
|