[ansible][fedora] Update package name
[barometer.git] / ci / utility / check_git_repo.sh
1 #!/bin/bash
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 TARGET_DIR=$1
17 REPO=$2
18
19 if [[ ! $1 ]]
20 then
21         echo "Test if target dir contains the given git repository"
22         echo "Usage: $0 <TARGET_DIR> <REPO_ADDRESS>"
23         exit 254
24 fi
25
26 cd $TARGET_DIR
27 if [[ $? != 0 ]]
28 then
29         echo "Directory is not existing"
30         exit 1
31 fi
32
33 git status &>/dev/null
34 if [[ $? != 0 ]]
35 then
36         echo "Not a git repo"
37         exit 2
38 else
39         REMOTE=`git remote -vv | sed -e "2d" -r -e 's|^\S+\s(\S+)\s\S+$|\1|'`
40         if [[ "$REMOTE" == "$REPO" ]]
41         then
42                 echo "YEP"
43                 exit 0
44         else
45                 echo "Wrong repo"
46                 exit 3
47         fi
48 fi
49
50 exit 255