-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_fetch_last_release.sh
More file actions
executable file
·93 lines (87 loc) · 2.01 KB
/
git_fetch_last_release.sh
File metadata and controls
executable file
·93 lines (87 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
_help_for_r() {
printf -- '\t-r\n\n'
printf '\tDefines the GIT repository, MANDATORY.\n\n'
printf '\tUsage\n'
printf '\t=====\n\n'
printf "\t-r 'https://github.com/PintaProject/Pinta.git\n"
}
_help_for_t() {
printf -- '\t-t\n\n'
printf '\tDefines the tag, by default the last one.\n\n'
printf '\tUsage\n'
printf '\t=====\n\n'
printf "\t-t '1.7'\n"
}
_help_for_d() {
printf -- '\t-d\n\n'
printf '\tDefines the git directory, by default git.\n\n'
printf '\tUsage\n'
printf '\t=====\n\n'
printf "\t-d 'my_git_directory'\n"
}
_help() {
_help_for_r
printf '\n'
_help_for_t
printf '\n'
_help_for_d
printf '\n'
}
_checkout(){
cd ${FETCHING_DIRECTORY}
git checkout ${TAG};
if [[ ! ${?} == 0 ]]; then
echo "The checkout of the tag failed." 1>&2;
exit 1;
fi
}
cd
GIT="git"
while getopts :r:t:d:h opt; do
case ${opt} in
r)
GIT_REPOSITORY=$OPTARG;;
t)
TAG=$OPTARG;;
d)
GIT=$OPTARG;;
h)
_help;;
*)
_help;;
esac
done
if [[ ! -z ${GIT_REPOSITORY} ]]; then
GIT_DIRECTORY=$(echo "${GIT_REPOSITORY##*/}")
GIT_DIRECTORY=$(echo "${GIT_DIRECTORY%.git}")
if [[ -z $TAG ]]; then
TAGS=`git ls-remote -t --refs $GIT_REPOSITORY`
TAG=`echo "${TAGS##*/}"`
fi
FETCHING_DIRECTORY="${HOME}/${GIT}/${GIT_DIRECTORY}"
printf 'Git remote repository : %s\n' ${GIT_REPOSITORY}
printf 'The slected tag is : %s\n' ${TAG}
printf 'Git directory : %s\n' ${GIT}
printf 'Fetching directory : %s\n' ${FETCHING_DIRECTORY}
if [[ ! -d ${GIT} ]]; then
printf "Creation of the %s directory.\n"
mkdir ${HOME}/${GIT}
if [[ ! ${?} = 0 ]]; then
echo "The creation of the %GIT directory is not possible" 1>&2
exit 1
fi
fi
cd ${HOME}/${GIT}
if [[ ! -d ${FETCHING_DIRECTORY} ]]; then
git clone ${GIT_REPOSITORY}
if [[ ! ${?} = 0 ]]; then
echo "The cloning of ${GIT_REPOSITORY} failed." 1>&2;
exit 1;
fi
fi
_checkout
else
echo "The git repository is unknown." 1>&2
exit 1
fi